summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-25 21:06:59 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-29 18:19:53 +0200
commit4b4cee0c0c99f531a45157fd27f5441e511db109 (patch)
tree825aae023f27c2f578536af35dfd01b1dc96e18e /tests
parentd87bffd89b9c0a26a65f0c629250fa87902b6cb8 (diff)
Replace file/getline usage with istream
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makemodule.am10
-rw-r--r--tests/fstree_from_file.c11
-rw-r--r--tests/fstree_fuzz.c13
-rw-r--r--tests/str_table.c29
4 files changed, 15 insertions, 48 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am
index 58cd27e..8d12d40 100644
--- a/tests/Makemodule.am
+++ b/tests/Makemodule.am
@@ -2,7 +2,7 @@ test_canonicalize_name_SOURCES = tests/canonicalize_name.c tests/test.h
test_canonicalize_name_LDADD = libfstree.a
test_str_table_SOURCES = tests/str_table.c tests/test.h
-test_str_table_LDADD = libutil.a libcompat.a
+test_str_table_LDADD = libutil.a libfstream.a libcompat.a
test_str_table_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests
test_str_table_CPPFLAGS += -I$(top_srcdir)/lib/sqfs
@@ -45,15 +45,15 @@ test_get_path_LDADD = libfstree.a libcompat.a
test_fstree_sort_SOURCES = tests/fstree_sort.c tests/test.h
test_fstree_sort_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree
-test_fstree_sort_LDADD = libfstree.a libcompat.a
+test_fstree_sort_LDADD = libfstree.a libfstream.a libcompat.a
test_fstree_from_file_SOURCES = tests/fstree_from_file.c tests/test.h
test_fstree_from_file_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/fstree1.txt
-test_fstree_from_file_LDADD = libfstree.a libcompat.a
+test_fstree_from_file_LDADD = libfstree.a libfstream.a libcompat.a
test_fstree_init_SOURCES = tests/fstree_init.c tests/test.h
test_fstree_init_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree
-test_fstree_init_LDADD = libfstree.a libcompat.a
+test_fstree_init_LDADD = libfstree.a libfstream.a libcompat.a
test_filename_sane_SOURCES = tests/filename_sane.c lib/fstree/filename_sane.c
@@ -225,7 +225,7 @@ test_tar_xattr_schily_bin_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar
test_tar_xattr_schily_bin_CPPFLAGS += -DTESTFILE=xattr/xattr-schily-binary.tar
fstree_fuzz_SOURCES = tests/fstree_fuzz.c
-fstree_fuzz_LDADD = libfstree.a libcompat.a
+fstree_fuzz_LDADD = libfstree.a libfstream.a libcompat.a
tar_fuzz_SOURCES = tests/tar_fuzz.c
tar_fuzz_LDADD = libtar.a libfstream.a libcompat.a
diff --git a/tests/fstree_from_file.c b/tests/fstree_from_file.c
index c00cabf..f8f0892 100644
--- a/tests/fstree_from_file.c
+++ b/tests/fstree_from_file.c
@@ -9,21 +9,13 @@
#include "fstree.h"
#include "test.h"
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
-
int main(void)
{
tree_node_t *n;
fstree_t fs;
- FILE *fp;
-
- fp = test_open_read(TEST_PATH);
TEST_ASSERT(fstree_init(&fs, NULL) == 0);
- TEST_ASSERT(fstree_from_file(&fs, "testfile", fp) == 0);
+ TEST_ASSERT(fstree_from_file(&fs, TEST_PATH) == 0);
fstree_post_process(&fs);
n = fs.root->data.dir.children;
@@ -92,7 +84,6 @@ int main(void)
TEST_STR_EQUAL(n->name, "sock");
TEST_NULL(n->next);
- fclose(fp);
fstree_cleanup(&fs);
return EXIT_SUCCESS;
}
diff --git a/tests/fstree_fuzz.c b/tests/fstree_fuzz.c
index 42d8942..9618814 100644
--- a/tests/fstree_fuzz.c
+++ b/tests/fstree_fuzz.c
@@ -15,29 +15,20 @@ int main(int argc, char **argv)
{
int ret = EXIT_FAILURE;
fstree_t fs;
- FILE *fp;
if (argc != 2) {
fputs("Usage: fstree_fuzz <input_file>\n", stderr);
return EXIT_FAILURE;
}
- fp = fopen(argv[1], "r");
- if (fp == NULL) {
- perror(argv[1]);
- return EXIT_FAILURE;
- }
-
if (fstree_init(&fs, NULL))
- goto out_fp;
+ return EXIT_FAILURE;
- if (fstree_from_file(&fs, argv[1], fp))
+ if (fstree_from_file(&fs, argv[1]))
goto out_fs;
ret = EXIT_SUCCESS;
out_fs:
fstree_cleanup(&fs);
-out_fp:
- fclose(fp);
return ret;
}
diff --git a/tests/str_table.c b/tests/str_table.c
index 0935c89..7bcf4cc 100644
--- a/tests/str_table.c
+++ b/tests/str_table.c
@@ -7,46 +7,31 @@
#include "config.h"
#include "str_table.h"
+#include "fstream.h"
#include "compat.h"
#include "test.h"
-#define STR(x) #x
-#define STRVALUE(x) STR(x)
-
-#define TEST_PATH STRVALUE(TESTPATH)
-
static char *strings[1000];
static int read_strings(void)
{
+ istream_t *fp;
ssize_t ret;
char *line;
- size_t n;
- FILE *fp;
int i;
- fp = test_open_read("words.txt");
+ fp = istream_open_file("words.txt");
+ TEST_NOT_NULL(fp);
for (i = 0; i < 1000; ++i) {
- line = NULL;
- n = 0;
-
- ret = getline(&line, &n, fp);
- if (ret < 0) {
- perror("reading words");
- goto fail;
- }
+ ret = istream_get_line(fp, &line, NULL, 0);
+ TEST_EQUAL_I(ret, 0);
strings[i] = line;
}
- fclose(fp);
+ sqfs_destroy(fp);
return 0;
-fail:
- for (i = 0; i < 1000; ++i)
- free(strings[i]);
- fclose(fp);
- return -1;
}
int main(void)