Merge pull request #8199 from keszybz/small-things

Sundry small cleanups
This commit is contained in:
Lennart Poettering
2018-02-19 16:55:10 +01:00
committed by GitHub
19 changed files with 258 additions and 220 deletions
+40
View File
@@ -226,6 +226,45 @@ static void test_config_parse_iec_uint64(void) {
assert_se(config_parse_iec_uint64(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4.5M", &offset, NULL) == 0);
}
static void test_config_parse_join_controllers(void) {
int r;
_cleanup_(strv_free_freep) char ***c = NULL;
char ***c2;
/* Test normal operation */
r = config_parse_join_controllers(NULL, "example.conf", 11, "Section", 10, "JoinControllers", 0, "cpu,cpuacct net_cls,netprio", &c, NULL);
assert_se(r == 0);
assert_se(c);
assert_se(strv_length(c[0]) == 2);
assert_se(strv_equal(c[0], STRV_MAKE("cpu", "cpuacct")));
assert_se(strv_length(c[1]) == 2);
assert_se(strv_equal(c[1], STRV_MAKE("net_cls", "netprio")));
assert_se(c[2] == NULL);
/* Test special case of no mounted controllers */
r = config_parse_join_controllers(NULL, "example.conf", 12, "Section", 10, "JoinControllers", 0, "", &c, NULL);
assert_se(r == 0);
assert_se(c);
assert_se(strv_equal(c[0], STRV_MAKE_EMPTY));
assert_se(c[1] == NULL);
/* Test merging of overlapping lists */
r = config_parse_join_controllers(NULL, "example.conf", 13, "Section", 10, "JoinControllers", 0, "a,b b,c", &c, NULL);
assert_se(r == 0);
assert_se(c);
assert_se(strv_length(c[0]) == 3);
assert_se(strv_contains(c[0], "a"));
assert_se(strv_contains(c[0], "b"));
assert_se(strv_contains(c[0], "c"));
assert_se(c[1] == NULL);
/* Test ignoring of bad lines */
c2 = c;
r = config_parse_join_controllers(NULL, "example.conf", 14, "Section", 10, "JoinControllers", 0, "a,\"b ", &c, NULL);
assert_se(r < 0);
assert_se(c == c2);
}
#define x10(x) x x x x x x x x x x
#define x100(x) x10(x10(x))
#define x1000(x) x10(x100(x))
@@ -365,6 +404,7 @@ int main(int argc, char **argv) {
test_config_parse_sec();
test_config_parse_nsec();
test_config_parse_iec_uint64();
test_config_parse_join_controllers();
for (i = 0; i < ELEMENTSOF(config_file); i++)
test_config_parse(i, config_file[i]);
+1 -1
View File
@@ -100,7 +100,7 @@ static void test_get_process_comm(pid_t pid) {
if (!detect_container())
assert_se(get_ctty_devnr(pid, &h) == -ENXIO || pid != 1);
getenv_for_pid(pid, "PATH", &i);
(void) getenv_for_pid(pid, "PATH", &i);
log_info("PID"PID_FMT" $PATH: '%s'", pid, strna(i));
}
+10
View File
@@ -106,6 +106,15 @@ static void test_utf16_to_utf8(void) {
free(a);
}
static void test_utf8_n_codepoints(void) {
assert_se(utf8_n_codepoints("abc") == 3);
assert_se(utf8_n_codepoints("zażółcić gęślą jaźń") == 19);
assert_se(utf8_n_codepoints("串") == 1);
assert_se(utf8_n_codepoints("") == 0);
assert_se(utf8_n_codepoints("…👊🔪💐…") == 5);
assert_se(utf8_n_codepoints("\xF1") == (size_t) -1);
}
int main(int argc, char *argv[]) {
test_utf8_is_valid();
test_utf8_is_printable();
@@ -114,6 +123,7 @@ int main(int argc, char *argv[]) {
test_utf8_escaping();
test_utf8_escaping_printable();
test_utf16_to_utf8();
test_utf8_n_codepoints();
return 0;
}