blob: 6423ccff334aa23fe70008965cbed4a31d93ed6a [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.
Laurence Lundbladef0ea5f32019-01-11 20:10:26 -08003 Copyright (c) 2018-2019, Laurence Lundblade.
Laurence Lundbladed92a6162018-11-01 11:38:35 +07004 All rights reserved.
Laurence Lundblade3aee3a32018-12-17 16:17:45 -08005
Laurence Lundblade0dbc9172018-11-01 14:17:21 +07006Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are
8met:
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.
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080019
Laurence Lundblade0dbc9172018-11-01 14:17:21 +070020THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
21WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
23ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
24BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Laurence Lundbladed92a6162018-11-01 11:38:35 +070031 ==============================================================================*/
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080032
33#ifndef __QCBOR__qcbort_decode_tests__
34#define __QCBOR__qcbort_decode_tests__
35
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080036
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080037/*
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080038 Notes:
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080039
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080040 - All the functions in qcbor.h are called once in the aggregation of all the tests below.
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080041
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080042 - All the types that are supported are given as input and parsed by these tests
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080043
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080044 - There is some hostile input such as invalid lengths and CBOR too complex
45 and types this parser doesn't handle
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080046
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080047 */
48
49
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080050/*
51 Parse a well-known set of integers including those around the boundaries and
52 make sure the expected values come out
53 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080054int IntegerValuesParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080055
56
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080057/*
58 Decode a simple CBOR encoded array and make sure it returns all the correct values.
59 This is a decode test.
60 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080061int SimpleArrayTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080062
Laurence Lundbladea65b4822019-09-08 12:17:03 -070063
Laurence Lundblade9916b1b2019-09-07 22:33:25 -070064/*
65 Tests with empty maps and arrays
66 */
67int EmptyMapsAndArraysTest(void);
68
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080069
70/*
71 Make sure a maximally deep array can be parsed and that the
72 reported nesting level is correct. This uses test vector
73 of CBOR encoded data with a depth of 10. This a parse test.
74 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080075int ParseDeepArrayTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080076
77
78/*
79 See that the correct error is reported when parsing
80 an array of depth 11, one too large.
81 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080082int ParseTooDeepArrayTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080083
84
85/*
86 Try to parse some legit CBOR types that this parsers
87 doesn't support.
88 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080089int UnsupportedCBORDecodeTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080090
91
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080092/*
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080093 This takes the encoded CBOR integers used in the above test and parses
94 it over and over with one more byte less each time. It should fail
95 every time on incorrect CBOR input. This is a hostile input decode test.
96 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +080097int ShortBufferParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080098
99
Laurence Lundblade3aee3a32018-12-17 16:17:45 -0800100/*
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800101 Same as ShortBufferParseTest, but with a different encoded CBOR input.
102 It is another hostile input test
103 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800104int ShortBufferParseTest2(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800105
106
107/*
108 Parses the somewhat complicated CBOR MAP and makes sure all the correct
109 values parse out. About 15 values are tested. This is a decode test.
110 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800111int ParseMapTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800112
113
Laurence Lundbladeccfb8cd2018-12-07 21:11:30 +0900114/*
Laurence Lundbladea65b4822019-09-08 12:17:03 -0700115Test the decoder mode where maps are treated as arrays.
Laurence Lundbladeccfb8cd2018-12-07 21:11:30 +0900116 */
117int ParseMapAsArrayTest(void);
118
119
Laurence Lundbladea65b4822019-09-08 12:17:03 -0700120/*
121 Test parsing of some simple values like true, false, null...
122 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800123int ParseSimpleTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800124
125
Laurence Lundbladebb1062e2019-08-12 23:28:54 -0700126/*
127 This tests all the not-well-formed CBOR from the CBOR RFC.
128 (This is the CBORbis RFC which is not yet published at the
129 time this test was added).
130 */
131int NotWellFormedTests(void);
132
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800133
134/*
135 Tests a number of failure cases on bad CBOR to get the right error code
136 */
Laurence Lundblade3a6042e2019-06-28 19:58:04 -0700137int DecodeFailureTests(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800138
139
140/*
Laurence Lundbladea2e29072018-12-30 09:20:06 -0800141 Parses all possible inputs that are two bytes long. Main point
142 is that the test doesn't crash as it doesn't evaluate the
143 input for correctness in any way.
Laurence Lundbladedf1c1cf2019-01-17 11:55:05 -0800144
Laurence Lundbladea2e29072018-12-30 09:20:06 -0800145 (Parsing all possible 3 byte strings takes too long on all but
Laurence Lundbladedf1c1cf2019-01-17 11:55:05 -0800146 very fast machines).
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800147 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800148int ComprehensiveInputTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800149
150
151/*
Laurence Lundbladea2e29072018-12-30 09:20:06 -0800152 Parses all possible inputs that are four bytes long. Main point
153 is that the test doesn't crash as it doesn't evaluate the
154 input for correctness in any way. This runs very slow, so it
155 is only practical as a once-in-a-while regression test on
156 fast machines.
157 */
158int BigComprehensiveInputTest(void);
159
160
161/*
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800162 Thest the date types -- epoch and strings
163 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800164int DateParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800165
166
167/*
168 Test optional tags like the CBOR magic number.
169 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800170int OptTagParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800171
172
173/*
174 Parse some big numbers, positive and negative
175 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800176int BignumParseTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800177
178
Laurence Lundbladea65b4822019-09-08 12:17:03 -0700179/*
180 Test of mode where only string labels are allowed
181 */
Laurence Lundbladeea567ac2018-12-09 14:03:21 -0800182int StringDecoderModeFailTest(void);
183
184
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800185/*
186 Parse some nested maps
187 */
Laurence Lundblade9e3651c2018-10-10 11:49:55 +0800188int NestedMapTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800189
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530190
191/*
192 Parse maps with indefinite lengths
193 */
Laurence Lundblade742df4a2018-10-13 20:07:17 +0800194int NestedMapTestIndefLen(void);
195
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800196
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530197/*
198 Parse some maps and arrays with indefinite lengths.
199 Includes some error cases.
200 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530201int IndefiniteLengthArrayMapTest(void);
Laurence Lundblade4d1ecba2018-10-12 21:22:30 +0800202
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530203
204/*
205 Parse indefinite length strings. Uses
206 MemPool. Includes error cases.
207 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530208int IndefiniteLengthStringTest(void);
Laurence Lundblade4d1ecba2018-10-12 21:22:30 +0800209
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530210
211/*
212 Test deep nesting of indefinite length
213 maps and arrays including too deep.
214 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530215int IndefiniteLengthNestTest(void);
216
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530217
218/*
219 Test parsing strings were all strings, not
220 just indefinite length strings, are
221 allocated. Includes error test cases.
222 */
Laurence Lundbladea44d5062018-10-17 18:45:12 +0530223int AllocAllStringsTest(void);
224
Laurence Lundblade0155b622018-10-12 20:04:37 +0800225
Laurence Lundbladefab1b522018-10-19 13:40:52 +0530226/*
227 Direct test of MemPool string allocator
228 */
229int MemPoolTest(void);
Laurence Lundblade0155b622018-10-12 20:04:37 +0800230
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800231
Laurence Lundblade1d7eb632019-02-17 17:23:38 -0800232/*
233 Test the setting up of an external string allocator.
234 */
235int SetUpAllocatorTest(void);
236
237
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800238#endif /* defined(__QCBOR__qcbort_decode_tests__) */