summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2024-05-17 14:01:01 (GMT)
committerThomas Haller <thaller@redhat.com>2024-05-17 14:01:01 (GMT)
commit401c2488624f2eb184e2b6f2e55d07c840854882 (patch)
tree358772a02021e645209e2b4abc6e61af6cddcb50
parent529c2ab89c89d3a7afb360043c7df9f8a2dde8a2 (diff)
downloadlibnl-401c2488624f2eb184e2b6f2e55d07c840854882.zip
libnl-401c2488624f2eb184e2b6f2e55d07c840854882.tar.gz
libnl-401c2488624f2eb184e2b6f2e55d07c840854882.tar.bz2
tests: fix _nltst_object_to_string() to print one line only
-rw-r--r--tests/nl-test-util.c26
-rw-r--r--tests/nl-test-util.h2
2 files changed, 25 insertions, 3 deletions
diff --git a/tests/nl-test-util.c b/tests/nl-test-util.c
index 52188a0..4bab90b 100644
--- a/tests/nl-test-util.c
+++ b/tests/nl-test-util.c
@@ -217,11 +217,13 @@ void _nltst_object_identical(const void *a, const void *b)
/*****************************************************************************/
-char *_nltst_object_to_string(struct nl_object *obj)
+char *_nltst_object_to_string(const struct nl_object *obj)
{
size_t L = 1024;
size_t l;
char *s;
+ struct nl_dump_params dp;
+ char canary;
if (!obj)
return strdup("(null)");
@@ -229,11 +231,31 @@ char *_nltst_object_to_string(struct nl_object *obj)
s = malloc(L);
ck_assert_ptr_nonnull(s);
- nl_object_dump_buf(obj, s, L);
+ canary = _nltst_rand_u32();
+ s[L - 1u] = canary;
+
+ dp = (struct nl_dump_params){
+ .dp_type = NL_DUMP_LINE,
+ .dp_buf = s,
+ .dp_buflen = L - 1u,
+ };
+
+ nl_object_dump((struct nl_object *)obj, &dp);
+
l = strlen(s);
+ ck_assert_int_ge(l, 2);
ck_assert_int_lt(l, L);
+ ck_assert(canary == s[L - 1u]);
s = realloc(s, l + 1);
ck_assert_ptr_nonnull(s);
+
+ ck_assert_msg(s[l - 1u] == '\n',
+ "expects newline after dump. Got \"%s\"", s);
+ s[l - 1u] = '\0';
+
+ ck_assert_msg(!strchr(s, '\n'),
+ "no further newline expected. Got \"%s\"", s);
+
return s;
}
diff --git a/tests/nl-test-util.h b/tests/nl-test-util.h
index 4d95a62..94e265c 100644
--- a/tests/nl-test-util.h
+++ b/tests/nl-test-util.h
@@ -370,7 +370,7 @@ void nltst_netns_leave(struct nltst_netns *nsdata);
void _nltst_object_identical(const void *a, const void *b);
-char *_nltst_object_to_string(struct nl_object *obj);
+char *_nltst_object_to_string(const struct nl_object *obj);
struct nl_object **_nltst_cache_get_all(struct nl_cache *cache,
size_t *out_len);