1b4d46af0SDmitri Tikhonov#include <assert.h>
2b4d46af0SDmitri Tikhonov#include <stdlib.h>
3b4d46af0SDmitri Tikhonov#include <string.h>
4b4d46af0SDmitri Tikhonov#include <sys/queue.h>
5b4d46af0SDmitri Tikhonov
6b4d46af0SDmitri Tikhonov#include "lsqpack.h"
7b4d46af0SDmitri Tikhonov#include "lsqpack-test.h"
8b4d46af0SDmitri Tikhonov
9b4d46af0SDmitri Tikhonov
101c5db3d9SDmitri Tikhonovstruct str_test
11b4d46af0SDmitri Tikhonov{
121c5db3d9SDmitri Tikhonov    int                      strt_lineno;
131c5db3d9SDmitri Tikhonov    unsigned                 strt_prefix_bits;
141c5db3d9SDmitri Tikhonov    const unsigned char     *strt_in_str;
1500415457SDmitri Tikhonov    unsigned                 strt_in_len;
161c5db3d9SDmitri Tikhonov    const unsigned char     *strt_out_buf;
171c5db3d9SDmitri Tikhonov    int                      strt_retval;
18b4d46af0SDmitri Tikhonov};
19b4d46af0SDmitri Tikhonov
20b4d46af0SDmitri Tikhonov
211c5db3d9SDmitri Tikhonovstatic const struct str_test tests[] =
22b4d46af0SDmitri Tikhonov{
23b4d46af0SDmitri Tikhonov
24b4d46af0SDmitri Tikhonov    {
25b4d46af0SDmitri Tikhonov        __LINE__,
2646a42218SDmitri Tikhonov        3,
27b4d46af0SDmitri Tikhonov        (unsigned char *) "",
28b4d46af0SDmitri Tikhonov        0,
29b4d46af0SDmitri Tikhonov        (unsigned char *) "\x00",
30b4d46af0SDmitri Tikhonov        1,
31b4d46af0SDmitri Tikhonov    },
32b4d46af0SDmitri Tikhonov
33b4d46af0SDmitri Tikhonov    {
34b4d46af0SDmitri Tikhonov        __LINE__,
3546a42218SDmitri Tikhonov        3,
36b4d46af0SDmitri Tikhonov        (unsigned char *) "a",
37b4d46af0SDmitri Tikhonov        1,
38b4d46af0SDmitri Tikhonov        (unsigned char *) "\x01" "a",
39b4d46af0SDmitri Tikhonov        2,
40b4d46af0SDmitri Tikhonov    },
41b4d46af0SDmitri Tikhonov
42b4d46af0SDmitri Tikhonov    {
43b4d46af0SDmitri Tikhonov        __LINE__,
4446a42218SDmitri Tikhonov        3,
45b4d46af0SDmitri Tikhonov        (unsigned char *) "aa",
46b4d46af0SDmitri Tikhonov        2,
47b4d46af0SDmitri Tikhonov        (unsigned char *) "\x02" "aa",
48b4d46af0SDmitri Tikhonov        3,
49b4d46af0SDmitri Tikhonov    },
50b4d46af0SDmitri Tikhonov
51b4d46af0SDmitri Tikhonov    {
52b4d46af0SDmitri Tikhonov        __LINE__,
5346a42218SDmitri Tikhonov        3,
54b4d46af0SDmitri Tikhonov        (unsigned char *) "aaa",
55b4d46af0SDmitri Tikhonov        3,
56b4d46af0SDmitri Tikhonov        (unsigned char *) "\x0A\x18\xc7",
57b4d46af0SDmitri Tikhonov        3,
58b4d46af0SDmitri Tikhonov    },
59b4d46af0SDmitri Tikhonov
60b4d46af0SDmitri Tikhonov    {
61b4d46af0SDmitri Tikhonov        __LINE__,
6246a42218SDmitri Tikhonov        3,
63b4d46af0SDmitri Tikhonov        (unsigned char *) "aaaaaaaaa",
64b4d46af0SDmitri Tikhonov        9,
65b4d46af0SDmitri Tikhonov        (unsigned char *) "\x0E\x18\xc6\x31\x8c\x63\x1f",
66b4d46af0SDmitri Tikhonov        7,
67b4d46af0SDmitri Tikhonov    },
68b4d46af0SDmitri Tikhonov
69b4d46af0SDmitri Tikhonov    {
70b4d46af0SDmitri Tikhonov        __LINE__,
7146a42218SDmitri Tikhonov        3,
72b4d46af0SDmitri Tikhonov        (unsigned char *) "aaaaaaaaaa",
73b4d46af0SDmitri Tikhonov        10,
74b4d46af0SDmitri Tikhonov        (unsigned char *) "\x0F\x00\x18\xc6\x31\x8c\x63\x18\xff",
75b4d46af0SDmitri Tikhonov        9,
76b4d46af0SDmitri Tikhonov    },
77b4d46af0SDmitri Tikhonov
78b4d46af0SDmitri Tikhonov    {
79b4d46af0SDmitri Tikhonov        __LINE__,
8046a42218SDmitri Tikhonov        3,
81b4d46af0SDmitri Tikhonov        (unsigned char *) "aaaaaaaaaabbb",
82b4d46af0SDmitri Tikhonov        13,
83b4d46af0SDmitri Tikhonov        (unsigned char *) "\x0F\x02\x18\xc6\x31\x8c\x63\x18\xe3\x8e\x3f",
84b4d46af0SDmitri Tikhonov        11,
85b4d46af0SDmitri Tikhonov    },
86b4d46af0SDmitri Tikhonov
87b4d46af0SDmitri Tikhonov    {
88b4d46af0SDmitri Tikhonov        __LINE__,
8946a42218SDmitri Tikhonov        3,
90b4d46af0SDmitri Tikhonov        (unsigned char *) "\x80\x90\xA0\xBA",
91b4d46af0SDmitri Tikhonov        4,
92b4d46af0SDmitri Tikhonov        (unsigned char *) "\x04\x80\x90\xA0\xBA",
93b4d46af0SDmitri Tikhonov        5,
94b4d46af0SDmitri Tikhonov    },
95b4d46af0SDmitri Tikhonov
96b4d46af0SDmitri Tikhonov    {
97b4d46af0SDmitri Tikhonov        __LINE__,
9846a42218SDmitri Tikhonov        3,
99b4d46af0SDmitri Tikhonov        (unsigned char *) "\x80\x90\xA0\xBA\x80\x90\xA0",
100b4d46af0SDmitri Tikhonov        7,
101b4d46af0SDmitri Tikhonov        (unsigned char *) "\x07\x00\x80\x90\xA0\xBA\x80\x90\xA0",
102b4d46af0SDmitri Tikhonov        9,
103b4d46af0SDmitri Tikhonov    },
104b4d46af0SDmitri Tikhonov
105b4d46af0SDmitri Tikhonov    {
106b4d46af0SDmitri Tikhonov        __LINE__,
10746a42218SDmitri Tikhonov        3,
108b4d46af0SDmitri Tikhonov        (unsigned char *) "\x80\x90\xA0\xBA\x80\x90\xA0" "foo",
109b4d46af0SDmitri Tikhonov        10,
110b4d46af0SDmitri Tikhonov        (unsigned char *) "\x07\x03\x80\x90\xA0\xBA\x80\x90\xA0" "foo",
111b4d46af0SDmitri Tikhonov        12,
112b4d46af0SDmitri Tikhonov    },
113b4d46af0SDmitri Tikhonov
114b4d46af0SDmitri Tikhonov};
115b4d46af0SDmitri Tikhonov
116b4d46af0SDmitri Tikhonov
117b4d46af0SDmitri Tikhonovint
118b4d46af0SDmitri Tikhonovmain (void)
119b4d46af0SDmitri Tikhonov{
1201c5db3d9SDmitri Tikhonov    const struct str_test *test;
121b4d46af0SDmitri Tikhonov    int r;
122205a2804SDmitri Tikhonov    unsigned char *out= malloc(0x1000);
123205a2804SDmitri Tikhonov
124205a2804SDmitri Tikhonov    if (!out)
125205a2804SDmitri Tikhonov        return 1;
126b4d46af0SDmitri Tikhonov
127b4d46af0SDmitri Tikhonov    for (test = tests; test < tests + sizeof(tests) / sizeof(tests[0]); ++test)
128b4d46af0SDmitri Tikhonov    {
129b4d46af0SDmitri Tikhonov        out[0] = 0;
130205a2804SDmitri Tikhonov        r = lsqpack_enc_enc_str(test->strt_prefix_bits, out, 0x1000,
1311c5db3d9SDmitri Tikhonov                                         test->strt_in_str, test->strt_in_len);
1321c5db3d9SDmitri Tikhonov        assert(r == test->strt_retval);
133b4d46af0SDmitri Tikhonov        if (r > 0)
1341c5db3d9SDmitri Tikhonov            assert(0 == memcmp(test->strt_out_buf, out, r));
135b4d46af0SDmitri Tikhonov    }
136b4d46af0SDmitri Tikhonov
137205a2804SDmitri Tikhonov    free(out);
138b4d46af0SDmitri Tikhonov    return 0;
139b4d46af0SDmitri Tikhonov}
140