]> git.ozlabs.org Git - ccan/blob - ccan/bdelta/test/run-medium.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / bdelta / test / run-medium.c
1 #include "common.h"
2
3 /*
4  * Note that bdelta_diff verifies the patch before returning it (except for
5  * when it returns a PT_LITERAL patch, as its correctness is easy to prove).
6  * Only the trivial tests check the result explicitly using bdiff_patch.
7  */
8 static int test_random(
9         uint32_t old_size, uint32_t diff_size,
10         unsigned int cardinality, unsigned int multiplier, unsigned int offset)
11 {
12         struct rstring_byte_range range;
13         uint8_t *old;
14         uint8_t *new_;
15         uint32_t new_size;
16         BDELTAcode rc;
17         
18         range.cardinality = cardinality;
19         range.multiplier = multiplier;
20         range.offset = offset;
21         
22         if (random_string_pair(old_size, diff_size, cardinality == 0 ? NULL : &range,
23                                &old, &new_, &new_size) != RSTRING_OK)
24         {
25                 fprintf(stderr, "Error generating random string pair\n");
26                 exit(EXIT_FAILURE);
27         }
28         
29         rc = bdelta_diff(old, old_size, new_, new_size, NULL, NULL);
30         if (rc != BDELTA_OK) {
31                 bdelta_perror("bdelta_diff", rc);
32                 return 0;
33         }
34         
35         free(new_);
36         free(old);
37         return 1;
38 }
39
40 int main(void)
41 {
42         int i;
43         int count = 25;
44         
45         plan_tests(count * 14);
46         
47         for (i = 0; i < count; i++)
48                 ok1(test_random(100, 10, 0, 0, 0));
49         for (i = 0; i < count; i++)
50                 ok1(test_random(100, rand32() % 200, 0, 0, 0));
51         for (i = 0; i < count; i++)
52                 ok1(test_random(1000, rand32() % 200, 0, 0, 0));
53         for (i = 0; i < count; i++)
54                 ok1(test_random(1000, rand32() % 2000, 0, 0, 0));
55         for (i = 0; i < count; i++)
56                 ok1(test_random(10000, rand32() % 200, 0, 0, 0));
57         for (i = 0; i < count; i++)
58                 ok1(test_random(10000, rand32() % 2000, 0, 0, 0));
59         for (i = 0; i < count; i++)
60                 ok1(test_random(rand32() % 20000, rand32() % 20000, 0, 0, 0));
61         
62         /* Low-cardinality tests */
63         for (i = 0; i < count; i++)
64                 ok1(test_random(100, 10, rand32() % 20 + 1, 1, i));
65         for (i = 0; i < count; i++)
66                 ok1(test_random(100, rand32() % 200, rand32() % 20 + 1, 1, i));
67         for (i = 0; i < count; i++)
68                 ok1(test_random(1000, rand32() % 200, rand32() % 20 + 1, 1, i));
69         for (i = 0; i < count; i++)
70                 ok1(test_random(1000, rand32() % 2000, rand32() % 20 + 1, 1, i));
71         for (i = 0; i < count; i++)
72                 ok1(test_random(10000, rand32() % 200, rand32() % 20 + 1, 1, i));
73         for (i = 0; i < count; i++)
74                 ok1(test_random(10000, rand32() % 2000, rand32() % 20 + 1, 1, i));
75         for (i = 0; i < count; i++)
76                 ok1(test_random(rand32() % 20000, rand32() % 20000, rand32() % 20 + 1, 1, i));
77         
78         return exit_status();
79 }