diff options
Diffstat (limited to 'xdelta3/xdelta3-test.h')
-rwxr-xr-x | xdelta3/xdelta3-test.h | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h index af90a90..ea0bd49 100755 --- a/xdelta3/xdelta3-test.h +++ b/xdelta3/xdelta3-test.h | |||
@@ -670,7 +670,7 @@ static const uint8_t test_apphead[] = "header test"; | |||
670 | static int | 670 | static int |
671 | test_compress_text (xd3_stream *stream, | 671 | test_compress_text (xd3_stream *stream, |
672 | uint8_t *encoded, | 672 | uint8_t *encoded, |
673 | usize_t *encoded_size) | 673 | usize_t *encoded_size) |
674 | { | 674 | { |
675 | int ret; | 675 | int ret; |
676 | xd3_config cfg; | 676 | xd3_config cfg; |
@@ -701,8 +701,8 @@ test_compress_text (xd3_stream *stream, | |||
701 | 701 | ||
702 | xd3_set_appheader (stream, test_apphead, sizeof (test_apphead)); | 702 | xd3_set_appheader (stream, test_apphead, sizeof (test_apphead)); |
703 | 703 | ||
704 | if ((ret = xd3_encode_completely_stream (stream, test_text, sizeof (test_text), | 704 | if ((ret = xd3_encode_stream (stream, test_text, sizeof (test_text), |
705 | encoded, encoded_size, 4*sizeof (test_text)))) { goto fail; } | 705 | encoded, encoded_size, 4*sizeof (test_text)))) { goto fail; } |
706 | 706 | ||
707 | if ((ret = xd3_close_stream (stream))) { goto fail; } | 707 | if ((ret = xd3_close_stream (stream))) { goto fail; } |
708 | 708 | ||
@@ -1384,7 +1384,7 @@ test_streaming (xd3_stream *in_stream, uint8_t *encbuf, uint8_t *decbuf, uint8_t | |||
1384 | 1384 | ||
1385 | if ((i % 200) == 199) { DOT (); } | 1385 | if ((i % 200) == 199) { DOT (); } |
1386 | 1386 | ||
1387 | if ((ret = xd3_process_completely_stream (& estream, xd3_encode_input, 0, | 1387 | if ((ret = xd3_process_stream (& estream, xd3_encode_input, 0, |
1388 | encbuf, 1 << 20, | 1388 | encbuf, 1 << 20, |
1389 | delbuf, & delsize, 1 << 10))) | 1389 | delbuf, & delsize, 1 << 10))) |
1390 | { | 1390 | { |
@@ -1392,7 +1392,7 @@ test_streaming (xd3_stream *in_stream, uint8_t *encbuf, uint8_t *decbuf, uint8_t | |||
1392 | goto fail; | 1392 | goto fail; |
1393 | } | 1393 | } |
1394 | 1394 | ||
1395 | if ((ret = xd3_process_completely_stream (& dstream, xd3_decode_input, 0, | 1395 | if ((ret = xd3_process_stream (& dstream, xd3_decode_input, 0, |
1396 | delbuf, delsize, | 1396 | delbuf, delsize, |
1397 | decbuf, & decsize, 1 << 20))) | 1397 | decbuf, & decsize, 1 << 20))) |
1398 | { | 1398 | { |
@@ -1921,7 +1921,7 @@ test_identical_behavior (xd3_stream *stream, int ignore) | |||
1921 | if ((ret = xd3_set_source (stream, & source))) { goto fail; } | 1921 | if ((ret = xd3_set_source (stream, & source))) { goto fail; } |
1922 | 1922 | ||
1923 | /* Decode. */ | 1923 | /* Decode. */ |
1924 | if ((ret = xd3_decode_completely_stream (stream, del, delpos, rec, & recsize, IDB_TGTSZ))) { goto fail; } | 1924 | if ((ret = xd3_decode_stream (stream, del, delpos, rec, & recsize, IDB_TGTSZ))) { goto fail; } |
1925 | 1925 | ||
1926 | /* Check result size and data. */ | 1926 | /* Check result size and data. */ |
1927 | if (recsize != IDB_TGTSZ) { stream->msg = "wrong size reconstruction"; goto fail; } | 1927 | if (recsize != IDB_TGTSZ) { stream->msg = "wrong size reconstruction"; goto fail; } |
@@ -2135,7 +2135,7 @@ test_iopt_flush_instructions (xd3_stream *stream, int ignore) | |||
2135 | target[tpos++] = i; | 2135 | target[tpos++] = i; |
2136 | } | 2136 | } |
2137 | 2137 | ||
2138 | if ((ret = xd3_encode_completely_stream (stream, target, tpos, | 2138 | if ((ret = xd3_encode_stream (stream, target, tpos, |
2139 | delta, & delta_size, sizeof (delta)))) | 2139 | delta, & delta_size, sizeof (delta)))) |
2140 | { | 2140 | { |
2141 | return ret; | 2141 | return ret; |
@@ -2144,8 +2144,8 @@ test_iopt_flush_instructions (xd3_stream *stream, int ignore) | |||
2144 | xd3_free_stream(stream); | 2144 | xd3_free_stream(stream); |
2145 | if ((ret = xd3_config_stream (stream, & config))) { return ret; } | 2145 | if ((ret = xd3_config_stream (stream, & config))) { return ret; } |
2146 | 2146 | ||
2147 | if ((ret = xd3_decode_completely_stream (stream, delta, delta_size, | 2147 | if ((ret = xd3_decode_stream (stream, delta, delta_size, |
2148 | recon, & recon_size, sizeof (recon)))) | 2148 | recon, & recon_size, sizeof (recon)))) |
2149 | { | 2149 | { |
2150 | return ret; | 2150 | return ret; |
2151 | } | 2151 | } |
@@ -2206,6 +2206,43 @@ test_source_cksum_offset (xd3_stream *stream, int ignore) | |||
2206 | return 0; | 2206 | return 0; |
2207 | } | 2207 | } |
2208 | 2208 | ||
2209 | static int | ||
2210 | test_in_memory (xd3_stream *stream, int ignore) | ||
2211 | { | ||
2212 | // test_text is 256 bytes | ||
2213 | char ibuf[sizeof(test_text)]; | ||
2214 | char dbuf[sizeof(test_text)]; | ||
2215 | char obuf[sizeof(test_text)]; | ||
2216 | int size = sizeof(test_text); | ||
2217 | int dsize, osize; | ||
2218 | int r1, r2; | ||
2219 | int eflags = SECONDARY_DJW ? XD3_SEC_DJW : 0; | ||
2220 | |||
2221 | memcpy(ibuf, test_text, size); | ||
2222 | memset(ibuf + 128, 0, 16); | ||
2223 | |||
2224 | r1 = xd3_encode_memory(ibuf, size, | ||
2225 | test_text, size, | ||
2226 | dbuf, &dsize, size, eflags); | ||
2227 | |||
2228 | r2 = xd3_decode_memory(dbuf, dsize, | ||
2229 | test_text, size, | ||
2230 | obuf, &osize, size, 0); | ||
2231 | |||
2232 | if (r1 != 0 || r2 != 0 || dsize >= (size/2) || dsize < 1 || | ||
2233 | osize != size) { | ||
2234 | stream->msg = "encode/decode size error"; | ||
2235 | return XD3_INTERNAL; | ||
2236 | } | ||
2237 | |||
2238 | if (memcmp(obuf, ibuf, size) != 0) { | ||
2239 | stream->msg = "encode/decode data error"; | ||
2240 | return XD3_INTERNAL; | ||
2241 | } | ||
2242 | |||
2243 | return 0; | ||
2244 | } | ||
2245 | |||
2209 | /****************************************************************************************** | 2246 | /****************************************************************************************** |
2210 | TEST MAIN | 2247 | TEST MAIN |
2211 | ******************************************************************************************/ | 2248 | ******************************************************************************************/ |
@@ -2248,6 +2285,7 @@ xd3_selftest (void) | |||
2248 | IF_GENCODETBL (DO_TEST (choose_instruction, XD3_ALT_CODE_TABLE, 0)); | 2285 | IF_GENCODETBL (DO_TEST (choose_instruction, XD3_ALT_CODE_TABLE, 0)); |
2249 | IF_GENCODETBL (DO_TEST (encode_code_table, 0, 0)); | 2286 | IF_GENCODETBL (DO_TEST (encode_code_table, 0, 0)); |
2250 | 2287 | ||
2288 | DO_TEST (in_memory, 0, 0); | ||
2251 | DO_TEST (identical_behavior, 0, 0); | 2289 | DO_TEST (identical_behavior, 0, 0); |
2252 | DO_TEST (iopt_flush_instructions, 0, 0); | 2290 | DO_TEST (iopt_flush_instructions, 0, 0); |
2253 | DO_TEST (source_cksum_offset, 0, 0); | 2291 | DO_TEST (source_cksum_offset, 0, 0); |