annotate src/lib/test-array.c @ 23007:36e01285b5b8

lib: buffer - Improve header comment for buffer_insert() and buffer_delete().
author Stephan Bosch <stephan.bosch@dovecot.fi>
date Mon, 18 Mar 2019 00:52:37 +0100
parents cb108f786fb4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22713
cb108f786fb4 Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21390
diff changeset
1 /* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "test-lib.h"
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "array.h"
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5
18110
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
6
10405
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
7 struct foo {
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
8 unsigned int a, b, c;
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
9 };
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
10
18212
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
11 static void test_array_count(void)
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
12 {
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
13 ARRAY(struct foo) foos;
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
14 struct foo nfoo;
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
15
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
16 test_begin("array count/empty");
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
17 t_array_init(&foos, 32);
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
18
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
19 test_assert(array_count(&foos) == 0);
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
20 test_assert(array_is_empty(&foos));
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
21 test_assert(!array_not_empty(&foos));
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
22 nfoo.a = nfoo.b = nfoo.c = 9;
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
23 array_append(&foos, &nfoo, 1);
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
24 test_assert(array_count(&foos) == 1);
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
25 test_assert(!array_is_empty(&foos));
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
26 test_assert(array_not_empty(&foos));
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
27
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
28 test_end();
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
29 }
10405
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
30 static void test_array_foreach(void)
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
31 {
14920
a097ef0a9d6d Array API changed: ARRAY_DEFINE(name, type) -> ARRAY(type) name
Timo Sirainen <tss@iki.fi>
parents: 14553
diff changeset
32 ARRAY(struct foo) foos;
10405
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
33 const struct foo *foo;
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
34 struct foo nfoo;
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
35 unsigned int i;
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
36
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
37 test_begin("array foreach");
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
38 t_array_init(&foos, 32);
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
39 for (i = 0; i < 10; i++) {
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
40 nfoo.a = nfoo.b = nfoo.c = i;
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
41 array_append(&foos, &nfoo, 1);
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
42 }
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
43
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
44 array_foreach(&foos, foo) {
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
45 i = array_foreach_idx(&foos, foo);
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
46 test_assert(foo->a == i);
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
47 test_assert(foo->b == i);
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
48 test_assert(foo->c == i);
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
49 }
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
50 test_end();
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
51 }
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
52
18200
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
53 static void test_array_swap(void)
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
54 {
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
55 ARRAY(struct foo) foos[3];
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
56 struct foo nfoo;
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
57 int i, j;
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
58
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
59 test_begin("array swap");
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
60 for (i = 1; i <= 3; i++) {
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
61 t_array_init(&foos[i-1], i);
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
62 for (j = 1; j <= 2*i+1; j++) {
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
63 nfoo.a = nfoo.b = nfoo.c = j;
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
64 array_append(&foos[i-1], &nfoo, 1);
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
65 }
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
66 }
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
67 for (i = 0; i < 1000; i++)
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
68 array_swap(&foos[rand()%3], &foos[rand()%3]);
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
69 /* Just want size 3, 5, and 7 in any order */
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
70 test_assert(array_count(&foos[0]) * array_count(&foos[1]) * array_count(&foos[2]) == 3*5*7);
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
71 test_assert(array_count(&foos[0]) + array_count(&foos[1]) + array_count(&foos[2]) == 3+5+7);
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
72 test_end();
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
73 }
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
74
18133
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
75 static int test_int_compare(const int *key, const int *elem)
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
76 {
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
77 return (*key < *elem) ? -1 :
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
78 (*key > *elem) ? 1 :
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
79 0;
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
80 }
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 static void test_array_reverse(void)
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 {
14920
a097ef0a9d6d Array API changed: ARRAY_DEFINE(name, type) -> ARRAY(type) name
Timo Sirainen <tss@iki.fi>
parents: 14553
diff changeset
83 ARRAY(int) intarr;
14553
cb80c575b00c Compiler warning fixes
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
84 int input[] = { -1234567890, -272585721, 272485922, 824725652 };
18133
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
85 const int tmpi = 999, *output;
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 unsigned int i, j;
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 test_begin("array reverse");
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 t_array_init(&intarr, 5);
18114
e9ac32255ef1 lib: test-array - fix off-by-one in test_reverse
Phil Carmody <phil@dovecot.fi>
parents: 18113
diff changeset
90 for (i = 0; i <= N_ELEMENTS(input); i++) {
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 array_clear(&intarr);
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 array_append(&intarr, input, i);
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 array_reverse(&intarr);
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 output = i == 0 ? NULL : array_idx(&intarr, 0);
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 for (j = 0; j < i; j++)
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 test_assert(input[i-j-1] == output[j]);
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 }
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 test_end();
18133
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
100
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
101 test_begin("array_lsearch");
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
102 for (i = 0; i < N_ELEMENTS(input); i++) {
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
103 output = array_lsearch(&intarr, &input[i], test_int_compare);
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
104 test_assert(output != NULL);
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
105 j = array_ptr_to_idx(&intarr, output);
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
106 test_assert_idx(j == N_ELEMENTS(input) - 1 - i, i);
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
107 }
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
108 output = array_lsearch(&intarr, &tmpi, test_int_compare);
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
109 test_assert(output == NULL);
fa815914dce6 lib: test-array - test new lsearch helper
Phil Carmody <phil@dovecot.fi>
parents: 18120
diff changeset
110 test_end();
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 }
18112
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
112 static int test_compare_ushort(const unsigned short *c1, const unsigned short *c2)
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
113 {
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
114 return *c1 > *c2 ? 1
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
115 : *c1 < *c2 ? -1
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
116 : 0;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
117 }
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
118 static int test_compare_ushort_fuzz(const unsigned short *c1, const unsigned short *c2, const int *pfuzz)
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
119 {
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
120 int d = (int)*c1 - (int)*c2;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
121 if (d <= *pfuzz && -d <= *pfuzz)
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
122 return 0;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
123 return d;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
124 }
18110
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
125 static void test_array_cmp(void)
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
126 {
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
127 static const unsigned short deltas[] = {
18405
7c90285a72a6 lib: test-array build warnings on Solaris 10
Phil Carmody <phil@dovecot.fi>
parents: 18212
diff changeset
128 0x8000, 0xc000, 0xfe00, 0xff00, 0xff80, 0xffc0, 0xfffe, 0xffff,
18110
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
129 0, 1, 2, 64, 128, 256, 512, 16384, 32768
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
130 };
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
131
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
132 #define NELEMS 5u
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
133 ARRAY(unsigned short) arr1, arr2;
18112
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
134 unsigned short elems[NELEMS+1];
18110
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
135 unsigned int i;
18112
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
136 int fuzz;
18110
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
137
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
138 test_begin("array compare (ushort)");
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
139 t_array_init(&arr1, NELEMS);
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
140 t_array_init(&arr2, NELEMS);
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
141 for (i = 0; i < NELEMS; i++) {
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
142 elems[i] = rand();
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
143 array_append(&arr2, &elems[i], 1);
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
144 }
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
145 array_append(&arr1, elems, NELEMS);
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
146 test_assert(array_cmp(&arr1, &arr2) == 1);
18112
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
147 test_assert(array_equal_fn(&arr1, &arr2, test_compare_ushort) == 1);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
148 fuzz = 0;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
149 test_assert(array_equal_fn_ctx(&arr1, &arr2, test_compare_ushort_fuzz, &fuzz) == 1);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
150
18110
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
151 for (i = 0; i < 256; i++) {
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
152 unsigned int j = rand() % NELEMS;
18405
7c90285a72a6 lib: test-array build warnings on Solaris 10
Phil Carmody <phil@dovecot.fi>
parents: 18212
diff changeset
153 const unsigned short *ptmp = array_idx(&arr2, j);
7c90285a72a6 lib: test-array build warnings on Solaris 10
Phil Carmody <phil@dovecot.fi>
parents: 18212
diff changeset
154 unsigned short tmp = *ptmp;
18110
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
155 unsigned short repl = tmp + deltas[rand() % N_ELEMENTS(deltas)];
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
156
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
157 array_idx_set(&arr2, j, &repl);
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
158 test_assert_idx(array_cmp(&arr1, &arr2) == (tmp == repl), i);
18112
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
159 test_assert_idx(array_equal_fn(&arr1, &arr2, test_compare_ushort) == (tmp == repl), i);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
160 fuzz = (int)tmp - (int)repl;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
161 if (fuzz < 0)
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
162 fuzz = -fuzz;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
163 test_assert_idx(array_equal_fn_ctx(&arr1, &arr2, test_compare_ushort_fuzz, &fuzz) == 1, i);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
164 if (fuzz > 0) {
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
165 fuzz--;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
166 test_assert_idx(array_equal_fn_ctx(&arr1, &arr2, test_compare_ushort_fuzz, &fuzz) == 0, i);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
167 }
18110
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
168 array_idx_set(&arr2, j, &tmp);
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
169 test_assert_idx(array_cmp(&arr1, &arr2) == TRUE, i);
18112
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
170 test_assert_idx(array_equal_fn(&arr1, &arr2, test_compare_ushort) == 1, i);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
171 fuzz = 0;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
172 test_assert_idx(array_equal_fn_ctx(&arr1, &arr2, test_compare_ushort_fuzz, &fuzz) == 1, i);
18110
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
173 }
18112
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
174 elems[NELEMS] = 0;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
175 array_append(&arr2, &elems[NELEMS], 1);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
176 test_assert(array_cmp(&arr1, &arr2) == 0);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
177 test_assert(array_equal_fn(&arr1, &arr2, test_compare_ushort) == 0);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
178 test_assert_idx(array_equal_fn_ctx(&arr1, &arr2, test_compare_ushort_fuzz, &fuzz) == 0, i);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
179
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
180 test_end();
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
181 }
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
182
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
183 static int test_compare_string(const char *const *c1, const char *const *c2)
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
184 {
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
185 return strcmp(*c1, *c2);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
186 }
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
187 static void test_array_cmp_str(void)
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
188 {
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
189 #define NELEMS 5u
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
190 ARRAY(const char *) arr1, arr2;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
191 const char *elemstrs[NELEMS+1];
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
192 unsigned int i;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
193
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
194 test_begin("array compare (char*)");
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
195 t_array_init(&arr1, NELEMS);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
196 t_array_init(&arr2, NELEMS);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
197 for (i = 0; i < NELEMS; i++) {
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
198 elemstrs[i] = t_strdup_printf("%x", rand()); /* never 0-length */
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
199 array_append(&arr2, &elemstrs[i], 1);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
200 }
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
201 array_append(&arr1, elemstrs, NELEMS);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
202 test_assert(array_cmp(&arr1, &arr2) == 1); /* pointers shared, so identical */
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
203 test_assert(array_equal_fn(&arr1, &arr2, test_compare_string) == 1); /* therefore value same */
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
204 for (i = 0; i < 2560; i++) {
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
205 unsigned int j = rand() % NELEMS;
18405
7c90285a72a6 lib: test-array build warnings on Solaris 10
Phil Carmody <phil@dovecot.fi>
parents: 18212
diff changeset
206 const char *const *ostr_p = array_idx(&arr2, j);
7c90285a72a6 lib: test-array build warnings on Solaris 10
Phil Carmody <phil@dovecot.fi>
parents: 18212
diff changeset
207 const char *ostr = *ostr_p;
18112
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
208 unsigned int olen = strlen(ostr);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
209 unsigned int rc = rand() % (olen + 1);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
210 char ochar = ostr[rc];
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
211 char buf[12];
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
212 const char *bufp = buf;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
213 memcpy(buf, ostr, olen+1);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
214 buf[rc] = rand() % (CHAR_MAX + 1 - CHAR_MIN) + CHAR_MIN;
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
215 if(rc == olen)
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
216 buf[rc+1] = '\0';
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
217 array_idx_set(&arr2, j, &bufp);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
218 test_assert(array_cmp(&arr1, &arr2) == 0); /* pointers now differ */
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
219 test_assert_idx(array_equal_fn(&arr1, &arr2, test_compare_string)
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
220 == (strcmp(ostr, buf) == 0), i); /* sometimes still the same */
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
221 test_assert_idx(array_equal_fn(&arr1, &arr2, test_compare_string)
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
222 == (ochar == buf[rc]), i); /* ditto */
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
223 array_idx_set(&arr2, j, &ostr);
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
224 test_assert(array_cmp(&arr1, &arr2) == 1); /* pointers now same again */
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
225 test_assert_idx(array_equal_fn(&arr1, &arr2, test_compare_string) == 1, i); /* duh! */
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
226 }
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
227 /* length differences being detected are tested in other tests */
18110
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
228 test_end();
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
229 }
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
230
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 void test_array(void)
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232 {
18212
90e1829ba80e lib: array - test count/isempty/nonepty
Phil Carmody <phil@dovecot.fi>
parents: 18200
diff changeset
233 test_array_count();
10405
cc4e9d1fef7e Added array_foreach_idx()
Timo Sirainen <tss@iki.fi>
parents: 9425
diff changeset
234 test_array_foreach();
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235 test_array_reverse();
18110
a45ee7e221b0 lib: test-array - test array_cmp()
Phil Carmody <phil@dovecot.fi>
parents: 17130
diff changeset
236 test_array_cmp();
18112
5522d5ce87a5 lib: test-array - new equality testers
Phil Carmody <phil@dovecot.fi>
parents: 18110
diff changeset
237 test_array_cmp_str();
18200
7557234ac0f4 lib: array - helper to swap array buffer ownership
Phil Carmody <phil@dovecot.fi>
parents: 18137
diff changeset
238 test_array_swap();
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 }
18113
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
240
21299
5be9ee567034 lib-test: Change test_fatal_func_t to take unsigned int stage as parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
241 enum fatal_test_state fatal_array(unsigned int stage)
18113
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
242 {
18117
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
243 double tmpd[2] = { 42., -42. };
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
244 short tmps[8] = {1,2,3,4,5,6,7,8};
18120
096d233acb7d lib: test-array - really really really stop gcc optimising away fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18117
diff changeset
245 static const void *useless_ptr; /* persuade gcc to not optimise the tests */
18117
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
246
18113
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
247 switch(stage) {
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
248 case 0: {
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
249 ARRAY(double) ad;
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
250 test_begin("fatal_array");
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
251 t_array_init(&ad, 3);
18117
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
252 /* allocation big enough, but memory not initialised */
18120
096d233acb7d lib: test-array - really really really stop gcc optimising away fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18117
diff changeset
253 useless_ptr = array_idx(&ad, 0);
18113
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
254 return FATAL_TEST_FAILURE;
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
255 } break;
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
256
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
257 case 1: {
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
258 ARRAY(double) ad;
18117
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
259 t_array_init(&ad, 2);
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
260 array_append(&ad, tmpd, 2);
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
261 /* actual out of range address requested */
18120
096d233acb7d lib: test-array - really really really stop gcc optimising away fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18117
diff changeset
262 useless_ptr = array_idx(&ad, 2);
18117
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
263 return FATAL_TEST_FAILURE;
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
264 } break;
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
265
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
266 case 2: {
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
267 ARRAY(double) ad;
18113
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
268 ARRAY(short) as;
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
269 t_array_init(&ad, 2);
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
270 t_array_init(&as, 8);
18117
8a4b536705ad lib: test-array - remove possibility to optimise out tests
Phil Carmody <phil@dovecot.fi>
parents: 18114
diff changeset
271 array_append(&as, tmps, 2);
18113
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
272 array_copy(&ad.arr, 1, &as.arr, 0, 4);
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
273 return FATAL_TEST_FAILURE;
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
274 } break;
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
275 }
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
276 test_end();
18120
096d233acb7d lib: test-array - really really really stop gcc optimising away fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18117
diff changeset
277 /* Forces the compiler to check the value of useless_ptr, so that it
096d233acb7d lib: test-array - really really really stop gcc optimising away fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18117
diff changeset
278 must call array_idx (which is marked as pure, and gcc was desperate
21299
5be9ee567034 lib-test: Change test_fatal_func_t to take unsigned int stage as parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
279 to optimise out. Of course, gcc is unaware stage is never UINT_MAX.*/
5be9ee567034 lib-test: Change test_fatal_func_t to take unsigned int stage as parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
280 return (useless_ptr != NULL && stage == UINT_MAX)
18120
096d233acb7d lib: test-array - really really really stop gcc optimising away fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18117
diff changeset
281 ? FATAL_TEST_FAILURE : FATAL_TEST_FINISHED;
18113
9141a16aff4e lib: test-array - fatal tests
Phil Carmody <phil@dovecot.fi>
parents: 18112
diff changeset
282 }