blob: 3d11883c9959c79062f1d43939468f2baae36109 [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 Lundbladeee851742020-01-08 08:37:05 -08003 Copyright (c) 2018-2020, 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 Lundbladeee851742020-01-08 08:37:05 -080031 =============================================================================*/
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080032
33#ifndef __QCBOR__qcbor_encode_tests__
34#define __QCBOR__qcbor_encode_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 Lundbladeee851742020-01-08 08:37:05 -080040 - All the functions in qcbor.h are called once in the aggregation of all
41 the tests below.
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080042
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080043 - All the types that are supported are given as input and parsed by these tests
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080044
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080045 - There is some hostile input such as invalid lengths and CBOR too complex
46 and types this parser doesn't handle
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080047
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080048 */
49
50
51/*
Laurence Lundblade4d1ecba2018-10-12 21:22:30 +080052 Most basic test.
53 */
Laurence Lundblade369b90a2018-10-22 02:04:37 +053054int BasicEncodeTest(void);
Laurence Lundblade4d1ecba2018-10-12 21:22:30 +080055
56
57/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080058 Encode lots of integer values, particularly around the boundary and
59 make sure they Match the expected binary output. Primarily an
60 encoding test.
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080061 */
Laurence Lundbladedc6e28e2018-10-11 19:19:27 +053062int IntegerValuesTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080063
64
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080065/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080066 Create nested arrays to the max depth allowed and make sure it
67 succeeds. This is an encoding test.
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080068 */
Laurence Lundbladedc6e28e2018-10-11 19:19:27 +053069int ArrayNestingTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080070
71
72/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080073 Create nested arrays to one more than the meax depth and make sure it
74 fails. This is an encoding test.
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080075 */
Laurence Lundbladedc6e28e2018-10-11 19:19:27 +053076int ArrayNestingTest2(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080077
78
79/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080080 Encoding test. Create arrays to max depth and close one extra time
81 and look for correct error code
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080082 */
Laurence Lundbladedc6e28e2018-10-11 19:19:27 +053083int ArrayNestingTest3(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080084
85
86/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080087 This tests the QCBOREncode_AddRaw() function by adding two chunks or
88 RAWCBOR to an array and comparing with expected values. This is an
89 encoding test.
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080090 */
Laurence Lundbladedc6e28e2018-10-11 19:19:27 +053091int EncodeRawTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080092
93
94/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080095 This creates a somewhat complicated CBOR MAP and verifies it against
96 expected data. This is an encoding test.
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080097 */
Laurence Lundbladedc6e28e2018-10-11 19:19:27 +053098int MapEncodeTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080099
100
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800101/*
102 Encodes a goodly number of floats and doubles and checks encoding is right
103 */
Laurence Lundbladedc6e28e2018-10-11 19:19:27 +0530104int FloatValuesTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800105
106
107/*
108 Encodes true, false and the like
109 */
Laurence Lundbladedc6e28e2018-10-11 19:19:27 +0530110int SimpleValuesTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800111
112
113/*
Jan Jongboom47d86c52019-07-25 08:54:16 +0200114 Encodes basic maps and arrays with indefinite length
115 */
116int SimpleValuesIndefiniteLengthTest1(void);
117
Laurence Lundbladeee851742020-01-08 08:37:05 -0800118
Jan Jongboom5d827882019-08-07 12:51:15 +0200119/*
Laurence Lundbladeee851742020-01-08 08:37:05 -0800120 Indefinite length arrays and maps use the 'magic' number 31, verify
121 that everything with length 31 still works properly
Jan Jongboom5d827882019-08-07 12:51:15 +0200122 */
123int EncodeLengthThirtyoneTest(void);
124
Jan Jongboom47d86c52019-07-25 08:54:16 +0200125
126/*
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800127 Encodes most data formats that are supported */
Laurence Lundbladedc6e28e2018-10-11 19:19:27 +0530128int EncodeDateTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800129
130
131/*
132 Encodes particular data structure that a particular app will need...
133 */
Laurence Lundbladedc6e28e2018-10-11 19:19:27 +0530134int RTICResultsTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800135
136
137/*
138 Calls all public encode methods in qcbor.h once.
139 */
Laurence Lundbladedc6e28e2018-10-11 19:19:27 +0530140int AllAddMethodsTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800141
142/*
143 The binary string wrapping of maps and arrays used by COSE
144 */
Laurence Lundblade369b90a2018-10-22 02:04:37 +0530145int BstrWrapTest(void);
Laurence Lundblade684aec22018-10-12 19:33:53 +0800146
Laurence Lundbladea65b4822019-09-08 12:17:03 -0700147
148/*
149 Test error cases for bstr wrapping encoding such as closing an open
150 array with CloseBstrWrap
151 */
Laurence Lundblade369b90a2018-10-22 02:04:37 +0530152int BstrWrapErrorTest(void);
Laurence Lundblade684aec22018-10-12 19:33:53 +0800153
Laurence Lundbladea65b4822019-09-08 12:17:03 -0700154
155/*
156 Test complicated nested bstr wrapping
157 */
Laurence Lundblade369b90a2018-10-22 02:04:37 +0530158int BstrWrapNestTest(void);
Laurence Lundblade684aec22018-10-12 19:33:53 +0800159
Laurence Lundbladea65b4822019-09-08 12:17:03 -0700160
161/*
162 Test encoding a COSE_Sign1 with bstr wrapping
163 */
Laurence Lundblade369b90a2018-10-22 02:04:37 +0530164int CoseSign1TBSTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800165
Laurence Lundblade1ef8b2d2018-12-14 23:13:34 -0800166
Laurence Lundblade59289e52019-12-30 13:44:37 -0800167#ifndef QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA
168/*
169 Test encoding of decimal fractions and big floats, both of which are
170 made up of an exponent and mantissa
171 */
172int ExponentAndMantissaEncodeTests(void);
173#endif /* QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA */
174
Laurence Lundbladea65b4822019-09-08 12:17:03 -0700175/*
176 Test the error cases when encoding CBOR such as buffer too large,
177 buffer too small, array nesting too deep. Aims to cover the error
178 codes returned when encoding CBOR
179 */
180int EncodeErrorTests(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800181
182
183#endif /* defined(__QCBOR__qcbor_encode_tests__) */