1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 
5 #include "test_common.h"
6 
fail_if_impl(bool val, const char *msg, const char *file, int line)7 void fail_if_impl(bool val, const char *msg, const char *file, int line) {
8     if (val) {
9         fprintf(stderr, "%s at %s:%d\n", msg, file, line);
10         exit(1);
11     }
12 }
13 
check_pair_equality(kvpair_t *one, kvpair_t *two)14 void check_pair_equality(kvpair_t *one, kvpair_t *two)
15 {
16     int i = 0;
17     fail_if(one == NULL, "one is null.");
18     fail_if(one == two, "Comparing identical pairs.");
19     fail_unless(strcmp(one->key, two->key) == 0, "Keys don't match.");
20 
21     for (i=0; one->values[i]; i++) {
22         fail_unless(two->values[i] != NULL, "Value at one, but not two");
23         fail_unless(strcmp(one->values[i], two->values[i]) == 0,
24                     "Values don't match.");
25         fail_unless((one->values[i+1] != NULL && two->values[i+1] != NULL)
26                     || (one->values[i+1] == NULL && two->values[i+1] == NULL),
27                     "Unbalanced values.");
28 
29     }
30 
31     if (one->next) {
32         fail_unless(two->next != NULL, "No two->next.");
33         check_pair_equality(one->next, two->next);
34     } else {
35         fail_if(two->next, "No one->next, but a two->next");
36     }
37 }
38