blob: 2fca41880c59cfefdc4fd68e351632632a8ed5db [file] [log] [blame]
Laurence Lundblade2ded3d92018-10-09 21:36:11 +08001/*==============================================================================
2Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions are
6met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above
10 copyright notice, this list of conditions and the following
11 disclaimer in the documentation and/or other materials provided
12 with the distribution.
13 * Neither the name of The Linux Foundation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28==============================================================================*/
29
30#ifndef __QCBOR__qcbort_decode_tests__
31#define __QCBOR__qcbort_decode_tests__
32
33#include "qcbor.h"
34
35
36/*
37 Notes:
38
39 - All the functions in qcbor.h are called once in the aggregation of all the tests below.
40
41 - All the types that are supported are given as input and parsed by these tests
42
43 - There is some hostile input such as invalid lengths and CBOR too complex
44 and types this parser doesn't handle
45
46 */
47
48
49
50
51/*
52 Parse a well-known set of integers including those around the boundaries and
53 make sure the expected values come out
54 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080055int IntegerValuesParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080056
57
58
59
60
61/*
62 Decode a simple CBOR encoded array and make sure it returns all the correct values.
63 This is a decode test.
64 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080065int SimpleArrayTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080066
67
68/*
69 Make sure a maximally deep array can be parsed and that the
70 reported nesting level is correct. This uses test vector
71 of CBOR encoded data with a depth of 10. This a parse test.
72 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080073int ParseDeepArrayTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080074
75
76/*
77 See that the correct error is reported when parsing
78 an array of depth 11, one too large.
79 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080080int ParseTooDeepArrayTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080081
82
83/*
84 Try to parse some legit CBOR types that this parsers
85 doesn't support.
86 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080087int UnsupportedCBORDecodeTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080088
89
90/*
91 This takes the encoded CBOR integers used in the above test and parses
92 it over and over with one more byte less each time. It should fail
93 every time on incorrect CBOR input. This is a hostile input decode test.
94 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080095int ShortBufferParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080096
97
98/*
99 Same as ShortBufferParseTest, but with a different encoded CBOR input.
100 It is another hostile input test
101 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800102int ShortBufferParseTest2(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800103
104
105/*
106 Parses the somewhat complicated CBOR MAP and makes sure all the correct
107 values parse out. About 15 values are tested. This is a decode test.
108 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800109int ParseMapTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800110
111
112
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800113int FloatValuesTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800114
115
116
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800117int SimpleValuesTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800118
119
120
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800121int ParseSimpleTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800122
123
124
125/*
126 Tests a number of failure cases on bad CBOR to get the right error code
127 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800128int FailureTests(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800129
130
131/*
132 Generate all possible input strings up to length x and tries to parse them completely
133 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800134int ComprehensiveInputTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800135
136
137/*
138 Thest the date types -- epoch and strings
139 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800140int DateParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800141
142
143/*
144 Test optional tags like the CBOR magic number.
145 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800146int OptTagParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800147
148
149/*
150 Parse some big numbers, positive and negative
151 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800152int BignumParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800153
154
155/*
156 Parse some nested maps
157 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800158int NestedMapTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800159
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530160
161/*
162 Parse maps with indefinite lengths
163 */
Laurence Lundblade742df4a2018-10-13 20:07:17 +0800164int NestedMapTestIndefLen(void);
165
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800166
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530167/*
168 Parse some maps and arrays with indefinite lengths.
169 Includes some error cases.
170 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530171int IndefiniteLengthArrayMapTest(void);
Laurence Lundblade4d1ecba2018-10-12 21:22:30 +0800172
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530173
174/*
175 Parse indefinite length strings. Uses
176 MemPool. Includes error cases.
177 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530178int IndefiniteLengthStringTest(void);
Laurence Lundblade4d1ecba2018-10-12 21:22:30 +0800179
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530180
181/*
182 Test deep nesting of indefinite length
183 maps and arrays including too deep.
184 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530185int IndefiniteLengthNestTest(void);
186
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530187
188/*
189 Test parsing strings were all strings, not
190 just indefinite length strings, are
191 allocated. Includes error test cases.
192 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530193int AllocAllStringsTest(void);
194
Laurence Lundblade0155b622018-10-12 20:04:37 +0800195
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530196/*
197 Direct test of MemPool string allocator
198 */
199int MemPoolTest(void);
Laurence Lundblade0155b622018-10-12 20:04:37 +0800200
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800201
202#endif /* defined(__QCBOR__qcbort_decode_tests__) */