1 /* This used to crash us on 64-bit; submitted by
2 Alex Wulms <alex.wulms@scarlet.be> */
3 #include <ccan/crcsync/crcsync.h>
4 #include <ccan/crcsync/crcsync.c>
5 #include <ccan/tap/tap.h>
10 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
17 static void crcblocks(crc_info_t *crc_info, const char *data, int datalen, int blocksize)
19 crc_info->block_count = (datalen+blocksize-1)/blocksize;
20 crc_info->crcs = malloc(sizeof(uint64_t)*(crc_info->block_count + 1));
21 crc_of_blocks(data, datalen, blocksize, 60, crc_info->crcs);
26 int main(int argc, char *argv[])
28 /* Divided into BLOCKSIZE blocks */
30 "abcde" "fghij" "klmno" "pqrst" "uvwxy" "z ABC"
31 "DEFGH" "IJKLM" "NOPQR" "STUVW" "XYZ 0" "12345" "6789";
32 /* Divided into blocks that match. */
39 "pqr-a-very-long-test-that-differs-between-two-invokations-of-the-same-page-st"
41 "uvwxy" "z ABC" "DEFGH" "IJKLM" "NOPQR" "STUVW" "XYZ 0" "12345"
49 -5, -6, -7, -8, -9, -10, -11, -12,
53 struct crc_context *crcctx;
57 size_t len2 = strlen(data2);
58 size_t tailsize = strlen(data1) % BLOCKSIZE;
61 plan_tests(ARRAY_SIZE(expected) + 2);
62 crcblocks(&crc_info1, data1, strlen(data1), BLOCKSIZE);
64 crcctx = crc_context_new(BLOCKSIZE, 60, crc_info1.crcs, crc_info1.block_count,
66 while ( offset < len2)
68 ndigested = crc_read_block(crcctx, &result, data2+offset, len2 - offset);
72 ok1(result == expected[expected_i++]);
75 ok1(result <= expected[expected_i]);
76 expected[expected_i] -= result;
77 if (!expected[expected_i])
82 while ((result = crc_read_flush(crcctx)) != 0) {
85 ok1(result == expected[expected_i++]);
88 ok1(result <= expected[expected_i]);
89 expected[expected_i] -= result;
90 if (!expected[expected_i])
94 ok1(expected_i == ARRAY_SIZE(expected));
95 crc_context_free(crcctx);