From: Nate Rosenblum Date: Fri, 5 Feb 2016 17:15:14 +0000 (-0800) Subject: Make assertions explicit in sparse tests X-Git-Tag: v3.1.901a~9^2~3^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fade3796228e1f75234bd0096a708f04d419f39b;p=thirdparty%2Flibarchive.git Make assertions explicit in sparse tests Instead of trying to special-case sparse data vs dense data detection in verify_sparse_file (by resetting the `data_blocks` if no holes are found), make the expected number of data blocks an explicit parameter. Simplifies a subsequently introduced test case; no functional changes. --- diff --git a/libarchive/test/test_sparse_basic.c b/libarchive/test/test_sparse_basic.c index 1541155fe..081fa3179 100644 --- a/libarchive/test/test_sparse_basic.c +++ b/libarchive/test/test_sparse_basic.c @@ -259,7 +259,7 @@ create_sparse_file(const char *path, const struct sparse *s) */ static void verify_sparse_file(struct archive *a, const char *path, - const struct sparse *sparse, int blocks) + const struct sparse *sparse, int blocks, int expected_data_blocks) { struct archive_entry *ae; const void *buff; @@ -288,9 +288,10 @@ verify_sparse_file(struct archive *a, const char *path, } total = offset + bytes_read; } - if (!hole && data_blocks == 1) - data_blocks = 0;/* There are no holes */ - assertEqualInt(blocks, data_blocks); + assertEqualInt(expected_data_blocks, data_blocks); + + if (blocks > 1) + assert(hole); /* There must be a hole if > 1 blocks were encoded */ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); archive_entry_free(ae); @@ -435,10 +436,11 @@ DEFINE_TEST(test_sparse_basic) */ assert((a = archive_read_disk_new()) != NULL); - verify_sparse_file(a, "file0", sparse_file0, 5); - verify_sparse_file(a, "file1", sparse_file1, 2); - verify_sparse_file(a, "file2", sparse_file2, 20); - verify_sparse_file(a, "file3", sparse_file3, 0); + verify_sparse_file(a, "file0", sparse_file0, 5, 5); + verify_sparse_file(a, "file1", sparse_file1, 2, 2); + verify_sparse_file(a, "file2", sparse_file2, 20, 20); + /* Encoded non sparse; expect a data block but no sparse entries. */ + verify_sparse_file(a, "file3", sparse_file3, 0, 1); assertEqualInt(ARCHIVE_OK, archive_read_free(a));