lsqpack 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +82 -0
- data/LICENSE +21 -0
- data/README.md +36 -0
- data/Rakefile +19 -0
- data/Steepfile +6 -0
- data/ext/lsqpack/extconf.rb +18 -0
- data/ext/lsqpack/lsqpack.c +426 -0
- data/ext/lsqpack/lsqpack.h +6 -0
- data/lib/lsqpack/version.rb +5 -0
- data/lib/lsqpack.rb +30 -0
- data/ls-qpack/.appveyor.yml +14 -0
- data/ls-qpack/.cirrus.yml +6 -0
- data/ls-qpack/.travis.yml +32 -0
- data/ls-qpack/CMakeLists.txt +66 -0
- data/ls-qpack/LICENSE +21 -0
- data/ls-qpack/README.md +65 -0
- data/ls-qpack/bin/CMakeLists.txt +21 -0
- data/ls-qpack/bin/encode-int.c +87 -0
- data/ls-qpack/bin/fuzz-decode.c +247 -0
- data/ls-qpack/bin/interop-decode.c +433 -0
- data/ls-qpack/bin/interop-encode.c +554 -0
- data/ls-qpack/deps/xxhash/xxhash.c +941 -0
- data/ls-qpack/deps/xxhash/xxhash.h +160 -0
- data/ls-qpack/fuzz/decode/a/README +3 -0
- data/ls-qpack/fuzz/decode/a/preamble +0 -0
- data/ls-qpack/fuzz/decode/a/test-cases/id_000000,sig_06,src_000390,op_havoc,rep_4 +0 -0
- data/ls-qpack/fuzz/decode/a/test-cases/id_000000,sig_06,src_000579,op_flip1,pos_14 +0 -0
- data/ls-qpack/fuzz/decode/a/test-cases/id_000000,src_000000,op_flip2,pos_12 +0 -0
- data/ls-qpack/fuzz/decode/a/test-cases/id_000001,sig_11,src_000579,op_havoc,rep_4 +0 -0
- data/ls-qpack/fuzz/decode/a/test-cases/id_000002,sig_11,src_000481,op_int16,pos_15,val_-1 +0 -0
- data/ls-qpack/fuzz/decode/a/test-cases/id_000002,src_000000,op_havoc,rep_8 +0 -0
- data/ls-qpack/fuzz/decode/a/test-cases/id_000006,src_000285,op_flip2,pos_14 +0 -0
- data/ls-qpack/fuzz/decode/a/test-cases/id_000008,src_000285,op_flip2,pos_20 +0 -0
- data/ls-qpack/fuzz/decode/a/test-cases/id_000010,src_000306,op_flip2,pos_75 +0 -0
- data/ls-qpack/fuzz/decode/a/test-cases/id_000011,src_000344,op_havoc,rep_2 +0 -0
- data/ls-qpack/fuzz/decode/a/test-cases/id_000014,src_000366,op_flip2,pos_28 +0 -0
- data/ls-qpack/fuzz/decode/b/README +1 -0
- data/ls-qpack/fuzz/decode/b/preamble +0 -0
- data/ls-qpack/fuzz/decode/b/test-cases/seed +0 -0
- data/ls-qpack/fuzz/decode/c/setup.sh +3 -0
- data/ls-qpack/fuzz/decode/c/test-cases/fb-req.qif.proxygen.out.256.100.0-chopped +0 -0
- data/ls-qpack/fuzz/decode/d/preamble +0 -0
- data/ls-qpack/fuzz/decode/d/setup.sh +3 -0
- data/ls-qpack/fuzz/decode/d/test-cases/fb-resp.minhq.256.128.0.ack +0 -0
- data/ls-qpack/fuzz/input/256.100.1/fb-req.out.256.100.1 +0 -0
- data/ls-qpack/fuzz/input/256.100.1/fb-resp.out.256.100.1 +0 -0
- data/ls-qpack/fuzz/input/256.100.1/netbsd.out.256.100.1 +0 -0
- data/ls-qpack/huff-tables.h +136247 -0
- data/ls-qpack/lsqpack.c +5547 -0
- data/ls-qpack/lsqpack.h +768 -0
- data/ls-qpack/test/CMakeLists.txt +76 -0
- data/ls-qpack/test/lsqpack-test.h +43 -0
- data/ls-qpack/test/qifs/fb-req.qif +4917 -0
- data/ls-qpack/test/qifs/fb-resp.qif +5982 -0
- data/ls-qpack/test/qifs/long-codes.qif +5984 -0
- data/ls-qpack/test/qifs/netbsd.qif +235 -0
- data/ls-qpack/test/run-qif.pl +97 -0
- data/ls-qpack/test/run-scenario.sh +68 -0
- data/ls-qpack/test/scenarios/0.95-reset.sce +10 -0
- data/ls-qpack/test/scenarios/cancel-stream.sce +22 -0
- data/ls-qpack/test/scenarios/drain-2.sce +37 -0
- data/ls-qpack/test/scenarios/drain.sce +37 -0
- data/ls-qpack/test/scenarios/end-dst-2.sce +14 -0
- data/ls-qpack/test/scenarios/end-dst.sce +14 -0
- data/ls-qpack/test/scenarios/incl-name.sce +13 -0
- data/ls-qpack/test/scenarios/multi-byte-int-dyn-ref-1.sce +110 -0
- data/ls-qpack/test/scenarios/multi-byte-int-dyn-ref-2.sce +161 -0
- data/ls-qpack/test/scenarios/post-base-1.sce +10 -0
- data/ls-qpack/test/scenarios/post-base-2.sce +13 -0
- data/ls-qpack/test/scenarios/post-base-nr.sce +10 -0
- data/ls-qpack/test/scenarios/set-max-cap.sce +15 -0
- data/ls-qpack/test/test_enc_str.c +139 -0
- data/ls-qpack/test/test_get_stx_id.c +144 -0
- data/ls-qpack/test/test_huff_dec.c +399 -0
- data/ls-qpack/test/test_int.c +220 -0
- data/ls-qpack/test/test_qpack.c +856 -0
- data/ls-qpack/test/test_read_enc_stream.c +256 -0
- data/ls-qpack/tools/har2qif.pl +139 -0
- data/ls-qpack/tools/randomize-cookies.pl +41 -0
- data/ls-qpack/tools/sort-qif.pl +31 -0
- data/ls-qpack/wincompat/getopt.c +758 -0
- data/ls-qpack/wincompat/getopt.h +131 -0
- data/ls-qpack/wincompat/getopt1.c +188 -0
- data/ls-qpack/wincompat/sys/queue.h +859 -0
- data/lsqpack.gemspec +39 -0
- data/sig/lsqpack.rbs +29 -0
- metadata +135 -0
@@ -0,0 +1,399 @@
|
|
1
|
+
/*
|
2
|
+
* Usage: test_huff_dec [-v] [-e]
|
3
|
+
*
|
4
|
+
* -v Verbose
|
5
|
+
* -e Run expensive tests
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include <assert.h>
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <stdlib.h>
|
11
|
+
#include <string.h>
|
12
|
+
#ifdef WIN32
|
13
|
+
#include "getopt.h"
|
14
|
+
#else
|
15
|
+
#include <unistd.h>
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#include "lsqpack.h"
|
19
|
+
#include "lsqpack-test.h"
|
20
|
+
|
21
|
+
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
22
|
+
|
23
|
+
static int verbose;
|
24
|
+
|
25
|
+
struct test_huff_dec
|
26
|
+
{
|
27
|
+
int lineno;
|
28
|
+
|
29
|
+
/* Input */
|
30
|
+
unsigned char *src;
|
31
|
+
size_t src_sz;
|
32
|
+
|
33
|
+
/* Output */
|
34
|
+
char *dst;
|
35
|
+
size_t dst_sz;
|
36
|
+
};
|
37
|
+
|
38
|
+
const struct test_huff_dec tests[] =
|
39
|
+
{
|
40
|
+
{ __LINE__,
|
41
|
+
(unsigned char *)
|
42
|
+
"\xbf\x6c\x85\xfa\x53\xc4\xe5\xb0\xaa\x19\x0a\x53\xe9\x42\x0e\xcf\xf3",
|
43
|
+
17,
|
44
|
+
"Dude, where is my car?",
|
45
|
+
22,
|
46
|
+
},
|
47
|
+
{ __LINE__,
|
48
|
+
(unsigned char *)
|
49
|
+
"\xd6\x32\x1a\xa9\x94\x8c\x64\xea\xa0\xea\x91\x49"
|
50
|
+
"\x4f\x62\x67\x51\x33\x95\x4a\x0b\x54\xc9\x9d\x43\xca\xa2\x67\x2a"
|
51
|
+
"\x93\x8d\x24\x9f\xc0\xfd\x21\x41\xd5\x22\x88\x1f\x71\xcc\x5a\x3d"
|
52
|
+
"\x28\x49\xcb\xe0\xd5\x4d\xff\xff\xff\xe2\x67\x2a\x85\xaa\x45\x0f"
|
53
|
+
"\x2a\x83\x50\x86\x98\x76\x7d\x29\xe0\x68\x51\x33\x95\x4a\x47\x52"
|
54
|
+
"\x9e\x27\x3a\x0a\xa1\x06\x8b\x47\x42\x93\x50\x3a\x88\x55\x27\x1c"
|
55
|
+
"\x8a\x58\x54\x12\xd2\xc8\xa5\x25\x52\x5b\x0f\x4f\xff\xff\xff\x89"
|
56
|
+
"\x9c\xaa\x20\xa3\x5d\x45\x31\x99\x0a\x4e\x53\x4d\x3a\x54\xf0\x34"
|
57
|
+
"\x29\x5d\x87\x8c\x71\xd1\xe9\x49\x4d\xdc\xaa\x4a\x52\xa5\x44\x96"
|
58
|
+
"\xa5\x0d\x51\x27\x2a\x3e\x94\x3d\x8a\x24\xb5\x28\x3a\xa4\x50\x7f"
|
59
|
+
"\xff\xff\xfe\x4e\x3a\x25\xfb\x52\x3b\x52\xa5\x3e\x94\x94\xd6\x21"
|
60
|
+
"\x2a\x1a\x9a\xec\x2a\x10\x63\xd5\xf4\xa1\xec\x52\x52\x96\x85\x0f"
|
61
|
+
"\x2a\x89\x9c\xaa\x52\x3a\xbe\x94\xf0\x34\x29\x51\xd2\xa1\xe5\x51"
|
62
|
+
"\x33\x99\x1f\x4a\x47\x6a\x7f\xff\xff\xfc\x3c\xaa\x4e\x64\x28\x84"
|
63
|
+
"\xd8\x5a\xa6\x4c\xeb\xa8\xa4\x35\x48\xa7\xa2\xa7\xe9\x4f\x13\x9a"
|
64
|
+
"\x82\xa9\x39\x54\xf0\x34\x28\x79\x54\xa4\x68\x41\xbb\x95\x48\xed"
|
65
|
+
"\x35\x12\x7d\x29\xe0\xc9\x9d\x48\xec\x38\xe4\xff\xff\xff\xf1\x13"
|
66
|
+
"\x9e\xda\x24\x2d\x88\x50\x75\x48\xa4\x85\x2d\x6a\x12\x72\xa1\x3f"
|
67
|
+
"\x4a\x64\x50\x87\xb6\x89\x14\xa8\xe9\x50\x93\x8e\xc1\x91\x25\xb0"
|
68
|
+
"\xde\xca\xa4\xe6\x42\x88\x4d\x85\xaa\x64\xce\xa0\xd1\xff\xff\xff"
|
69
|
+
"\xe5\x23\x42\x0d\xdc\xab\xa8\xa6\x44\xa9\xe0\x68\x53\xc4\xe3\x4a"
|
70
|
+
"\x94\x9a\x69\xd2\xa4\x65\x51\x25\xb2\x92\xc8\xa0\xd4\x41\xaa\x2f"
|
71
|
+
"\x8f\x5f\x4a\x75\xa8\xe9\x4f\xa5\x10\x9b\x0b\x54\xc9\x9f\xe9\x43"
|
72
|
+
"\xca\xa2\x67\x2f\xff\xff\xff\x9d\x4d\x54\x8a\x78\x2a\x83\x41\x2c"
|
73
|
+
"\x34\x65\x51\x27\x52\x82\x8e\xa5\x07\x54\x8a\x78\x35\x9e\x94\xa4"
|
74
|
+
"\xb5\x7d\x29\x1d\xa9\x53\xc4\xe6\x24\xff\x4a\x1a\xa5\x27\x35\x3f"
|
75
|
+
"\x4a\x46\x52\x0e\xd4\x15\x43\xca\xa4\xe6\x47\xff\xff\xff\x93\x94"
|
76
|
+
"\x7d\xfd\x29\x1d\xa6\xa2\x4f\xa5\x2b\x1d\x89\x39\xfa\xa9\x49\xec"
|
77
|
+
"\x2a\x87\x95\x44\xce\x55\x0b\x55\x03\xb2\x62\xc8\xa4\xc7\xb0\xd4"
|
78
|
+
"\x50\x35\x0f\x64\x85\xb1\x75\x14\xd2\x74\xa8\x99\xc6\x95\x0d\x57"
|
79
|
+
"\xff\xff\xff\x83\xae\xb2\x8e\xc1\xd4\x42\xa9\x39\x54\x41\x4b\x49"
|
80
|
+
"\x64\x50\xd5\x28\x99\xca\xa5\x05\x1a\x12\xa4\xc7\xb0\xd4\x50\x35"
|
81
|
+
"\xa8\x37\x52\xae\xa2\x9c\xa7\x1a\x54\xc8\xa0\xe9\x51\x09\xb0\xdd"
|
82
|
+
"\xcd\x54\xca\x24\xff\xff\xff\xfe\x17\xcd\x76\x15\x08\x50\xc8\x51"
|
83
|
+
"\x33\x99\x0a\x21\x36\x16\xa9\x93\x3a\x86\x4a\x0b\x44\xbf\x4a\x52"
|
84
|
+
"\x7b\x0a\xa0\xd0\xa0\xd4\x4c\xe6\xaa\x65\x07\x58\xec\x4a\x92\xd8"
|
85
|
+
"\x7a\x54\x9c\xc8\x52\xb9\xfd\x20\xc4\x1d\x1f\xff\xff\xfe\x20\xb4"
|
86
|
+
"\xc7\x40\xea\x21\x57\x51\x4c\x89\x53\xc0\xd0\xa0\xd4\x42\x6c\x2d"
|
87
|
+
"\x53\x26\x75\x3c\x15\x41\xd8\x55\x3c\x1e\xa4\xa8\x93\xa8\x34\x20"
|
88
|
+
"\xe4\x30\xd2\x55\x3c\x19\x33\xa8\x99\xcd\x54\xc8\xff\xff\xff\xf2"
|
89
|
+
"\xbb\x0d\x49\x92\x6e\xe5\xfa\x53\xc1\x93\x3a\x9e\x0d\x44\x8a\x0e"
|
90
|
+
"\xa3\x52\x3a\x11\xf4\xa0\xea\x91\x44\xce\x55\x09\x61\x46\x9b\x6c"
|
91
|
+
"\x2a\x14\xf0\x55\x0d\x48\xe6\x35\x45\x50\xf6\xd9\xff\xff\xff\xe2"
|
92
|
+
"\x6c\x29\x56\x93\xc1\x68\xa0\xd5\x4c\xa5\x76\x1d\x27\x4f\xaa\xca"
|
93
|
+
"\x85\x12\x75\x27\x1f\x72\xa9\x19\x4b\x57\xff\xf6\xff\xff\x37\xff"
|
94
|
+
"\xff\x70\xd4\x42\x6c\x2d\x53\x26\x75\x10\x3e\xe3\x98\xbf\x4a\x4a"
|
95
|
+
"\x5b\x0e\x43\x1e\xd4\x7d\x28\x3a\x0d\xdc\xbf\xff\xff\xfe\x1a\xa5"
|
96
|
+
"\x0c\x94\x16\x89\x7e\x94\x4c\xe5\x50\xa8\x41\x6a\x21\x54\x3c\xaa"
|
97
|
+
"\x50\x69\x4a\xa1\xaa\x51\x33\x8d\x2a\x19\x2a\x19\x0a\x26\x72\xa9"
|
98
|
+
"\x59\xd2\x5a\x89\xe9\x43\xca\xa5\x27\x49\x8f\x57\xd2\x89\x9c\xbf"
|
99
|
+
"\xff\xff\xfe\x16\x82\xd2\x5a\x92\x3a\x14\x42\x6d\x96\x55\x0c\x94"
|
100
|
+
"\x16\x89\x54\x3d\xa9\x50\xf2\xa9\xe2\x73\x12\x75\x13\x39\x54\xa4"
|
101
|
+
"\x75\x7a\x52\x53\xd9\x4a\x14\x3c\xaa\x50\x69\x4a\xa4\xe3\xee\x55"
|
102
|
+
"\x23\x29\x6a\xff\xff\xff\xf2\x93\xdb\x44\x85\x93\xed\x43\x54\xa2"
|
103
|
+
"\x27\x3d\x89\xfa\x51\x33\x8d\x2a\x78\x9c\xc4\x9d\x4f\x16\x19\x33"
|
104
|
+
"\x95\x0a\x1a\xa5\x13\x39\x54\x8c\xf2\x7a\x50\xf2\xa8\x35\x11\x50"
|
105
|
+
"\xfa\x95\x4f\x13\x96\xa5\x13\x39\x7f\xff\xff\xfc\x9c\xa3\x91\x43"
|
106
|
+
"\x21\x42\x5a\x95\x0f\x2c\xbf\x4a\x0e\xa9\x14\x4c\xe5\x51\x15\x0f"
|
107
|
+
"\xa9\x7e\x94\x1a\x14\x1a\x88\xa8\x7d\x4b\xf4\xa1\x90\xa4\x85\x1c"
|
108
|
+
"\x9f\x4a\x1e\xc5\x3c\x4e\x62\x4e\xa5\x06\xaa\x62\xd8\x85\x0d\x57"
|
109
|
+
"\xff\xff\xff\x89\x9c\xaa\x22\x71\xd6\x5a\x0a\x84\x29\x45\xb4\xd6"
|
110
|
+
"\xa1\xe5\x51\x36\xd8\x9a\x0a\xb5\x25\x1a\x54\x1d\x52\x29\x61\x48"
|
111
|
+
"\x73\x50\x85\x07\x54\x8a\x76\xb4\xdd\xcb\x62\x14\x96\xc3\xd2\xa2"
|
112
|
+
"\x67\x2a\x95\xd8\x79\x3f\xff\xff\xfc\x3c\xaa\x0d\x49\x4d\x54\xc5"
|
113
|
+
"\xb1\x7f\xff\xff\xff\x3f\xff\xff\xfc\xdd\x69\x27\x53\xc0\xd0\xa2"
|
114
|
+
"\x67\x2a\x86\xa6\xbb\x0a\x84\x18\xf5\x28\x79\x54\x42\x6c\x2d\x53"
|
115
|
+
"\x26\x75\x32\x29\x30\xd3\x39\x6c\x2c\x8a\x4b\x61\xe9\x51\x33\x99"
|
116
|
+
"\x0a\x52\x3a\x94\xf1\x39\xd4\xac\x64\x2c\x8a\x5b\x5f\xff\xff\xff"
|
117
|
+
"\x83\xaa\x45\x24\x3f\x8a\x97\x51\x4c\x65\x53\xc0\xd0\xa4\xa6\xb2"
|
118
|
+
"\x9a\x3d\x29\x5d\x03\xa9\x25\x91\x43\xd4\xa4\xe6\x42\x94\x16\x64"
|
119
|
+
"\x7d\xa9\x39\x90\xa4\xa5\x2a\x54\x42\x6c\xb4\x9d\x54\x4c\xe5\x52"
|
120
|
+
"\x42\x93\xaf\xff\xff\xff\x88\xed\x68\xec\x2d\x1e\x94\x1d\x52\x29"
|
121
|
+
"\xe0\xc9\x9d\x44\x5b\x61\x53\xeb\xed\x42\xf7\x2d\x9e\x94\xa4\xfd"
|
122
|
+
"\xcb\x49\x6a\x4a\x87\x95\x41\xa9\x4d\xa8\x25\x05\xfa\x52\x5b\x0f"
|
123
|
+
"\x4a\x89\x9c\xaa\x4e\x51\xf7\x2a\x87\x97\xff\xff\xff\xc4\xce\x55"
|
124
|
+
"\x11\x39\xed\xa2\x42\xd8\x85\x12\x75\x13\x39\x54\x49\xa6\x9d\x25"
|
125
|
+
"\xa8\xd5\x4c\xa1\xe5\x51\x33\x95\x4a\x0d\x5a\x14\x1c\x67\xb5\x2a"
|
126
|
+
"\x26\x72\xa8\x43\x4c\x3b\x3e\x94\xf0\x34\x7f\xff\xff\xf9\x21\x48"
|
127
|
+
"\x64\x1b\xb9\x7e\x94\x1d\x52\x28\x82\x96\x92\xc8\xa2\x4e\xa1\x0f"
|
128
|
+
"\x49\x54\x3d\xa9\x50\xf2\xa8\x35\x10\x9b\x0b\x54\xc9\x9d\x44\xce"
|
129
|
+
"\x34\xa9\xe0\x68\x50\xbe\x48\x54\x20\xdd\xca\xa0\xea\x93\xff\xff"
|
130
|
+
"\xff\xc3\xf7\x2d\x9e\x27\x2d\x14\x9a\xa9\x97\x51\x4c\x95\x29\x28"
|
131
|
+
"\xc8\x9f\xa5\x13\x39\xed\x9a\x75\x13\x39\x90\xa2\x13\x61\x6a\x99"
|
132
|
+
"\x33\xa9\x59\x6c\xee\x39\x0b\x22\x85\xee\x5b\x3d\x28\x32\x24\xc7"
|
133
|
+
"\xa9\x43\xcb\xff\xff\xff\xe4\xe6\x47\xd2\x86\x4a\x88\x29\x69\x2c"
|
134
|
+
"\x8a\x47\x6a\x54\x4c\xe5\x50\x72\x77\x2d\x89\x32\x0b\x49\x6a\x4a"
|
135
|
+
"\x87\x95\x41\xa9\x35\x85\x1a\x4b\x62\x88\x4d\x85\xaa\x64\xce\xa2"
|
136
|
+
"\x67\x1a\x54\xa2\xdb\x3a\x96\x4f\xff\xff\xff\x3c\x19\x33\x9a\xaf"
|
137
|
+
"\xa5\x13\x38\xd2\xa5\x03\xf4\xa4\x87\xb2\x91\xd4\x95\x07\x54\x8a"
|
138
|
+
"\x54\x75\x29\x3d\x85\x51\x33\x8e\xa5\x10\x93\x59\x61\x64\x52\x5b"
|
139
|
+
"\x0f\x4a\x89\x35\x25\x51\x27\x51\x26\xa4\xbf\x4a\x47\x6a\x7f\xff"
|
140
|
+
"\xff\xfc\xf1\x39\x89\x3a\x94\x9a\x69\xd2\xa0\xec\x3d\xa8\x2f\xd2"
|
141
|
+
"\x83\x4a\x83\xab\xd2\x94\x9e\x92\xd4\x9f\xa5\x12\x5b\x2c\x34\x74"
|
142
|
+
"\x15\x41\xd5\x22\x84\x3d\x35\x96\x8a\x0d\x54\xdf\x4a\x50\x6e\xa5"
|
143
|
+
"\x51\x33\x95\x4b\x07\x31\x7f\xff\xff\xfc\x3c\xaa\x0d\x4a\x0c\x7a"
|
144
|
+
"\x94\x3d\x8a\x26\x72\xa9\xe2\xc1\xa6\x75\x0f\x2a\x83\x51\x09\x3d"
|
145
|
+
"\x94\xaf\xff\xff\xff\xe7\xff\xff\xff\x9b\xe7\x2a\x84\x39\xfa\xa8"
|
146
|
+
"\x84\xda\x4e\xaa\x4e\x64\x29\x39\x47\x22\x87\xb5\x2a\x1e\x55\x13"
|
147
|
+
"\x39\x54\x98\x74\x50\x5f\x4a\x48\x73\xd8\xa0\xea\x91\x49\xac\x35"
|
148
|
+
"\x55\x16\x45\x0b\x51\x0f\x6d\x83\x98\xd5\x4d\x47\xaf\xff\xff\xff"
|
149
|
+
"\x06\x95\x29\x2f\xd2\x83\x4a\x89\x9c\xaa\x20\x74\x95\x44\x9a\x92"
|
150
|
+
"\xa9\xd0\xb6\x75\x35\x53\x29\x39\x90\xa2\x67\xb6\x98\xd4\x35\x4a"
|
151
|
+
"\x26\x72\xa9\x21\xac\x29\x12\x63\xd4\xa1\xe5\x51\x33\x95\x4a\x47"
|
152
|
+
"\x52\x9e\x27\x3f\xff\xff\xff\x95\x8c\x85\x91\x4b\x6b\x50\x75\x48"
|
153
|
+
"\xa4\x87\xf1\x52\x91\xfa\x51\x33\x95\x49\xc6\x92\x4f\xe0\x7e\x97"
|
154
|
+
"\x51\x4d\xf3\xda\x85\x32\x29\xe0\x68\x52\x63\x77\x2d\x4a\x24\xea"
|
155
|
+
"\x5b\x54\x85\xb1\x09\x1d\x52\x28\x99\xc6\x9f\xff\xff\xff\x27\x2a"
|
156
|
+
"\x9e\x06\x85\x13\x39\x54\x20\xeb\x48\xcd\x57\xd2\x89\x9c\xaa\x7f"
|
157
|
+
"\xff\x6f\xff\xf3\x7f\xff\xb3\xaa\x89\x14\xd0\x3a\xbe\xbf\xff\xb7"
|
158
|
+
"\xff\xf9\xbf\xff\xf3\x28\x6a\x94\x4c\xe5\x50\x87\x3f\x5f\xff\xed"
|
159
|
+
"\xff\xfe\x6f\xff\xee\x21\x4e\xe5\xb2\xa1\x92\xda\x07\x67\xd2\x89"
|
160
|
+
"\x9c\xbf\xff\xff\xfe\x1a\xa9\x0d\xdc\xd2\x5a\x3a\x14\xf1\x39\xe9"
|
161
|
+
"\x53\x22\x94\xda\x84\xa8\x6a\x92\x5b\x3b\x98\xbe\x14\x1d\x52\x29"
|
162
|
+
"\x5d\xa9\x51\x27\x51\x33\x95\x44\xd8\x7b\x63\xa0\xaa\x1e\x55\x10"
|
163
|
+
"\x7a\x4b\x39\xfc\x7f\xff\xff\xf9\x31\x52\x93\x55\x32\x94\x95\x41"
|
164
|
+
"\xa2\x73\xd8\x55\xd4\x53\x22\x93\x8e\x45\x27\x1d\x12\xa8\x84\x8e"
|
165
|
+
"\xc4\x96\x45\x25\x3d\x9e\x07\x64\x9f\x4a\x24\xea\x4c\x54\xa8\x7e"
|
166
|
+
"\xe5\xb1\x4f\x06\x4c\xea\x78\x9c\x69\x53\x27\xff\xff\xff\x9e\x06"
|
167
|
+
"\x85\x08\x5b\x12\x33\x54\xa7\x83\xdb\x44\x8a\x46\x55\x06\xa2\x12"
|
168
|
+
"\x7b\x29\xf4\xa4\xa6\xee\x55\x29\x35\x56\xa4\xa8\xfa\x53\xc4\xe5"
|
169
|
+
"\xa9\x41\xa9\x49\xec\x2a\x9d\xcc\x7a\x0b\x52\x7f\xff\xff\xfc\x45"
|
170
|
+
"\xb2\xca\x72\x0d\x26\xaa\x65\x2b\x1d\x87\xf3\xe9\x14\xa8\x82\x9b"
|
171
|
+
"\xd9\x64\x51\x33\x95\x4b\x6a\x94\xf6\x26\xda\x86\x92\xa9\x59\x6c"
|
172
|
+
"\x41\xea\x53\xc4\xe7\x53\xc0\xd0\xa5\x1e\x8d\x54\xca\x1e\xa5\x27"
|
173
|
+
"\x32\x3f\xff\xff\xfc\x8c\x64\xea\xba\x8a\x63\x2a\x9e\x2c\x2d\x44"
|
174
|
+
"\x9c\xb2\x28\x3a\xa4\x53\xc5\x86\x4c\xe5\x91\x41\xc6\x7b\x52\xa1"
|
175
|
+
"\x0f\x57\x7b\x68\x41\xbb\x96\x8f\x4b\xa8\xa6\xf9\xca\xa1\x27\x35"
|
176
|
+
"\x5f\x4a\x78\x32\x67\x51\x33\x97\xff\xff\xff\xc9\x07\x4d\x6a\x47"
|
177
|
+
"\x40\xc9\xd5\x48\xca\x3b\x24\xfa\x52\xb3\x9a\xa4\x96\x45\x27\x34"
|
178
|
+
"\xd3\x96\xc5\x0d\x52\x89\x9c\xaa\x0c\xd6\x28\x34\x28\x99\xca\xa4"
|
179
|
+
"\x63\x27\x55\x29\xb5\x04\xa0\xa8\x51\x09\x34\xb2\x96\xa2\xc9\xff"
|
180
|
+
"\xff\xff\xe0\xea\x91\x44\xce\x55\x09\x39\x50\x95\x11\xe0\xb4\x50"
|
181
|
+
"\x59\x14\x35\x4a\x0e\xa5\x2d\xa8\x87\xa9\x04\x31\xed\x42\x83\xaa"
|
182
|
+
"\x45\x0d\x52\x12\x6a\x88\x93\x77\x2a\x85\x96\x53\xd8\x95\x12\x75"
|
183
|
+
"\x26\x2a\x7f\xff\xff\xfc\xa4\xf6\x15\x41\x9a\xc5\xd4\x53\x85\x52"
|
184
|
+
"\x16\xc5\x13\x39\x54\xf1\x39\x91\xd4\xb6\x23\xe9\x41\xd5\x22\x83"
|
185
|
+
"\xa2\x85\x2d\xa9\x05\x2d\x5f\x4a\x64\x53\xad\x45\xf0\xa2\x67\x1a"
|
186
|
+
"\x54\x4c\xe5\x51\x1d\x4d\x52\x9e\x06\x8f\xff\xff\xff\x12\x3e\xa6"
|
187
|
+
"\xaa\x65\x0f\x52\x83\x52\xbb\x6c\xae\x83\x22\x75\x27\xb4\xab\xff"
|
188
|
+
"\xff\xff\xf9\xff\xff\xff\xe6\xf9\xca\xa1\x07\x5a\x46\x6a\xbe\x94"
|
189
|
+
"\x3d\x8a\x72\x3d\x12\xa9\x9c\x76\x20\xb5\x7d\x28\x34\x29\x49\x6a"
|
190
|
+
"\x50\x83\xa2\x82\xc8\xa4\xe6\xa7\xe9\x42\x14\x68\x2c\x8a\x56\x32"
|
191
|
+
"\x1a\xa9\x94\x1d\x52\x29\x30\xfd\x96\x4f\xff\xff\xff\x24\x3f\x8a"
|
192
|
+
"\x94\x1a\x54\x4c\xe5\x52\x4f\x46\xaa\x65\x29\x1d\x4b\xa8\xa6\xe3"
|
193
|
+
"\xa9\x29\x8b\x61\x0a\xa4\xe3\x91\x44\xce\x64\x29\x29\xaa\x1d\x0a"
|
194
|
+
"\x21\x36\x5b\x34\xd4\x15\x48\xca\x43\xd2\x55\x13\x38\xd2\xa2\x67"
|
195
|
+
"\x2f\xff\xff\xff\x88\x19\xa8\x3d\x8a\x56\x3b\x50\x59\x14\x35\x4a"
|
196
|
+
"\x26\x72\xa8\x32\x25\x43\xca\xa4\xb4\x1a\xa9\x8d\x54\xca\x52\x7b"
|
197
|
+
"\x0a\xa7\x81\xa4\xb6\x28\x7e\xe5\xb1\x49\xcd\x4a\x83\xaa\x45\x10"
|
198
|
+
"\x91\xd8\x59\x3f\xff\xff\xfc\x25\xb6\x18\xf6\xa2\x8f\x5f\x4a\x26"
|
199
|
+
"\x72\xa8\x41\xd5\xdc\x68\x52\x3b\x49\xd4\xa9\x52\xb1\xd8\x9a\x3d"
|
200
|
+
"\x28\x93\x50\x92\xc8\xa0\xea\x91\x49\x2c\x35\x75\x9a\xa9\x94\x32"
|
201
|
+
"\x50\xa1\x0f\x52\x4b\x52\x50\xa2\x4f\xff\xff\xff\xe2\x67\x2a\x92"
|
202
|
+
"\x14\x9d\x57\x51\x4d\xf3\x95\x49\x3d\x1a\xa9\x94\xa4\x75\x29\x19"
|
203
|
+
"\x46\x95\x06\xa2\x46\x94\x9c\xea\x1e\xa5\x13\x39\x54\x9c\x69\x24"
|
204
|
+
"\xea\x78\x32\x67\x52\x73\x21\x49\xca\x5a\x11\xf5\xff\xff\xff\xe2"
|
205
|
+
"\x13\x60\xcd\x34\xe9\x2d\x45\x91\x43\xda\x95\x27\x32\x14\xa0\xb3"
|
206
|
+
"\x23\xe9\x41\xd5\x22\x88\x49\xa5\x94\xb5\x16\x45\x0d\x52\x87\xa8"
|
207
|
+
"\xaa\x4d\x61\x46\x95\x12\x5a\x90\x55\x0b\x2c\xa7\xb1\x3f\x4a\x0e"
|
208
|
+
"\xa9\x3f\xff\xff\xfc\xb0\xf4\x50\x59\x14\x9c\xc8\x52\x72\x8e\x45"
|
209
|
+
"\x25\xb0\xf4\xa8\x83\x48\x55\x12\x75\x10\x69\x0a\xba\x8a\x6f\x9c"
|
210
|
+
"\xb5\x28\x99\xca\xa5\x36\xa0\x94\x15\x0a\x58\x5a\x07\xe4\xb2\x7d"
|
211
|
+
"\x28\x99\xca\xa4\xe5\x1c\x9f\xff\xff\xfe\x21\x27\xae\xb2\xc8\xa5"
|
212
|
+
"\x87\xa2\x83\x55\x37\xd2\x83\xaa\x45\x06\xa2\x0d\x34\xff\x4a\x0d"
|
213
|
+
"\x0a\x1e\x55\x2b\xb0\xf2\x9e\xda\xa4\x52\xc2\xd0\x62\xcb\xf4\xa4"
|
214
|
+
"\xb4\x1c\x69\x2c\x8a\x5b\x5f\x81\xd9\x22\x92\xd8\x7a\x7f\xff\xff"
|
215
|
+
"\xfc\x9c\xc8\x52\x83\x56\x85\xd4\x53\x7c\xe5\x53\xa0\xfc\x29\x25"
|
216
|
+
"\x87\xae\xb2\xc9\xf4\xa2\x67\x2a\x96\xd7\x59\x6c\x52\x83\x56\xa5"
|
217
|
+
"\x06\x95\x25\x93\xe9\x41\xd5\x22\x89\xf0\x75\x2c\x3f\x84\x28\x79"
|
218
|
+
"\x7f\xff\xff\xfc\x49\xe3\x19\x08\x75\xa4\x32\x08\x7a\x0f\x6d\x85"
|
219
|
+
"\x91\x44\x94\xa9\x9d\x41\xd7\x59\x47\x61\x64\x5d\x45\x32\x25\x44"
|
220
|
+
"\x14\xb4\x96\x45\x06\x85\x13\x39\xed\x9a\x75\x27\x32\x14\x94\xa3"
|
221
|
+
"\x4d\xb6\x15\x0a\x4e\x39\x3f\xff\xff\xfc\x96\xc3\xfb\x2d\x4a\x1a"
|
222
|
+
"\xa4\x9d\x41\xa9\x21\x87\x19\xe8\x31\x07\x42\x93\x58\x6a\x94\x1a"
|
223
|
+
"\x54\x4c\xe5\x53\xc1\xec\xa2\x45\x27\x2a\x93\x8e\x45\x28\x2c\xa9"
|
224
|
+
"\x50\x75\x48\xa1\xed\x4f\x83\x25\x25\x91\x7f",
|
225
|
+
12 + 16 * 174 + 11,
|
226
|
+
"Pacing back and forth the length of the hatchways and savagely chewing\n"
|
227
|
+
"the end of a cigar, was the man whose casual glance had rescued me from\n"
|
228
|
+
"the sea. His height was probably five feet ten inches, or ten and a\n"
|
229
|
+
"half; but my first impression, or feel of the man, was not of this, but\n"
|
230
|
+
"of his strength. And yet, while he was of massive build, with broad\n"
|
231
|
+
"shoulders and deep chest, I could not characterize his strength as\n"
|
232
|
+
"massive. It was what might be termed a sinewy, knotty strength, of the\n"
|
233
|
+
"kind we ascribe to lean and wiry men, but which, in him, because of his\n"
|
234
|
+
"heavy build, partook more of the enlarged gorilla order. Not that in\n"
|
235
|
+
"appearance he seemed in the least gorilla-like. What I am striving to\n"
|
236
|
+
"express is this strength itself, more as a thing apart from his physical\n"
|
237
|
+
"semblance. It was a strength we are wont to associate with things\n"
|
238
|
+
"primitive, with wild animals, and the creatures we imagine our\n"
|
239
|
+
"tree-dwelling prototypes to have been—a strength savage, ferocious, alive\n"
|
240
|
+
"in itself, the essence of life in that it is the potency of motion, the\n"
|
241
|
+
"elemental stuff itself out of which the many forms of life have been\n"
|
242
|
+
"moulded; in short, that which writhes in the body of a snake when the\n"
|
243
|
+
"head is cut off, and the snake, as a snake, is dead, or which lingers in\n"
|
244
|
+
"the shapeless lump of turtle-meat and recoils and quivers from the prod\n"
|
245
|
+
"of a finger.\n"
|
246
|
+
"\n"
|
247
|
+
"Such was the impression of strength I gathered from this man who paced up\n"
|
248
|
+
"and down. He was firmly planted on his legs; his feet struck the deck\n"
|
249
|
+
"squarely and with surety; every movement of a muscle, from the heave of\n"
|
250
|
+
"the shoulders to the tightening of the lips about the cigar, was\n"
|
251
|
+
"decisive, and seemed to come out of a strength that was excessive and\n"
|
252
|
+
"overwhelming. In fact, though this strength pervaded every action of\n"
|
253
|
+
"his, it seemed but the advertisement of a greater strength that lurked\n"
|
254
|
+
"within, that lay dormant and no more than stirred from time to time, but\n"
|
255
|
+
"which might arouse, at any moment, terrible and compelling, like the rage\n"
|
256
|
+
"of a lion or the wrath of a storm.\n"
|
257
|
+
"\n"
|
258
|
+
"The cook stuck his head out of the galley door and grinned encouragingly\n"
|
259
|
+
"at me, at the same time jerking his thumb in the direction of the man who\n"
|
260
|
+
"paced up and down by the hatchway. Thus I was given to understand that\n"
|
261
|
+
"he was the captain, the “Old Man,” in the cook’s vernacular, the\n"
|
262
|
+
"individual whom I must interview and put to the trouble of somehow\n"
|
263
|
+
"getting me ashore. I had half started forward, to get over with what I\n"
|
264
|
+
"was certain would be a stormy five minutes, when a more violent\n"
|
265
|
+
"suffocating paroxysm seized the unfortunate person who was lying on his\n"
|
266
|
+
"back. He wrenched and writhed about convulsively. The chin, with the\n"
|
267
|
+
"damp black beard, pointed higher in the air as the back muscles stiffened\n"
|
268
|
+
"and the chest swelled in an unconscious and instinctive effort to get\n"
|
269
|
+
"more air. Under the whiskers, and all unseen, I knew that the skin was\n"
|
270
|
+
"taking on a purplish hue.\n"
|
271
|
+
"\n"
|
272
|
+
"The captain, or Wolf Larsen, as men called him, ceased pacing and gazed\n"
|
273
|
+
"down at the dying man. So fierce had this final struggle become that the\n"
|
274
|
+
"sailor paused in the act of flinging more water over him and stared\n"
|
275
|
+
"curiously, the canvas bucket partly tilted and dripping its contents to\n"
|
276
|
+
"the deck. The dying man beat a tattoo on the hatch with his heels,\n"
|
277
|
+
"straightened out his legs, and stiffened in one great tense effort, and\n"
|
278
|
+
"rolled his head from side to side. Then the muscles relaxed, the head\n"
|
279
|
+
"stopped rolling, and a sigh, as of profound relief, floated upward from\n"
|
280
|
+
"his lips. The jaw dropped, the upper lip lifted, and two rows of\n"
|
281
|
+
"tobacco-discoloured teeth appeared. It seemed as though his features had\n"
|
282
|
+
"frozen into a diabolical grin at the world he had left and outwitted.",
|
283
|
+
3687,
|
284
|
+
},
|
285
|
+
{ __LINE__,
|
286
|
+
(unsigned char *)
|
287
|
+
"\xe5\x39\x6a\x50\xd5\x28\x99\xca\xa5\xe3\xdb\x62"
|
288
|
+
"\x0a\xa1\xe5\x52\x7b\x69\x1d\x4a\x17\xb9\x6a\x4a\x14\x32\x54\x8c"
|
289
|
+
"\xa4\x3d\x25\x42\x95\x14\x85\x42\x07\x67\xa5\x25\x3d\x8a\x1e\xa2"
|
290
|
+
"\xa9\x59\x4f\x5d\x05\x51\x27\x52\x43\x21\x07\xa3\xb9\x54\x4c\xe5"
|
291
|
+
"\x52\xb3\xd0\x64\x98\x83\xa1\x48\xc7\x54\x88\x53\xc4\xe6\x24\xea"
|
292
|
+
"\x4e\x3e\xe5\x50\x87\xaa\xa2\x91\x25\x91\x44\xce\x5a\x54\xf0\x64"
|
293
|
+
"\xce\xa0\xea\x3a\x67\x2d\x8a\x0e\xa9\x14\x49\xd4\x1a\x11\x6d\x25"
|
294
|
+
"\x50\x74\x9e\xa9\x94\x4c\xe5\x52\xb3\xf8\x2d\x88\x50\xf2\xa8\x99"
|
295
|
+
"\xca\xa1\x47\x62\x67\xfa\x51\x33\x95\x44\x16\xb1\xd8\x34\x95\x41"
|
296
|
+
"\xd5\x22\x85\xed\x68\xe8\x51\x09\x1a\x4c\x7a\x94\x49\xd4\xf1\x39"
|
297
|
+
"\x89\x3a\x89\x9c\xaa\x67\x1f\x84\x28\x79\x54\xd2\x34\xdb\x61\x54"
|
298
|
+
"\x1d\x52\x28\x79\x54\xd2\x34\xdb\x61\x7f\xd2\x14\xc4\x79\x14\x2d"
|
299
|
+
"\x49\x32\x68\x2a\x89\x9c\xb4\xfd\x28\x35\x24\x29\x0b\x52\x54\xb0"
|
300
|
+
"\xa8\xac\xa4\x4a\x89\x3a\x89\x9c\xaa\x1e\xb3\x54\x63\xd4\x85\x0f"
|
301
|
+
"\x2a\x94\x8e\xae\xa6\xaa\x45\x2c\x2f\x6b\x4d\x61\x50\xa2\x67\x1a"
|
302
|
+
"\x54\x4c\xe5\xf4\xa2\x27\x3d\xb4\x48\xa4\x85\x25\x03\xb0\xaa\x26"
|
303
|
+
"\x72\xa8\x41\xda\x82\xa1\x4f\x13\x98\x93\xa8\x6a\x6b\x2d\x0a\x26"
|
304
|
+
"\x72\xd2\xa2\x4e\xa2\x67\x2a\x88\x2d\x63\xb0\x69\x31\xea\x5f",
|
305
|
+
12 + 16 * 16 + 15,
|
306
|
+
"When in the Course of human events it becomes necessary for one "
|
307
|
+
"people to dissolve the political bands which have connected them "
|
308
|
+
"with another and to assume among the powers of the earth, the "
|
309
|
+
"separate and equal station to which the Laws of Nature and of "
|
310
|
+
"Nature's God entitle them, a decent respect to the opinions of "
|
311
|
+
"mankind requires that they should declare the causes which impel "
|
312
|
+
"them to the separation.",
|
313
|
+
404,
|
314
|
+
},
|
315
|
+
};
|
316
|
+
|
317
|
+
void
|
318
|
+
run_test (const struct test_huff_dec *test)
|
319
|
+
{
|
320
|
+
struct huff_decode_retval retval;
|
321
|
+
struct lsqpack_huff_decode_state state;
|
322
|
+
unsigned in_chunk_sz, out_chunk_sz, in_off, out_off, n_to_read, n_to_write;
|
323
|
+
char output[0x1000];
|
324
|
+
|
325
|
+
if (verbose)
|
326
|
+
fprintf(stderr, "Run test on line %u\n", test->lineno);
|
327
|
+
|
328
|
+
for (in_chunk_sz = 1; in_chunk_sz <= test->src_sz; ++in_chunk_sz)
|
329
|
+
{
|
330
|
+
if (verbose)
|
331
|
+
fprintf(stderr, "chunk %u out of %zu\n", in_chunk_sz, test->src_sz);
|
332
|
+
for (out_chunk_sz = 1; out_chunk_sz <= test->dst_sz; ++out_chunk_sz)
|
333
|
+
{
|
334
|
+
in_off = 0;
|
335
|
+
out_off = 0;
|
336
|
+
state.resume = 0;
|
337
|
+
n_to_read = MIN(test->src_sz, in_chunk_sz);
|
338
|
+
n_to_write = MIN(test->dst_sz, out_chunk_sz);
|
339
|
+
|
340
|
+
do
|
341
|
+
{
|
342
|
+
assert(in_off + n_to_read <= test->src_sz); /* self-test */
|
343
|
+
retval = lsqpack_huff_decode_full(test->src + in_off, n_to_read,
|
344
|
+
(unsigned char *) output + out_off, n_to_write, &state,
|
345
|
+
test->src_sz == in_off + n_to_read);
|
346
|
+
switch (retval.status)
|
347
|
+
{
|
348
|
+
case HUFF_DEC_OK:
|
349
|
+
in_off += retval.n_src;
|
350
|
+
out_off += retval.n_dst;
|
351
|
+
assert(test->dst_sz == out_off);
|
352
|
+
assert(test->src_sz == in_off);
|
353
|
+
assert(0 == memcmp(test->dst, output, out_off));
|
354
|
+
break;
|
355
|
+
case HUFF_DEC_END_SRC:
|
356
|
+
case HUFF_DEC_END_DST:
|
357
|
+
in_off += retval.n_src;
|
358
|
+
out_off += retval.n_dst;
|
359
|
+
n_to_write = MIN(sizeof(output) - out_off, out_chunk_sz);
|
360
|
+
n_to_read = MIN(test->src_sz - in_off, in_chunk_sz);
|
361
|
+
break;
|
362
|
+
default:
|
363
|
+
assert(retval.status == HUFF_DEC_ERROR);
|
364
|
+
assert(0);
|
365
|
+
}
|
366
|
+
}
|
367
|
+
while (in_off < test->src_sz);
|
368
|
+
assert(retval.status == HUFF_DEC_OK);
|
369
|
+
}
|
370
|
+
}
|
371
|
+
}
|
372
|
+
|
373
|
+
int
|
374
|
+
main (int argc, char **argv)
|
375
|
+
{
|
376
|
+
const struct test_huff_dec *test;
|
377
|
+
int opt, run_expensive = 0;
|
378
|
+
|
379
|
+
while (-1 != (opt = getopt(argc, argv, "ve")))
|
380
|
+
{
|
381
|
+
switch (opt)
|
382
|
+
{
|
383
|
+
case 'v':
|
384
|
+
verbose = 1;
|
385
|
+
break;
|
386
|
+
case 'e':
|
387
|
+
run_expensive = 1;
|
388
|
+
break;
|
389
|
+
default:
|
390
|
+
exit(EXIT_FAILURE);
|
391
|
+
}
|
392
|
+
}
|
393
|
+
|
394
|
+
for (test = tests; test < tests + sizeof(tests) / sizeof(tests[0]); ++test)
|
395
|
+
if (run_expensive || test->src_sz * test->dst_sz < 150000)
|
396
|
+
run_test(test);
|
397
|
+
|
398
|
+
return 0;
|
399
|
+
}
|
@@ -0,0 +1,220 @@
|
|
1
|
+
#include <assert.h>
|
2
|
+
#include <stdint.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <string.h>
|
5
|
+
|
6
|
+
#include "lsqpack.h"
|
7
|
+
#include "lsqpack-test.h"
|
8
|
+
|
9
|
+
struct int_test
|
10
|
+
{
|
11
|
+
int it_lineno;
|
12
|
+
unsigned it_prefix_bits;
|
13
|
+
unsigned char it_encoded[20];
|
14
|
+
size_t it_enc_sz;
|
15
|
+
uint64_t it_decoded;
|
16
|
+
int it_dec_retval;
|
17
|
+
};
|
18
|
+
|
19
|
+
static const struct int_test tests[] =
|
20
|
+
{
|
21
|
+
|
22
|
+
{ .it_lineno = __LINE__,
|
23
|
+
.it_prefix_bits = 7,
|
24
|
+
.it_encoded = { 0x7F, 0x02, },
|
25
|
+
.it_enc_sz = 2,
|
26
|
+
.it_decoded = 0x81,
|
27
|
+
.it_dec_retval = 0,
|
28
|
+
},
|
29
|
+
|
30
|
+
/* RFC 7541, Appendinx C.1.1 */
|
31
|
+
{ .it_lineno = __LINE__,
|
32
|
+
.it_prefix_bits = 5,
|
33
|
+
.it_encoded = { 0b1010, 0x02, },
|
34
|
+
.it_enc_sz = 1,
|
35
|
+
.it_decoded = 10,
|
36
|
+
.it_dec_retval = 0,
|
37
|
+
},
|
38
|
+
|
39
|
+
/* RFC 7541, Appendinx C.1.2 */
|
40
|
+
{ .it_lineno = __LINE__,
|
41
|
+
.it_prefix_bits = 5,
|
42
|
+
.it_encoded = { 0b11111, 0b10011010, 0b00001010, },
|
43
|
+
.it_enc_sz = 3,
|
44
|
+
.it_decoded = 1337,
|
45
|
+
.it_dec_retval = 0,
|
46
|
+
},
|
47
|
+
|
48
|
+
/* RFC 7541, Appendinx C.1.3 */
|
49
|
+
{ .it_lineno = __LINE__,
|
50
|
+
.it_prefix_bits = 8,
|
51
|
+
.it_encoded = { 0b101010, },
|
52
|
+
.it_enc_sz = 1,
|
53
|
+
.it_decoded = 42,
|
54
|
+
.it_dec_retval = 0,
|
55
|
+
},
|
56
|
+
|
57
|
+
{ .it_lineno = __LINE__,
|
58
|
+
.it_prefix_bits = 7,
|
59
|
+
.it_encoded = { 0b01111111, 0b10000001, 0b10000010, 0b00000011, },
|
60
|
+
.it_enc_sz = 4,
|
61
|
+
/* 01234560123456 */
|
62
|
+
.it_decoded = 0b1100000100000001 + 0b1111111,
|
63
|
+
.it_dec_retval = 0,
|
64
|
+
},
|
65
|
+
|
66
|
+
{ .it_lineno = __LINE__,
|
67
|
+
.it_prefix_bits = 7,
|
68
|
+
.it_encoded = { 0b01111111, 0b10000001, 0b10000010, 0b10000011,
|
69
|
+
0b00000011, },
|
70
|
+
.it_enc_sz = 5,
|
71
|
+
/* 012345601234560123456 */
|
72
|
+
.it_decoded = 0b11000001100000100000001 + 0b1111111,
|
73
|
+
.it_dec_retval = 0,
|
74
|
+
},
|
75
|
+
|
76
|
+
{ .it_lineno = __LINE__,
|
77
|
+
.it_prefix_bits = 7,
|
78
|
+
.it_encoded = { 0b01111111, 0b10000001, 0b10000010, 0b10000011,
|
79
|
+
0b10000100, 0b10000101, 0b10000110, 0b10000111,
|
80
|
+
0b10001000,
|
81
|
+
0b00000011, },
|
82
|
+
.it_enc_sz = 10,
|
83
|
+
/* 01234560123456012345601234560123456012345601234560123456 */
|
84
|
+
.it_decoded = 0b1100010000000111000011000001010000100000001100000100000001
|
85
|
+
+ 0b1111111,
|
86
|
+
.it_dec_retval = 0,
|
87
|
+
},
|
88
|
+
|
89
|
+
{ .it_lineno = __LINE__,
|
90
|
+
.it_prefix_bits = 7,
|
91
|
+
.it_encoded = { 0b01111111, 0b10000001, 0b10000010, 0b10000011,
|
92
|
+
0b10000100, 0b10000101, 0b10000110, 0b10000111,
|
93
|
+
0b10001000, 0b10001001,
|
94
|
+
0b00000001, },
|
95
|
+
.it_enc_sz = 11,
|
96
|
+
/* 012345601234560123456012345601234560123456012345601234560123456 */
|
97
|
+
.it_decoded = 0b1000100100010000000111000011000001010000100000001100000100000001
|
98
|
+
+ 0b1111111,
|
99
|
+
.it_dec_retval = 0,
|
100
|
+
},
|
101
|
+
|
102
|
+
{ .it_lineno = __LINE__,
|
103
|
+
.it_prefix_bits = 7,
|
104
|
+
.it_encoded = { 0b01111111, 0b10000000, 0b11111111, 0b11111111,
|
105
|
+
0b11111111, 0b11111111, 0b11111111, 0b11111111,
|
106
|
+
0b11111111, 0b11111111,
|
107
|
+
0b00000001, },
|
108
|
+
.it_enc_sz = 11,
|
109
|
+
.it_decoded = UINT64_MAX,
|
110
|
+
.it_dec_retval = 0,
|
111
|
+
},
|
112
|
+
|
113
|
+
{ .it_lineno = __LINE__,
|
114
|
+
.it_prefix_bits = 7,
|
115
|
+
/* Same as above, but with extra bit that overflows it */
|
116
|
+
/* ----v---- */
|
117
|
+
.it_encoded = { 0b01111111, 0b10010000, 0b11111111, 0b11111111,
|
118
|
+
0b11111111, 0b11111111, 0b11111111, 0b11111111,
|
119
|
+
0b11111111, 0b11111111,
|
120
|
+
0b00000001, },
|
121
|
+
.it_enc_sz = 11,
|
122
|
+
.it_dec_retval = -2,
|
123
|
+
},
|
124
|
+
|
125
|
+
{ .it_lineno = __LINE__,
|
126
|
+
.it_prefix_bits = 8,
|
127
|
+
.it_encoded = { 0b11111111, 0b10000001, 0b10000010, 0b10000011,
|
128
|
+
0b10000100, 0b10000101, 0b10000110, 0b10000111,
|
129
|
+
0b10001000, 0b10001001, 0b00000001, },
|
130
|
+
.it_enc_sz = 11,
|
131
|
+
/* 012345601234560123456012345601234560123456012345601234560123456 */
|
132
|
+
.it_decoded = 0b1000100100010000000111000011000001010000100000001100000100000001
|
133
|
+
+ 0b11111111,
|
134
|
+
.it_dec_retval = 0,
|
135
|
+
},
|
136
|
+
|
137
|
+
{ .it_lineno = __LINE__,
|
138
|
+
.it_prefix_bits = 7,
|
139
|
+
.it_encoded = { 0b01111111, 0b11101111, 0b11111111, 0b11111111,
|
140
|
+
0b11111111, 0b11111111, 0b11111111, 0b11111111,
|
141
|
+
0b11111111, 0b11111111,
|
142
|
+
0b00000001, },
|
143
|
+
.it_enc_sz = 11,
|
144
|
+
.it_dec_retval = -2,
|
145
|
+
},
|
146
|
+
|
147
|
+
{ .it_lineno = __LINE__,
|
148
|
+
.it_prefix_bits = 7,
|
149
|
+
.it_encoded = { 0b01111111, 0b10000001, 0b10000010, 0b10000011,
|
150
|
+
0b10000100, 0b10000101, 0b10000110, 0b10000111,
|
151
|
+
0b10001000, 0b10001001,
|
152
|
+
0b00000011, },
|
153
|
+
.it_enc_sz = 11,
|
154
|
+
.it_dec_retval = -2,
|
155
|
+
},
|
156
|
+
|
157
|
+
{ .it_lineno = __LINE__,
|
158
|
+
.it_prefix_bits = 7,
|
159
|
+
.it_encoded = { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
160
|
+
0xFF, 0xFF, 0xFF, },
|
161
|
+
.it_enc_sz = 11,
|
162
|
+
.it_dec_retval = -2,
|
163
|
+
},
|
164
|
+
|
165
|
+
};
|
166
|
+
|
167
|
+
int
|
168
|
+
main (void)
|
169
|
+
{
|
170
|
+
const struct int_test *test;
|
171
|
+
const unsigned char *src;
|
172
|
+
unsigned char *dst;
|
173
|
+
unsigned char buf[ sizeof(((struct int_test *) NULL)->it_encoded) ];
|
174
|
+
uint64_t val;
|
175
|
+
size_t sz;
|
176
|
+
int rv;
|
177
|
+
|
178
|
+
/* Test the decoder */
|
179
|
+
for (test = tests; test < tests + sizeof(tests) / sizeof(tests[0]); ++test)
|
180
|
+
{
|
181
|
+
struct lsqpack_dec_int_state state;
|
182
|
+
state.resume = 0;
|
183
|
+
for (sz = 0; sz < test->it_enc_sz - 1; ++sz)
|
184
|
+
{
|
185
|
+
src = test->it_encoded + sz;
|
186
|
+
rv = lsqpack_dec_int(&src, src + 1, test->it_prefix_bits,
|
187
|
+
&val, &state);
|
188
|
+
assert(-1 == rv);
|
189
|
+
}
|
190
|
+
src = test->it_encoded + sz;
|
191
|
+
rv = lsqpack_dec_int(&src, src + 1, test->it_prefix_bits,
|
192
|
+
&val, &state);
|
193
|
+
assert(rv == test->it_dec_retval);
|
194
|
+
if (0 == rv)
|
195
|
+
assert(val == test->it_decoded);
|
196
|
+
}
|
197
|
+
|
198
|
+
/* Test the encoder */
|
199
|
+
for (test = tests; test < tests + sizeof(tests) / sizeof(tests[0]); ++test)
|
200
|
+
{
|
201
|
+
if (test->it_dec_retval != 0)
|
202
|
+
continue;
|
203
|
+
for (sz = 1; sz < test->it_enc_sz; ++sz)
|
204
|
+
{
|
205
|
+
dst = lsqpack_enc_int(buf, buf + sz, test->it_decoded,
|
206
|
+
test->it_prefix_bits);
|
207
|
+
assert(dst == buf); /* Not enough room */
|
208
|
+
}
|
209
|
+
for (; sz <= sizeof(buf); ++sz)
|
210
|
+
{
|
211
|
+
buf[0] = '\0';
|
212
|
+
dst = lsqpack_enc_int(buf, buf + sz, test->it_decoded,
|
213
|
+
test->it_prefix_bits);
|
214
|
+
assert(dst - buf == (intptr_t) test->it_enc_sz);
|
215
|
+
assert(0 == memcmp(buf, test->it_encoded, test->it_enc_sz));
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
return 0;
|
220
|
+
}
|