diff options
Diffstat (limited to 'xdelta3-test.h')
-rw-r--r-- | xdelta3-test.h | 109 |
1 files changed, 90 insertions, 19 deletions
diff --git a/xdelta3-test.h b/xdelta3-test.h index 948a1d6..6d7d85b 100644 --- a/xdelta3-test.h +++ b/xdelta3-test.h @@ -109,7 +109,7 @@ mt_exp_rand (uint32_t mean, uint32_t max_value) (double)UINT32_MAX)); uint32_t x = (uint32_t) (mean_d * erand + 0.5); - return min (x, max_value); + return xd3_min (x, max_value); } #if SHELL_TESTS @@ -215,11 +215,26 @@ test_random_numbers (xd3_stream *stream, int ignore) return XD3_INTERNAL; } +static int +test_printf_xoff (xd3_stream *stream, int ignore) +{ + char buf[64]; + xoff_t x = XOFF_T_MAX; + snprintf_func (buf, sizeof(buf), "%"Q"u", x); + const char *expect = XD3_USE_LARGEFILE64 ? + "18446744073709551615" : "4294967295"; + if (strcmp (buf, expect) == 0) { + return 0; + } + return XD3_INTERNAL; +} + static void test_unlink (char* file) { int ret; - if ((ret = unlink (file)) != 0 && errno != ENOENT) + if (file != NULL && *file != 0 && + (ret = unlink (file)) != 0 && errno != ENOENT) { XPR(NT "unlink %s failed: %s\n", file, strerror(ret)); } @@ -242,14 +257,26 @@ test_cleanup (void) int test_setup (void) { static int x = 0; + pid_t pid = getpid(); x++; - snprintf_func (TEST_TARGET_FILE, TESTFILESIZE, "/tmp/xdtest.target.%d", x); - snprintf_func (TEST_SOURCE_FILE, TESTFILESIZE, "/tmp/xdtest.source.%d", x); - snprintf_func (TEST_DELTA_FILE, TESTFILESIZE, "/tmp/xdtest.delta.%d", x); - snprintf_func (TEST_RECON_FILE, TESTFILESIZE, "/tmp/xdtest.recon.%d", x); - snprintf_func (TEST_RECON2_FILE, TESTFILESIZE, "/tmp/xdtest.recon2.%d", x); - snprintf_func (TEST_COPY_FILE, TESTFILESIZE, "/tmp/xdtest.copy.%d", x); - snprintf_func (TEST_NOPERM_FILE, TESTFILESIZE, "/tmp/xdtest.noperm.%d", x); + + test_cleanup(); + + snprintf_func (TEST_TARGET_FILE, TESTFILESIZE, + "/tmp/xdtest.%d.target.%d", pid, x); + snprintf_func (TEST_SOURCE_FILE, TESTFILESIZE, + "/tmp/xdtest.%d.source.%d", pid, x); + snprintf_func (TEST_DELTA_FILE, TESTFILESIZE, + "/tmp/xdtest.%d.delta.%d", pid, x); + snprintf_func (TEST_RECON_FILE, TESTFILESIZE, + "/tmp/xdtest.%d.recon.%d", pid, x); + snprintf_func (TEST_RECON2_FILE, TESTFILESIZE, + "/tmp/xdtest.%d.recon2.%d", pid, x); + snprintf_func (TEST_COPY_FILE, TESTFILESIZE, + "/tmp/xdtest.%d.copy.%d", pid, x); + snprintf_func (TEST_NOPERM_FILE, TESTFILESIZE, + "/tmp/xdtest.%d.noperm.%d", pid, x); + test_cleanup(); return 0; } @@ -300,7 +327,7 @@ test_make_inputs (xd3_stream *stream, xoff_t *ss_out, xoff_t *ts_out) double add_prob = (left == 0) ? 0 : (add_left / (double) left); int do_copy; - next = min (left, next); + next = xd3_min (left, next); do_copy = (next > add_left || (mt_random (&static_mtrand) / \ (double)USIZE_T_MAX) >= add_prob); @@ -735,10 +762,10 @@ test_address_cache (xd3_stream *stream, int unused) p = (mt_random (&static_mtrand) / (double)USIZE_T_MAX); prev_i = mt_random (&static_mtrand) % offset; nearby = (mt_random (&static_mtrand) % 256) % offset; - nearby = max (1U, nearby); + nearby = xd3_max (1U, nearby); if (p < 0.1) { addr = addrs[offset-nearby]; } - else if (p < 0.4) { addr = min (addrs[prev_i] + nearby, offset-1); } + else if (p < 0.4) { addr = xd3_min (addrs[prev_i] + nearby, offset-1); } else { addr = prev_i; } if ((ret = xd3_encode_address (stream, addr, offset, & modes[offset]))) { return ret; } @@ -884,7 +911,7 @@ test_decompress_text (xd3_stream *stream, uint8_t *enc, usize_t enc_size, usize_ input: /* Test decoding test_desize input bytes at a time */ - take = min (enc_size - pos, test_desize); + take = xd3_min (enc_size - pos, test_desize); CHECK(take > 0); xd3_avail_input (stream, enc + pos, take); @@ -1061,9 +1088,9 @@ test_decompress_single_bit_error (xd3_stream *stream, int expected_non_failures) } /* Check expected non-failures */ - if (non_failures != expected_non_failures) + if (non_failures > expected_non_failures) { - XPR(NT "non-failures %u; expected %u", + XPR(NT "non-failures %u > expected %u", non_failures, expected_non_failures); stream->msg = "incorrect"; return XD3_INTERNAL; @@ -1440,7 +1467,7 @@ test_secondary (xd3_stream *stream, const xd3_sec_type *sec, usize_t groups) * decoding. Really looking for faults here. */ { int i; - int bytes = min (compress_size, 10U); + int bytes = xd3_min (compress_size, 10U); for (i = 0; i < bytes * 8; i += 1) { dec_input[i/8] ^= 1 << (i%8); @@ -1487,7 +1514,8 @@ IF_DJW (static int test_secondary_huff (xd3_stream *stream, usize_t gp) { return test_secondary (stream, & djw_sec_type, gp); }) IF_LZMA (static int test_secondary_lzma (xd3_stream *stream, usize_t gp) { return test_secondary (stream, & lzma_sec_type, gp); }) -#endif + +#endif /* SECONDARY_ANY */ /*********************************************************************** TEST INSTRUCTION TABLE @@ -1884,7 +1912,7 @@ test_recode_command2 (xd3_stream *stream, int has_source, recoded_adler32 ? "" : "-n ", !change_apphead ? "" : (recoded_apphead ? "-A=recode_apphead " : "-A= "), - recoded_secondary ? "-S djw " : "-S none ", + recoded_secondary ? "-S djw " : "-S= ", TEST_DELTA_FILE, TEST_COPY_FILE); @@ -1980,6 +2008,7 @@ test_recode_command2 (xd3_stream *stream, int has_source, { return ret; } + test_cleanup (); return 0; } @@ -2018,7 +2047,46 @@ test_recode_command (xd3_stream *stream, int ignore) return 0; } -#endif + +#if SECONDARY_LZMA +int test_secondary_lzma_default (xd3_stream *stream, int ignore) +{ + char ecmd[TESTBUFSIZE]; + int ret; + + test_setup (); + + if ((ret = test_make_inputs (stream, NULL, NULL))) + { + return ret; + } + + /* First encode */ + snprintf_func (ecmd, TESTBUFSIZE, "%s -e %s %s", + program_name, + TEST_TARGET_FILE, + TEST_DELTA_FILE); + + if ((ret = system (ecmd)) != 0) + { + return XD3_INTERNAL; + } + + if ((ret = check_vcdiff_header (stream, + TEST_DELTA_FILE, + "VCDIFF secondary compressor", + "lzma", + 1))) + { + return ret; + } + + test_cleanup (); + return 0; +} + +#endif /* SECONDARY_LZMA */ +#endif /* SHELL_TESTS */ /*********************************************************************** EXTERNAL I/O DECOMPRESSION/RECOMPRESSION @@ -2400,6 +2468,7 @@ test_appheader (xd3_stream *stream, int ignore) return XD3_INVALID; // Must have crashed! } + test_cleanup (); return 0; } @@ -2852,6 +2921,7 @@ xd3_selftest (void) int ret; DO_TEST (random_numbers, 0, 0); + DO_TEST (printf_xoff, 0, 0); DO_TEST (decode_integer_end_of_input, 0, 0); DO_TEST (decode_integer_overflow, 0, 0); @@ -2890,6 +2960,7 @@ xd3_selftest (void) #endif DO_TEST (recode_command, 0, 0); + IF_LZMA (DO_TEST (secondary_lzma_default, 0, 0)); #endif IF_LZMA (DO_TEST (secondary_lzma, 0, 1)); |