aboutsummaryrefslogtreecommitdiff
path: root/lib/ext/qcbor/test/qcbor_decode_tests.h
blob: 6423ccff334aa23fe70008965cbed4a31d93ed6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*==============================================================================
 Copyright (c) 2016-2018, The Linux Foundation.
 Copyright (c) 2018-2019, Laurence Lundblade.
 All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.
    * Neither the name of The Linux Foundation nor the names of its
      contributors, nor the name "Laurence Lundblade" may be used to
      endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ==============================================================================*/

#ifndef __QCBOR__qcbort_decode_tests__
#define __QCBOR__qcbort_decode_tests__


/*
 Notes:

 - All the functions in qcbor.h are called once in the aggregation of all the tests below.

 - All the types that are supported are given as input and parsed by these tests

 - There is some hostile input such as invalid lengths and CBOR too complex
   and types this parser doesn't handle

 */


/*
 Parse a well-known set of integers including those around the boundaries and
 make sure the expected values come out
 */
int IntegerValuesParseTest(void);


/*
 Decode a simple CBOR encoded array and make sure it returns all the correct values.
 This is a decode test.
 */
int SimpleArrayTest(void);


/*
 Tests with empty maps and arrays
 */
int EmptyMapsAndArraysTest(void);


/*
 Make sure a maximally deep array can be parsed and that the
 reported nesting level is correct.  This uses test vector
 of CBOR encoded data with a depth of 10.  This a parse test.
 */
int ParseDeepArrayTest(void);


/*
 See that the correct error is reported when parsing
 an array of depth 11, one too large.
 */
int ParseTooDeepArrayTest(void);


/*
  Try to parse some legit CBOR types that this parsers
  doesn't support.
 */
int UnsupportedCBORDecodeTest(void);


/*
  This takes the encoded CBOR integers used in the above test and parses
  it over and over with one more byte less each time. It should fail
  every time on incorrect CBOR input. This is a hostile input decode test.
 */
int ShortBufferParseTest(void);


/*
   Same as ShortBufferParseTest, but with a different encoded CBOR input.
   It is another hostile input test
 */
int ShortBufferParseTest2(void);


/*
  Parses the somewhat complicated CBOR MAP and makes sure all the correct
  values parse out.  About 15 values are tested. This is a decode test.
 */
int ParseMapTest(void);


/*
Test the decoder mode where maps are treated as arrays.
 */
int ParseMapAsArrayTest(void);


/*
 Test parsing of some simple values like true, false, null...
 */
int ParseSimpleTest(void);


/*
 This tests all the not-well-formed CBOR from the CBOR RFC.
 (This is the CBORbis RFC which is not yet published at the
 time this test was added).
 */
int NotWellFormedTests(void);


/*
 Tests a number of failure cases on bad CBOR to get the right error code
 */
int DecodeFailureTests(void);


/*
 Parses all possible inputs that are two bytes long. Main point
 is that the test doesn't crash as it doesn't evaluate the
 input for correctness in any way.

 (Parsing all possible 3 byte strings takes too long on all but
  very fast machines).
 */
int ComprehensiveInputTest(void);


/*
 Parses all possible inputs that are four bytes long. Main point
 is that the test doesn't crash as it doesn't evaluate the
 input for correctness in any way. This runs very slow, so it
 is only practical as a once-in-a-while regression test on
 fast machines.
 */
int BigComprehensiveInputTest(void);


/*
 Thest the date types -- epoch and strings
 */
int DateParseTest(void);


/*
  Test optional tags like the CBOR magic number.
 */
int OptTagParseTest(void);


/*
 Parse some big numbers, positive and negative
 */
int BignumParseTest(void);


/*
 Test of mode where only string labels are allowed
 */
int StringDecoderModeFailTest(void);


/*
 Parse some nested maps
 */
int NestedMapTest(void);


/*
 Parse maps with indefinite lengths
 */
int NestedMapTestIndefLen(void);


/*
 Parse some maps and arrays with indefinite lengths.
 Includes some error cases.
 */
int IndefiniteLengthArrayMapTest(void);


/*
 Parse indefinite length strings. Uses
 MemPool. Includes error cases.
 */
int IndefiniteLengthStringTest(void);


/*
 Test deep nesting of indefinite length
 maps and arrays including too deep.
 */
int IndefiniteLengthNestTest(void);


/*
 Test parsing strings were all strings, not
 just indefinite length strings, are
 allocated. Includes error test cases.
 */
int AllocAllStringsTest(void);


/*
 Direct test of MemPool string allocator
 */
int MemPoolTest(void);


/*
 Test the setting up of an external string allocator.
 */
int SetUpAllocatorTest(void);


#endif /* defined(__QCBOR__qcbort_decode_tests__) */