Mistake on this page?
Report an issue in GitHub or email us
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 
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  ==============================================================================*/
32 
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  */
58 int IntegerValuesParseTest(void);
59 
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  */
68 int SimpleArrayTest(void);
69 
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  */
76 int ParseDeepArrayTest(void);
77 
78 
79 /*
80  See that the correct error is reported when parsing
81  an array of depth 11, one too large.
82  */
83 int ParseTooDeepArrayTest(void);
84 
85 
86 /*
87  Try to parse some legit CBOR types that this parsers
88  doesn't support.
89  */
90 int UnsupportedCBORDecodeTest(void);
91 
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  */
98 int ShortBufferParseTest(void);
99 
100 
101 /*
102  Same as ShortBufferParseTest, but with a different encoded CBOR input.
103  It is another hostile input test
104  */
105 int ShortBufferParseTest2(void);
106 
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  */
112 int ParseMapTest(void);
113 
114 
115 
116 int FloatValuesTest1(void);
117 
118 
119 
120 int SimpleValuesTest1(void);
121 
122 
123 /*
124 
125  */
126 int ParseMapAsArrayTest(void);
127 
128 
129 
130 int ParseSimpleTest(void);
131 
132 
133 
134 /*
135  Tests a number of failure cases on bad CBOR to get the right error code
136  */
137 int FailureTests(void);
138 
139 
140 /*
141  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.
144 
145  (Parsing all possible 3 byte strings takes too long on all but
146  very fast machines).
147  */
148 int ComprehensiveInputTest(void);
149 
150 
151 /*
152  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  */
158 int BigComprehensiveInputTest(void);
159 
160 
161 /*
162  Thest the date types -- epoch and strings
163  */
164 int DateParseTest(void);
165 
166 
167 /*
168  Test optional tags like the CBOR magic number.
169  */
170 int OptTagParseTest(void);
171 
172 
173 /*
174  Parse some big numbers, positive and negative
175  */
176 int BignumParseTest(void);
177 
178 
179 int StringDecoderModeFailTest(void);
180 
181 
182 /*
183  Parse some nested maps
184  */
185 int NestedMapTest(void);
186 
187 
188 /*
189  Parse maps with indefinite lengths
190  */
191 int NestedMapTestIndefLen(void);
192 
193 
194 /*
195  Parse some maps and arrays with indefinite lengths.
196  Includes some error cases.
197  */
198 int IndefiniteLengthArrayMapTest(void);
199 
200 
201 /*
202  Parse indefinite length strings. Uses
203  MemPool. Includes error cases.
204  */
205 int IndefiniteLengthStringTest(void);
206 
207 
208 /*
209  Test deep nesting of indefinite length
210  maps and arrays including too deep.
211  */
212 int IndefiniteLengthNestTest(void);
213 
214 
215 /*
216  Test parsing strings were all strings, not
217  just indefinite length strings, are
218  allocated. Includes error test cases.
219  */
220 int AllocAllStringsTest(void);
221 
222 
223 /*
224  Direct test of MemPool string allocator
225  */
226 int MemPoolTest(void);
227 
228 
229 #endif /* defined(__QCBOR__qcbort_decode_tests__) */
Q C B O R E n c o d e / D e c o d e.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.