forked from vslapik/ugeneric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fuzz.c
69 lines (58 loc) · 1.98 KB
/
test_fuzz.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "generic.h"
#include "ut_utils.h"
int main(int argc, char **argv)
{
unsigned int seed;
bool verbose = false;
if (argc >= 2)
{
seed = atol(argv[1]);
ugeneric_random_init_with_seed(seed);
}
else
{
seed = ugeneric_random_init();
}
printf("================================== %u ==============================\n", seed);
ugeneric_t rv = gen_random_vector(7, verbose);
uvector_t *vector = G_AS_PTR(rv);
printf("Generation done ================== %u ==============================\n", seed);
if (verbose)
{
uvector_print(vector);
}
uvector_sort(G_AS_PTR(rv));
UASSERT(uvector_is_sorted(G_AS_PTR(rv)));
printf("Sorting done ===================== %u ==============================\n", seed);
char *t1 = ugeneric_as_str(rv);
printf("Serialization done================ %u ==============================\n", seed);
ugeneric_t rv_copy = ugeneric_copy(rv);
uvector_sort(G_AS_PTR(rv_copy));
UASSERT(uvector_is_sorted(G_AS_PTR(rv_copy)));
printf("Copy is ready ==================== %u ==============================\n", seed);
char *t2 = ugeneric_as_str(rv_copy);
printf("Copy serialization done=========== %u ==============================\n", seed);
UASSERT(ugeneric_compare_v(rv, rv_copy, uvector_get_void_comparator(vector)) == 0);
ugeneric_t g = ugeneric_parse(t2);
if (G_IS_ERROR(g))
{
ugeneric_error_print(g);
ugeneric_error_destroy(g);
UABORT("test failed");
}
UASSERT(G_IS_VECTOR(g));
uvector_sort(G_AS_PTR(g));
UASSERT(uvector_is_sorted(G_AS_PTR(g)));
if (verbose)
{
ugeneric_print(rv);
ugeneric_print(g);
}
UASSERT(ugeneric_compare_v(rv, g, uvector_get_void_comparator(vector)) == 0);
ufree(t1);
ufree(t2);
ugeneric_destroy(rv_copy);
ugeneric_destroy(rv);
ugeneric_destroy(g);
printf("Destoyed ========================= %u ==============================\n", seed);
}