summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3-test.h
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/xdelta3-test.h')
-rw-r--r--xdelta3/xdelta3-test.h39
1 files changed, 25 insertions, 14 deletions
diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h
index 948a1d6..3d505fc 100644
--- a/xdelta3/xdelta3-test.h
+++ b/xdelta3/xdelta3-test.h
@@ -139,7 +139,10 @@ static char TEST_RECON2_FILE[TESTFILESIZE];
139static char TEST_COPY_FILE[TESTFILESIZE]; 139static char TEST_COPY_FILE[TESTFILESIZE];
140static char TEST_NOPERM_FILE[TESTFILESIZE]; 140static char TEST_NOPERM_FILE[TESTFILESIZE];
141 141
142#define CHECK(cond) if (!(cond)) { XPR(NT "check failure: " #cond); abort(); } 142#define CHECK(cond) \
143 if (!(cond)) { \
144 XPR(NT __FILE__":%d: check failure: " #cond, __LINE__); \
145 abort(); }
143 146
144#if SHELL_TESTS 147#if SHELL_TESTS
145/* Use a fixed soft config so that test values are fixed. See also 148/* Use a fixed soft config so that test values are fixed. See also
@@ -199,7 +202,7 @@ test_random_numbers (xd3_stream *stream, int ignore)
199 202
200 for (i = 0; i < n_rounds; i += 1) 203 for (i = 0; i < n_rounds; i += 1)
201 { 204 {
202 sum += mt_exp_rand (mean, USIZE_T_MAX); 205 sum += mt_exp_rand (mean, UINT32_MAX);
203 } 206 }
204 207
205 average = (double) sum / (double) n_rounds; 208 average = (double) sum / (double) n_rounds;
@@ -411,7 +414,7 @@ test_compare_files (const char* tgt, const char *rec)
411 { 414 {
412 if (obuf[i] != rbuf[i]) 415 if (obuf[i] != rbuf[i])
413 { 416 {
414 XPR(NT "byte %u (read %u @ %"Q"u) %d != %d\n", 417 XPR(NT "byte %u (read %u @ %"Q") %d != %d\n",
415 (int)i, (int)oc, offset, obuf[i], rbuf[i]); 418 (int)i, (int)oc, offset, obuf[i], rbuf[i]);
416 diffs++; 419 diffs++;
417 return XD3_INTERNAL; 420 return XD3_INTERNAL;
@@ -677,13 +680,13 @@ test_forward_match (xd3_stream *stream, int unused)
677 680
678 for (i = 0; i < 256; i++) 681 for (i = 0; i < 256; i++)
679 { 682 {
680 CHECK(xd3_forward_match(buf1, buf2, i) == (int)i); 683 CHECK(xd3_forward_match(buf1, buf2, i) == i);
681 } 684 }
682 685
683 for (i = 0; i < 255; i++) 686 for (i = 0; i < 255; i++)
684 { 687 {
685 buf2[i] = 1; 688 buf2[i] = 1;
686 CHECK(xd3_forward_match(buf1, buf2, 256) == (int)i); 689 CHECK(xd3_forward_match(buf1, buf2, 256) == i);
687 buf2[i] = 0; 690 buf2[i] = 0;
688 } 691 }
689 692
@@ -732,7 +735,7 @@ test_address_cache (xd3_stream *stream, int unused)
732 usize_t prev_i; 735 usize_t prev_i;
733 usize_t nearby; 736 usize_t nearby;
734 737
735 p = (mt_random (&static_mtrand) / (double)USIZE_T_MAX); 738 p = (mt_random (&static_mtrand) / (double)UINT32_MAX);
736 prev_i = mt_random (&static_mtrand) % offset; 739 prev_i = mt_random (&static_mtrand) % offset;
737 nearby = (mt_random (&static_mtrand) % 256) % offset; 740 nearby = (mt_random (&static_mtrand) % 256) % offset;
738 nearby = max (1U, nearby); 741 nearby = max (1U, nearby);
@@ -763,9 +766,13 @@ test_address_cache (xd3_stream *stream, int unused)
763 766
764 for (offset = 1; offset < ADDR_CACHE_ROUNDS; offset += 1) 767 for (offset = 1; offset < ADDR_CACHE_ROUNDS; offset += 1)
765 { 768 {
766 uint32_t addr; 769 usize_t addr;
767 770
768 if ((ret = xd3_decode_address (stream, offset, modes[offset], & buf, buf_max, & addr))) { return ret; } 771 if ((ret = xd3_decode_address (stream, offset, modes[offset],
772 & buf, buf_max, & addr)))
773 {
774 return ret;
775 }
769 776
770 if (addr != addrs[offset]) 777 if (addr != addrs[offset])
771 { 778 {
@@ -1391,7 +1398,7 @@ test_secondary (xd3_stream *stream, const xd3_sec_type *sec, usize_t groups)
1391 if ((ret = sec->encode (stream, enc_stream, 1398 if ((ret = sec->encode (stream, enc_stream,
1392 in_head, out_head, & cfg))) 1399 in_head, out_head, & cfg)))
1393 { 1400 {
1394 XPR(NT "test %u: encode: %s", test_i, stream->msg); 1401 XPR(NT "test %"Z": encode: %s", test_i, stream->msg);
1395 goto fail; 1402 goto fail;
1396 } 1403 }
1397 1404
@@ -1430,7 +1437,7 @@ test_secondary (xd3_stream *stream, const xd3_sec_type *sec, usize_t groups)
1430 compress_size, dec_input, 1437 compress_size, dec_input,
1431 dec_correct, dec_output))) 1438 dec_correct, dec_output)))
1432 { 1439 {
1433 XPR(NT "test %u: decode: %s", test_i, stream->msg); 1440 XPR(NT "test %"Z": decode: %s", test_i, stream->msg);
1434 goto fail; 1441 goto fail;
1435 } 1442 }
1436 1443
@@ -1759,7 +1766,7 @@ test_command_line_arguments (xd3_stream *stream, int ignore)
1759 if (ratio >= TEST_ADD_RATIO + TEST_EPSILON) 1766 if (ratio >= TEST_ADD_RATIO + TEST_EPSILON)
1760 { 1767 {
1761 XPR(NT "test encode with size ratio %.4f, " 1768 XPR(NT "test encode with size ratio %.4f, "
1762 "expected < %.4f (%"Q"u, %"Q"u)\n", 1769 "expected < %.4f (%"Q", %"Q")\n",
1763 ratio, TEST_ADD_RATIO + TEST_EPSILON, dsize, tsize); 1770 ratio, TEST_ADD_RATIO + TEST_EPSILON, dsize, tsize);
1764 stream->msg = "strange encoding"; 1771 stream->msg = "strange encoding";
1765 return XD3_INTERNAL; 1772 return XD3_INTERNAL;
@@ -2645,14 +2652,14 @@ test_string_matching (xd3_stream *stream, int ignore)
2645 default: CHECK(0); 2652 default: CHECK(0);
2646 } 2653 }
2647 2654
2648 snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%d/%d", 2655 snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"Z"/%"Z"",
2649 inst->pos, inst->size); 2656 inst->pos, inst->size);
2650 rptr += strlen (rptr); 2657 rptr += strlen (rptr);
2651 2658
2652 if (inst->type == XD3_CPY) 2659 if (inst->type == XD3_CPY)
2653 { 2660 {
2654 *rptr++ = '@'; 2661 *rptr++ = '@';
2655 snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"Q"d", inst->addr); 2662 snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"Q, inst->addr);
2656 rptr += strlen (rptr); 2663 rptr += strlen (rptr);
2657 } 2664 }
2658 2665
@@ -2668,7 +2675,7 @@ test_string_matching (xd3_stream *stream, int ignore)
2668 2675
2669 if (strcmp (rbuf, test->result) != 0) 2676 if (strcmp (rbuf, test->result) != 0)
2670 { 2677 {
2671 XPR(NT "test %u: expected %s: got %s", i, test->result, rbuf); 2678 XPR(NT "test %"Z": expected %s: got %s", i, test->result, rbuf);
2672 stream->msg = "wrong result"; 2679 stream->msg = "wrong result";
2673 return XD3_INTERNAL; 2680 return XD3_INTERNAL;
2674 } 2681 }
@@ -2743,6 +2750,7 @@ test_iopt_flush_instructions (xd3_stream *stream, int ignore)
2743/* 2750/*
2744 * This tests the 32/64bit ambiguity for source-window matching. 2751 * This tests the 32/64bit ambiguity for source-window matching.
2745 */ 2752 */
2753#if !XD3_USE_LARGEWINDOW64
2746static int 2754static int
2747test_source_cksum_offset (xd3_stream *stream, int ignore) 2755test_source_cksum_offset (xd3_stream *stream, int ignore)
2748{ 2756{
@@ -2788,6 +2796,7 @@ test_source_cksum_offset (xd3_stream *stream, int ignore)
2788 } 2796 }
2789 return 0; 2797 return 0;
2790} 2798}
2799#endif /* !XD3_USE_LARGEWINDOW64 */
2791 2800
2792static int 2801static int
2793test_in_memory (xd3_stream *stream, int ignore) 2802test_in_memory (xd3_stream *stream, int ignore)
@@ -2868,7 +2877,9 @@ xd3_selftest (void)
2868 DO_TEST (in_memory, 0, 0); 2877 DO_TEST (in_memory, 0, 0);
2869 2878
2870 DO_TEST (iopt_flush_instructions, 0, 0); 2879 DO_TEST (iopt_flush_instructions, 0, 0);
2880#if !XD3_USE_LARGEWINDOW64
2871 DO_TEST (source_cksum_offset, 0, 0); 2881 DO_TEST (source_cksum_offset, 0, 0);
2882#endif
2872 2883
2873 DO_TEST (decompress_single_bit_error, 0, 3); 2884 DO_TEST (decompress_single_bit_error, 0, 3);
2874 DO_TEST (decompress_single_bit_error, XD3_ADLER32, 3); 2885 DO_TEST (decompress_single_bit_error, XD3_ADLER32, 3);