aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/blogc/check_rusage.c23
-rw-r--r--tests/blogc/check_sysinfo.c64
2 files changed, 87 insertions, 0 deletions
diff --git a/tests/blogc/check_rusage.c b/tests/blogc/check_rusage.c
index e828fb2..ff64297 100644
--- a/tests/blogc/check_rusage.c
+++ b/tests/blogc/check_rusage.c
@@ -65,6 +65,10 @@ test_rusage_format_cpu_time(void **state)
assert_string_equal(f, "1.234ms");
free(f);
+ f = blogc_rusage_format_cpu_time(3000);
+ assert_string_equal(f, "3ms");
+ free(f);
+
f = blogc_rusage_format_cpu_time(12345678);
assert_string_equal(f, "12.346s");
free(f);
@@ -92,6 +96,24 @@ test_rusage_format_memory(void **state)
}
+static void
+test_rusage_inject(void **state)
+{
+ bc_trie_t *t = bc_trie_new(free);
+
+ will_return(__wrap_getrusage, -1);
+ blogc_rusage_inject(t);
+ assert_int_equal(bc_trie_size(t), 0);
+
+ will_return(__wrap_getrusage, 0);
+ blogc_rusage_inject(t);
+ assert_int_equal(bc_trie_size(t), 2);
+ assert_string_equal(bc_trie_lookup(t, "BLOGC_RUSAGE_CPU_TIME"), "4.000s");
+ assert_string_equal(bc_trie_lookup(t, "BLOGC_RUSAGE_MEMORY"), "10.010MB");
+ bc_trie_free(t);
+}
+
+
int
main(void)
{
@@ -99,6 +121,7 @@ main(void)
unit_test(test_rusage_get),
unit_test(test_rusage_format_cpu_time),
unit_test(test_rusage_format_memory),
+ unit_test(test_rusage_inject),
};
return run_tests(tests);
}
diff --git a/tests/blogc/check_sysinfo.c b/tests/blogc/check_sysinfo.c
index af19fb1..d1034fc 100644
--- a/tests/blogc/check_sysinfo.c
+++ b/tests/blogc/check_sysinfo.c
@@ -121,6 +121,25 @@ test_sysinfo_get_hostname(void **state)
static void
+test_sysinfo_inject_hostname(void **state)
+{
+ bc_trie_t *t = bc_trie_new(free);
+
+ will_return(__wrap_gethostname, NULL);
+ will_return(__wrap_gethostname, -1);
+ blogc_sysinfo_inject_hostname(t);
+ assert_int_equal(bc_trie_size(t), 0);
+
+ will_return(__wrap_gethostname, "bola");
+ will_return(__wrap_gethostname, 0);
+ blogc_sysinfo_inject_hostname(t);
+ assert_int_equal(bc_trie_size(t), 1);
+ assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_HOSTNAME"), "bola");
+ bc_trie_free(t);
+}
+
+
+static void
test_sysinfo_get_username(void **state)
{
will_return(__wrap_getpwuid, NULL);
@@ -136,6 +155,23 @@ test_sysinfo_get_username(void **state)
static void
+test_sysinfo_inject_username(void **state)
+{
+ bc_trie_t *t = bc_trie_new(free);
+
+ will_return(__wrap_getpwuid, NULL);
+ blogc_sysinfo_inject_username(t);
+ assert_int_equal(bc_trie_size(t), 0);
+
+ will_return(__wrap_getpwuid, "bola");
+ blogc_sysinfo_inject_username(t);
+ assert_int_equal(bc_trie_size(t), 1);
+ assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_USERNAME"), "bola");
+ bc_trie_free(t);
+}
+
+
+static void
test_sysinfo_get_datetime(void **state)
{
will_return(__wrap_time, -1);
@@ -155,6 +191,27 @@ test_sysinfo_get_datetime(void **state)
static void
+test_sysinfo_inject_datetime(void **state)
+{
+ bc_trie_t *t = bc_trie_new(free);
+
+ will_return(__wrap_time, -1);
+ blogc_sysinfo_inject_datetime(t);
+ assert_int_equal(bc_trie_size(t), 0);
+
+ will_return(__wrap_time, 2);
+ blogc_sysinfo_inject_datetime(t);
+ assert_int_equal(bc_trie_size(t), 0);
+
+ will_return(__wrap_time, 1);
+ blogc_sysinfo_inject_datetime(t);
+ assert_int_equal(bc_trie_size(t), 1);
+ assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_DATETIME"), "1906-06-04 03:02:01");
+ bc_trie_free(t);
+}
+
+
+static void
test_sysinfo_get_inside_docker(void **state)
{
// the "positive" case was already tested in check_funcvars. this is done
@@ -164,6 +221,10 @@ test_sysinfo_get_inside_docker(void **state)
}
+// the blogc_sysinfo_inject_inside_docker() function was already indirectly
+// tested in check_funcvars.c
+
+
int
main(void)
{
@@ -171,14 +232,17 @@ main(void)
#ifdef HAVE_SYSINFO_HOSTNAME
unit_test(test_sysinfo_get_hostname),
+ unit_test(test_sysinfo_inject_hostname),
#endif
#ifdef HAVE_SYSINFO_USERNAME
unit_test(test_sysinfo_get_username),
+ unit_test(test_sysinfo_inject_username),
#endif
#ifdef HAVE_SYSINFO_DATETIME
unit_test(test_sysinfo_get_datetime),
+ unit_test(test_sysinfo_inject_datetime),
#endif
unit_test(test_sysinfo_get_inside_docker),