Mbed OS Reference
Loading...
Searching...
No Matches
qcbor_decode_tests.h
1/*==============================================================================
2 Copyright (c) 2016-2018, The Linux Foundation.
3 Copyright (c) 2018-2019, Laurence Lundblade.
4 All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6
7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions are
9met:
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16 * Neither the name of The Linux Foundation nor the names of its
17 contributors, nor the name "Laurence Lundblade" may be used to
18 endorse or promote products derived from this software without
19 specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
22WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
24ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
31IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ==============================================================================*/
33
34#ifndef __QCBOR__qcbort_decode_tests__
35#define __QCBOR__qcbort_decode_tests__
36
37#include "qcbor.h"
38
39
40/*
41 Notes:
42
43 - All the functions in qcbor.h are called once in the aggregation of all the tests below.
44
45 - All the types that are supported are given as input and parsed by these tests
46
47 - There is some hostile input such as invalid lengths and CBOR too complex
48 and types this parser doesn't handle
49
50 */
51
52
53
54
55/*
56 Parse a well-known set of integers including those around the boundaries and
57 make sure the expected values come out
58 */
59int IntegerValuesParseTest(void);
60
61
62
63
64
65/*
66 Decode a simple CBOR encoded array and make sure it returns all the correct values.
67 This is a decode test.
68 */
69int SimpleArrayTest(void);
70
71
72/*
73 Make sure a maximally deep array can be parsed and that the
74 reported nesting level is correct. This uses test vector
75 of CBOR encoded data with a depth of 10. This a parse test.
76 */
77int ParseDeepArrayTest(void);
78
79
80/*
81 See that the correct error is reported when parsing
82 an array of depth 11, one too large.
83 */
84int ParseTooDeepArrayTest(void);
85
86
87/*
88 Try to parse some legit CBOR types that this parsers
89 doesn't support.
90 */
91int UnsupportedCBORDecodeTest(void);
92
93
94/*
95 This takes the encoded CBOR integers used in the above test and parses
96 it over and over with one more byte less each time. It should fail
97 every time on incorrect CBOR input. This is a hostile input decode test.
98 */
99int ShortBufferParseTest(void);
100
101
102/*
103 Same as ShortBufferParseTest, but with a different encoded CBOR input.
104 It is another hostile input test
105 */
106int ShortBufferParseTest2(void);
107
108
109/*
110 Parses the somewhat complicated CBOR MAP and makes sure all the correct
111 values parse out. About 15 values are tested. This is a decode test.
112 */
113int ParseMapTest(void);
114
115
116
117int FloatValuesTest1(void);
118
119
120
121int SimpleValuesTest1(void);
122
123
124/*
125
126 */
127int ParseMapAsArrayTest(void);
128
129
130
131int ParseSimpleTest(void);
132
133
134
135/*
136 Tests a number of failure cases on bad CBOR to get the right error code
137 */
138int FailureTests(void);
139
140
141/*
142 Parses all possible inputs that are two bytes long. Main point
143 is that the test doesn't crash as it doesn't evaluate the
144 input for correctness in any way.
145
146 (Parsing all possible 3 byte strings takes too long on all but
147 very fast machines).
148 */
149int ComprehensiveInputTest(void);
150
151
152/*
153 Parses all possible inputs that are four bytes long. Main point
154 is that the test doesn't crash as it doesn't evaluate the
155 input for correctness in any way. This runs very slow, so it
156 is only practical as a once-in-a-while regression test on
157 fast machines.
158 */
159int BigComprehensiveInputTest(void);
160
161
162/*
163 Thest the date types -- epoch and strings
164 */
165int DateParseTest(void);
166
167
168/*
169 Test optional tags like the CBOR magic number.
170 */
171int OptTagParseTest(void);
172
173
174/*
175 Parse some big numbers, positive and negative
176 */
177int BignumParseTest(void);
178
179
180int StringDecoderModeFailTest(void);
181
182
183/*
184 Parse some nested maps
185 */
186int NestedMapTest(void);
187
188
189/*
190 Parse maps with indefinite lengths
191 */
192int NestedMapTestIndefLen(void);
193
194
195/*
196 Parse some maps and arrays with indefinite lengths.
197 Includes some error cases.
198 */
199int IndefiniteLengthArrayMapTest(void);
200
201
202/*
203 Parse indefinite length strings. Uses
204 MemPool. Includes error cases.
205 */
206int IndefiniteLengthStringTest(void);
207
208
209/*
210 Test deep nesting of indefinite length
211 maps and arrays including too deep.
212 */
213int IndefiniteLengthNestTest(void);
214
215
216/*
217 Test parsing strings were all strings, not
218 just indefinite length strings, are
219 allocated. Includes error test cases.
220 */
221int AllocAllStringsTest(void);
222
223
224/*
225 Direct test of MemPool string allocator
226 */
227int MemPoolTest(void);
228
229
230#endif /* defined(__QCBOR__qcbort_decode_tests__) */
Q C B O R E n c o d e / D e c o d e.