xref: /lighttpd1.4/src/t/test_array.c (revision bab0e5d0)
1 #include "first.h"
2 
3 #undef NDEBUG
4 #include <assert.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 
8 #include "array.c"
9 #include "buffer.h"
10 
test_array_get_int_ptr(void)11 static void test_array_get_int_ptr (void) {
12     data_integer *di;
13     int *i;
14     array *a = array_init(0);
15 
16     i = array_get_int_ptr(a, CONST_STR_LEN("abc"));
17     assert(NULL != i);
18     *i = 4;
19     i = array_get_int_ptr(a, CONST_STR_LEN("abc"));
20     assert(NULL != i);
21     assert(*i == 4);
22     di = (data_integer *)array_get_element_klen(a, CONST_STR_LEN("does-not-exist"));
23     assert(NULL == di);
24     di = (data_integer *)array_get_element_klen(a, CONST_STR_LEN("abc"));
25     assert(NULL != di);
26     assert(di->value == 4);
27 
28     array_free(a);
29 }
30 
test_array_insert_value(void)31 static void test_array_insert_value (void) {
32     data_string *ds;
33     array *a = array_init(0);
34 
35     array_insert_value(a, CONST_STR_LEN("def"));
36     ds = (data_string *)a->data[0];
37     assert(NULL != ds);
38     assert(buffer_eq_slen(&ds->value, CONST_STR_LEN("def")));
39 
40     array_free(a);
41 }
42 
test_array_set_key_value(void)43 static void test_array_set_key_value (void) {
44     data_string *ds;
45     array *a = array_init(0);
46 
47     array_set_key_value(a, CONST_STR_LEN("abc"), CONST_STR_LEN("def"));
48     ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("does-not-exist"));
49     assert(NULL == ds);
50     ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("abc"));
51     assert(NULL != ds);
52     assert(buffer_eq_slen(&ds->key, CONST_STR_LEN("abc")));
53     assert(buffer_eq_slen(&ds->value, CONST_STR_LEN("def")));
54 
55     array_set_key_value(a, CONST_STR_LEN("abc"), CONST_STR_LEN("ghi"));
56     ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("does-not-exist"));
57     assert(NULL == ds);
58     ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("abc"));
59     assert(NULL != ds);
60     assert(buffer_eq_slen(&ds->key, CONST_STR_LEN("abc")));
61     assert(buffer_eq_slen(&ds->value, CONST_STR_LEN("ghi")));
62 
63     array_free(a);
64 }
65 
66 void test_array (void);
test_array(void)67 void test_array (void)
68 {
69     test_array_get_int_ptr();
70     test_array_insert_value();
71     test_array_set_key_value();
72 }
73