mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +01:00
Test checksumming fragmented input
This commit is contained in:
1 parent
7f0923a9cf
commit
3ab749be0d
2 files changed
+58
-22
No files matched your search
+29
-11
@@ -102,17 +102,35 @@ void test_wuffs_crc32_ieee_golden() {
|
|||||||
if (!read_file(&src, test_cases[i].filename)) {
|
if (!read_file(&src, test_cases[i].filename)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wuffs_crc32__ieee checksum;
|
|
||||||
wuffs_crc32__ieee__initialize(&checksum, WUFFS_VERSION, 0);
|
int j;
|
||||||
uint32_t got =
|
for (j = 0; j < 2; j++) {
|
||||||
wuffs_crc32__ieee__update(&checksum, ((wuffs_base__slice_u8){
|
wuffs_crc32__ieee checksum;
|
||||||
.ptr = src.ptr + src.ri,
|
wuffs_crc32__ieee__initialize(&checksum, WUFFS_VERSION, 0);
|
||||||
.len = src.wi - src.ri,
|
|
||||||
}));
|
uint32_t got;
|
||||||
if (got != test_cases[i].want) {
|
size_t num_fragments = 0;
|
||||||
FAIL("i=%d, filename=\"%s\": got 0x%08" PRIX32 ", want 0x%08" PRIX32 "\n",
|
size_t num_bytes = 0;
|
||||||
i, test_cases[i].filename, got, test_cases[i].want);
|
do {
|
||||||
return;
|
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) {
|
||||||
|
FAIL("i=%d, j=%d, filename=\"%s\": got 0x%08" PRIX32
|
||||||
|
", want 0x%08" PRIX32 "\n",
|
||||||
|
i, j, test_cases[i].filename, got, test_cases[i].want);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-11
@@ -128,17 +128,35 @@ void test_wuffs_adler32_golden() {
|
|||||||
if (!read_file(&src, test_cases[i].filename)) {
|
if (!read_file(&src, test_cases[i].filename)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wuffs_zlib__adler32 checksum;
|
|
||||||
wuffs_zlib__adler32__initialize(&checksum, WUFFS_VERSION, 0);
|
int j;
|
||||||
uint32_t got =
|
for (j = 0; j < 2; j++) {
|
||||||
wuffs_zlib__adler32__update(&checksum, ((wuffs_base__slice_u8){
|
wuffs_zlib__adler32 checksum;
|
||||||
.ptr = src.ptr + src.ri,
|
wuffs_zlib__adler32__initialize(&checksum, WUFFS_VERSION, 0);
|
||||||
.len = src.wi - src.ri,
|
|
||||||
}));
|
uint32_t got;
|
||||||
if (got != test_cases[i].want) {
|
size_t num_fragments = 0;
|
||||||
FAIL("i=%d, filename=\"%s\": got 0x%08" PRIX32 ", want 0x%08" PRIX32 "\n",
|
size_t num_bytes = 0;
|
||||||
i, test_cases[i].filename, got, test_cases[i].want);
|
do {
|
||||||
return;
|
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) {
|
||||||
|
FAIL("i=%d, j=%d, filename=\"%s\": got 0x%08" PRIX32
|
||||||
|
", want 0x%08" PRIX32 "\n",
|
||||||
|
i, j, test_cases[i].filename, got, test_cases[i].want);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user