test_arr.c revision a74702c6
1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov#include <assert.h>
350aadb33SDmitri Tikhonov
450aadb33SDmitri Tikhonov#include "lsquic_arr.h"
550aadb33SDmitri Tikhonov
650aadb33SDmitri Tikhonovstatic void
750aadb33SDmitri Tikhonovtest1 (void)
850aadb33SDmitri Tikhonov{
950aadb33SDmitri Tikhonov    struct lsquic_arr arr;
1050aadb33SDmitri Tikhonov    lsquic_arr_init(&arr);
1150aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ecba0);
1250aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eccb0);
1350aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ecdb0);
1450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ece90);
1550aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ecf70);
1650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed0e0);
1750aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed1e0);
1850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed2c0);
1950aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed3a0);
2050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed510);
2150aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed5d0);
2250aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed6b0);
2350aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed7b0);
2450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed890);
2550aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed970);
2650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eda50);
2750aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ec450);
2850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ec510);
2950aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee210);
3050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee310);
3150aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee3f0);
3250aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee4e0);
3350aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee5f0);
3450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee6d0);
3550aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21edb50);
3650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21edb90);
3750aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eea20);
3850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eeb00);
3950aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ec790);
4050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ec870);
4150aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ec990);
4250aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eca70);
4350aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ecb50);
4450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee820);
4550aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee860);
4650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ef830);
4750aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ef930);
4850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21efa30);
4950aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21efb40);
5050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21efc20);
5150aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ef470);
5250aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ef530);
5350aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eff40);
5450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21f0020);
5550aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21f0100);
5650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21f0200);
5750aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21f02c0);
5850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21f03d0);
5950aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21efd20);
6050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21efe00);
6150aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21edc30);
6250aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21edd10);
6350aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eddf0);
6450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21edf00);
6550aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee000);
6650aadb33SDmitri Tikhonov    assert(0x21ecba0 == lsquic_arr_shift(&arr));
6750aadb33SDmitri Tikhonov    assert(0x21eccb0 == lsquic_arr_shift(&arr));
6850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eccb0);
6950aadb33SDmitri Tikhonov    assert(0x21ecdb0 == lsquic_arr_shift(&arr));
7050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ecdb0);
7150aadb33SDmitri Tikhonov    assert(0x21ece90 == lsquic_arr_shift(&arr));
7250aadb33SDmitri Tikhonov    assert(0x21ecf70 == lsquic_arr_shift(&arr));
7350aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ecf70);
7450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ece90);
7550aadb33SDmitri Tikhonov    assert(0x21ed0e0 == lsquic_arr_shift(&arr));
7650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed0e0);
7750aadb33SDmitri Tikhonov    assert(0x21ed1e0 == lsquic_arr_shift(&arr));
7850aadb33SDmitri Tikhonov    assert(0x21ed2c0 == lsquic_arr_shift(&arr));
7950aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed2c0);
8050aadb33SDmitri Tikhonov    assert(0x21ed3a0 == lsquic_arr_shift(&arr));
8150aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed3a0);
8250aadb33SDmitri Tikhonov    assert(0x21ed510 == lsquic_arr_shift(&arr));
8350aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed510);
8450aadb33SDmitri Tikhonov    assert(0x21ed5d0 == lsquic_arr_shift(&arr));
8550aadb33SDmitri Tikhonov    assert(0x21ed6b0 == lsquic_arr_shift(&arr));
8650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed6b0);
8750aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed5f0);
8850aadb33SDmitri Tikhonov    assert(0x21ed7b0 == lsquic_arr_shift(&arr));
8950aadb33SDmitri Tikhonov    assert(0x21ed890 == lsquic_arr_shift(&arr));
9050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed890);
9150aadb33SDmitri Tikhonov    assert(0x21ed970 == lsquic_arr_shift(&arr));
9250aadb33SDmitri Tikhonov    assert(0x21eda50 == lsquic_arr_shift(&arr));
9350aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eda50);
9450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ed990);
9550aadb33SDmitri Tikhonov    assert(0x21ec450 == lsquic_arr_shift(&arr));
9650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ec450);
9750aadb33SDmitri Tikhonov    assert(0x21ec510 == lsquic_arr_shift(&arr));
9850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ec510);
9950aadb33SDmitri Tikhonov    assert(0x21ee210 == lsquic_arr_shift(&arr));
10050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee210);
10150aadb33SDmitri Tikhonov    assert(0x21ee310 == lsquic_arr_shift(&arr));
10250aadb33SDmitri Tikhonov    assert(0x21ee3f0 == lsquic_arr_shift(&arr));
10350aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee3f0);
10450aadb33SDmitri Tikhonov    assert(0x21ee4e0 == lsquic_arr_shift(&arr));
10550aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee4e0);
10650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee330);
10750aadb33SDmitri Tikhonov    assert(0x21ee5f0 == lsquic_arr_shift(&arr));
10850aadb33SDmitri Tikhonov    assert(0x21ee6d0 == lsquic_arr_shift(&arr));
10950aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee6d0);
11050aadb33SDmitri Tikhonov    assert(0x21edb50 == lsquic_arr_shift(&arr));
11150aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21edb50);
11250aadb33SDmitri Tikhonov    assert(0x21edb90 == lsquic_arr_shift(&arr));
11350aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21edb90);
11450aadb33SDmitri Tikhonov    assert(0x21eea20 == lsquic_arr_shift(&arr));
11550aadb33SDmitri Tikhonov    assert(0x21eeb00 == lsquic_arr_shift(&arr));
11650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eeb00);
11750aadb33SDmitri Tikhonov    assert(0x21ec790 == lsquic_arr_shift(&arr));
11850aadb33SDmitri Tikhonov    assert(0x21ec870 == lsquic_arr_shift(&arr));
11950aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ec870);
12050aadb33SDmitri Tikhonov    assert(0x21ec990 == lsquic_arr_shift(&arr));
12150aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ec990);
12250aadb33SDmitri Tikhonov    assert(0x21eca70 == lsquic_arr_shift(&arr));
12350aadb33SDmitri Tikhonov    assert(0x21ecb50 == lsquic_arr_shift(&arr));
12450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ecb50);
12550aadb33SDmitri Tikhonov    assert(0x21ee820 == lsquic_arr_shift(&arr));
12650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee820);
12750aadb33SDmitri Tikhonov    assert(0x21ee860 == lsquic_arr_shift(&arr));
12850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ee860);
12950aadb33SDmitri Tikhonov    assert(0x21ef830 == lsquic_arr_shift(&arr));
13050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ef830);
13150aadb33SDmitri Tikhonov    assert(0x21ef930 == lsquic_arr_shift(&arr));
13250aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ef930);
13350aadb33SDmitri Tikhonov    assert(0x21efa30 == lsquic_arr_shift(&arr));
13450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21efa30);
13550aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eca90);
13650aadb33SDmitri Tikhonov    assert(0x21efb40 == lsquic_arr_shift(&arr));
13750aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21efb40);
13850aadb33SDmitri Tikhonov    assert(0x21efc20 == lsquic_arr_shift(&arr));
13950aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21efc20);
14050aadb33SDmitri Tikhonov    assert(0x21ef470 == lsquic_arr_shift(&arr));
14150aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ef470);
14250aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ec7d0);
14350aadb33SDmitri Tikhonov    assert(0x21ef530 == lsquic_arr_shift(&arr));
14450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21ef530);
14550aadb33SDmitri Tikhonov    assert(0x21eff40 == lsquic_arr_shift(&arr));
14650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21eff40);
14750aadb33SDmitri Tikhonov    assert(0x21f0020 == lsquic_arr_shift(&arr));
14850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21f0020);
14950aadb33SDmitri Tikhonov    assert(0x21f0100 == lsquic_arr_shift(&arr));
15050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21f0100);
15150aadb33SDmitri Tikhonov    assert(0x21f0200 == lsquic_arr_shift(&arr));
15250aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21f0200);
15350aadb33SDmitri Tikhonov    assert(0x21f02c0 == lsquic_arr_shift(&arr));
15450aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21f02c0);
15550aadb33SDmitri Tikhonov    assert(0x21f03d0 == lsquic_arr_shift(&arr));
15650aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21f03d0);
15750aadb33SDmitri Tikhonov    assert(0x21efd20 == lsquic_arr_shift(&arr));
15850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21efd20);
15950aadb33SDmitri Tikhonov    assert(0x21efe00 == lsquic_arr_shift(&arr));
16050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21efe00);
16150aadb33SDmitri Tikhonov    assert(0x21edc30 == lsquic_arr_shift(&arr));
16250aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 0x21edc30);
16350aadb33SDmitri Tikhonov    assert(0x21edd10 == lsquic_arr_shift(&arr));
16450aadb33SDmitri Tikhonov    assert(0x21eddf0 == lsquic_arr_shift(&arr));
16550aadb33SDmitri Tikhonov    lsquic_arr_cleanup(&arr);
16650aadb33SDmitri Tikhonov}
16750aadb33SDmitri Tikhonov
16850aadb33SDmitri Tikhonov
16950aadb33SDmitri Tikhonovint
17050aadb33SDmitri Tikhonovmain (void)
17150aadb33SDmitri Tikhonov{
17250aadb33SDmitri Tikhonov    struct lsquic_arr arr;
17350aadb33SDmitri Tikhonov    uintptr_t val;
17450aadb33SDmitri Tikhonov
17550aadb33SDmitri Tikhonov    lsquic_arr_init(&arr);
17650aadb33SDmitri Tikhonov
17750aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 1);
17850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 2);
17950aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 3);
18050aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 4);
18150aadb33SDmitri Tikhonov
18250aadb33SDmitri Tikhonov    assert(4 == lsquic_arr_count(&arr));
18350aadb33SDmitri Tikhonov
18450aadb33SDmitri Tikhonov    val = lsquic_arr_get(&arr, 0);
18550aadb33SDmitri Tikhonov    assert(1 == val);
18650aadb33SDmitri Tikhonov    val = lsquic_arr_get(&arr, 3);
18750aadb33SDmitri Tikhonov    assert(4 == val);
18850aadb33SDmitri Tikhonov
18950aadb33SDmitri Tikhonov    val = lsquic_arr_shift(&arr);
19050aadb33SDmitri Tikhonov
19150aadb33SDmitri Tikhonov    assert(1 == val);
19250aadb33SDmitri Tikhonov    assert(3 == lsquic_arr_count(&arr));
19350aadb33SDmitri Tikhonov
19450aadb33SDmitri Tikhonov    val = lsquic_arr_shift(&arr);
19550aadb33SDmitri Tikhonov    assert(2 == val);
19650aadb33SDmitri Tikhonov    val = lsquic_arr_shift(&arr);
19750aadb33SDmitri Tikhonov    assert(3 == val);
19850aadb33SDmitri Tikhonov    assert(1 == lsquic_arr_count(&arr));
19950aadb33SDmitri Tikhonov    val = lsquic_arr_get(&arr, 0);
20050aadb33SDmitri Tikhonov    assert(4 == val);
20150aadb33SDmitri Tikhonov
20250aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 5);
20350aadb33SDmitri Tikhonov    val = lsquic_arr_get(&arr, 0);
20450aadb33SDmitri Tikhonov    assert(4 == val);
20550aadb33SDmitri Tikhonov    assert(2 == lsquic_arr_count(&arr));
20650aadb33SDmitri Tikhonov
20750aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 6);
20850aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 7);
20950aadb33SDmitri Tikhonov    lsquic_arr_push(&arr, 8);
21050aadb33SDmitri Tikhonov    assert(5 == lsquic_arr_count(&arr));
21150aadb33SDmitri Tikhonov    assert(4 == lsquic_arr_shift(&arr));
21250aadb33SDmitri Tikhonov    assert(5 == lsquic_arr_shift(&arr));
21350aadb33SDmitri Tikhonov    assert(6 == lsquic_arr_shift(&arr));
21450aadb33SDmitri Tikhonov    assert(7 == lsquic_arr_shift(&arr));
21550aadb33SDmitri Tikhonov    assert(8 == lsquic_arr_shift(&arr));
21650aadb33SDmitri Tikhonov    assert(0 == lsquic_arr_count(&arr));
21750aadb33SDmitri Tikhonov
21850aadb33SDmitri Tikhonov    lsquic_arr_cleanup(&arr);
21950aadb33SDmitri Tikhonov
22050aadb33SDmitri Tikhonov    test1();
22150aadb33SDmitri Tikhonov
22250aadb33SDmitri Tikhonov    return 0;
22350aadb33SDmitri Tikhonov}
224