3 void testi(int *recieved, int *wanted, int length) {
4 for (int i = 0; i < length; i++)
5 expecti(recieved[i], wanted[i]);
8 void tests(short *recieved, short *wanted, int length) {
9 for (int i = 0; i < length; i++)
10 expects(recieved[i], wanted[i]);
13 void testarray(void) {
14 int a[] = { 1, 2, 3 };
15 int b[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
16 int c[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
17 int d[3][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
18 int e[] = { 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0 };
19 int f[4][3] = { { 1 }, { 2 }, { 3 }, { 4 } };
44 void teststruct(void) {
53 } data[] = { { 1 }, 2 };
58 void testnesting(void) {
70 } data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
72 expecti(data.a.a.a, 1);
73 expecti(data.a.a.b, 2);
74 expecti(data.a.b.a[0], 3);
75 expecti(data.a.b.a[1], 4);
76 expecti(data.a.b.a[2], 5);
77 expecti(data.a.b.a[3], 6);
78 expecti(data.a.b.a[4], 7);
79 expecti(data.a.b.a[5], 8);
80 expecti(data.a.b.a[6], 9);
81 expecti(data.a.b.a[7], 10);
84 void testdesignated(void) {
85 struct { int a, b, c; } a = {
91 struct { int a, b, c; } b = {
97 struct { int a, b, c; } c = {
113 // array designated initializers
114 int array[3] = { [1] = 1024 };
115 expecti(array[0], 0);
116 expecti(array[1], 1024);
117 expecti(array[2], 0);
122 } data[2] = { [1] = { 1, 2 } };
124 expecti(data[1].a, 1);
125 expecti(data[1].b, 2);
126 expecti(data[0].a, 0);
127 expecti(data[0].b, 0);
132 } data2[3] = { [1] = 10, 20, 30, 40 };
133 expecti(data2[0].a, 0);
134 expecti(data2[0].b, 0);
135 expecti(data2[1].a, 10);
136 expecti(data2[1].b, 20);
137 expecti(data2[2].a, 30);
138 expecti(data2[2].b, 40);
145 [1].c[0].b = 10, 20, 30, 40, 50,
148 expecti(10, again[1].c[0].b);
149 expecti(20, again[1].c[1].a);
150 expecti(30, again[1].c[1].b);
151 expecti(40, again[1].c[2].a);
152 expecti(50, again[1].c[2].b);
153 expecti(60, again[0].c[2].b);
154 expecti(70, again[1].c[0].a);
156 int A[][3] = { [0][0] = 10, [1][0] = 20 };
157 struct { int a, b[3]; } B = { .a = 10, .b[0] = 20, .b[1] = 30 };
159 expecti(A[0][0], 10);
160 expecti(A[1][0], 20);
167 void testorder(void) {
168 int order[4] = { [2] = 30, [0] = 10, 20 };
170 expecti(order[0], 10);
171 expecti(order[1], 20);
172 expecti(order[2], 30);
175 void testzero(void) {
176 struct { int a, b; } a = { 1024 };
177 struct { int a, b; } b = { .b = 1024 };
185 void testtypedef(void) {
187 array a = { 1, 2, 3 };
188 array b = { 4, 5, 6 };
190 expecti(sizeof(a) / sizeof(*a), 3);
191 expecti(sizeof(b) / sizeof(*b), 3);
210 int primitive = { 1024 };
211 expecti(primitive, 1024);
213 // test odd string initializers
214 char f[] = "abc"; expectstr(f, "abc");
215 char g[] = { "cba" }; expectstr(g, "cba");