summaryrefslogtreecommitdiffstats
path: root/src/test/test-memstream-util.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/test/test-memstream-util.c
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-memstream-util.c')
-rw-r--r--src/test/test-memstream-util.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/test-memstream-util.c b/src/test/test-memstream-util.c
new file mode 100644
index 0000000..254bdca
--- /dev/null
+++ b/src/test/test-memstream-util.c
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "memstream-util.h"
+#include "string-util.h"
+#include "tests.h"
+
+TEST(memstream_done) {
+ _cleanup_(memstream_done) MemStream m = {};
+
+ assert_se(memstream_init(&m));
+}
+
+TEST(memstream_empty) {
+ _cleanup_(memstream_done) MemStream m = {};
+ _cleanup_free_ char *buf = NULL;
+ size_t sz;
+
+ assert_se(memstream_init(&m));
+ assert_se(memstream_finalize(&m, &buf, &sz) >= 0);
+ assert_se(streq(buf, ""));
+ assert_se(sz == 0);
+}
+
+TEST(memstream) {
+ _cleanup_(memstream_done) MemStream m = {};
+ _cleanup_free_ char *buf = NULL;
+ size_t sz;
+ FILE *f;
+
+ assert_se(f = memstream_init(&m));
+ fputs("hoge", f);
+ fputs("おはよう!", f);
+ fputs(u8"😀😀😀", f);
+ assert_se(memstream_finalize(&m, &buf, &sz) >= 0);
+ assert_se(streq(buf, u8"hogeおはよう!😀😀😀"));
+ assert_se(sz == strlen(u8"hogeおはよう!😀😀😀"));
+
+ buf = mfree(buf);
+
+ assert_se(f = memstream_init(&m));
+ fputs("second", f);
+ assert_se(memstream_finalize(&m, &buf, &sz) >= 0);
+ assert_se(streq(buf, "second"));
+ assert_se(sz == strlen("second"));
+}
+
+TEST(memstream_dump) {
+ _cleanup_(memstream_done) MemStream m = {};
+ FILE *f;
+
+ assert_se(f = memstream_init(&m));
+ fputs("first", f);
+ assert_se(memstream_dump(LOG_DEBUG, &m) >= 0);
+
+ assert_se(f = memstream_init(&m));
+ fputs("second", f);
+ assert_se(memstream_dump(LOG_DEBUG, &m) >= 0);
+}
+
+DEFINE_TEST_MAIN(LOG_DEBUG);