Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 1 | /*============================================================================== |
Laurence Lundblade | d92a616 | 2018-11-01 11:38:35 +0700 | [diff] [blame] | 2 | Copyright (c) 2016-2018, The Linux Foundation. |
| 3 | Copyright (c) 2018, Laurence Lundblade. |
| 4 | All rights reserved. |
| 5 | |
Laurence Lundblade | 0dbc917 | 2018-11-01 14:17:21 +0700 | [diff] [blame^] | 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. |
Laurence Lundblade | d92a616 | 2018-11-01 11:38:35 +0700 | [diff] [blame] | 19 | |
Laurence Lundblade | 0dbc917 | 2018-11-01 14:17:21 +0700 | [diff] [blame^] | 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. |
Laurence Lundblade | d92a616 | 2018-11-01 11:38:35 +0700 | [diff] [blame] | 31 | ==============================================================================*/ |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 32 | |
| 33 | #ifndef __QCBOR__qcbor_encode_tests__ |
| 34 | #define __QCBOR__qcbor_encode_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 | /* |
Laurence Lundblade | 4d1ecba | 2018-10-12 21:22:30 +0800 | [diff] [blame] | 53 | Most basic test. |
| 54 | */ |
Laurence Lundblade | 369b90a | 2018-10-22 02:04:37 +0530 | [diff] [blame] | 55 | int BasicEncodeTest(void); |
Laurence Lundblade | 4d1ecba | 2018-10-12 21:22:30 +0800 | [diff] [blame] | 56 | |
| 57 | |
| 58 | /* |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 59 | Encode lots of integer values, particularly around the boundary and make sure they |
| 60 | Match the expected binary output. Primarily an encoding test. |
| 61 | */ |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 62 | int IntegerValuesTest1(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 63 | |
| 64 | |
| 65 | |
| 66 | /* |
| 67 | Create nested arrays to the max depth allowed and make sure it succeeds. |
| 68 | This is an encoding test. |
| 69 | */ |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 70 | int ArrayNestingTest1(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 71 | |
| 72 | |
| 73 | /* |
| 74 | Create nested arrays to one more than the meax depth and make sure it fails. |
| 75 | This is an encoding test. |
| 76 | */ |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 77 | int ArrayNestingTest2(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 78 | |
| 79 | |
| 80 | /* |
| 81 | Encoding test. |
| 82 | Create arrays to max depth and close one extra time and look for correct error code |
| 83 | */ |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 84 | int ArrayNestingTest3(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 85 | |
| 86 | |
| 87 | /* |
| 88 | This tests the QCBOREncode_AddRaw() function by adding two chunks or RAWCBOR to an |
| 89 | array and comparing with expected values. This is an encoding test. |
| 90 | */ |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 91 | int EncodeRawTest(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 92 | |
| 93 | |
| 94 | /* |
| 95 | This creates a somewhat complicated CBOR MAP and verifies it against expected |
| 96 | data. This is an encoding test. |
| 97 | */ |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 98 | int MapEncodeTest(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 99 | |
| 100 | |
| 101 | |
| 102 | /* |
| 103 | Encodes a goodly number of floats and doubles and checks encoding is right |
| 104 | */ |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 105 | int FloatValuesTest1(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 106 | |
| 107 | |
| 108 | /* |
| 109 | Encodes true, false and the like |
| 110 | */ |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 111 | int SimpleValuesTest1(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 112 | |
| 113 | |
| 114 | /* |
| 115 | Encodes most data formats that are supported */ |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 116 | int EncodeDateTest(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 117 | |
| 118 | |
| 119 | /* |
| 120 | Encodes particular data structure that a particular app will need... |
| 121 | */ |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 122 | int RTICResultsTest(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 123 | |
| 124 | |
| 125 | /* |
| 126 | Calls all public encode methods in qcbor.h once. |
| 127 | */ |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 128 | int AllAddMethodsTest(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | The binary string wrapping of maps and arrays used by COSE |
| 132 | */ |
Laurence Lundblade | 369b90a | 2018-10-22 02:04:37 +0530 | [diff] [blame] | 133 | int BstrWrapTest(void); |
Laurence Lundblade | 684aec2 | 2018-10-12 19:33:53 +0800 | [diff] [blame] | 134 | |
Laurence Lundblade | 369b90a | 2018-10-22 02:04:37 +0530 | [diff] [blame] | 135 | int BstrWrapErrorTest(void); |
Laurence Lundblade | 684aec2 | 2018-10-12 19:33:53 +0800 | [diff] [blame] | 136 | |
Laurence Lundblade | 369b90a | 2018-10-22 02:04:37 +0530 | [diff] [blame] | 137 | int BstrWrapNestTest(void); |
Laurence Lundblade | 684aec2 | 2018-10-12 19:33:53 +0800 | [diff] [blame] | 138 | |
Laurence Lundblade | 369b90a | 2018-10-22 02:04:37 +0530 | [diff] [blame] | 139 | int CoseSign1TBSTest(void); |
Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame] | 140 | |
| 141 | |
| 142 | |
| 143 | #endif /* defined(__QCBOR__qcbor_encode_tests__) */ |