1/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc.  See LICENSE. */
2#include <assert.h>
3
4#include "lsquic_arr.h"
5
6static void
7test1 (void)
8{
9    struct lsquic_arr arr;
10    lsquic_arr_init(&arr);
11    lsquic_arr_push(&arr, 0x21ecba0);
12    lsquic_arr_push(&arr, 0x21eccb0);
13    lsquic_arr_push(&arr, 0x21ecdb0);
14    lsquic_arr_push(&arr, 0x21ece90);
15    lsquic_arr_push(&arr, 0x21ecf70);
16    lsquic_arr_push(&arr, 0x21ed0e0);
17    lsquic_arr_push(&arr, 0x21ed1e0);
18    lsquic_arr_push(&arr, 0x21ed2c0);
19    lsquic_arr_push(&arr, 0x21ed3a0);
20    lsquic_arr_push(&arr, 0x21ed510);
21    lsquic_arr_push(&arr, 0x21ed5d0);
22    lsquic_arr_push(&arr, 0x21ed6b0);
23    lsquic_arr_push(&arr, 0x21ed7b0);
24    lsquic_arr_push(&arr, 0x21ed890);
25    lsquic_arr_push(&arr, 0x21ed970);
26    lsquic_arr_push(&arr, 0x21eda50);
27    lsquic_arr_push(&arr, 0x21ec450);
28    lsquic_arr_push(&arr, 0x21ec510);
29    lsquic_arr_push(&arr, 0x21ee210);
30    lsquic_arr_push(&arr, 0x21ee310);
31    lsquic_arr_push(&arr, 0x21ee3f0);
32    lsquic_arr_push(&arr, 0x21ee4e0);
33    lsquic_arr_push(&arr, 0x21ee5f0);
34    lsquic_arr_push(&arr, 0x21ee6d0);
35    lsquic_arr_push(&arr, 0x21edb50);
36    lsquic_arr_push(&arr, 0x21edb90);
37    lsquic_arr_push(&arr, 0x21eea20);
38    lsquic_arr_push(&arr, 0x21eeb00);
39    lsquic_arr_push(&arr, 0x21ec790);
40    lsquic_arr_push(&arr, 0x21ec870);
41    lsquic_arr_push(&arr, 0x21ec990);
42    lsquic_arr_push(&arr, 0x21eca70);
43    lsquic_arr_push(&arr, 0x21ecb50);
44    lsquic_arr_push(&arr, 0x21ee820);
45    lsquic_arr_push(&arr, 0x21ee860);
46    lsquic_arr_push(&arr, 0x21ef830);
47    lsquic_arr_push(&arr, 0x21ef930);
48    lsquic_arr_push(&arr, 0x21efa30);
49    lsquic_arr_push(&arr, 0x21efb40);
50    lsquic_arr_push(&arr, 0x21efc20);
51    lsquic_arr_push(&arr, 0x21ef470);
52    lsquic_arr_push(&arr, 0x21ef530);
53    lsquic_arr_push(&arr, 0x21eff40);
54    lsquic_arr_push(&arr, 0x21f0020);
55    lsquic_arr_push(&arr, 0x21f0100);
56    lsquic_arr_push(&arr, 0x21f0200);
57    lsquic_arr_push(&arr, 0x21f02c0);
58    lsquic_arr_push(&arr, 0x21f03d0);
59    lsquic_arr_push(&arr, 0x21efd20);
60    lsquic_arr_push(&arr, 0x21efe00);
61    lsquic_arr_push(&arr, 0x21edc30);
62    lsquic_arr_push(&arr, 0x21edd10);
63    lsquic_arr_push(&arr, 0x21eddf0);
64    lsquic_arr_push(&arr, 0x21edf00);
65    lsquic_arr_push(&arr, 0x21ee000);
66    assert(0x21ecba0 == lsquic_arr_shift(&arr));
67    assert(0x21eccb0 == lsquic_arr_shift(&arr));
68    lsquic_arr_push(&arr, 0x21eccb0);
69    assert(0x21ecdb0 == lsquic_arr_shift(&arr));
70    lsquic_arr_push(&arr, 0x21ecdb0);
71    assert(0x21ece90 == lsquic_arr_shift(&arr));
72    assert(0x21ecf70 == lsquic_arr_shift(&arr));
73    lsquic_arr_push(&arr, 0x21ecf70);
74    lsquic_arr_push(&arr, 0x21ece90);
75    assert(0x21ed0e0 == lsquic_arr_shift(&arr));
76    lsquic_arr_push(&arr, 0x21ed0e0);
77    assert(0x21ed1e0 == lsquic_arr_shift(&arr));
78    assert(0x21ed2c0 == lsquic_arr_shift(&arr));
79    lsquic_arr_push(&arr, 0x21ed2c0);
80    assert(0x21ed3a0 == lsquic_arr_shift(&arr));
81    lsquic_arr_push(&arr, 0x21ed3a0);
82    assert(0x21ed510 == lsquic_arr_shift(&arr));
83    lsquic_arr_push(&arr, 0x21ed510);
84    assert(0x21ed5d0 == lsquic_arr_shift(&arr));
85    assert(0x21ed6b0 == lsquic_arr_shift(&arr));
86    lsquic_arr_push(&arr, 0x21ed6b0);
87    lsquic_arr_push(&arr, 0x21ed5f0);
88    assert(0x21ed7b0 == lsquic_arr_shift(&arr));
89    assert(0x21ed890 == lsquic_arr_shift(&arr));
90    lsquic_arr_push(&arr, 0x21ed890);
91    assert(0x21ed970 == lsquic_arr_shift(&arr));
92    assert(0x21eda50 == lsquic_arr_shift(&arr));
93    lsquic_arr_push(&arr, 0x21eda50);
94    lsquic_arr_push(&arr, 0x21ed990);
95    assert(0x21ec450 == lsquic_arr_shift(&arr));
96    lsquic_arr_push(&arr, 0x21ec450);
97    assert(0x21ec510 == lsquic_arr_shift(&arr));
98    lsquic_arr_push(&arr, 0x21ec510);
99    assert(0x21ee210 == lsquic_arr_shift(&arr));
100    lsquic_arr_push(&arr, 0x21ee210);
101    assert(0x21ee310 == lsquic_arr_shift(&arr));
102    assert(0x21ee3f0 == lsquic_arr_shift(&arr));
103    lsquic_arr_push(&arr, 0x21ee3f0);
104    assert(0x21ee4e0 == lsquic_arr_shift(&arr));
105    lsquic_arr_push(&arr, 0x21ee4e0);
106    lsquic_arr_push(&arr, 0x21ee330);
107    assert(0x21ee5f0 == lsquic_arr_shift(&arr));
108    assert(0x21ee6d0 == lsquic_arr_shift(&arr));
109    lsquic_arr_push(&arr, 0x21ee6d0);
110    assert(0x21edb50 == lsquic_arr_shift(&arr));
111    lsquic_arr_push(&arr, 0x21edb50);
112    assert(0x21edb90 == lsquic_arr_shift(&arr));
113    lsquic_arr_push(&arr, 0x21edb90);
114    assert(0x21eea20 == lsquic_arr_shift(&arr));
115    assert(0x21eeb00 == lsquic_arr_shift(&arr));
116    lsquic_arr_push(&arr, 0x21eeb00);
117    assert(0x21ec790 == lsquic_arr_shift(&arr));
118    assert(0x21ec870 == lsquic_arr_shift(&arr));
119    lsquic_arr_push(&arr, 0x21ec870);
120    assert(0x21ec990 == lsquic_arr_shift(&arr));
121    lsquic_arr_push(&arr, 0x21ec990);
122    assert(0x21eca70 == lsquic_arr_shift(&arr));
123    assert(0x21ecb50 == lsquic_arr_shift(&arr));
124    lsquic_arr_push(&arr, 0x21ecb50);
125    assert(0x21ee820 == lsquic_arr_shift(&arr));
126    lsquic_arr_push(&arr, 0x21ee820);
127    assert(0x21ee860 == lsquic_arr_shift(&arr));
128    lsquic_arr_push(&arr, 0x21ee860);
129    assert(0x21ef830 == lsquic_arr_shift(&arr));
130    lsquic_arr_push(&arr, 0x21ef830);
131    assert(0x21ef930 == lsquic_arr_shift(&arr));
132    lsquic_arr_push(&arr, 0x21ef930);
133    assert(0x21efa30 == lsquic_arr_shift(&arr));
134    lsquic_arr_push(&arr, 0x21efa30);
135    lsquic_arr_push(&arr, 0x21eca90);
136    assert(0x21efb40 == lsquic_arr_shift(&arr));
137    lsquic_arr_push(&arr, 0x21efb40);
138    assert(0x21efc20 == lsquic_arr_shift(&arr));
139    lsquic_arr_push(&arr, 0x21efc20);
140    assert(0x21ef470 == lsquic_arr_shift(&arr));
141    lsquic_arr_push(&arr, 0x21ef470);
142    lsquic_arr_push(&arr, 0x21ec7d0);
143    assert(0x21ef530 == lsquic_arr_shift(&arr));
144    lsquic_arr_push(&arr, 0x21ef530);
145    assert(0x21eff40 == lsquic_arr_shift(&arr));
146    lsquic_arr_push(&arr, 0x21eff40);
147    assert(0x21f0020 == lsquic_arr_shift(&arr));
148    lsquic_arr_push(&arr, 0x21f0020);
149    assert(0x21f0100 == lsquic_arr_shift(&arr));
150    lsquic_arr_push(&arr, 0x21f0100);
151    assert(0x21f0200 == lsquic_arr_shift(&arr));
152    lsquic_arr_push(&arr, 0x21f0200);
153    assert(0x21f02c0 == lsquic_arr_shift(&arr));
154    lsquic_arr_push(&arr, 0x21f02c0);
155    assert(0x21f03d0 == lsquic_arr_shift(&arr));
156    lsquic_arr_push(&arr, 0x21f03d0);
157    assert(0x21efd20 == lsquic_arr_shift(&arr));
158    lsquic_arr_push(&arr, 0x21efd20);
159    assert(0x21efe00 == lsquic_arr_shift(&arr));
160    lsquic_arr_push(&arr, 0x21efe00);
161    assert(0x21edc30 == lsquic_arr_shift(&arr));
162    lsquic_arr_push(&arr, 0x21edc30);
163    assert(0x21edd10 == lsquic_arr_shift(&arr));
164    assert(0x21eddf0 == lsquic_arr_shift(&arr));
165    lsquic_arr_cleanup(&arr);
166}
167
168
169int
170main (void)
171{
172    struct lsquic_arr arr;
173    uintptr_t val;
174
175    lsquic_arr_init(&arr);
176
177    lsquic_arr_push(&arr, 1);
178    lsquic_arr_push(&arr, 2);
179    lsquic_arr_push(&arr, 3);
180    lsquic_arr_push(&arr, 4);
181
182    assert(4 == lsquic_arr_count(&arr));
183
184    val = lsquic_arr_get(&arr, 0);
185    assert(1 == val);
186    val = lsquic_arr_get(&arr, 3);
187    assert(4 == val);
188
189    val = lsquic_arr_shift(&arr);
190
191    assert(1 == val);
192    assert(3 == lsquic_arr_count(&arr));
193
194    val = lsquic_arr_shift(&arr);
195    assert(2 == val);
196    val = lsquic_arr_shift(&arr);
197    assert(3 == val);
198    assert(1 == lsquic_arr_count(&arr));
199    val = lsquic_arr_get(&arr, 0);
200    assert(4 == val);
201
202    lsquic_arr_push(&arr, 5);
203    val = lsquic_arr_get(&arr, 0);
204    assert(4 == val);
205    assert(2 == lsquic_arr_count(&arr));
206
207    lsquic_arr_push(&arr, 6);
208    lsquic_arr_push(&arr, 7);
209    lsquic_arr_push(&arr, 8);
210    assert(5 == lsquic_arr_count(&arr));
211    assert(4 == lsquic_arr_shift(&arr));
212    assert(5 == lsquic_arr_shift(&arr));
213    assert(6 == lsquic_arr_shift(&arr));
214    assert(7 == lsquic_arr_shift(&arr));
215    assert(8 == lsquic_arr_shift(&arr));
216    assert(0 == lsquic_arr_count(&arr));
217
218    lsquic_arr_cleanup(&arr);
219
220    test1();
221
222    return 0;
223}
224