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.
8 static int test_random(
9 uint32_t old_size, uint32_t diff_size,
10 unsigned int cardinality, unsigned int multiplier, unsigned int offset)
12 struct rstring_byte_range range;
18 range.cardinality = cardinality;
19 range.multiplier = multiplier;
20 range.offset = offset;
22 if (random_string_pair(old_size, diff_size, cardinality == 0 ? NULL : &range,
23 &old, &new_, &new_size) != RSTRING_OK)
25 fprintf(stderr, "Error generating random string pair\n");
29 rc = bdelta_diff(old, old_size, new_, new_size, NULL, NULL);
30 if (rc != BDELTA_OK) {
31 bdelta_perror("bdelta_diff", rc);
45 plan_tests(count * 14);
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));
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));