blob: f19e3b6c8369010310559aa9e4a4aa4e35fd15b3 [file] [log] [blame]
Laurence Lundblade2ded3d92018-10-09 21:36:11 +08001/*==============================================================================
Laurence Lundbladed92a6162018-11-01 11:38:35 +07002 Copyright (c) 2016-2018, The Linux Foundation.
3 Copyright (c) 2018, Laurence Lundblade.
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above
12 copyright notice, this list of conditions and the following
13 disclaimer in the documentation and/or other materials provided
14 with the distribution.
15 * Neither the name of The Linux Foundation nor the names of its
16 contributors, nor the name "Laurence Lundblade" may be used to
17 endorse or promote products derived from this software without
18 specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
21 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
24 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ==============================================================================*/
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080032
33#ifndef __QCBOR__qcbort_decode_tests__
34#define __QCBOR__qcbort_decode_tests__
35
36#include "qcbor.h"
37
38
39/*
40 Notes:
41
42 - All the functions in qcbor.h are called once in the aggregation of all the tests below.
43
44 - All the types that are supported are given as input and parsed by these tests
45
46 - There is some hostile input such as invalid lengths and CBOR too complex
47 and types this parser doesn't handle
48
49 */
50
51
52
53
54/*
55 Parse a well-known set of integers including those around the boundaries and
56 make sure the expected values come out
57 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080058int IntegerValuesParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080059
60
61
62
63
64/*
65 Decode a simple CBOR encoded array and make sure it returns all the correct values.
66 This is a decode test.
67 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080068int SimpleArrayTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080069
70
71/*
72 Make sure a maximally deep array can be parsed and that the
73 reported nesting level is correct. This uses test vector
74 of CBOR encoded data with a depth of 10. This a parse test.
75 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080076int ParseDeepArrayTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080077
78
79/*
80 See that the correct error is reported when parsing
81 an array of depth 11, one too large.
82 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080083int ParseTooDeepArrayTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080084
85
86/*
87 Try to parse some legit CBOR types that this parsers
88 doesn't support.
89 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080090int UnsupportedCBORDecodeTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080091
92
93/*
94 This takes the encoded CBOR integers used in the above test and parses
95 it over and over with one more byte less each time. It should fail
96 every time on incorrect CBOR input. This is a hostile input decode test.
97 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080098int ShortBufferParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080099
100
101/*
102 Same as ShortBufferParseTest, but with a different encoded CBOR input.
103 It is another hostile input test
104 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800105int ShortBufferParseTest2(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800106
107
108/*
109 Parses the somewhat complicated CBOR MAP and makes sure all the correct
110 values parse out. About 15 values are tested. This is a decode test.
111 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800112int ParseMapTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800113
114
115
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800116int FloatValuesTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800117
118
119
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800120int SimpleValuesTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800121
122
123
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800124int ParseSimpleTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800125
126
127
128/*
129 Tests a number of failure cases on bad CBOR to get the right error code
130 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800131int FailureTests(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800132
133
134/*
135 Generate all possible input strings up to length x and tries to parse them completely
136 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800137int ComprehensiveInputTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800138
139
140/*
141 Thest the date types -- epoch and strings
142 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800143int DateParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800144
145
146/*
147 Test optional tags like the CBOR magic number.
148 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800149int OptTagParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800150
151
152/*
153 Parse some big numbers, positive and negative
154 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800155int BignumParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800156
157
158/*
159 Parse some nested maps
160 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800161int NestedMapTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800162
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530163
164/*
165 Parse maps with indefinite lengths
166 */
Laurence Lundblade742df4a2018-10-13 20:07:17 +0800167int NestedMapTestIndefLen(void);
168
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800169
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530170/*
171 Parse some maps and arrays with indefinite lengths.
172 Includes some error cases.
173 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530174int IndefiniteLengthArrayMapTest(void);
Laurence Lundblade4d1ecba2018-10-12 21:22:30 +0800175
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530176
177/*
178 Parse indefinite length strings. Uses
179 MemPool. Includes error cases.
180 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530181int IndefiniteLengthStringTest(void);
Laurence Lundblade4d1ecba2018-10-12 21:22:30 +0800182
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530183
184/*
185 Test deep nesting of indefinite length
186 maps and arrays including too deep.
187 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530188int IndefiniteLengthNestTest(void);
189
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530190
191/*
192 Test parsing strings were all strings, not
193 just indefinite length strings, are
194 allocated. Includes error test cases.
195 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530196int AllocAllStringsTest(void);
197
Laurence Lundblade0155b622018-10-12 20:04:37 +0800198
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530199/*
200 Direct test of MemPool string allocator
201 */
202int MemPoolTest(void);
Laurence Lundblade0155b622018-10-12 20:04:37 +0800203
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800204
205#endif /* defined(__QCBOR__qcbort_decode_tests__) */