diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-cgroup-util.c | 15 | ||||
-rw-r--r-- | src/test/test-string-util.c | 29 |
2 files changed, 37 insertions, 7 deletions
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index cb5a981dc3..4e7805b40a 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -328,12 +328,13 @@ TEST(shift_path) { TEST(mask_supported, .sd_booted = true) { CGroupMask m; - CGroupController c; assert_se(cg_mask_supported(&m) >= 0); - for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) - printf("'%s' is supported: %s\n", cgroup_controller_to_string(c), yes_no(m & CGROUP_CONTROLLER_TO_MASK(c))); + for (CGroupController c = 0; c < _CGROUP_CONTROLLER_MAX; c++) + printf("'%s' is supported: %s\n", + cgroup_controller_to_string(c), + yes_no(m & CGROUP_CONTROLLER_TO_MASK(c))); } TEST(is_cgroup_fs, .sd_booted = true) { @@ -392,7 +393,7 @@ TEST(cg_tests) { TEST(cg_get_keyed_attribute) { _cleanup_free_ char *val = NULL; char *vals3[3] = {}, *vals3a[3] = {}; - int i, r; + int r; r = cg_get_keyed_attribute("cpu", "/init.scope", "no_such_file", STRV_MAKE("no_such_attr"), &val); if (IN_SET(r, -ENOMEDIUM, -ENOENT) || ERRNO_IS_PRIVILEGE(r)) { @@ -430,7 +431,7 @@ TEST(cg_get_keyed_attribute) { assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec", "user_usec", "system_usec"), vals3) == 0); - for (i = 0; i < 3; i++) + for (size_t i = 0; i < 3; i++) free(vals3[i]); assert_se(cg_get_keyed_attribute_graceful("cpu", "/init.scope", "cpu.stat", @@ -440,7 +441,7 @@ TEST(cg_get_keyed_attribute) { assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", STRV_MAKE("system_usec", "user_usec", "usage_usec"), vals3a) == 0); - for (i = 0; i < 3; i++) + for (size_t i = 0; i < 3; i++) free(vals3a[i]); assert_se(cg_get_keyed_attribute_graceful("cpu", "/init.scope", "cpu.stat", @@ -448,7 +449,7 @@ TEST(cg_get_keyed_attribute) { log_info("cpu /init.scope cpu.stat [system_usec user_usec usage_usec] → \"%s\", \"%s\", \"%s\"", vals3a[0], vals3a[1], vals3a[2]); - for (i = 0; i < 3; i++) { + for (size_t i = 0; i < 3; i++) { free(vals3[i]); free(vals3a[i]); } diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index 92f1083a4c..3b003e885f 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -88,6 +88,35 @@ TEST(free_and_strndup) { } } +TEST(strdup_to_full) { + _cleanup_free_ char *dst; + + assert_se(strdup_to_full(NULL, NULL) == 0); + assert_se(strdup_to_full(&dst, NULL) == 0); + + assert_se(strdup_to_full(NULL, "") == 1); + assert_se(strdup_to_full(&dst, "") == 1); + assert_se(streq_ptr(dst, "")); + dst = mfree(dst); + + assert_se(strdup_to_full(NULL, "x") == 1); + assert_se(strdup_to_full(&dst, "x") == 1); + assert_se(streq_ptr(dst, "x")); +} + +TEST(strdup_to) { + _cleanup_free_ char *dst; + + assert_se(strdup_to(&dst, NULL) == 0); + + assert_se(strdup_to(&dst, "") == 0); + assert_se(streq_ptr(dst, "")); + dst = mfree(dst); + + assert_se(strdup_to(&dst, "x") == 0); + assert_se(streq_ptr(dst, "x")); +} + TEST(ascii_strcasecmp_n) { assert_se(ascii_strcasecmp_n("", "", 0) == 0); assert_se(ascii_strcasecmp_n("", "", 1) == 0); |