diff options
author | kientzle <kientzle@FreeBSD.org> | 2008-01-01 22:28:04 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2008-01-01 22:28:04 +0000 |
commit | 02ff80aa514f0bbb5712a71b96f5593ada26bb80 (patch) | |
tree | 0719828e5aab493661568e13eaa8b2aa062e27da /lib/libarchive/test/test_write_format_cpio.c | |
parent | f89bbe213dfe121e5c9af00662285358ab07dc81 (diff) | |
download | FreeBSD-src-02ff80aa514f0bbb5712a71b96f5593ada26bb80.zip FreeBSD-src-02ff80aa514f0bbb5712a71b96f5593ada26bb80.tar.gz |
Extensive improvements to the libarchive_test test program that
exercises and verifies the libarchive APIs:
* Improved error reporting; hexdumps are now provided for
many file/memory content differences.
* Overall status more clearly counts "tests" and "assertions"
* Reference files can now be stored on disk instead of having
to be compiled into the test program itself. A couple of
tests have been converted to this more natural structure.
* Several memory leaks corrected so that leaks within libarchive
itself can be more easily detected and diagnosed.
* New test: GNU tar compatibility
* New test: Zip compatibility
* New test: Zero-byte writes to a compressed archive entry
* New test: archive_entry_strmode() format verification
* New test: mtree reader
* New test: write/read of large (2G - 1TB) entries to tar archives
(thanks to recent performance work, this test only requires a few seconds)
* New test: detailed format verification of cpio odc and newc writers
* Many minor additions/improvements to existing tests as well.
Diffstat (limited to 'lib/libarchive/test/test_write_format_cpio.c')
-rw-r--r-- | lib/libarchive/test/test_write_format_cpio.c | 70 |
1 files changed, 63 insertions, 7 deletions
diff --git a/lib/libarchive/test/test_write_format_cpio.c b/lib/libarchive/test/test_write_format_cpio.c index 886942e..5368e56 100644 --- a/lib/libarchive/test/test_write_format_cpio.c +++ b/lib/libarchive/test/test_write_format_cpio.c @@ -37,6 +37,7 @@ test_format(int (*set_format)(struct archive *)) size_t used; size_t buffsize = 1000000; char *buff; + int damaged = 0; buff = malloc(buffsize); @@ -67,6 +68,26 @@ test_format(int (*set_format)(struct archive *)) assertA(8 == archive_write_data(a, "12345678", 9)); /* + * Write another file to it. + */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_set_mtime(ae, 1, 10); + assert(1 == archive_entry_mtime(ae)); + assert(10 == archive_entry_mtime_nsec(ae)); + p = strdup("file2"); + archive_entry_copy_pathname(ae, p); + strcpy(p, "XXXX"); + free(p); + assertEqualString("file2", archive_entry_pathname(ae)); + archive_entry_set_mode(ae, S_IFREG | 0755); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + archive_entry_set_size(ae, 4); + + assertA(0 == archive_write_header(a, ae)); + archive_entry_free(ae); + assertA(4 == archive_write_data(a, "1234", 5)); + + /* * Write a directory to it. */ assert((ae = archive_entry_new()) != NULL); @@ -90,6 +111,22 @@ test_format(int (*set_format)(struct archive *)) #endif /* + * Damage the second entry to test the search-ahead recovery. + */ + { + int i; + for (i = 80; i < 150; i++) { + if (memcmp(buff + i, "07070", 5) == 0) { + damaged = 1; + buff[i] = 'X'; + break; + } + } + } + failure("Unable to locate the second header for damage-recovery test."); + assert(damaged = 1); + + /* * Now, read the data back. */ assert((a = archive_read_new()) != NULL); @@ -97,29 +134,48 @@ test_format(int (*set_format)(struct archive *)) assertA(0 == archive_read_support_compression_all(a)); assertA(0 == archive_read_open_memory(a, buff, used)); - assertA(0 == archive_read_next_header(a, &ae)); + assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assert(1 == archive_entry_mtime(ae)); + assertEqualInt(1, archive_entry_mtime(ae)); /* Not the same as above: cpio doesn't store hi-res times. */ assert(0 == archive_entry_mtime_nsec(ae)); assert(0 == archive_entry_atime(ae)); assert(0 == archive_entry_ctime(ae)); assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assert(8 == archive_entry_size(ae)); + assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); + assertEqualInt(8, archive_entry_size(ae)); assertA(8 == archive_read_data(a, filedata, 10)); assert(0 == memcmp(filedata, "12345678", 8)); /* + * Read the second file back. + */ + if (!damaged) { + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualInt(1, archive_entry_mtime(ae)); + /* Not the same as above: cpio doesn't store hi-res times. */ + assert(0 == archive_entry_mtime_nsec(ae)); + assert(0 == archive_entry_atime(ae)); + assert(0 == archive_entry_ctime(ae)); + assertEqualString("file2", archive_entry_pathname(ae)); + assert((S_IFREG | 0755) == archive_entry_mode(ae)); + assertEqualInt(4, archive_entry_size(ae)); + assertEqualIntA(a, 4, archive_read_data(a, filedata, 10)); + assert(0 == memcmp(filedata, "1234", 4)); + } + + /* * Read the dir entry back. */ - assertA(0 == archive_read_next_header(a, &ae)); - assert(11 == archive_entry_mtime(ae)); + assertEqualIntA(a, + damaged ? ARCHIVE_WARN : ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualInt(11, archive_entry_mtime(ae)); assert(0 == archive_entry_mtime_nsec(ae)); assert(0 == archive_entry_atime(ae)); assert(0 == archive_entry_ctime(ae)); assertEqualString("dir", archive_entry_pathname(ae)); - assert((S_IFDIR | 0755) == archive_entry_mode(ae)); + assertEqualInt((S_IFDIR | 0755), archive_entry_mode(ae)); assertEqualInt(0, archive_entry_size(ae)); assertEqualIntA(a, 0, archive_read_data(a, filedata, 10)); |