blob: 526bfaf2f1f4434ed02856774c324abb799dee89 [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 Lundblade240ca822024-01-16 11:11:00 -07003 Copyright (c) 2018-2024, 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 Lundbladec5fef682020-01-25 11:38:45 -080036#include <stdint.h>
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080037
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080038/*
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080039 Notes:
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080040
Laurence Lundblade844bb5c2020-03-01 17:27:25 -080041 - All the functions in qcbor_encode.h are called once in the aggregation of all
Laurence Lundbladeee851742020-01-08 08:37:05 -080042 the tests below.
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080043
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080044 */
45
46
47/*
Laurence Lundblade4d1ecba2018-10-12 21:22:30 +080048 Most basic test.
49 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -080050int32_t BasicEncodeTest(void);
Laurence Lundblade4d1ecba2018-10-12 21:22:30 +080051
52
53/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080054 Encode lots of integer values, particularly around the boundary and
55 make sure they Match the expected binary output. Primarily an
56 encoding test.
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080057 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -080058int32_t IntegerValuesTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080059
60
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080061/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080062 Create nested arrays to the max depth allowed and make sure it
63 succeeds. This is an encoding test.
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080064 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -080065int32_t ArrayNestingTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080066
67
68/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080069 Create nested arrays to one more than the meax depth and make sure it
70 fails. This is an encoding test.
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080071 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -080072int32_t ArrayNestingTest2(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080073
74
75/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080076 Encoding test. Create arrays to max depth and close one extra time
77 and look for correct error code
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080078 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -080079int32_t ArrayNestingTest3(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080080
81
82/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080083 This tests the QCBOREncode_AddRaw() function by adding two chunks or
84 RAWCBOR to an array and comparing with expected values. This is an
85 encoding test.
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080086 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -080087int32_t EncodeRawTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080088
89
90/*
Laurence Lundbladeee851742020-01-08 08:37:05 -080091 This creates a somewhat complicated CBOR MAP and verifies it against
92 expected data. This is an encoding test.
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080093 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -080094int32_t MapEncodeTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080095
96
Laurence Lundblade2ded3d92018-10-09 21:36:11 +080097/*
98 Encodes a goodly number of floats and doubles and checks encoding is right
99 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800100int32_t FloatValuesTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800101
102
103/*
104 Encodes true, false and the like
105 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800106int32_t SimpleValuesTest1(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800107
108
109/*
Jan Jongboom47d86c52019-07-25 08:54:16 +0200110 Encodes basic maps and arrays with indefinite length
111 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800112int32_t SimpleValuesIndefiniteLengthTest1(void);
Jan Jongboom47d86c52019-07-25 08:54:16 +0200113
Laurence Lundbladeee851742020-01-08 08:37:05 -0800114
Jan Jongboom5d827882019-08-07 12:51:15 +0200115/*
Laurence Lundbladeee851742020-01-08 08:37:05 -0800116 Indefinite length arrays and maps use the 'magic' number 31, verify
117 that everything with length 31 still works properly
Jan Jongboom5d827882019-08-07 12:51:15 +0200118 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800119int32_t EncodeLengthThirtyoneTest(void);
Jan Jongboom5d827882019-08-07 12:51:15 +0200120
Jan Jongboom47d86c52019-07-25 08:54:16 +0200121
122/*
Laurence Lundblade46d63e92021-05-13 11:37:10 -0700123 * Tests Encoding most data formats that are supported.
124 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800125int32_t EncodeDateTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800126
127
128/*
129 Encodes particular data structure that a particular app will need...
130 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800131int32_t RTICResultsTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800132
133
134/*
Laurence Lundblade844bb5c2020-03-01 17:27:25 -0800135 Calls all public encode methods in qcbor_encode.h once.
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800136 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800137int32_t AllAddMethodsTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800138
Laurence Lundbladeb24faef2022-04-26 11:03:08 -0600139
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800140/*
141 The binary string wrapping of maps and arrays used by COSE
142 */
Laurence Lundbladeb24faef2022-04-26 11:03:08 -0600143int32_t BstrWrapTest(void);
Laurence Lundblade684aec22018-10-12 19:33:53 +0800144
Laurence Lundbladea65b4822019-09-08 12:17:03 -0700145
146/*
147 Test error cases for bstr wrapping encoding such as closing an open
148 array with CloseBstrWrap
149 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800150int32_t BstrWrapErrorTest(void);
Laurence Lundblade684aec22018-10-12 19:33:53 +0800151
Laurence Lundbladea65b4822019-09-08 12:17:03 -0700152
153/*
154 Test complicated nested bstr wrapping
155 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800156int32_t BstrWrapNestTest(void);
Laurence Lundblade684aec22018-10-12 19:33:53 +0800157
Laurence Lundbladea65b4822019-09-08 12:17:03 -0700158
159/*
160 Test encoding a COSE_Sign1 with bstr wrapping
161 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800162int32_t CoseSign1TBSTest(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800163
Laurence Lundblade1ef8b2d2018-12-14 23:13:34 -0800164
Laurence Lundbladedd6e76e2021-03-10 01:54:01 -0700165#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
Laurence Lundblade59289e52019-12-30 13:44:37 -0800166/*
167 Test encoding of decimal fractions and big floats, both of which are
168 made up of an exponent and mantissa
169 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800170int32_t ExponentAndMantissaEncodeTests(void);
Laurence Lundbladedd6e76e2021-03-10 01:54:01 -0700171#endif /* QCBOR_DISABLE_EXP_AND_MANTISSA */
Laurence Lundblade59289e52019-12-30 13:44:37 -0800172
Laurence Lundbladec9f0fbc2020-02-07 10:48:33 +0000173
Laurence Lundbladea65b4822019-09-08 12:17:03 -0700174/*
175 Test the error cases when encoding CBOR such as buffer too large,
176 buffer too small, array nesting too deep. Aims to cover the error
177 codes returned when encoding CBOR
178 */
Laurence Lundbladec5fef682020-01-25 11:38:45 -0800179int32_t EncodeErrorTests(void);
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800180
181
Laurence Lundbladec9f0fbc2020-02-07 10:48:33 +0000182/*
183 Test QCBOREncode_EncodeHead(). This is a minimal test because every other
184 test here exercises it in some way.
185 */
186int32_t QCBORHeadTest(void);
187
188
Laurence Lundbladeb24faef2022-04-26 11:03:08 -0600189/* Fully test QCBOREncode_OpenBytes(), QCBOREncode_CloseBytes()
190 * and friends.
191 */
192int32_t OpenCloseBytesTest(void);
193
194
Laurence Lundbladed6e13022023-11-26 10:14:02 -0700195/* Test map sorting */
196int32_t SortMapTest(void);
197
Laurence Lundbladec9f0fbc2020-02-07 10:48:33 +0000198
Laurence Lundblade240ca822024-01-16 11:11:00 -0700199/* Test CDE Encoding Mode (TODO: CDE definition is in progress in IETF) */
200int32_t CDETest(void);
201
202int32_t DCBORTest(void);
203
Laurence Lundblade2ded3d92018-10-09 21:36:11 +0800204#endif /* defined(__QCBOR__qcbor_encode_tests__) */