Test checksumming fragmented input

This commit is contained in:
Nigel Tao committed 2018-04-26 13:11:05 +10:00
1 parent 7f0923a9cf
commit 3ab749be0d
2 files changed
+50 -14

No files matched your search

+25 -7
View File
@@ -102,20 +102,38 @@ void test_wuffs_crc32_ieee_golden() {
if (!read_file(&src, test_cases[i].filename)) { if (!read_file(&src, test_cases[i].filename)) {
return; return;
} }
int j;
for (j = 0; j < 2; j++) {
wuffs_crc32__ieee checksum; wuffs_crc32__ieee checksum;
wuffs_crc32__ieee__initialize(&checksum, WUFFS_VERSION, 0); wuffs_crc32__ieee__initialize(&checksum, WUFFS_VERSION, 0);
uint32_t got =
wuffs_crc32__ieee__update(&checksum, ((wuffs_base__slice_u8){ uint32_t got;
.ptr = src.ptr + src.ri, size_t num_fragments = 0;
.len = src.wi - src.ri, size_t num_bytes = 0;
})); do {
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
.ptr = src.ptr + num_bytes,
.len = src.wi - num_bytes,
});
size_t limit = 101 + 103 * num_fragments;
if ((j > 0) && (data.len > limit)) {
data.len = limit;
}
got = wuffs_crc32__ieee__update(&checksum, data);
num_fragments++;
num_bytes += data.len;
} while (num_bytes < src.wi);
if (got != test_cases[i].want) { if (got != test_cases[i].want) {
FAIL("i=%d, filename=\"%s\": got 0x%08" PRIX32 ", want 0x%08" PRIX32 "\n", FAIL("i=%d, j=%d, filename=\"%s\": got 0x%08" PRIX32
i, test_cases[i].filename, got, test_cases[i].want); ", want 0x%08" PRIX32 "\n",
i, j, test_cases[i].filename, got, test_cases[i].want);
return; return;
} }
} }
} }
}
void test_wuffs_crc32_ieee_pi() { void test_wuffs_crc32_ieee_pi() {
CHECK_FOCUS(__func__); CHECK_FOCUS(__func__);
+25 -7
View File
@@ -128,20 +128,38 @@ void test_wuffs_adler32_golden() {
if (!read_file(&src, test_cases[i].filename)) { if (!read_file(&src, test_cases[i].filename)) {
return; return;
} }
int j;
for (j = 0; j < 2; j++) {
wuffs_zlib__adler32 checksum; wuffs_zlib__adler32 checksum;
wuffs_zlib__adler32__initialize(&checksum, WUFFS_VERSION, 0); wuffs_zlib__adler32__initialize(&checksum, WUFFS_VERSION, 0);
uint32_t got =
wuffs_zlib__adler32__update(&checksum, ((wuffs_base__slice_u8){ uint32_t got;
.ptr = src.ptr + src.ri, size_t num_fragments = 0;
.len = src.wi - src.ri, size_t num_bytes = 0;
})); do {
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
.ptr = src.ptr + num_bytes,
.len = src.wi - num_bytes,
});
size_t limit = 101 + 103 * num_fragments;
if ((j > 0) && (data.len > limit)) {
data.len = limit;
}
got = wuffs_zlib__adler32__update(&checksum, data);
num_fragments++;
num_bytes += data.len;
} while (num_bytes < src.wi);
if (got != test_cases[i].want) { if (got != test_cases[i].want) {
FAIL("i=%d, filename=\"%s\": got 0x%08" PRIX32 ", want 0x%08" PRIX32 "\n", FAIL("i=%d, j=%d, filename=\"%s\": got 0x%08" PRIX32
i, test_cases[i].filename, got, test_cases[i].want); ", want 0x%08" PRIX32 "\n",
i, j, test_cases[i].filename, got, test_cases[i].want);
return; return;
} }
} }
} }
}
void test_wuffs_adler32_pi() { void test_wuffs_adler32_pi() {
CHECK_FOCUS(__func__); CHECK_FOCUS(__func__);