From: Tim Kientzle Date: Mon, 27 Jul 2009 03:40:50 +0000 (-0400) Subject: Portability refactoring of a few more libarchive tests. X-Git-Tag: v2.8.0~499 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2f08c532fc0f324ae166d4f555565b60c80b4d2;p=thirdparty%2Flibarchive.git Portability refactoring of a few more libarchive tests. SVN-Revision: 1284 --- diff --git a/libarchive/test/test_read_format_isorr_bz2.c b/libarchive/test/test_read_format_isorr_bz2.c index d01057419..1e5b51963 100644 --- a/libarchive/test/test_read_format_isorr_bz2.c +++ b/libarchive/test/test_read_format_isorr_bz2.c @@ -78,7 +78,7 @@ DEFINE_TEST(test_read_format_isorr_bz2) if (strcmp(".", archive_entry_pathname(ae)) == 0) { /* '.' root directory. */ - assert(S_ISDIR(archive_entry_stat(ae)->st_mode)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); assertEqualInt(2048, archive_entry_size(ae)); assertEqualInt(86401, archive_entry_mtime(ae)); assertEqualInt(0, archive_entry_mtime_nsec(ae)); @@ -91,7 +91,7 @@ DEFINE_TEST(test_read_format_isorr_bz2) } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { /* A directory. */ assertEqualString("dir", archive_entry_pathname(ae)); - assert(S_ISDIR(archive_entry_stat(ae)->st_mode)); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); assertEqualInt(2048, archive_entry_size(ae)); assertEqualInt(86401, archive_entry_mtime(ae)); assertEqualInt(86401, archive_entry_atime(ae)); @@ -101,7 +101,7 @@ DEFINE_TEST(test_read_format_isorr_bz2) } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { /* A regular file. */ assertEqualString("file", archive_entry_pathname(ae)); - assert(S_ISREG(archive_entry_stat(ae)->st_mode)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualInt(12345684, archive_entry_size(ae)); assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); @@ -120,7 +120,7 @@ DEFINE_TEST(test_read_format_isorr_bz2) * This test should tolerate that, since it's a * perfectly permissible thing for libarchive to do. */ assertEqualString("hardlink", archive_entry_pathname(ae)); - assert(S_ISREG(archive_entry_stat(ae)->st_mode)); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualString("file", archive_entry_hardlink(ae)); assertEqualInt(0, archive_entry_size_is_set(ae)); assertEqualInt(0, archive_entry_size(ae)); @@ -131,7 +131,7 @@ DEFINE_TEST(test_read_format_isorr_bz2) assertEqualInt(2, archive_entry_gid(ae)); } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { /* A symlink to the regular file. */ - assert(S_ISLNK(archive_entry_stat(ae)->st_mode)); + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); assertEqualString("file", archive_entry_symlink(ae)); assertEqualInt(0, archive_entry_size(ae)); assertEqualInt(172802, archive_entry_mtime(ae)); @@ -141,7 +141,7 @@ DEFINE_TEST(test_read_format_isorr_bz2) assertEqualInt(2, archive_entry_gid(ae)); } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { /* A symlink to /tmp (an absolute path) */ - assert(S_ISLNK(archive_entry_stat(ae)->st_mode)); + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); assertEqualString("/tmp", archive_entry_symlink(ae)); assertEqualInt(0, archive_entry_size(ae)); assertEqualInt(1, archive_entry_stat(ae)->st_nlink); @@ -149,7 +149,7 @@ DEFINE_TEST(test_read_format_isorr_bz2) assertEqualInt(2, archive_entry_gid(ae)); } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { /* A symlink to /tmp/.. (with a ".." component) */ - assert(S_ISLNK(archive_entry_stat(ae)->st_mode)); + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); assertEqualString("/tmp/..", archive_entry_symlink(ae)); assertEqualInt(0, archive_entry_size(ae)); assertEqualInt(1, archive_entry_stat(ae)->st_nlink); @@ -157,7 +157,7 @@ DEFINE_TEST(test_read_format_isorr_bz2) assertEqualInt(2, archive_entry_gid(ae)); } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { /* A symlink to a path with ".." and "." components */ - assert(S_ISLNK(archive_entry_stat(ae)->st_mode)); + assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); assertEqualString(".././../tmp", archive_entry_symlink(ae)); assertEqualInt(0, archive_entry_size(ae)); diff --git a/libarchive/test/test_read_format_mtree.c b/libarchive/test/test_read_format_mtree.c index 2bc774765..87205bee5 100644 --- a/libarchive/test/test_read_format_mtree.c +++ b/libarchive/test/test_read_format_mtree.c @@ -52,7 +52,7 @@ DEFINE_TEST(test_read_format_mtree) char buff[16]; struct archive_entry *ae; struct archive *a; - int fd; + FILE *f; /* * An access error occurred on some platform when mtree @@ -74,15 +74,15 @@ DEFINE_TEST(test_read_format_mtree) /* * Read "file", whose data is available on disk. */ - fd = open("file", O_WRONLY | O_CREAT | O_BINARY, 0777); - assert(fd >= 0); - assertEqualInt(3, write(fd, "hi\n", 3)); - close(fd); + f = fopen("file", "wb"); + assert(f != NULL); + assertEqualInt(3, fwrite("hi\n", 1, 3, f)); + fclose(f); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE); assertEqualString(archive_entry_pathname(ae), "file"); assertEqualInt(archive_entry_uid(ae), 18); - assert(S_ISREG(archive_entry_mode(ae))); + assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0123); assertEqualInt(archive_entry_size(ae), 3); assertEqualInt(3, archive_read_data(a, buff, 3)); @@ -90,7 +90,7 @@ DEFINE_TEST(test_read_format_mtree) assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir"); - assert(S_ISDIR(archive_entry_mode(ae))); + assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); assertEqualString(archive_entry_pathname(ae), "dir/file with space"); diff --git a/libarchive/test/test_read_format_tar.c b/libarchive/test/test_read_format_tar.c index 1c8ba1d98..2d6fcab55 100644 --- a/libarchive/test/test_read_format_tar.c +++ b/libarchive/test/test_read_format_tar.c @@ -101,9 +101,9 @@ static unsigned char archive1[] = { static void verify1(struct archive_entry *ae) { /* A hardlink is not a symlink. */ - assert(!S_ISLNK(archive_entry_mode(ae))); + assert(archive_entry_filetype(ae) != AE_IFLNK); /* Nor is it a directory. */ - assert(!S_ISDIR(archive_entry_mode(ae))); + assert(archive_entry_filetype(ae) != AE_IFDIR); assertEqualInt(archive_entry_mode(ae) & 0777, 0644); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); @@ -132,7 +132,7 @@ static unsigned char archive2[] = { static void verify2(struct archive_entry *ae) { - assert(S_ISLNK(archive_entry_mode(ae))); + assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); @@ -161,7 +161,7 @@ static unsigned char archive3[] = { static void verify3(struct archive_entry *ae) { - assert(S_ISCHR(archive_entry_mode(ae))); + assertEqualInt(archive_entry_filetype(ae), AE_IFCHR); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); @@ -190,7 +190,7 @@ static unsigned char archive4[] = { static void verify4(struct archive_entry *ae) { - assert(S_ISBLK(archive_entry_mode(ae))); + assertEqualInt(archive_entry_filetype(ae), AE_IFBLK); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); @@ -219,7 +219,7 @@ static unsigned char archive5[] = { static void verify5(struct archive_entry *ae) { - assert(S_ISDIR(archive_entry_mode(ae))); + assertEqualInt(archive_entry_filetype(ae), AE_IFDIR); assertEqualInt(archive_entry_mtime(ae), 1131430878); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), 1000); @@ -245,7 +245,7 @@ static unsigned char archive6[] = { static void verify6(struct archive_entry *ae) { - assert(S_ISFIFO(archive_entry_mode(ae))); + assertEqualInt(archive_entry_filetype(ae), AE_IFIFO); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); @@ -316,7 +316,7 @@ static unsigned char archiveK[] = { static void verifyK(struct archive_entry *ae) { - assert(S_ISLNK(archive_entry_mode(ae))); + assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); @@ -402,7 +402,7 @@ static unsigned char archivexL[] = { static void verifyxL(struct archive_entry *ae) { - assert(S_ISLNK(archive_entry_mode(ae))); + assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); assertEqualInt(archive_entry_mode(ae) & 0777, 0755); assertEqualInt(archive_entry_uid(ae), 1000); assertEqualInt(archive_entry_gid(ae), 1000); diff --git a/libarchive/test/test_read_large.c b/libarchive/test/test_read_large.c index 43a8f5e60..1e72d473a 100644 --- a/libarchive/test/test_read_large.c +++ b/libarchive/test/test_read_large.c @@ -38,6 +38,7 @@ DEFINE_TEST(test_read_large) size_t used; struct archive *a; struct archive_entry *entry; + FILE *f; for (i = 0; i < sizeof(testdata); i++) testdata[i] = (unsigned char)(rand()); @@ -52,11 +53,7 @@ DEFINE_TEST(test_read_large) assertA(0 == archive_write_header(a, entry)); archive_entry_free(entry); assertA(sizeof(testdata) == archive_write_data(a, testdata, sizeof(testdata))); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else assertA(0 == archive_write_finish(a)); -#endif assert(NULL != (a = archive_read_new())); assertA(0 == archive_read_support_format_all(a)); @@ -64,11 +61,7 @@ DEFINE_TEST(test_read_large) assertA(0 == archive_read_open_memory(a, buff, sizeof(buff))); assertA(0 == archive_read_next_header(a, &entry)); assertA(0 == archive_read_data_into_buffer(a, testdatacopy, sizeof(testdatacopy))); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else assertA(0 == archive_read_finish(a)); -#endif assert(0 == memcmp(testdata, testdatacopy, sizeof(testdata))); @@ -77,19 +70,15 @@ DEFINE_TEST(test_read_large) assertA(0 == archive_read_support_compression_all(a)); assertA(0 == archive_read_open_memory(a, buff, sizeof(buff))); assertA(0 == archive_read_next_header(a, &entry)); + // TODO: Provide a Windows-friendly version of this? assert(0 < (tmpfilefd = open(tmpfilename, O_WRONLY | O_CREAT | O_BINARY, 0755))); assertA(0 == archive_read_data_into_fd(a, tmpfilefd)); close(tmpfilefd); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else assertA(0 == archive_read_finish(a)); -#endif - tmpfilefd = open(tmpfilename, O_RDONLY | O_BINARY); - read(tmpfilefd, testdatacopy, sizeof(testdatacopy)); - close(tmpfilefd); - assert(0 == memcmp(testdata, testdatacopy, sizeof(testdata))); - unlink(tmpfilename); + f = fopen(tmpfilename, "rb"); + fread(testdatacopy, 1, sizeof(testdatacopy), f); + fclose(f); + assert(0 == memcmp(testdata, testdatacopy, sizeof(testdata))); }