Skip to content

Commit

Permalink
ASSERT_NULL/ASSERT_NOT_NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
ikruglov authored and mrc0mmand committed Apr 10, 2024
1 parent 0ab87eb commit 5152b84
Show file tree
Hide file tree
Showing 32 changed files with 154 additions and 154 deletions.
4 changes: 2 additions & 2 deletions src/test/test-cgroup-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ TEST(cg_get_keyed_attribute) {
}

assert_se(r == -ENOENT);
assert_se(val == NULL);
ASSERT_NULL(val);

if (access("/sys/fs/cgroup/init.scope/cpu.stat", R_OK) < 0) {
log_info_errno(errno, "Skipping most of %s, /init.scope/cpu.stat not accessible: %m", __func__);
Expand All @@ -411,7 +411,7 @@ TEST(cg_get_keyed_attribute) {

assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", STRV_MAKE("no_such_attr"), &val) == -ENXIO);
assert_se(cg_get_keyed_attribute_graceful("cpu", "/init.scope", "cpu.stat", STRV_MAKE("no_such_attr"), &val) == 0);
assert_se(val == NULL);
ASSERT_NULL(val);

assert_se(cg_get_keyed_attribute("cpu", "/init.scope", "cpu.stat", STRV_MAKE("usage_usec"), &val) == 0);
val = mfree(val);
Expand Down
4 changes: 2 additions & 2 deletions src/test/test-cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ TEST(cg_split_spec) {
assert_se(cg_split_spec("fo/obar:/", &c, &p) < 0);

assert_se(cg_split_spec("/", &c, &p) >= 0);
assert_se(c == NULL);
ASSERT_NULL(c);
assert_se(streq(p, "/"));
p = mfree(p);

assert_se(cg_split_spec("foo", &c, &p) >= 0);
assert_se(streq(c, "foo"));
assert_se(p == NULL);
ASSERT_NULL(p);
c = mfree(c);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/test-conf-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ static void test_config_parse_one(unsigned i, const char *s) {

case 15 ... 16:
assert_se(r == -ENOBUFS);
assert_se(setting1 == NULL);
ASSERT_NULL(setting1);
break;

case 17:
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-core-unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void test_unit_escape_setting_one(
assert_se(t = unit_escape_setting(s, 0, &a));
assert_se(a_esc = cescape(t));
log_debug("%s: [%s] → [%s]", __func__, s_esc, a_esc);
assert_se(a == NULL);
ASSERT_NULL(a);
assert_se(t == s);

assert_se(t = unit_escape_setting(s, UNIT_ESCAPE_EXEC_SYNTAX_ENV, &b));
Expand Down
12 changes: 6 additions & 6 deletions src/test/test-creds.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ TEST(read_credential_strings) {
assert_se(saved = strdup(e));

assert_se(read_credential_strings_many("foo", &x, "bar", &y) == 0);
assert_se(x == NULL);
assert_se(y == NULL);
ASSERT_NULL(x);
ASSERT_NULL(y);

assert_se(mkdtemp_malloc(NULL, &tmp) >= 0);

assert_se(setenv("CREDENTIALS_DIRECTORY", tmp, /* override= */ true) >= 0);

assert_se(read_credential_strings_many("foo", &x, "bar", &y) == 0);
assert_se(x == NULL);
assert_se(y == NULL);
ASSERT_NULL(x);
ASSERT_NULL(y);

assert_se(p = path_join(tmp, "bar"));
assert_se(write_string_file(p, "piff", WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_AVOID_NEWLINE) >= 0);

assert_se(read_credential_strings_many("foo", &x, "bar", &y) == 0);
assert_se(x == NULL);
ASSERT_NULL(x);
assert_se(streq(y, "piff"));

assert_se(write_string_file(p, "paff", WRITE_STRING_FILE_TRUNCATE|WRITE_STRING_FILE_AVOID_NEWLINE) >= 0);

assert_se(read_credential_strings_many("foo", &x, "bar", &y) == 0);
assert_se(x == NULL);
ASSERT_NULL(x);
assert_se(streq(y, "paff"));

p = mfree(p);
Expand Down
12 changes: 6 additions & 6 deletions src/test/test-env-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TEST(load_env_file_1) {
assert_se(streq(data[3], "g=g "));
assert_se(streq(data[4], "h=ąęół śćńźżμ"));
assert_se(streq(data[5], "i=i"));
assert_se(data[6] == NULL);
ASSERT_NULL(data[6]);
}

TEST(load_env_file_2) {
Expand All @@ -81,7 +81,7 @@ TEST(load_env_file_2) {
_cleanup_strv_free_ char **data = NULL;
assert_se(load_env_file(NULL, name, &data) == 0);
assert_se(streq(data[0], "a=a"));
assert_se(data[1] == NULL);
ASSERT_NULL(data[1]);
}

TEST(load_env_file_3) {
Expand All @@ -92,7 +92,7 @@ TEST(load_env_file_3) {
assert_se(load_env_file(NULL, name, &data) == 0);
assert_se(streq(data[0], "normal1=line111"));
assert_se(streq(data[1], "normal2=line222"));
assert_se(data[2] == NULL);
ASSERT_NULL(data[2]);
}

TEST(load_env_file_4) {
Expand All @@ -104,7 +104,7 @@ TEST(load_env_file_4) {
assert_se(streq(data[0], "HWMON_MODULES=coretemp f71882fg"));
assert_se(streq(data[1], "MODULE_0=coretemp"));
assert_se(streq(data[2], "MODULE_1=f71882fg"));
assert_se(data[3] == NULL);
ASSERT_NULL(data[3]);
}

TEST(load_env_file_5) {
Expand All @@ -115,7 +115,7 @@ TEST(load_env_file_5) {
assert_se(load_env_file(NULL, name, &data) == 0);
assert_se(streq(data[0], "a="));
assert_se(streq(data[1], "b="));
assert_se(data[2] == NULL);
ASSERT_NULL(data[2]);
}

TEST(load_env_file_6) {
Expand All @@ -128,7 +128,7 @@ TEST(load_env_file_6) {
assert_se(streq(data[1], "b=$'"));
assert_se(streq(data[2], "c= \\n\\t\\$\\`\\\\\n"));
assert_se(streq(data[3], "d= \\n\\t$`\\\n"));
assert_se(data[4] == NULL);
ASSERT_NULL(data[4]);
}

TEST(load_env_file_invalid_utf8) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/test-env-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ TEST(env_clean) {
assert_se(streq(e[5], "another=final one"));
assert_se(streq(e[6], "CRLF=\r\n"));
assert_se(streq(e[7], "LESS_TERMCAP_mb=\x1b[01;31m"));
assert_se(e[8] == NULL);
ASSERT_NULL(e[8]);
}

TEST(env_name_is_valid) {
Expand Down Expand Up @@ -576,7 +576,7 @@ TEST(getenv_path_list) {
assert_se(streq(path_list[2], "/hello/world"));
assert_se(streq(path_list[3], "/path with spaces"));
assert_se(streq(path_list[4], "/final"));
assert_se(path_list[5] == NULL);
ASSERT_NULL(path_list[5]);

assert_se(unsetenv("TEST_GETENV_PATH_LIST") >= 0);
}
Expand Down
24 changes: 12 additions & 12 deletions src/test/test-extract-word.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ TEST(extract_first_word) {
assert_se(extract_first_word(&p, &t, ":", EXTRACT_DONT_COALESCE_SEPARATORS) == 1);
assert_se(streq(t, ""));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

assert_se(extract_first_word(&p, &t, ":", EXTRACT_DONT_COALESCE_SEPARATORS) == 0);
assert_se(!t);
Expand All @@ -335,25 +335,25 @@ TEST(extract_first_word) {
assert_se(extract_first_word(&p, &t, NULL, 0) > 0);
assert_se(streq(t, "fooxbar"));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

p = "foo\\xbar";
assert_se(extract_first_word(&p, &t, NULL, EXTRACT_RETAIN_ESCAPE) > 0);
assert_se(streq(t, "foo\\xbar"));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

p = "\\:";
assert_se(extract_first_word(&p, &t, ":", EXTRACT_UNESCAPE_SEPARATORS) == 1);
assert_se(streq(t, ":"));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

p = "a\\:b";
assert_se(extract_first_word(&p, &t, ":", EXTRACT_UNESCAPE_SEPARATORS) == 1);
assert_se(streq(t, "a:b"));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

p = "a\\ b:c";
assert_se(extract_first_word(&p, &t, WHITESPACE ":", EXTRACT_UNESCAPE_SEPARATORS) == 1);
Expand All @@ -362,7 +362,7 @@ TEST(extract_first_word) {
assert_se(extract_first_word(&p, &t, WHITESPACE ":", EXTRACT_UNESCAPE_SEPARATORS) == 1);
assert_se(streq(t, "c"));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

p = "a\\ b:c\\x";
assert_se(extract_first_word(&p, &t, ":", EXTRACT_UNESCAPE_SEPARATORS) == -EINVAL);
Expand All @@ -374,19 +374,19 @@ TEST(extract_first_word) {
assert_se(extract_first_word(&p, &t, ":", EXTRACT_UNESCAPE_SEPARATORS) == 1);
assert_se(streq(t, "c\\x"));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

p = "\\:";
assert_se(extract_first_word(&p, &t, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS) == 1);
assert_se(streq(t, ":"));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

p = "a\\:b";
assert_se(extract_first_word(&p, &t, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS) == 1);
assert_se(streq(t, "a:b"));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

p = "a\\ b:c";
assert_se(extract_first_word(&p, &t, WHITESPACE ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS) == 1);
Expand All @@ -395,7 +395,7 @@ TEST(extract_first_word) {
assert_se(extract_first_word(&p, &t, WHITESPACE ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS) == 1);
assert_se(streq(t, "c"));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

p = "a\\ b:c\\x";
assert_se(extract_first_word(&p, &t, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS) == -EINVAL);
Expand All @@ -407,7 +407,7 @@ TEST(extract_first_word) {
assert_se(extract_first_word(&p, &t, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS) == 1);
assert_se(streq(t, "c\\x"));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

p = "\\:";
assert_se(extract_first_word(&p, &t, ":", EXTRACT_CUNESCAPE) == -EINVAL);
Expand All @@ -426,7 +426,7 @@ TEST(extract_first_word) {
assert_se(extract_first_word(&p, &t, WHITESPACE ":", EXTRACT_CUNESCAPE) == 1);
assert_se(streq(t, "c"));
free(t);
assert_se(p == NULL);
ASSERT_NULL(p);

p = original = "foobar=\"waldo\"maldo, baldo";
assert_se(extract_first_word(&p, &t, "=\", ", 0) > 0);
Expand Down
10 changes: 5 additions & 5 deletions src/test/test-fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ TEST(parse_env_file) {
assert_se(streq_ptr(a[10], "eleven=value"));
assert_se(streq_ptr(a[11], "twelve=\\value"));
assert_se(streq_ptr(a[12], "thirteen=\\value"));
assert_se(a[13] == NULL);
ASSERT_NULL(a[13]);

strv_env_clean(a);

Expand Down Expand Up @@ -134,7 +134,7 @@ TEST(parse_env_file) {
assert_se(streq(seven, "sevenval#nocomment"));
assert_se(streq(eight, "eightval #nocomment"));
assert_se(streq(nine, "nineval"));
assert_se(ten == NULL);
ASSERT_NULL(ten);
assert_se(streq(eleven, "value"));
assert_se(streq(twelve, "\\value"));
assert_se(streq(thirteen, "\\value"));
Expand Down Expand Up @@ -201,7 +201,7 @@ TEST(parse_multiline_env_file) {
assert_se(streq_ptr(a[0], "one=BAR VAR\tGAR"));
assert_se(streq_ptr(a[1], "two=bar var\tgar"));
assert_se(streq_ptr(a[2], "tri=bar var \tgar "));
assert_se(a[3] == NULL);
ASSERT_NULL(a[3]);

{
_cleanup_close_ int fd = mkostemp_safe(p);
Expand Down Expand Up @@ -256,7 +256,7 @@ TEST(merge_env_file) {
assert_se(streq(a[7], "zzz=replacement"));
assert_se(streq(a[8], "zzzz="));
assert_se(streq(a[9], "zzzzz="));
assert_se(a[10] == NULL);
ASSERT_NULL(a[10]);

r = merge_env_file(&a, NULL, t);
assert_se(r >= 0);
Expand All @@ -275,7 +275,7 @@ TEST(merge_env_file) {
assert_se(streq(a[7], "zzz=replacement"));
assert_se(streq(a[8], "zzzz="));
assert_se(streq(a[9], "zzzzz="));
assert_se(a[10] == NULL);
ASSERT_NULL(a[10]);
}

TEST(merge_env_file_invalid) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/test-glob-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST(glob_first) {
assert_se(r == 0);
r = glob_first("/tmp/test-glob_first*", &first);
assert_se(r == 0);
assert_se(first == NULL);
ASSERT_NULL(first);
}

TEST(glob_exists) {
Expand Down Expand Up @@ -110,7 +110,7 @@ TEST(safe_glob) {
assert_se(r == 0);
assert_se(g.gl_pathc == 1);
assert_se(streq(g.gl_pathv[0], fname));
assert_se(g.gl_pathv[1] == NULL);
ASSERT_NULL(g.gl_pathv[1]);

(void) rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL);
}
Expand Down
Loading

0 comments on commit 5152b84

Please sign in to comment.