diff options
-rw-r--r-- | tests/Makemodule.am | 46 | ||||
-rw-r--r-- | tests/abi.c | 14 | ||||
-rw-r--r-- | tests/add_by_path.c | 160 | ||||
-rw-r--r-- | tests/canonicalize_name.c | 5 | ||||
-rw-r--r-- | tests/filename_sane.c | 48 | ||||
-rw-r--r-- | tests/fstree_from_file.c | 126 | ||||
-rw-r--r-- | tests/fstree_init.c | 39 | ||||
-rw-r--r-- | tests/fstree_sort.c | 71 | ||||
-rw-r--r-- | tests/gen_inode_numbers.c | 43 | ||||
-rw-r--r-- | tests/get_path.c | 27 | ||||
-rw-r--r-- | tests/mknode_dir.c | 56 | ||||
-rw-r--r-- | tests/mknode_reg.c | 25 | ||||
-rw-r--r-- | tests/mknode_simple.c | 73 | ||||
-rw-r--r-- | tests/mknode_slink.c | 45 | ||||
-rw-r--r-- | tests/rbtree.c | 38 | ||||
-rw-r--r-- | tests/str_table.c | 43 | ||||
-rw-r--r-- | tests/tar_gnu.c | 187 | ||||
-rw-r--r-- | tests/tar_pax.c | 164 | ||||
-rw-r--r-- | tests/tar_sparse_gnu.c | 136 | ||||
-rw-r--r-- | tests/tar_sparse_gnu1.c | 96 | ||||
-rw-r--r-- | tests/tar_sparse_gnu2.c | 172 | ||||
-rw-r--r-- | tests/tar_ustar.c | 188 | ||||
-rw-r--r-- | tests/tar_xattr_bsd.c | 56 | ||||
-rw-r--r-- | tests/tar_xattr_schily.c | 56 | ||||
-rw-r--r-- | tests/tar_xattr_schily_bin.c | 56 | ||||
-rw-r--r-- | tests/test.h | 119 | ||||
-rw-r--r-- | tests/xxhash.c | 5 |
27 files changed, 1013 insertions, 1081 deletions
diff --git a/tests/Makemodule.am b/tests/Makemodule.am index 0d0f26b..f4aca03 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -1,12 +1,12 @@ -test_canonicalize_name_SOURCES = tests/canonicalize_name.c +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 +test_str_table_SOURCES = tests/str_table.c tests/test.h test_str_table_LDADD = libutil.a libcompat.a test_str_table_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests test_str_table_CPPFLAGS += -I$(top_srcdir)/lib/sqfs -test_rbtree_SOURCES = tests/rbtree.c +test_rbtree_SOURCES = tests/rbtree.c tests/test.h test_rbtree_LDADD = libutil.a libcompat.a test_rbtree_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/sqfs @@ -14,7 +14,7 @@ test_xxhash_SOURCES = tests/xxhash.c test_xxhash_LDADD = libutil.a libcompat.a test_xxhash_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/sqfs -test_abi_SOURCES = tests/abi.c +test_abi_SOURCES = tests/abi.c tests/test.h test_abi_LDADD = libsquashfs.la check_PROGRAMS += test_canonicalize_name test_str_table test_abi test_rbtree @@ -22,36 +22,36 @@ check_PROGRAMS += test_xxhash TESTS += test_canonicalize_name test_str_table test_abi test_rbtree test_xxhash if BUILD_TOOLS -test_mknode_simple_SOURCES = tests/mknode_simple.c +test_mknode_simple_SOURCES = tests/mknode_simple.c tests/test.h test_mknode_simple_LDADD = libfstree.a libcompat.a -test_mknode_slink_SOURCES = tests/mknode_slink.c +test_mknode_slink_SOURCES = tests/mknode_slink.c tests/test.h test_mknode_slink_LDADD = libfstree.a libcompat.a -test_mknode_reg_SOURCES = tests/mknode_reg.c +test_mknode_reg_SOURCES = tests/mknode_reg.c tests/test.h test_mknode_reg_LDADD = libfstree.a libcompat.a -test_mknode_dir_SOURCES = tests/mknode_dir.c +test_mknode_dir_SOURCES = tests/mknode_dir.c tests/test.h test_mknode_dir_LDADD = libfstree.a libcompat.a -test_gen_inode_numbers_SOURCES = tests/gen_inode_numbers.c +test_gen_inode_numbers_SOURCES = tests/gen_inode_numbers.c tests/test.h test_gen_inode_numbers_LDADD = libfstree.a libcompat.a -test_add_by_path_SOURCES = tests/add_by_path.c +test_add_by_path_SOURCES = tests/add_by_path.c tests/test.h test_add_by_path_LDADD = libfstree.a libcompat.a -test_get_path_SOURCES = tests/get_path.c +test_get_path_SOURCES = tests/get_path.c tests/test.h test_get_path_LDADD = libfstree.a libcompat.a -test_fstree_sort_SOURCES = tests/fstree_sort.c +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_from_file_SOURCES = tests/fstree_from_file.c +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_init_SOURCES = tests/fstree_init.c +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 @@ -61,42 +61,42 @@ test_filename_sane_w32_SOURCES = tests/filename_sane.c test_filename_sane_w32_SOURCES += lib/fstree/filename_sane.c test_filename_sane_w32_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_WIN32=1 -test_tar_gnu_SOURCES = tests/tar_gnu.c +test_tar_gnu_SOURCES = tests/tar_gnu.c tests/test.h test_tar_gnu_LDADD = libtar.a libcompat.a test_tar_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_pax_SOURCES = tests/tar_pax.c +test_tar_pax_SOURCES = tests/tar_pax.c tests/test.h test_tar_pax_LDADD = libtar.a libcompat.a test_tar_pax_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_ustar_SOURCES = tests/tar_ustar.c +test_tar_ustar_SOURCES = tests/tar_ustar.c tests/test.h test_tar_ustar_LDADD = libtar.a libcompat.a test_tar_ustar_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_sparse_gnu_SOURCES = tests/tar_sparse_gnu.c +test_tar_sparse_gnu_SOURCES = tests/tar_sparse_gnu.c tests/test.h test_tar_sparse_gnu_LDADD = libtar.a libcompat.a test_tar_sparse_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_sparse_gnu1_SOURCES = tests/tar_sparse_gnu1.c +test_tar_sparse_gnu1_SOURCES = tests/tar_sparse_gnu1.c tests/test.h test_tar_sparse_gnu1_LDADD = libtar.a libcompat.a test_tar_sparse_gnu1_CPPFLAGS = $(AM_CPPFLAGS) test_tar_sparse_gnu1_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_sparse_gnu2_SOURCES = tests/tar_sparse_gnu1.c +test_tar_sparse_gnu2_SOURCES = tests/tar_sparse_gnu1.c tests/test.h test_tar_sparse_gnu2_LDADD = libtar.a libcompat.a test_tar_sparse_gnu2_CPPFLAGS = $(AM_CPPFLAGS) test_tar_sparse_gnu2_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_xattr_bsd_SOURCES = tests/tar_xattr_bsd.c +test_tar_xattr_bsd_SOURCES = tests/tar_xattr_bsd.c tests/test.h test_tar_xattr_bsd_LDADD = libtar.a libcompat.a test_tar_xattr_bsd_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_xattr_schily_SOURCES = tests/tar_xattr_schily.c +test_tar_xattr_schily_SOURCES = tests/tar_xattr_schily.c tests/test.h test_tar_xattr_schily_LDADD = libtar.a libcompat.a test_tar_xattr_schily_CPPFLAGS = $(AM_CPPFLAGS) test_tar_xattr_schily_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar -test_tar_xattr_schily_bin_SOURCES = tests/tar_xattr_schily_bin.c +test_tar_xattr_schily_bin_SOURCES = tests/tar_xattr_schily_bin.c tests/test.h test_tar_xattr_schily_bin_LDADD = libtar.a libcompat.a test_tar_xattr_schily_bin_CPPFLAGS = $(AM_CPPFLAGS) test_tar_xattr_schily_bin_CPPFLAGS += -DTESTPATH=$(top_srcdir)/tests/tar diff --git a/tests/abi.c b/tests/abi.c index 1601e0a..ce1a9aa 100644 --- a/tests/abi.c +++ b/tests/abi.c @@ -7,19 +7,17 @@ #include "config.h" #include "sqfs/compressor.h" - -#include <assert.h> -#include <stdlib.h> +#include "test.h" int main(void) { sqfs_compressor_config_t cfg; - assert(sizeof(cfg.opt.gzip) == sizeof(cfg.opt)); - assert(sizeof(cfg.opt.zstd) == sizeof(cfg.opt)); - assert(sizeof(cfg.opt.lzo) == sizeof(cfg.opt)); - assert(sizeof(cfg.opt.xz) == sizeof(cfg.opt)); - assert(sizeof(cfg.opt.padd0) == sizeof(cfg.opt)); + TEST_EQUAL_UI(sizeof(cfg.opt.gzip), sizeof(cfg.opt)); + TEST_EQUAL_UI(sizeof(cfg.opt.zstd), sizeof(cfg.opt)); + TEST_EQUAL_UI(sizeof(cfg.opt.lzo), sizeof(cfg.opt)); + TEST_EQUAL_UI(sizeof(cfg.opt.xz), sizeof(cfg.opt)); + TEST_EQUAL_UI(sizeof(cfg.opt.padd0), sizeof(cfg.opt)); return EXIT_SUCCESS; } diff --git a/tests/add_by_path.c b/tests/add_by_path.c index 6abf05f..f575011 100644 --- a/tests/add_by_path.c +++ b/tests/add_by_path.c @@ -7,11 +7,7 @@ #include "config.h" #include "fstree.h" - -#include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <errno.h> +#include "test.h" int main(void) { @@ -21,7 +17,7 @@ int main(void) char *opts; opts = strdup("mode=0755,uid=21,gid=42"); - assert(fstree_init(&fs, opts) == 0); + TEST_ASSERT(fstree_init(&fs, opts) == 0); free(opts); memset(&sb, 0, sizeof(sb)); @@ -29,88 +25,88 @@ int main(void) sb.st_uid = 1000; sb.st_gid = 100; - assert(fs.root->link_count == 2); + TEST_EQUAL_UI(fs.root->link_count, 2); a = fstree_add_generic(&fs, "dir", &sb, NULL); - assert(a != NULL); - assert(strcmp(a->name, "dir") == 0); - assert(a->mode == sb.st_mode); - assert(a->uid == sb.st_uid); - assert(a->gid == sb.st_gid); - assert(a->parent == fs.root); - assert(a->link_count == 2); - assert(a->next == NULL); - assert(fs.root->data.dir.children == a); - assert(fs.root->link_count == 3); - assert(!a->data.dir.created_implicitly); + TEST_NOT_NULL(a); + TEST_STR_EQUAL(a->name, "dir"); + TEST_EQUAL_UI(a->mode, sb.st_mode); + TEST_EQUAL_UI(a->uid, sb.st_uid); + TEST_EQUAL_UI(a->gid, sb.st_gid); + TEST_ASSERT(a->parent == fs.root); + TEST_EQUAL_UI(a->link_count, 2); + TEST_NULL(a->next); + TEST_ASSERT(fs.root->data.dir.children == a); + TEST_EQUAL_UI(fs.root->link_count, 3); + TEST_ASSERT(!a->data.dir.created_implicitly); memset(&sb, 0, sizeof(sb)); sb.st_mode = S_IFBLK | 0640; sb.st_rdev = 1234; b = fstree_add_generic(&fs, "blkdev", &sb, NULL); - assert(b != NULL); - assert(b != a); - assert(strcmp(b->name, "blkdev") == 0); - assert(b->mode == sb.st_mode); - assert(b->uid == sb.st_uid); - assert(b->gid == sb.st_gid); - assert(b->parent == fs.root); - assert(b->link_count == 1); - assert(b->data.devno == sb.st_rdev); - assert(b->next == a); - assert(fs.root->link_count == 4); - assert(fs.root->data.dir.children == b); - - assert(fstree_add_generic(&fs, "blkdev/foo", &sb, NULL) == NULL); - assert(errno == ENOTDIR); - - assert(fstree_add_generic(&fs, "dir", &sb, NULL) == NULL); - assert(errno == EEXIST); + TEST_NOT_NULL(b); + TEST_ASSERT(b != a); + TEST_STR_EQUAL(b->name, "blkdev"); + TEST_EQUAL_UI(b->mode, sb.st_mode); + TEST_EQUAL_UI(b->uid, sb.st_uid); + TEST_EQUAL_UI(b->gid, sb.st_gid); + TEST_ASSERT(b->parent == fs.root); + TEST_EQUAL_UI(b->link_count, 1); + TEST_EQUAL_UI(b->data.devno, sb.st_rdev); + TEST_ASSERT(b->next == a); + TEST_EQUAL_UI(fs.root->link_count, 4); + TEST_ASSERT(fs.root->data.dir.children == b); + + TEST_NULL(fstree_add_generic(&fs, "blkdev/foo", &sb, NULL)); + TEST_EQUAL_UI(errno, ENOTDIR); + + TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL)); + TEST_EQUAL_UI(errno, EEXIST); memset(&sb, 0, sizeof(sb)); sb.st_mode = S_IFDIR | 0755; - assert(fstree_add_generic(&fs, "dir", &sb, NULL) == NULL); - assert(errno == EEXIST); + TEST_NULL(fstree_add_generic(&fs, "dir", &sb, NULL)); + TEST_EQUAL_UI(errno, EEXIST); memset(&sb, 0, sizeof(sb)); sb.st_mode = S_IFCHR | 0444; b = fstree_add_generic(&fs, "dir/chrdev", &sb, NULL); - assert(b != NULL); - assert(b->mode == sb.st_mode); - assert(b->uid == sb.st_uid); - assert(b->gid == sb.st_gid); - assert(b->link_count == 1); - assert(b->parent == a); - assert(b->data.devno == sb.st_rdev); - assert(b->next == NULL); - assert(a->data.dir.children == b); - - assert(a->link_count == 3); - assert(fs.root->link_count == 4); + TEST_NOT_NULL(b); + TEST_EQUAL_UI(b->mode, sb.st_mode); + TEST_EQUAL_UI(b->uid, sb.st_uid); + TEST_EQUAL_UI(b->gid, sb.st_gid); + TEST_EQUAL_UI(b->link_count, 1); + TEST_ASSERT(b->parent == a); + TEST_EQUAL_UI(b->data.devno, sb.st_rdev); + TEST_NULL(b->next); + TEST_ASSERT(a->data.dir.children == b); + + TEST_EQUAL_UI(a->link_count, 3); + TEST_EQUAL_UI(fs.root->link_count, 4); b = fstree_add_generic(&fs, "dir/foo/chrdev", &sb, NULL); - assert(b != NULL); - assert(b->next == NULL); - assert(b->mode == sb.st_mode); - assert(b->uid == sb.st_uid); - assert(b->gid == sb.st_gid); - assert(b->link_count == 1); - assert(b->parent != a); - assert(b->parent->parent == a); - assert(b->data.devno == sb.st_rdev); - assert(b->next == NULL); - - assert(a->link_count == 4); - assert(fs.root->link_count == 4); - assert(a->data.dir.children != b); + TEST_NOT_NULL(b); + TEST_NULL(b->next); + TEST_EQUAL_UI(b->mode, sb.st_mode); + TEST_EQUAL_UI(b->uid, sb.st_uid); + TEST_EQUAL_UI(b->gid, sb.st_gid); + TEST_EQUAL_UI(b->link_count, 1); + TEST_ASSERT(b->parent != a); + TEST_ASSERT(b->parent->parent == a); + TEST_EQUAL_UI(b->data.devno, sb.st_rdev); + TEST_NULL(b->next); + + TEST_EQUAL_UI(a->link_count, 4); + TEST_EQUAL_UI(fs.root->link_count, 4); + TEST_ASSERT(a->data.dir.children != b); b = b->parent; - assert(b->data.dir.created_implicitly); - assert(b->mode == (S_IFDIR | 0755)); - assert(b->uid == 21); - assert(b->gid == 42); - assert(b->link_count == 3); + TEST_ASSERT(b->data.dir.created_implicitly); + TEST_EQUAL_UI(b->mode, S_IFDIR | 0755); + TEST_EQUAL_UI(b->uid, 21); + TEST_EQUAL_UI(b->gid, 42); + TEST_EQUAL_UI(b->link_count, 3); memset(&sb, 0, sizeof(sb)); sb.st_mode = S_IFDIR | 0750; @@ -118,19 +114,19 @@ int main(void) sb.st_gid = 100; a = fstree_add_generic(&fs, "dir/foo", &sb, NULL); - assert(a != NULL); - assert(a == b); - assert(!a->data.dir.created_implicitly); - assert(a->mode == sb.st_mode); - assert(a->uid == sb.st_uid); - assert(a->gid == sb.st_gid); - assert(a->link_count == 3); - - assert(a->parent->link_count == 4); - assert(fs.root->link_count == 4); - - assert(fstree_add_generic(&fs, "dir/foo", &sb, NULL) == NULL); - assert(errno == EEXIST); + TEST_NOT_NULL(a); + TEST_ASSERT(a == b); + TEST_ASSERT(!a->data.dir.created_implicitly); + TEST_EQUAL_UI(a->mode, sb.st_mode); + TEST_EQUAL_UI(a->uid, sb.st_uid); + TEST_EQUAL_UI(a->gid, sb.st_gid); + TEST_EQUAL_UI(a->link_count, 3); + + TEST_EQUAL_UI(a->parent->link_count, 4); + TEST_EQUAL_UI(fs.root->link_count, 4); + + TEST_NULL(fstree_add_generic(&fs, "dir/foo", &sb, NULL)); + TEST_EQUAL_UI(errno, EEXIST); fstree_cleanup(&fs); return EXIT_SUCCESS; diff --git a/tests/canonicalize_name.c b/tests/canonicalize_name.c index 3601569..679cd06 100644 --- a/tests/canonicalize_name.c +++ b/tests/canonicalize_name.c @@ -6,10 +6,7 @@ */ #include "config.h" #include "fstree.h" - -#include <string.h> -#include <stdlib.h> -#include <stdio.h> +#include "test.h" static const struct { const char *in; diff --git a/tests/filename_sane.c b/tests/filename_sane.c index a9f7224..3c1fd4f 100644 --- a/tests/filename_sane.c +++ b/tests/filename_sane.c @@ -6,11 +6,7 @@ */ #include "config.h" #include "fstree.h" - -#include <string.h> -#include <stdlib.h> -#include <assert.h> -#include <stdio.h> +#include "test.h" static const char *must_work[] = { "foobar", @@ -48,18 +44,48 @@ int main(void) size_t i; for (i = 0; must_work[i] != NULL; ++i) { - assert(is_filename_sane(must_work[i], false)); - assert(is_filename_sane(must_work[i], true)); + if (!is_filename_sane(must_work[i], false)) { + fprintf(stderr, "%s was rejected!\n", must_work[i]); + return EXIT_FAILURE; + } + + if (!is_filename_sane(must_work[i], true)) { + fprintf(stderr, + "%s was rejected when testing for " + "OS specific stuff!\n", must_work[i]); + return EXIT_FAILURE; + } } for (i = 0; must_not_work[i] != NULL; ++i) { - assert(!is_filename_sane(must_not_work[i], false)); - assert(!is_filename_sane(must_not_work[i], true)); + if (is_filename_sane(must_not_work[i], false)) { + fprintf(stderr, "%s was accepted!\n", + must_not_work[i]); + return EXIT_FAILURE; + } + + if (is_filename_sane(must_not_work[i], true)) { + fprintf(stderr, + "%s was accepted when testing for " + "OS specific stuff!\n", must_not_work[i]); + return EXIT_FAILURE; + } } for (i = 0; must_not_work_here[i] != NULL; ++i) { - assert( is_filename_sane(must_not_work_here[i], false)); - assert(!is_filename_sane(must_not_work_here[i], true)); + if (!is_filename_sane(must_not_work_here[i], false)) { + fprintf(stderr, + "%s was rejected in the generic test!\n", + must_not_work_here[i]); + return EXIT_FAILURE; + } + + if (is_filename_sane(must_not_work_here[i], true)) { + fprintf(stderr, + "%s was accepted when testing for " + "OS specific stuff!\n", must_not_work_here[i]); + return EXIT_FAILURE; + } } return EXIT_SUCCESS; diff --git a/tests/fstree_from_file.c b/tests/fstree_from_file.c index 34215c9..c00cabf 100644 --- a/tests/fstree_from_file.c +++ b/tests/fstree_from_file.c @@ -7,108 +7,90 @@ #include "config.h" #include "fstree.h" - -#include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <stdio.h> +#include "test.h" #define STR(x) #x #define STRVALUE(x) STR(x) #define TEST_PATH STRVALUE(TESTPATH) -static FILE *open_read(const char *path) -{ - FILE *fp = fopen(path, "rb"); - - if (fp == NULL) { - perror(path); - exit(EXIT_FAILURE); - } - - return fp; -} - int main(void) { tree_node_t *n; fstree_t fs; FILE *fp; - fp = open_read(TEST_PATH); - assert(fp != NULL); + fp = test_open_read(TEST_PATH); - assert(fstree_init(&fs, NULL) == 0); - assert(fstree_from_file(&fs, "testfile", fp) == 0); + TEST_ASSERT(fstree_init(&fs, NULL) == 0); + TEST_ASSERT(fstree_from_file(&fs, "testfile", fp) == 0); fstree_post_process(&fs); n = fs.root->data.dir.children; - assert(fs.root->link_count == 9); + TEST_EQUAL_UI(fs.root->link_count, 9); - assert(n->mode == (S_IFBLK | 0600)); - assert(n->uid == 8); - assert(n->gid == 9); - assert(n->link_count == 1); - assert(strcmp(n->name, "blkdev") == 0); - assert(n->data.devno == makedev(42, 21)); + TEST_EQUAL_UI(n->mode, S_IFBLK | 0600); + TEST_EQUAL_UI(n->uid, 8); + TEST_EQUAL_UI(n->gid, 9); + TEST_EQUAL_UI(n->link_count, 1); + TEST_STR_EQUAL(n->name, "blkdev"); + TEST_EQUAL_UI(n->data.devno, makedev(42, 21)); n = n->next; - assert(n->mode == (S_IFCHR | 0600)); - assert(n->uid == 6); - assert(n->gid == 7); - assert(n->link_count == 1); - assert(strcmp(n->name, "chardev") == 0); - assert(n->data.devno == makedev(13, 37)); + TEST_EQUAL_UI(n->mode, S_IFCHR | 0600); + TEST_EQUAL_UI(n->uid, 6); + TEST_EQUAL_UI(n->gid, 7); + TEST_EQUAL_UI(n->link_count, 1); + TEST_STR_EQUAL(n->name, "chardev"); + TEST_EQUAL_UI(n->data.devno, makedev(13, 37)); n = n->next; - assert(n->mode == (S_IFDIR | 0755)); - assert(n->uid == 4); - assert(n->gid == 5); - assert(n->link_count == 2); - assert(strcmp(n->name, "dir") == 0); - assert(n->data.dir.children == NULL); + TEST_EQUAL_UI(n->mode, S_IFDIR | 0755); + TEST_EQUAL_UI(n->uid, 4); + TEST_EQUAL_UI(n->gid, 5); + TEST_EQUAL_UI(n->link_count, 2); + TEST_STR_EQUAL(n->name, "dir"); + TEST_NULL(n->data.dir.children); n = n->next; - assert(n->mode == (S_IFDIR | 0755)); - assert(n->uid == 0); - assert(n->gid == 0); - assert(n->link_count == 3); - assert(strcmp(n->name, "foo bar") == 0); - assert(n->data.dir.children != NULL); - - assert(n->data.dir.children->next == NULL); - assert(n->data.dir.children->mode == (S_IFDIR | 0755)); - assert(n->data.dir.children->uid == 0); - assert(n->data.dir.children->gid == 0); - assert(n->data.dir.children->link_count == 2); - assert(strcmp(n->data.dir.children->name, " test \"") == 0); - assert(n->data.dir.children->data.dir.children == NULL); + TEST_EQUAL_UI(n->mode, S_IFDIR | 0755); + TEST_EQUAL_UI(n->uid, 0); + TEST_EQUAL_UI(n->gid, 0); + TEST_EQUAL_UI(n->link_count, 3); + TEST_STR_EQUAL(n->name, "foo bar"); + TEST_NOT_NULL(n->data.dir.children); + + TEST_NULL(n->data.dir.children->next); + TEST_EQUAL_UI(n->data.dir.children->mode, S_IFDIR | 0755); + TEST_EQUAL_UI(n->data.dir.children->uid, 0); + TEST_EQUAL_UI(n->data.dir.children->gid, 0); + TEST_EQUAL_UI(n->data.dir.children->link_count, 2); + TEST_STR_EQUAL(n->data.dir.children->name, " test \""); + TEST_NULL(n->data.dir.children->data.dir.children); n = n->next; - assert(n->mode == (S_IFIFO | 0644)); - assert(n->uid == 10); - assert(n->gid == 11); - assert(n->link_count == 1); - assert(strcmp(n->name, "pipe") == 0); + TEST_EQUAL_UI(n->mode, S_IFIFO | 0644); + TEST_EQUAL_UI(n->uid, 10); + TEST_EQUAL_UI(n->gid, 11); + TEST_EQUAL_UI(n->link_count, 1); + TEST_STR_EQUAL(n->name, "pipe"); n = n->next; - assert(n->mode == (S_IFLNK | 0777)); - assert(n->uid == 2); - assert(n->gid == 3); - assert(n->link_count == 1); - assert(strcmp(n->name, "slink") == 0); - fprintf(stderr, "'%s'\n", n->data.target); - assert(strcmp(n->data.target, "slinktarget") == 0); + TEST_EQUAL_UI(n->mode, S_IFLNK | 0777); + TEST_EQUAL_UI(n->uid, 2); + TEST_EQUAL_UI(n->gid, 3); + TEST_EQUAL_UI(n->link_count, 1); + TEST_STR_EQUAL(n->name, "slink"); + TEST_STR_EQUAL(n->data.target, "slinktarget"); n = n->next; - assert(n->mode == (S_IFSOCK | 0555)); - assert(n->uid == 12); - assert(n->gid == 13); - assert(n->link_count == 1); - assert(strcmp(n->name, "sock") == 0); - assert(n->next == NULL); + TEST_EQUAL_UI(n->mode, S_IFSOCK | 0555); + TEST_EQUAL_UI(n->uid, 12); + TEST_EQUAL_UI(n->gid, 13); + TEST_EQUAL_UI(n->link_count, 1); + TEST_STR_EQUAL(n->name, "sock"); + TEST_NULL(n->next); fclose(fp); fstree_cleanup(&fs); diff --git a/tests/fstree_init.c b/tests/fstree_init.c index 3a526d1..5970159 100644 --- a/tests/fstree_init.c +++ b/tests/fstree_init.c @@ -8,11 +8,7 @@ #include "fstree.h" #include "internal.h" - -#include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <stdio.h> +#include "test.h" int main(void) { @@ -20,32 +16,33 @@ int main(void) char *str; str = strdup("mtime=1337,uid=1000,gid=100,mode=0321"); - assert(str != NULL); - assert(fstree_init(&fs, str) == 0); + TEST_NOT_NULL(str); + TEST_ASSERT(fstree_init(&fs, str) == 0); free(str); - assert(fs.defaults.st_mtime == 1337); - assert(fs.defaults.st_uid == 1000); - assert(fs.defaults.st_gid == 100); - assert(fs.defaults.st_mode == (S_IFDIR | 0321)); + TEST_EQUAL_UI(fs.defaults.st_mtime, 1337); + TEST_EQUAL_UI(fs.defaults.st_uid, 1000); + TEST_EQUAL_UI(fs.defaults.st_gid, 100); + TEST_EQUAL_UI(fs.defaults.st_mode, S_IFDIR | 0321); fstree_cleanup(&fs); - assert(fstree_init(&fs, NULL) == 0); - assert(fs.defaults.st_mtime == 0 || - fs.defaults.st_mtime == get_source_date_epoch()); - assert(fs.defaults.st_uid == 0); - assert(fs.defaults.st_gid == 0); - assert(fs.defaults.st_mode == (S_IFDIR | 0755)); + TEST_ASSERT(fstree_init(&fs, NULL) == 0); + if (fs.defaults.st_mtime != 0) { + TEST_EQUAL_UI(fs.defaults.st_mtime, get_source_date_epoch()); + } + TEST_EQUAL_UI(fs.defaults.st_uid, 0); + TEST_EQUAL_UI(fs.defaults.st_gid, 0); + TEST_EQUAL_UI(fs.defaults.st_mode, S_IFDIR | 0755); fstree_cleanup(&fs); str = strdup("mode=07777"); - assert(str != NULL); - assert(fstree_init(&fs, str) == 0); + TEST_NOT_NULL(str); + TEST_ASSERT(fstree_init(&fs, str) == 0); free(str); fstree_cleanup(&fs); str = strdup("mode=017777"); - assert(str != NULL); - assert(fstree_init(&fs, str) != 0); + TEST_NOT_NULL(str); + TEST_ASSERT(fstree_init(&fs, str) != 0); free(str); return EXIT_SUCCESS; diff --git a/tests/fstree_sort.c b/tests/fstree_sort.c index 5557678..40a270f 100644 --- a/tests/fstree_sort.c +++ b/tests/fstree_sort.c @@ -8,10 +8,7 @@ #include "fstree.h" #include "internal.h" - -#include <stdlib.h> -#include <string.h> -#include <assert.h> +#include "test.h" int main(void) { @@ -28,41 +25,41 @@ int main(void) b = fstree_mknode(NULL, "b", 1, NULL, &sb); c = fstree_mknode(NULL, "c", 1, NULL, &sb); d = fstree_mknode(NULL, "d", 1, NULL, &sb); - assert(a != NULL && b != NULL && c != NULL && d != NULL); + TEST_ASSERT(a != NULL && b != NULL && c != NULL && d != NULL); /* empty list */ - assert(tree_node_list_sort(NULL) == NULL); + TEST_NULL(tree_node_list_sort(NULL)); /* single element */ - assert(tree_node_list_sort(a) == a); - assert(a->next == NULL); + TEST_ASSERT(tree_node_list_sort(a) == a); + TEST_NULL(a->next); /* two elements, reverse order */ b->next = a; - assert(tree_node_list_sort(b) == a); - assert(a->next == b); - assert(b->next == NULL); + TEST_ASSERT(tree_node_list_sort(b) == a); + TEST_ASSERT(a->next == b); + TEST_NULL(b->next); /* two elements, sorted order */ - assert(tree_node_list_sort(a) == a); - assert(a->next == b); - assert(b->next == NULL); + TEST_ASSERT(tree_node_list_sort(a) == a); + TEST_ASSERT(a->next == b); + TEST_NULL(b->next); /* three elements, reverse order */ c->next = b; b->next = a; a->next = NULL; - assert(tree_node_list_sort(c) == a); - assert(a->next == b); - assert(b->next == c); - assert(c->next == NULL); + TEST_ASSERT(tree_node_list_sort(c) == a); + TEST_ASSERT(a->next == b); + TEST_ASSERT(b->next == c); + TEST_NULL(c->next); /* three elements, ordered */ - assert(tree_node_list_sort(a) == a); - assert(a->next == b); - assert(b->next == c); - assert(c->next == NULL); + TEST_ASSERT(tree_node_list_sort(a) == a); + TEST_ASSERT(a->next == b); + TEST_ASSERT(b->next == c); + TEST_NULL(c->next); /* four elements, reverse order */ d->next = c; @@ -70,18 +67,18 @@ int main(void) b->next = a; a->next = NULL; - assert(tree_node_list_sort(d) == a); - assert(a->next == b); - assert(b->next == c); - assert(c->next == d); - assert(d->next == NULL); + TEST_ASSERT(tree_node_list_sort(d) == a); + TEST_ASSERT(a->next == b); + TEST_ASSERT(b->next == c); + TEST_ASSERT(c->next == d); + TEST_NULL(d->next); /* four elements, sorted order */ - assert(tree_node_list_sort(a) == a); - assert(a->next == b); - assert(b->next == c); - assert(c->next == d); - assert(d->next == NULL); + TEST_ASSERT(tree_node_list_sort(a) == a); + TEST_ASSERT(a->next == b); + TEST_ASSERT(b->next == c); + TEST_ASSERT(c->next == d); + TEST_NULL(d->next); /* force merge sort to go through LRLR pattern */ b->next = a; @@ -89,11 +86,11 @@ int main(void) d->next = c; c->next = NULL; - assert(tree_node_list_sort(b) == a); - assert(a->next == b); - assert(b->next == c); - assert(c->next == d); - assert(d->next == NULL); + TEST_ASSERT(tree_node_list_sort(b) == a); + TEST_ASSERT(a->next == b); + TEST_ASSERT(b->next == c); + TEST_ASSERT(c->next == d); + TEST_NULL(d->next); /* cleanup and done */ free(a); diff --git a/tests/gen_inode_numbers.c b/tests/gen_inode_numbers.c index dc8ca4c..68b06e8 100644 --- a/tests/gen_inode_numbers.c +++ b/tests/gen_inode_numbers.c @@ -7,10 +7,7 @@ #include "config.h" #include "fstree.h" - -#include <stdlib.h> -#include <assert.h> -#include <string.h> +#include "test.h" static tree_node_t *gen_node(tree_node_t *parent, const char *name) { @@ -27,7 +24,7 @@ static void check_children_before_root(tree_node_t *root) tree_node_t *n; for (n = root->data.dir.children; n != NULL; n = n->next) - assert(n->inode_num < root->inode_num); + TEST_LESS_THAN_UI(n->inode_num, root->inode_num); for (n = root->data.dir.children; n != NULL; n = n->next) check_children_before_root(n); @@ -39,7 +36,7 @@ static void check_children_continuous(tree_node_t *root) for (n = root->data.dir.children; n != NULL; n = n->next) { if (n->next != NULL) { - assert(n->next->inode_num == (n->inode_num + 1)); + TEST_EQUAL_UI(n->next->inode_num, (n->inode_num + 1)); } } @@ -53,36 +50,36 @@ int main(void) fstree_t fs; // inode table for the empty tree - assert(fstree_init(&fs, NULL) == 0); + TEST_ASSERT(fstree_init(&fs, NULL) == 0); fstree_post_process(&fs); - assert(fs.unique_inode_count == 1); - assert(fs.root->inode_num == 1); + TEST_EQUAL_UI(fs.unique_inode_count, 1); + TEST_EQUAL_UI(fs.root->inode_num, 1); fstree_cleanup(&fs); // tree with 2 levels under root, fan out 3 - assert(fstree_init(&fs, NULL) == 0); + TEST_ASSERT(fstree_init(&fs, NULL) == 0); a = gen_node(fs.root, "a"); b = gen_node(fs.root, "b"); c = gen_node(fs.root, "c"); - assert(a != NULL); - assert(b != NULL); - assert(c != NULL); + TEST_NOT_NULL(a); + TEST_NOT_NULL(b); + TEST_NOT_NULL(c); - assert(gen_node(a, "a_a") != NULL); - assert(gen_node(a, "a_b") != NULL); - assert(gen_node(a, "a_c") != NULL); + TEST_NOT_NULL(gen_node(a, "a_a")); + TEST_NOT_NULL(gen_node(a, "a_b")); + TEST_NOT_NULL(gen_node(a, "a_c")); - assert(gen_node(b, "b_a") != NULL); - assert(gen_node(b, "b_b") != NULL); - assert(gen_node(b, "b_c") != NULL); + TEST_NOT_NULL(gen_node(b, "b_a")); + TEST_NOT_NULL(gen_node(b, "b_b")); + TEST_NOT_NULL(gen_node(b, "b_c")); - assert(gen_node(c, "c_a") != NULL); - assert(gen_node(c, "c_b") != NULL); - assert(gen_node(c, "c_c") != NULL); + TEST_NOT_NULL(gen_node(c, "c_a")); + TEST_NOT_NULL(gen_node(c, "c_b")); + TEST_NOT_NULL(gen_node(c, "c_c")); fstree_post_process(&fs); - assert(fs.unique_inode_count == 13); + TEST_EQUAL_UI(fs.unique_inode_count, 13); check_children_before_root(fs.root); check_children_continuous(fs.root); diff --git a/tests/get_path.c b/tests/get_path.c index 7d37f4c..8ca0ce0 100644 --- a/tests/get_path.c +++ b/tests/get_path.c @@ -7,10 +7,7 @@ #include "config.h" #include "fstree.h" - -#include <stdlib.h> -#include <string.h> -#include <assert.h> +#include "test.h" int main(void) { @@ -19,7 +16,7 @@ int main(void) fstree_t fs; char *str; - assert(fstree_init(&fs, NULL) == 0); + TEST_ASSERT(fstree_init(&fs, NULL) == 0); memset(&sb, 0, sizeof(sb)); sb.st_mode = S_IFDIR | 0750; @@ -32,28 +29,28 @@ int main(void) d = fstree_add_generic(&fs, "foo/bar/baz/dir", &sb, NULL); str = fstree_get_path(fs.root); - assert(str != NULL); - assert(strcmp(str, "/") == 0); + TEST_NOT_NULL(str); + TEST_STR_EQUAL(str, "/"); free(str); str = fstree_get_path(a); - assert(str != NULL); - assert(strcmp(str, "/foo") == 0); + TEST_NOT_NULL(str); + TEST_STR_EQUAL(str, "/foo"); free(str); str = fstree_get_path(b); - assert(str != NULL); - assert(strcmp(str, "/foo/bar") == 0); + TEST_NOT_NULL(str); + TEST_STR_EQUAL(str, "/foo/bar"); free(str); str = fstree_get_path(c); - assert(str != NULL); - assert(strcmp(str, "/foo/bar/baz") == 0); + TEST_NOT_NULL(str); + TEST_STR_EQUAL(str, "/foo/bar/baz"); free(str); str = fstree_get_path(d); - assert(str != NULL); - assert(strcmp(str, "/foo/bar/baz/dir") == 0); + TEST_NOT_NULL(str); + TEST_STR_EQUAL(str, "/foo/bar/baz/dir"); free(str); fstree_cleanup(&fs); diff --git a/tests/mknode_dir.c b/tests/mknode_dir.c index 8f2131c..9495bb8 100644 --- a/tests/mknode_dir.c +++ b/tests/mknode_dir.c @@ -7,10 +7,7 @@ #include "config.h" #include "fstree.h" - -#include <stdlib.h> -#include <assert.h> -#include <string.h> +#include "test.h" int main(void) { @@ -27,36 +24,35 @@ int main(void) sb.st_size = 4096; root = fstree_mknode(NULL, "rootdir", 7, NULL, &sb); - assert(root->uid == sb.st_uid); - assert(root->gid == sb.st_gid); - assert(root->mode == sb.st_mode); - assert(root->link_count == 2); - assert((char *)root->name >= (char *)root->payload); - assert(root->name >= (char *)root->payload); - assert(strcmp(root->name, "rootdir") == 0); - assert(root->data.dir.children == NULL); - assert(root->parent == NULL); - assert(root->next == NULL); + TEST_EQUAL_UI(root->uid, sb.st_uid); + TEST_EQUAL_UI(root->gid, sb.st_gid); + TEST_EQUAL_UI(root->mode, sb.st_mode); + TEST_EQUAL_UI(root->link_count, 2); + TEST_ASSERT(root->name >= (char *)root->payload); + TEST_STR_EQUAL(root->name, "rootdir"); + TEST_NULL(root->data.dir.children); + TEST_NULL(root->parent); + TEST_NULL(root->next); a = fstree_mknode(root, "adir", 4, NULL, &sb); - assert(a->parent == root); - assert(a->next == NULL); - assert(a->link_count == 2); - assert(root->link_count == 3); - assert(root->data.dir.children == a); - assert(root->parent == NULL); - assert(root->next == NULL); + TEST_ASSERT(a->parent == root); + TEST_NULL(a->next); + TEST_EQUAL_UI(a->link_count, 2); + TEST_EQUAL_UI(root->link_count, 3); + TEST_ASSERT(root->data.dir.children == a); + TEST_NULL(root->parent); + TEST_NULL(root->next); b = fstree_mknode(root, "bdir", 4, NULL, &sb); - assert(a->parent == root); - assert(b->parent == root); - assert(b->link_count == 2); - assert(root->data.dir.children == b); - assert(root->link_count == 4); - assert(b->next == a); - assert(a->next == NULL); - assert(root->parent == NULL); - assert(root->next == NULL); + TEST_ASSERT(a->parent == root); + TEST_ASSERT(b->parent == root); + TEST_EQUAL_UI(b->link_count, 2); + TEST_ASSERT(root->data.dir.children == b); + TEST_EQUAL_UI(root->link_count, 4); + TEST_ASSERT(b->next == a); + TEST_NULL(a->next); + TEST_NULL(root->parent); + TEST_NULL(root->next); free(root); free(a); diff --git a/tests/mknode_reg.c b/tests/mknode_reg.c index 40966f8..677c934 100644 --- a/tests/mknode_reg.c +++ b/tests/mknode_reg.c @@ -7,10 +7,7 @@ #include "config.h" #include "fstree.h" - -#include <stdlib.h> -#include <assert.h> -#include <string.h> +#include "test.h" int main(void) { @@ -28,16 +25,16 @@ int main(void) sb.st_size = 4096; node = fstree_mknode(NULL, "filename", 8, "input", &sb); - assert(node->uid == sb.st_uid); - assert(node->gid == sb.st_gid); - assert(node->mode == sb.st_mode); - assert(node->parent == NULL); - assert(node->link_count == 1); - assert((char *)node->name >= (char *)node->payload); - assert(node->data.file.input_file >= (char *)node->payload); - assert(node->data.file.input_file >= node->name + 8); - assert(strcmp(node->name, "filename") == 0); - assert(strcmp(node->data.file.input_file, "input") == 0); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_NULL(node->parent); + TEST_EQUAL_UI(node->link_count, 1); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_ASSERT(node->data.file.input_file >= (char *)node->payload); + TEST_ASSERT(node->data.file.input_file >= node->name + 8); + TEST_STR_EQUAL(node->name, "filename"); + TEST_STR_EQUAL(node->data.file.input_file, "input"); free(node); return EXIT_SUCCESS; diff --git a/tests/mknode_simple.c b/tests/mknode_simple.c index ef2a466..271ff96 100644 --- a/tests/mknode_simple.c +++ b/tests/mknode_simple.c @@ -7,10 +7,7 @@ #include "config.h" #include "fstree.h" - -#include <stdlib.h> -#include <assert.h> -#include <string.h> +#include "test.h" int main(void) { @@ -27,15 +24,15 @@ int main(void) sb.st_size = 1337; node = fstree_mknode(NULL, "sockfile", 8, NULL, &sb); - assert((char *)node->name >= (char *)node->payload); - assert(strcmp(node->name, "sockfile") == 0); - assert(node->uid == sb.st_uid); - assert(node->gid == sb.st_gid); - assert(node->mode == sb.st_mode); - assert(node->link_count == 1); - assert(node->parent == NULL); - assert(node->data.target == NULL); - assert(node->data.devno == 0); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_STR_EQUAL(node->name, "sockfile"); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->link_count, 1); + TEST_NULL(node->parent); + TEST_NULL(node->data.target); + TEST_EQUAL_UI(node->data.devno, 0); free(node); memset(&fs, 0, sizeof(fs)); @@ -47,15 +44,15 @@ int main(void) sb.st_size = 1337; node = fstree_mknode(NULL, "fifo", 4, NULL, &sb); - assert((char *)node->name >= (char *)node->payload); - assert(strcmp(node->name, "fifo") == 0); - assert(node->uid == sb.st_uid); - assert(node->gid == sb.st_gid); - assert(node->mode == sb.st_mode); - assert(node->link_count == 1); - assert(node->parent == NULL); - assert(node->data.target == NULL); - assert(node->data.devno == 0); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_STR_EQUAL(node->name, "fifo"); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->link_count, 1); + TEST_NULL(node->parent); + TEST_NULL(node->data.target); + TEST_EQUAL_UI(node->data.devno, 0); free(node); memset(&fs, 0, sizeof(fs)); @@ -67,14 +64,14 @@ int main(void) sb.st_size = 1337; node = fstree_mknode(NULL, "blkdev", 6, NULL, &sb); - assert((char *)node->name >= (char *)node->payload); - assert(strcmp(node->name, "blkdev") == 0); - assert(node->uid == sb.st_uid); - assert(node->gid == sb.st_gid); - assert(node->mode == sb.st_mode); - assert(node->link_count == 1); - assert(node->data.devno == sb.st_rdev); - assert(node->parent == NULL); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_STR_EQUAL(node->name, "blkdev"); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->link_count, 1); + TEST_EQUAL_UI(node->data.devno, sb.st_rdev); + TEST_NULL(node->parent); free(node); memset(&fs, 0, sizeof(fs)); @@ -86,14 +83,14 @@ int main(void) sb.st_size = 1337; node = fstree_mknode(NULL, "chardev", 7, NULL, &sb); - assert((char *)node->name >= (char *)node->payload); - assert(strcmp(node->name, "chardev") == 0); - assert(node->uid == sb.st_uid); - assert(node->gid == sb.st_gid); - assert(node->mode == sb.st_mode); - assert(node->link_count == 1); - assert(node->data.devno == sb.st_rdev); - assert(node->parent == NULL); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_STR_EQUAL(node->name, "chardev"); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, sb.st_mode); + TEST_EQUAL_UI(node->link_count, 1); + TEST_EQUAL_UI(node->data.devno, sb.st_rdev); + TEST_NULL(node->parent); free(node); return EXIT_SUCCESS; diff --git a/tests/mknode_slink.c b/tests/mknode_slink.c index bcb28f0..19fc8f2 100644 --- a/tests/mknode_slink.c +++ b/tests/mknode_slink.c @@ -7,10 +7,7 @@ #include "config.h" #include "fstree.h" - -#include <stdlib.h> -#include <assert.h> -#include <string.h> +#include "test.h" int main(void) { @@ -27,29 +24,29 @@ int main(void) sb.st_size = 1337; node = fstree_mknode(NULL, "symlink", 7, "target", &sb); - assert(node->uid == sb.st_uid); - assert(node->gid == sb.st_gid); - assert(node->mode == (S_IFLNK | 0777)); - assert(node->link_count == 1); - assert(node->parent == NULL); - assert((char *)node->name >= (char *)node->payload); - assert(node->data.target >= (char *)node->payload); - assert(node->data.target >= node->name + 8); - assert(strcmp(node->name, "symlink") == 0); - assert(strcmp(node->data.target, "target") == 0); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, S_IFLNK | 0777); + TEST_EQUAL_UI(node->link_count, 1); + TEST_NULL(node->parent); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_ASSERT(node->data.target >= (char *)node->payload); + TEST_ASSERT(node->data.target >= node->name + 8); + TEST_STR_EQUAL(node->name, "symlink"); + TEST_STR_EQUAL(node->data.target, "target"); free(node); node = fstree_mknode(NULL, "symlink", 7, "", &sb); - assert(node->uid == sb.st_uid); - assert(node->gid == sb.st_gid); - assert(node->mode == (S_IFLNK | 0777)); - assert(node->link_count == 1); - assert(node->parent == NULL); - assert((char *)node->name >= (char *)node->payload); - assert(node->data.target >= (char *)node->payload); - assert(node->data.target >= node->name + 8); - assert(strcmp(node->name, "symlink") == 0); - assert(node->data.target[0] == '\0'); + TEST_EQUAL_UI(node->uid, sb.st_uid); + TEST_EQUAL_UI(node->gid, sb.st_gid); + TEST_EQUAL_UI(node->mode, S_IFLNK | 0777); + TEST_EQUAL_UI(node->link_count, 1); + TEST_NULL(node->parent); + TEST_ASSERT((char *)node->name >= (char *)node->payload); + TEST_ASSERT(node->data.target >= (char *)node->payload); + TEST_ASSERT(node->data.target >= node->name + 8); + TEST_STR_EQUAL(node->name, "symlink"); + TEST_STR_EQUAL(node->data.target, ""); free(node); return EXIT_SUCCESS; diff --git a/tests/rbtree.c b/tests/rbtree.c index 1c5ab4d..fc607a5 100644 --- a/tests/rbtree.c +++ b/tests/rbtree.c @@ -6,12 +6,8 @@ */ #include "config.h" -#include <stdlib.h> -#include <assert.h> -#include <string.h> -#include <stdio.h> - #include "rbtree.h" +#include "test.h" static int key_compare(const void *a, const void *b) { @@ -70,14 +66,14 @@ static void check_binary_tree_dfs(rbtree_node_t *n) if (n->left != NULL) { cmp = rbtree_node_key(n->left); - assert(key_compare(cmp, key) < 0); + TEST_ASSERT(key_compare(cmp, key) < 0); check_binary_tree_dfs(n->left); } if (n->right != NULL) { cmp = rbtree_node_key(n->right); - assert(key_compare(cmp, key) > 0); + TEST_ASSERT(key_compare(cmp, key) > 0); check_binary_tree_dfs(n->right); } @@ -86,8 +82,8 @@ static void check_binary_tree_dfs(rbtree_node_t *n) static void check_colors_dfs(rbtree_node_t *n) { if (n->is_red) { - assert(n->left == NULL || !n->left->is_red); - assert(n->right == NULL || !n->right->is_red); + TEST_ASSERT(n->left == NULL || !n->left->is_red); + TEST_ASSERT(n->right == NULL || !n->right->is_red); } if (n->left != NULL) @@ -104,7 +100,7 @@ static void check_black_depth_dfs(rbtree_node_t *n, size_t ref, counter += 1; if (n->left == NULL || n->right == NULL) - assert(counter == ref); + TEST_EQUAL_UI(counter, ref); if (n->left != NULL) check_black_depth_dfs(n->left, ref, counter); @@ -121,37 +117,37 @@ int main(void) sqfs_u64 value; rbtree_t rb; - assert(rbtree_init(&rb, sizeof(sqfs_s32), - sizeof(sqfs_u64), key_compare) == 0); + TEST_ASSERT(rbtree_init(&rb, sizeof(sqfs_s32), + sizeof(sqfs_u64), key_compare) == 0); count = 0; for (key = -1000; key < 1000; ++key) { /* lookup of current key must fail prior to insert */ - assert(rbtree_lookup(&rb, &key) == NULL); + TEST_NULL(rbtree_lookup(&rb, &key)); /* previous key/value pairs must still be there */ for (key2 = -1000; key2 < key; ++key2) { n = rbtree_lookup(&rb, &key2); - assert(n != NULL); + TEST_NOT_NULL(n); value = *((sqfs_u64 *)rbtree_node_value(n)); - assert((sqfs_u64)(key2 + 10000) == value); + TEST_EQUAL_UI((sqfs_u64)(key2 + 10000), value); } /* insert key value pair */ value = key + 10000; - assert(rbtree_insert(&rb, &key, &value) == 0); + TEST_ASSERT(rbtree_insert(&rb, &key, &value) == 0); count += 1; /* check if the tree has the right number of nodes */ - assert(count_nodes_dfs(rb.root) == count); + TEST_EQUAL_UI(count_nodes_dfs(rb.root), count); /* check if it is still a binary tree */ check_binary_tree_dfs(rb.root); /* root node must be black. Every red node must have black children. */ - assert(!rb.root->is_red); + TEST_ASSERT(!rb.root->is_red); check_colors_dfs(rb.root); /* every path from the root to a leave must have @@ -163,13 +159,13 @@ int main(void) twice as long as the shortest. */ mind = min_depth(rb.root); maxd = max_depth(rb.root); - assert(maxd <= mind * 2); + TEST_ASSERT(maxd <= mind * 2); /* lookup of current key must work after insert */ n = rbtree_lookup(&rb, &key); - assert(n != NULL); + TEST_NOT_NULL(n); value = *((sqfs_u64 *)rbtree_node_value(n)); - assert((sqfs_u64)(key + 10000) == value); + TEST_EQUAL_UI((sqfs_u64)(key + 10000), value); } rbtree_cleanup(&rb); diff --git a/tests/str_table.c b/tests/str_table.c index 4e306b5..0935c89 100644 --- a/tests/str_table.c +++ b/tests/str_table.c @@ -6,13 +6,9 @@ */ #include "config.h" -#include <stdlib.h> -#include <assert.h> -#include <string.h> -#include <stdio.h> - #include "str_table.h" #include "compat.h" +#include "test.h" #define STR(x) #x #define STRVALUE(x) STR(x) @@ -29,12 +25,7 @@ static int read_strings(void) FILE *fp; int i; - fp = fopen("words.txt", "r"); - - if (fp == NULL) { - perror("words.txt"); - return -1; - } + fp = test_open_read("words.txt"); for (i = 0; i < 1000; ++i) { line = NULL; @@ -64,41 +55,39 @@ int main(void) size_t i, j, idx; const char *str; - assert(chdir(TEST_PATH) == 0); + TEST_ASSERT(chdir(TEST_PATH) == 0); if (read_strings()) return EXIT_FAILURE; - assert(str_table_init(&table, 64) == 0); + TEST_ASSERT(str_table_init(&table, 64) == 0); for (i = 0; i < 1000; ++i) { - assert(str_table_get_index(&table, strings[i], &idx) == 0); + TEST_ASSERT(str_table_get_index(&table, strings[i], &idx) == 0); - assert(idx == i); + TEST_EQUAL_UI(idx, i); for (j = 0; j <= i; ++j) { str = str_table_get_string(&table, j); - assert(str != NULL); - assert(str != strings[i]); - assert(strcmp(str, strings[j]) == 0); + TEST_NOT_NULL(str); + TEST_ASSERT(str != strings[i]); + TEST_STR_EQUAL(str, strings[j]); } - for (; j < 1000; ++j) { - str = str_table_get_string(&table, j); - assert(str == NULL); - } + for (; j < 1000; ++j) + TEST_NULL(str_table_get_string(&table, j)); } for (i = 0; i < 1000; ++i) { - assert(str_table_get_index(&table, strings[i], &idx) == 0); - assert(idx == i); + TEST_ASSERT(str_table_get_index(&table, strings[i], &idx) == 0); + TEST_EQUAL_UI(idx, i); str = str_table_get_string(&table, i); - assert(str != NULL); - assert(str != strings[i]); - assert(strcmp(str, strings[i]) == 0); + TEST_NOT_NULL(str); + TEST_ASSERT(str != strings[i]); + TEST_STR_EQUAL(str, strings[i]); } str_table_cleanup(&table); diff --git a/tests/tar_gnu.c b/tests/tar_gnu.c index de3af5b..9d0b010 100644 --- a/tests/tar_gnu.c +++ b/tests/tar_gnu.c @@ -8,28 +8,13 @@ #include "tar.h" -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include "test.h" #define STR(x) #x #define STRVALUE(x) STR(x) #define TEST_PATH STRVALUE(TESTPATH) -static FILE *open_read(const char *path) -{ - FILE *fp = fopen(path, "rb"); - - if (fp == NULL) { - perror(path); - exit(EXIT_FAILURE); - } - - return fp; -} - static const char *filename = "012345678901234567890123456789/012345678901234567890123456789/" "012345678901234567890123456789/012345678901234567890123456789/" @@ -41,118 +26,118 @@ int main(void) char buffer[6]; FILE *fp; - assert(chdir(TEST_PATH) == 0); - - fp = open_read("format-acceptance/gnu.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542905892); - assert(hdr.mtime == 1542905892); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data0", fp, buffer, 5) == 0); + TEST_ASSERT(chdir(TEST_PATH) == 0); + + fp = test_open_read("format-acceptance/gnu.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1542905892); + TEST_EQUAL_UI(hdr.mtime, 1542905892); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("format-acceptance/gnu-g.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 013375560044); - assert(hdr.mtime == 013375560044); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data1", fp, buffer, 5) == 0); + fp = test_open_read("format-acceptance/gnu-g.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 013375560044); + TEST_EQUAL_UI(hdr.mtime, 013375560044); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data1", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("file-size/gnu.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 8589934592); - assert(hdr.sb.st_mtime == 013375730126); - assert(hdr.mtime == 013375730126); - assert(strcmp(hdr.name, "big-file.bin") == 0); - assert(!hdr.unknown_record); + fp = test_open_read("file-size/gnu.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 8589934592); + TEST_EQUAL_UI(hdr.sb.st_mtime, 013375730126); + TEST_EQUAL_UI(hdr.mtime, 013375730126); + TEST_STR_EQUAL(hdr.name, "big-file.bin"); + TEST_ASSERT(!hdr.unknown_record); clear_header(&hdr); fclose(fp); - fp = open_read("user-group-largenum/gnu.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 0x80000000); - assert(hdr.sb.st_gid == 0x80000000); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 013376036700); - assert(hdr.mtime == 013376036700); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data2", fp, buffer, 5) == 0); + fp = test_open_read("user-group-largenum/gnu.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 0x80000000); + TEST_EQUAL_UI(hdr.sb.st_gid, 0x80000000); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 013376036700); + TEST_EQUAL_UI(hdr.mtime, 013376036700); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data2", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("large-mtime/gnu.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); + fp = test_open_read("large-mtime/gnu.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); #if SIZEOF_TIME_T < 8 - assert(hdr.sb.st_mtime == INT32_MAX); + TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX); #else - assert(hdr.sb.st_mtime == 8589934592L); + TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L); #endif - assert(hdr.mtime == 8589934592L); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data3", fp, buffer, 5) == 0); + TEST_EQUAL_UI(hdr.mtime, 8589934592L); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data3", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("negative-mtime/gnu.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == -315622800); - assert(hdr.mtime == -315622800); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data4", fp, buffer, 5) == 0); + fp = test_open_read("negative-mtime/gnu.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_I(hdr.sb.st_mtime, -315622800); + TEST_EQUAL_I(hdr.mtime, -315622800); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data4", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("long-paths/gnu.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542909670); - assert(hdr.mtime == 1542909670); - assert(strcmp(hdr.name, filename) == 0); - assert(!hdr.unknown_record); - assert(read_retry("data5", fp, buffer, 5) == 0); + fp = test_open_read("long-paths/gnu.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1542909670); + TEST_EQUAL_UI(hdr.mtime, 1542909670); + TEST_STR_EQUAL(hdr.name, filename); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data5", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); diff --git a/tests/tar_pax.c b/tests/tar_pax.c index 8134591..f2e4c5f 100644 --- a/tests/tar_pax.c +++ b/tests/tar_pax.c @@ -7,29 +7,13 @@ #include "config.h" #include "tar.h" - -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include "test.h" #define STR(x) #x #define STRVALUE(x) STR(x) #define TEST_PATH STRVALUE(TESTPATH) -static FILE *open_read(const char *path) -{ - FILE *fp = fopen(path, "rb"); - - if (fp == NULL) { - perror(path); - exit(EXIT_FAILURE); - } - - return fp; -} - static const char *filename = "012345678901234567890123456789/012345678901234567890123456789/" "012345678901234567890123456789/012345678901234567890123456789/" @@ -41,102 +25,102 @@ int main(void) char buffer[6]; FILE *fp; - assert(chdir(TEST_PATH) == 0); - - fp = open_read("format-acceptance/pax.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542905892); - assert(hdr.mtime == 1542905892); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data0", fp, buffer, 5) == 0); + TEST_ASSERT(chdir(TEST_PATH) == 0); + + fp = test_open_read("format-acceptance/pax.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1542905892); + TEST_EQUAL_UI(hdr.mtime, 1542905892); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("file-size/pax.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 8589934592); - assert(hdr.sb.st_mtime == 1542959190); - assert(hdr.mtime == 1542959190); - assert(strcmp(hdr.name, "big-file.bin") == 0); - assert(!hdr.unknown_record); + fp = test_open_read("file-size/pax.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 8589934592); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1542959190); + TEST_EQUAL_UI(hdr.mtime, 1542959190); + TEST_STR_EQUAL(hdr.name, "big-file.bin"); + TEST_ASSERT(!hdr.unknown_record); clear_header(&hdr); fclose(fp); - fp = open_read("user-group-largenum/pax.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 2147483648); - assert(hdr.sb.st_gid == 2147483648); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 013376036700); - assert(hdr.mtime == 013376036700); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data1", fp, buffer, 5) == 0); + fp = test_open_read("user-group-largenum/pax.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 2147483648); + TEST_EQUAL_UI(hdr.sb.st_gid, 2147483648); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 013376036700); + TEST_EQUAL_UI(hdr.mtime, 013376036700); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data1", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("large-mtime/pax.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); + fp = test_open_read("large-mtime/pax.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); #if SIZEOF_TIME_T < 8 - assert(hdr.sb.st_mtime == INT32_MAX); + TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX); #else - assert(hdr.sb.st_mtime == 8589934592L); + TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L); #endif - assert(hdr.mtime == 8589934592L); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data2", fp, buffer, 5) == 0); + TEST_EQUAL_UI(hdr.mtime, 8589934592L); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data2", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("negative-mtime/pax.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == -315622800); - assert(hdr.mtime == -315622800); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data3", fp, buffer, 5) == 0); + fp = test_open_read("negative-mtime/pax.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_I(hdr.sb.st_mtime, -315622800); + TEST_EQUAL_UI(hdr.mtime, -315622800); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data3", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("long-paths/pax.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542909670); - assert(hdr.mtime == 1542909670); - assert(strcmp(hdr.name, filename) == 0); - assert(!hdr.unknown_record); - assert(read_retry("data4", fp, buffer, 5) == 0); + fp = test_open_read("long-paths/pax.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1542909670); + TEST_EQUAL_UI(hdr.mtime, 1542909670); + TEST_STR_EQUAL(hdr.name, filename); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data4", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); diff --git a/tests/tar_sparse_gnu.c b/tests/tar_sparse_gnu.c index 9b28b17..efbd8b8 100644 --- a/tests/tar_sparse_gnu.c +++ b/tests/tar_sparse_gnu.c @@ -7,126 +7,110 @@ #include "config.h" #include "tar.h" - -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include "test.h" #define STR(x) #x #define STRVALUE(x) STR(x) #define TEST_PATH STRVALUE(TESTPATH) -static FILE *open_read(const char *path) -{ - FILE *fp = fopen(path, "rb"); - - if (fp == NULL) { - perror(path); - exit(EXIT_FAILURE); - } - - return fp; -} - int main(void) { tar_header_decoded_t hdr; sparse_map_t *sparse; FILE *fp; - assert(chdir(TEST_PATH) == 0); + TEST_ASSERT(chdir(TEST_PATH) == 0); - fp = open_read("sparse-files/gnu-small.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 524288); - assert(hdr.actual_size == 524288); - assert(hdr.record_size == 8192); - assert(strcmp(hdr.name, "input.bin") == 0); - assert(!hdr.unknown_record); + fp = test_open_read("sparse-files/gnu-small.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 524288); + TEST_EQUAL_UI(hdr.actual_size, 524288); + TEST_EQUAL_UI(hdr.record_size, 8192); + TEST_STR_EQUAL(hdr.name, "input.bin"); + TEST_ASSERT(!hdr.unknown_record); sparse = hdr.sparse; - assert(sparse != NULL); - assert(sparse->offset == 0); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 0); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 262144); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 262144); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 524288); - assert(sparse->count == 0); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 524288); + TEST_EQUAL_UI(sparse->count, 0); - assert(sparse->next == NULL); + TEST_NULL(sparse->next); clear_header(&hdr); fclose(fp); - fp = open_read("sparse-files/gnu.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 2097152); - assert(hdr.actual_size == 2097152); - assert(hdr.record_size == 32768); - assert(strcmp(hdr.name, "input.bin") == 0); - assert(!hdr.unknown_record); + fp = test_open_read("sparse-files/gnu.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 2097152); + TEST_EQUAL_UI(hdr.actual_size, 2097152); + TEST_EQUAL_UI(hdr.record_size, 32768); + TEST_STR_EQUAL(hdr.name, "input.bin"); + TEST_ASSERT(!hdr.unknown_record); sparse = hdr.sparse; - assert(sparse != NULL); - assert(sparse->offset == 0); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 0); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 262144); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 262144); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 524288); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 524288); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 786432); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 786432); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1048576); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1048576); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1310720); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1310720); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1572864); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1572864); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1835008); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1835008); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 2097152); - assert(sparse->count == 0); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 2097152); + TEST_EQUAL_UI(sparse->count, 0); sparse = sparse->next; - assert(sparse == NULL); + TEST_NULL(sparse); clear_header(&hdr); fclose(fp); diff --git a/tests/tar_sparse_gnu1.c b/tests/tar_sparse_gnu1.c index db812a0..9bfd5b5 100644 --- a/tests/tar_sparse_gnu1.c +++ b/tests/tar_sparse_gnu1.c @@ -7,95 +7,79 @@ #include "config.h" #include "tar.h" - -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include "test.h" #define STR(x) #x #define STRVALUE(x) STR(x) #define TEST_PATH STRVALUE(TESTPATH) -static FILE *open_read(const char *path) -{ - FILE *fp = fopen(path, "rb"); - - if (fp == NULL) { - perror(path); - exit(EXIT_FAILURE); - } - - return fp; -} - int main(void) { tar_header_decoded_t hdr; sparse_map_t *sparse; FILE *fp; - assert(chdir(TEST_PATH) == 0); + TEST_ASSERT(chdir(TEST_PATH) == 0); - fp = open_read("sparse-files/pax-gnu0-0.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 2097152); - assert(hdr.actual_size == 2097152); - assert(hdr.record_size == 32768); - assert(strcmp(hdr.name, "input.bin") == 0); - assert(!hdr.unknown_record); + fp = test_open_read("sparse-files/pax-gnu0-0.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 2097152); + TEST_EQUAL_UI(hdr.actual_size, 2097152); + TEST_EQUAL_UI(hdr.record_size, 32768); + TEST_STR_EQUAL(hdr.name, "input.bin"); + TEST_ASSERT(!hdr.unknown_record); sparse = hdr.sparse; - assert(sparse != NULL); - assert(sparse->offset == 0); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 0); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 262144); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 262144); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 524288); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 524288); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 786432); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 786432); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1048576); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1048576); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1310720); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1310720); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1572864); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1572864); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1835008); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1835008); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 2097152); - assert(sparse->count == 0); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 2097152); + TEST_EQUAL_UI(sparse->count, 0); sparse = sparse->next; - assert(sparse == NULL); + TEST_NULL(sparse); clear_header(&hdr); fclose(fp); diff --git a/tests/tar_sparse_gnu2.c b/tests/tar_sparse_gnu2.c index 4c8b860..84a18ec 100644 --- a/tests/tar_sparse_gnu2.c +++ b/tests/tar_sparse_gnu2.c @@ -7,157 +7,141 @@ #include "config.h" #include "tar.h" - -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include "test.h" #define STR(x) #x #define STRVALUE(x) STR(x) #define TEST_PATH STRVALUE(TESTPATH) -static FILE *open_read(const char *path) -{ - FILE *fp = open(path, O_RDONLY); - - if (fp == NULL) { - perror(path); - exit(EXIT_FAILURE); - } - - return fp; -} - int main(void) { tar_header_decoded_t hdr; sparse_map_t *sparse; FILE *fp; - assert(chdir(TEST_PATH) == 0); + TEST_ASSERT(chdir(TEST_PATH) == 0); - fp = open_read("sparse-files/pax-gnu0-1.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 2097152); - assert(hdr.actual_size == 2097152); - assert(hdr.record_size == 32768); - assert(strcmp(hdr.name, "input.bin") == 0); - assert(!hdr.unknown_record); + fp = test_open_read("sparse-files/pax-gnu0-1.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 2097152); + TEST_EQUAL_UI(hdr.actual_size, 2097152); + TEST_EQUAL_UI(hdr.record_size, 32768); + TEST_STR_EQUAL(hdr.name, "input.bin"); + TEST_ASSERT(!hdr.unknown_record); sparse = hdr.sparse; - assert(sparse != NULL); - assert(sparse->offset == 0); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 0); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 262144); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 262144); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 524288); - assert(sparse->count == 4096); + TSET_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 524288); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 786432); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 786432); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1048576); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1048576); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1310720); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1310720); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1572864); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1572864); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1835008); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1835008); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 2097152); - assert(sparse->count == 0); + TEST_NOT_NULL(sparse != NULL); + TEST_EQUAL_UI(sparse->offset, 2097152); + TEST_EQUAL_UI(sparse->count, 0); sparse = sparse->next; - assert(sparse == NULL); + TEST_NULL(sparse); clear_header(&hdr); fclose(fp); - fp = open_read("sparse-files/pax-gnu1-0.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 2097152); - assert(hdr.actual_size == 2097152); - assert(hdr.record_size == 32768); - assert(strcmp(hdr.name, "input.bin") == 0); - assert(!hdr.unknown_record); + fp = test_open_read("sparse-files/pax-gnu1-0.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 2097152); + TEST_EQUAL_UI(hdr.actual_size, 2097152); + TEST_EQUAL_UI(hdr.record_size, 32768); + TEST_STR_EQUAL(hdr.name, "input.bin"); + TEST_ASSERT(!hdr.unknown_record); sparse = hdr.sparse; - assert(sparse != NULL); - assert(sparse->offset == 0); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 0); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 262144); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 262144); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 524288); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 524288); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 786432); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 786432); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1048576); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1048576); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1310720); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1310720); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1572864); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1572864); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 1835008); - assert(sparse->count == 4096); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 1835008); + TEST_EQUAL_UI(sparse->count, 4096); sparse = sparse->next; - assert(sparse != NULL); - assert(sparse->offset == 2097152); - assert(sparse->count == 0); + TEST_NOT_NULL(sparse); + TEST_EQUAL_UI(sparse->offset, 2097152); + TEST_EQUAL_UI(sparse->count, 0); sparse = sparse->next; - assert(sparse == NULL); + TEST_NULL(sparse); clear_header(&hdr); fclose(fp); diff --git a/tests/tar_ustar.c b/tests/tar_ustar.c index e015989..8d4c828 100644 --- a/tests/tar_ustar.c +++ b/tests/tar_ustar.c @@ -7,29 +7,13 @@ #include "config.h" #include "tar.h" - -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include "test.h" #define STR(x) #x #define STRVALUE(x) STR(x) #define TEST_PATH STRVALUE(TESTPATH) -static FILE *open_read(const char *path) -{ - FILE *fp = fopen(path, "rb"); - - if (fp == NULL) { - perror(path); - exit(EXIT_FAILURE); - } - - return fp; -} - static const char *filename = "012345678901234567890123456789/012345678901234567890123456789/" "012345678901234567890123456789/012345678901234567890123456789/" @@ -41,118 +25,118 @@ int main(void) char buffer[6]; FILE *fp; - assert(chdir(TEST_PATH) == 0); - - fp = open_read("format-acceptance/ustar.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542905892); - assert(hdr.mtime == 1542905892); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data0", fp, buffer, 5) == 0); + TEST_ASSERT(chdir(TEST_PATH) == 0); + + fp = test_open_read("format-acceptance/ustar.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1542905892); + TEST_EQUAL_UI(hdr.mtime, 1542905892); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("format-acceptance/ustar-pre-posix.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542905892); - assert(hdr.mtime == 1542905892); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data1", fp, buffer, 5) == 0); + fp = test_open_read("format-acceptance/ustar-pre-posix.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1542905892); + TEST_EQUAL_UI(hdr.mtime, 1542905892); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data1", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("format-acceptance/v7.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542905892); - assert(hdr.mtime == 1542905892); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data2", fp, buffer, 5) == 0); + fp = test_open_read("format-acceptance/v7.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1542905892); + TEST_EQUAL_UI(hdr.mtime, 1542905892); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data2", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("file-size/12-digit.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 8589934592); - assert(hdr.sb.st_mtime == 013375730126); - assert(hdr.mtime == 013375730126); - assert(strcmp(hdr.name, "big-file.bin") == 0); - assert(!hdr.unknown_record); + fp = test_open_read("file-size/12-digit.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 8589934592); + TEST_EQUAL_UI(hdr.sb.st_mtime, 013375730126); + TEST_EQUAL_UI(hdr.mtime, 013375730126); + TEST_STR_EQUAL(hdr.name, "big-file.bin"); + TEST_ASSERT(!hdr.unknown_record); clear_header(&hdr); fclose(fp); - fp = open_read("user-group-largenum/8-digit.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 8388608); - assert(hdr.sb.st_gid == 8388608); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 013376036700); - assert(hdr.mtime == 013376036700); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data3", fp, buffer, 5) == 0); + fp = test_open_read("user-group-largenum/8-digit.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 8388608); + TEST_EQUAL_UI(hdr.sb.st_gid, 8388608); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 013376036700); + TEST_EQUAL_UI(hdr.mtime, 013376036700); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data3", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("large-mtime/12-digit.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); + fp = test_open_read("large-mtime/12-digit.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); #if SIZEOF_TIME_T < 8 - assert(hdr.sb.st_mtime == INT32_MAX); + TEST_EQUAL_UI(hdr.sb.st_mtime, INT32_MAX); #else - assert(hdr.sb.st_mtime == 8589934592L); + TEST_EQUAL_UI(hdr.sb.st_mtime, 8589934592L); #endif - assert(hdr.mtime == 8589934592L); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data4", fp, buffer, 5) == 0); + TEST_EQUAL_UI(hdr.mtime, 8589934592L); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data4", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); - fp = open_read("long-paths/ustar.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1542909670); - assert(hdr.mtime == 1542909670); - assert(strcmp(hdr.name, filename) == 0); - assert(!hdr.unknown_record); - assert(read_retry("data5", fp, buffer, 5) == 0); + fp = test_open_read("long-paths/ustar.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1542909670); + TEST_EQUAL_UI(hdr.mtime, 1542909670); + TEST_STR_EQUAL(hdr.name, filename); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data5", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); clear_header(&hdr); fclose(fp); diff --git a/tests/tar_xattr_bsd.c b/tests/tar_xattr_bsd.c index 0741511..8b5f1b0 100644 --- a/tests/tar_xattr_bsd.c +++ b/tests/tar_xattr_bsd.c @@ -7,56 +7,40 @@ #include "config.h" #include "tar.h" - -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include "test.h" #define STR(x) #x #define STRVALUE(x) STR(x) #define TEST_PATH STRVALUE(TESTPATH) -static FILE *open_read(const char *path) -{ - FILE *fp = fopen(path, "rb"); - - if (fp == NULL) { - perror(path); - exit(EXIT_FAILURE); - } - - return fp; -} - int main(void) { tar_header_decoded_t hdr; char buffer[6]; FILE *fp; - assert(chdir(TEST_PATH) == 0); - - fp = open_read("xattr/xattr-libarchive.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1543094477); - assert(hdr.mtime == 1543094477); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data0", fp, buffer, 5) == 0); + TEST_ASSERT(chdir(TEST_PATH) == 0); + + fp = test_open_read("xattr/xattr-libarchive.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477); + TEST_EQUAL_UI(hdr.mtime, 1543094477); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); - assert(hdr.xattr != NULL); - assert(strcmp(hdr.xattr->key, "user.mime_type") == 0); - assert(strcmp((const char *)hdr.xattr->value, "text/plain") == 0); - assert(hdr.xattr->value_len == 10); - assert(hdr.xattr->next == NULL); + TEST_NOT_NULL(hdr.xattr); + TEST_STR_EQUAL(hdr.xattr->key, "user.mime_type"); + TEST_STR_EQUAL((const char *)hdr.xattr->value, "text/plain"); + TEST_EQUAL_UI(hdr.xattr->value_len, 10); + TEST_NULL(hdr.xattr->next); clear_header(&hdr); fclose(fp); diff --git a/tests/tar_xattr_schily.c b/tests/tar_xattr_schily.c index f562b43..e1bf3f3 100644 --- a/tests/tar_xattr_schily.c +++ b/tests/tar_xattr_schily.c @@ -7,56 +7,40 @@ #include "config.h" #include "tar.h" - -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include "test.h" #define STR(x) #x #define STRVALUE(x) STR(x) #define TEST_PATH STRVALUE(TESTPATH) -static FILE *open_read(const char *path) -{ - FILE *fp = fopen(path, "rb"); - - if (fp == NULL) { - perror(path); - exit(EXIT_FAILURE); - } - - return fp; -} - int main(void) { tar_header_decoded_t hdr; char buffer[6]; FILE *fp; - assert(chdir(TEST_PATH) == 0); - - fp = open_read("xattr/xattr-schily.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1543094477); - assert(hdr.mtime == 1543094477); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data0", fp, buffer, 5) == 0); + TEST_ASSERT(chdir(TEST_PATH) == 0); + + fp = test_open_read("xattr/xattr-schily.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477); + TEST_EQUAL_UI(hdr.mtime, 1543094477); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); - assert(hdr.xattr != NULL); - assert(strcmp(hdr.xattr->key, "user.mime_type") == 0); - assert(strcmp((const char *)hdr.xattr->value, "text/plain") == 0); - assert(hdr.xattr->value_len == 10); - assert(hdr.xattr->next == NULL); + TEST_NOT_NULL(hdr.xattr); + TEST_STR_EQUAL(hdr.xattr->key, "user.mime_type"); + TEST_STR_EQUAL((const char *)hdr.xattr->value, "text/plain"); + TEST_EQUAL_UI(hdr.xattr->value_len, 10); + TEST_NULL(hdr.xattr->next); clear_header(&hdr); fclose(fp); diff --git a/tests/tar_xattr_schily_bin.c b/tests/tar_xattr_schily_bin.c index d8d5161..29587f6 100644 --- a/tests/tar_xattr_schily_bin.c +++ b/tests/tar_xattr_schily_bin.c @@ -7,29 +7,13 @@ #include "config.h" #include "tar.h" - -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include "test.h" #define STR(x) #x #define STRVALUE(x) STR(x) #define TEST_PATH STRVALUE(TESTPATH) -static FILE *open_read(const char *path) -{ - FILE *fp = fopen(path, "rb"); - - if (fp == NULL) { - perror(path); - exit(EXIT_FAILURE); - } - - return fp; -} - static const uint8_t value[] = { 0x00, 0x00, 0x00, 0x02, 0x00, 0x30, 0x00, 0x00, @@ -44,27 +28,27 @@ int main(void) char buffer[6]; FILE *fp; - assert(chdir(TEST_PATH) == 0); - - fp = open_read("xattr/xattr-schily-binary.tar"); - assert(read_header(fp, &hdr) == 0); - assert(hdr.sb.st_mode == (S_IFREG | 0644)); - assert(hdr.sb.st_uid == 01750); - assert(hdr.sb.st_gid == 01750); - assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 1543094477); - assert(hdr.mtime == 1543094477); - assert(strcmp(hdr.name, "input.txt") == 0); - assert(!hdr.unknown_record); - assert(read_retry("data0", fp, buffer, 5) == 0); + TEST_ASSERT(chdir(TEST_PATH) == 0); + + fp = test_open_read("xattr/xattr-schily-binary.tar"); + TEST_ASSERT(read_header(fp, &hdr) == 0); + TEST_EQUAL_UI(hdr.sb.st_mode, S_IFREG | 0644); + TEST_EQUAL_UI(hdr.sb.st_uid, 01750); + TEST_EQUAL_UI(hdr.sb.st_gid, 01750); + TEST_EQUAL_UI(hdr.sb.st_size, 5); + TEST_EQUAL_UI(hdr.sb.st_mtime, 1543094477); + TEST_EQUAL_UI(hdr.mtime, 1543094477); + TEST_STR_EQUAL(hdr.name, "input.txt"); + TEST_ASSERT(!hdr.unknown_record); + TEST_ASSERT(read_retry("data0", fp, buffer, 5) == 0); buffer[5] = '\0'; - assert(strcmp(buffer, "test\n") == 0); + TEST_STR_EQUAL(buffer, "test\n"); - assert(hdr.xattr != NULL); - assert(strcmp(hdr.xattr->key, "security.capability") == 0); - assert(hdr.xattr->value_len == sizeof(value)); - assert(memcmp(hdr.xattr->value, value, sizeof(value)) == 0); - assert(hdr.xattr->next == NULL); + TEST_NOT_NULL(hdr.xattr); + TEST_STR_EQUAL(hdr.xattr->key, "security.capability"); + TEST_EQUAL_UI(hdr.xattr->value_len, sizeof(value)); + TEST_ASSERT(memcmp(hdr.xattr->value, value, sizeof(value)) == 0); + TEST_NULL(hdr.xattr->next); clear_header(&hdr); fclose(fp); diff --git a/tests/test.h b/tests/test.h new file mode 100644 index 0000000..4e05dac --- /dev/null +++ b/tests/test.h @@ -0,0 +1,119 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * test.h + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#ifndef TEST_H +#define TEST_H + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <errno.h> + +#if defined(__GNUC__) || defined(__clang__) +# define ATTRIB_UNUSED __attribute__ ((unused)) +#else +# define ATTRIB_UNUSED +#endif + +static ATTRIB_UNUSED FILE *test_open_read(const char *path) +{ + FILE *fp = fopen(path, "rb"); + + if (fp == NULL) { + perror(path); + abort(); + } + + return fp; +} + +static ATTRIB_UNUSED void test_assert(const char *expr, int value, + int linenum) +{ + if (value == 0) { + fprintf(stderr, "%d: '%s' is false!\n", linenum, expr); + abort(); + } +} + +static ATTRIB_UNUSED void test_str_equal(const char *expr, const char *value, + const char *ref, int linenum) +{ + if (strcmp(value, ref) != 0) { + fprintf(stderr, + "%d: '%s' should be '%s', but actually is '%s'!\n", + linenum, expr, ref, value); + abort(); + } +} + +static ATTRIB_UNUSED void test_not_null(const void *value, const char *expr, + int linenum) +{ + if (value == NULL) { + fprintf(stderr, "%d: '%s' should not be NULL, but is!\n", + linenum, expr); + abort(); + } +} + +static ATTRIB_UNUSED void test_null(const void *value, const char *expr, + int linenum) +{ + if (value != NULL) { + fprintf(stderr, "%d: '%s' should be NULL, but is!\n", + linenum, expr); + abort(); + } +} + +static ATTRIB_UNUSED void test_equal_ul(const char *lhs, const char *rhs, + unsigned long lval, unsigned long rval, + int linenum) +{ + if (lval != rval) { + fprintf(stderr, "%d: %s (%lu) does not equal %s (%lu)!\n", + linenum, lhs, lval, rhs, rval); + abort(); + } +} + +static ATTRIB_UNUSED void test_equal_sl(const char *lhs, const char *rhs, + long lval, long rval, int linenum) +{ + if (lval != rval) { + fprintf(stderr, "%d: %s (%ld) does not equal %s (%ld)!\n", + linenum, lhs, lval, rhs, rval); + abort(); + } +} + +static ATTRIB_UNUSED void test_lt_ul(const char *lhs, const char *rhs, + unsigned long lval, unsigned long rval, + int linenum) +{ + if (lval >= rval) { + fprintf(stderr, "%d: %s (%lu) is not less than %s (%lu)!\n", + linenum, lhs, lval, rhs, rval); + abort(); + } +} + +#define TEST_STR_EQUAL(str, ref) test_str_equal(#str, str, ref, __LINE__) + +#define TEST_NULL(expr) test_null(expr, #expr, __LINE__) + +#define TEST_NOT_NULL(expr) test_not_null(expr, #expr, __LINE__) + +#define TEST_EQUAL_I(a, b) test_equal_sl(#a, #b, a, b, __LINE__) + +#define TEST_EQUAL_UI(a, b) test_equal_ul(#a, #b, a, b, __LINE__) + +#define TEST_LESS_THAN_UI(a, b) test_lt_ul(#a, #b, a, b, __LINE__) + +#define TEST_ASSERT(expr) test_assert(#expr, (expr), __LINE__) + +#endif /* TEST_H */ diff --git a/tests/xxhash.c b/tests/xxhash.c index f586481..a7ab4a9 100644 --- a/tests/xxhash.c +++ b/tests/xxhash.c @@ -6,11 +6,8 @@ */ #include "config.h" -#include <stdlib.h> -#include <string.h> -#include <stdio.h> - #include "util.h" +#include "test.h" static const struct { const char *plaintext; |