Laurence Lundblade | 2ded3d9 | 2018-10-09 21:36:11 +0800 | [diff] [blame^] | 1 | /*============================================================================== |
| 2 | Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. |
| 3 | |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions are |
| 6 | met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above |
| 10 | copyright notice, this list of conditions and the following |
| 11 | disclaimer in the documentation and/or other materials provided |
| 12 | with the distribution. |
| 13 | * Neither the name of The Linux Foundation nor the names of its |
| 14 | contributors may be used to endorse or promote products derived |
| 15 | from this software without specific prior written permission. |
| 16 | |
| 17 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | ==============================================================================*/ |
| 29 | |
| 30 | #ifndef __QCBOR__qcbort_decode_tests__ |
| 31 | #define __QCBOR__qcbort_decode_tests__ |
| 32 | |
| 33 | #include "qcbor.h" |
| 34 | |
| 35 | |
| 36 | /* |
| 37 | Notes: |
| 38 | |
| 39 | - All the functions in qcbor.h are called once in the aggregation of all the tests below. |
| 40 | |
| 41 | - All the types that are supported are given as input and parsed by these tests |
| 42 | |
| 43 | - There is some hostile input such as invalid lengths and CBOR too complex |
| 44 | and types this parser doesn't handle |
| 45 | |
| 46 | */ |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | /* |
| 52 | Parse a well-known set of integers including those around the boundaries and |
| 53 | make sure the expected values come out |
| 54 | */ |
| 55 | int IntegerValuesParseTest(); |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | /* |
| 62 | Decode a simple CBOR encoded array and make sure it returns all the correct values. |
| 63 | This is a decode test. |
| 64 | */ |
| 65 | int SimpleArrayTest(); |
| 66 | |
| 67 | |
| 68 | /* |
| 69 | Make sure a maximally deep array can be parsed and that the |
| 70 | reported nesting level is correct. This uses test vector |
| 71 | of CBOR encoded data with a depth of 10. This a parse test. |
| 72 | */ |
| 73 | int ParseDeepArrayTest(); |
| 74 | |
| 75 | |
| 76 | /* |
| 77 | See that the correct error is reported when parsing |
| 78 | an array of depth 11, one too large. |
| 79 | */ |
| 80 | int ParseTooDeepArrayTest(); |
| 81 | |
| 82 | |
| 83 | /* |
| 84 | Try to parse some legit CBOR types that this parsers |
| 85 | doesn't support. |
| 86 | */ |
| 87 | int UnsupportedCBORDecodeTest(); |
| 88 | |
| 89 | |
| 90 | /* |
| 91 | This takes the encoded CBOR integers used in the above test and parses |
| 92 | it over and over with one more byte less each time. It should fail |
| 93 | every time on incorrect CBOR input. This is a hostile input decode test. |
| 94 | */ |
| 95 | int ShortBufferParseTest(); |
| 96 | |
| 97 | |
| 98 | /* |
| 99 | Same as ShortBufferParseTest, but with a different encoded CBOR input. |
| 100 | It is another hostile input test |
| 101 | */ |
| 102 | int ShortBufferParseTest2(); |
| 103 | |
| 104 | |
| 105 | /* |
| 106 | Parses the somewhat complicated CBOR MAP and makes sure all the correct |
| 107 | values parse out. About 15 values are tested. This is a decode test. |
| 108 | */ |
| 109 | int ParseMapTest(); |
| 110 | |
| 111 | |
| 112 | |
| 113 | int FloatValuesTest1(); |
| 114 | |
| 115 | |
| 116 | |
| 117 | int SimpleValuesTest1(); |
| 118 | |
| 119 | |
| 120 | |
| 121 | int ParseSimpleTest(); |
| 122 | |
| 123 | |
| 124 | |
| 125 | /* |
| 126 | Tests a number of failure cases on bad CBOR to get the right error code |
| 127 | */ |
| 128 | int FailureTests(); |
| 129 | |
| 130 | |
| 131 | /* |
| 132 | Generate all possible input strings up to length x and tries to parse them completely |
| 133 | */ |
| 134 | int ComprehensiveInputTest(); |
| 135 | |
| 136 | |
| 137 | /* |
| 138 | Thest the date types -- epoch and strings |
| 139 | */ |
| 140 | int DateParseTest(); |
| 141 | |
| 142 | |
| 143 | /* |
| 144 | Test optional tags like the CBOR magic number. |
| 145 | */ |
| 146 | int OptTagParseTest(); |
| 147 | |
| 148 | |
| 149 | /* |
| 150 | Parse some big numbers, positive and negative |
| 151 | */ |
| 152 | int BignumParseTest(); |
| 153 | |
| 154 | |
| 155 | /* |
| 156 | Parse some nested maps |
| 157 | */ |
| 158 | int NestedMapTest(); |
| 159 | |
| 160 | |
| 161 | |
| 162 | #endif /* defined(__QCBOR__qcbort_decode_tests__) */ |