s4-torture: test file_line_parse as well
authorGünther Deschner <gd@samba.org>
Tue, 10 Nov 2020 16:10:27 +0000 (17:10 +0100)
committerGünther Deschner <gd@samba.org>
Fri, 13 Nov 2020 17:47:33 +0000 (17:47 +0000)
Guenther

Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Günther Deschner <gd@samba.org>
Autobuild-Date(master): Fri Nov 13 17:47:33 UTC 2020 on sn-devel-184

lib/util/tests/file.c

index 55c9d4cec9a6e5adffb1a48299307223be11e781..3501c7e135feef79e3bd160265b92ae51159d4b1 100644 (file)
@@ -243,6 +243,34 @@ done:
        return ret;
 }
 
+static bool test_file_lines_parse(struct torture_context *tctx)
+{
+       char **lines;
+       int numlines;
+       TALLOC_CTX *mem_ctx = tctx;
+       char *buf;
+       size_t size;
+
+       torture_assert(tctx, file_save(TEST_FILENAME,
+                                      (const void *)TEST_DATA,
+                                      strlen(TEST_DATA)),
+                       "saving file");
+
+       buf = file_load(TEST_FILENAME, &size, 0, mem_ctx);
+       torture_assert(tctx, buf, "failed to load file");
+       unlink(TEST_FILENAME);
+
+       lines = file_lines_parse(buf,
+                                size,
+                                &numlines,
+                                mem_ctx);
+       torture_assert(tctx, lines, "failed to parse lines");
+
+       TALLOC_FREE(lines);
+       TALLOC_FREE(buf);
+       return true;
+}
+
 struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx)
 {
        struct torture_suite *suite = torture_suite_create(mem_ctx, "file");
@@ -256,5 +284,8 @@ struct torture_suite *torture_local_util_file(TALLOC_CTX *mem_ctx)
 
        torture_suite_add_simple_test(suite, "afdgets", test_afdgets);
 
+       torture_suite_add_simple_test(suite, "file_lines_parse",
+                       test_file_lines_parse);
+
        return suite;
 }