Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 1 | /*============================================================================== |
| 2 | run_tests.c -- test aggregator and results reporting |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 3 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 4 | Created on 9/30/18 |
| 5 | |
| 6 | Copyright (c) 2018-2019, Laurence Lundblade. |
Laurence Lundblade | d92a616 | 2018-11-01 11:38:35 +0700 | [diff] [blame] | 7 | All rights reserved. |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 8 | |
Laurence Lundblade | 0dbc917 | 2018-11-01 14:17:21 +0700 | [diff] [blame] | 9 | Redistribution and use in source and binary forms, with or without |
| 10 | modification, are permitted provided that the following conditions are |
| 11 | met: |
| 12 | * Redistributions of source code must retain the above copyright |
| 13 | notice, this list of conditions and the following disclaimer. |
| 14 | * Redistributions in binary form must reproduce the above |
| 15 | copyright notice, this list of conditions and the following |
| 16 | disclaimer in the documentation and/or other materials provided |
| 17 | with the distribution. |
| 18 | * The name "Laurence Lundblade" may not be used to |
| 19 | endorse or promote products derived from this software without |
| 20 | specific prior written permission. |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 21 | |
Laurence Lundblade | 0dbc917 | 2018-11-01 14:17:21 +0700 | [diff] [blame] | 22 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 23 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 24 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 25 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 26 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 27 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 28 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 29 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 30 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 31 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
Laurence Lundblade | 88b6ece | 2018-12-04 12:27:19 +0900 | [diff] [blame] | 32 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | ==============================================================================*/ |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 34 | |
| 35 | |
| 36 | #include "run_tests.h" |
| 37 | #include "UsefulBuf.h" |
| 38 | #include <stdbool.h> |
| 39 | |
Laurence Lundblade | 2d85ce4 | 2018-10-12 14:12:47 +0800 | [diff] [blame] | 40 | #include "float_tests.h" |
Laurence Lundblade | 9e3651c | 2018-10-10 11:49:55 +0800 | [diff] [blame] | 41 | #include "qcbor_decode_tests.h" |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 42 | #include "qcbor_encode_tests.h" |
| 43 | #include "UsefulBuf_Tests.h" |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 44 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 45 | |
| 46 | |
| 47 | // Used to test RunTests |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 48 | int fail_test() |
| 49 | { |
| 50 | return -44; |
| 51 | } |
| 52 | |
| 53 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 54 | |
| 55 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 56 | /* |
| 57 | Convert a number up to 999999999 to a string. This is so sprintf doesn't |
| 58 | have to be linked in so as to minimized dependencies even in test code. |
Laurence Lundblade | 1544c48 | 2018-12-05 20:52:35 +0900 | [diff] [blame] | 59 | */ |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 60 | const char *NumToString(int32_t nNum, UsefulBuf StringMem) |
| 61 | { |
Laurence Lundblade | 570fab5 | 2018-10-13 18:28:27 +0800 | [diff] [blame] | 62 | const int32_t nMax = 1000000000; |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 63 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 64 | UsefulOutBuf OutBuf; |
| 65 | UsefulOutBuf_Init(&OutBuf, StringMem); |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 66 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 67 | if(nNum < 0) { |
| 68 | UsefulOutBuf_AppendByte(&OutBuf, '-'); |
| 69 | nNum = -nNum; |
| 70 | } |
Laurence Lundblade | 570fab5 | 2018-10-13 18:28:27 +0800 | [diff] [blame] | 71 | if(nNum > nMax-1) { |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 72 | return "XXX"; |
| 73 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 74 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 75 | bool bDidSomeOutput = false; |
Laurence Lundblade | 570fab5 | 2018-10-13 18:28:27 +0800 | [diff] [blame] | 76 | for(int n = nMax; n > 0; n/=10) { |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 77 | int x = nNum/n; |
| 78 | if(x || bDidSomeOutput){ |
| 79 | bDidSomeOutput = true; |
| 80 | UsefulOutBuf_AppendByte(&OutBuf, '0' + x); |
| 81 | nNum -= x * n; |
| 82 | } |
| 83 | } |
| 84 | if(!bDidSomeOutput){ |
| 85 | UsefulOutBuf_AppendByte(&OutBuf, '0'); |
| 86 | } |
| 87 | UsefulOutBuf_AppendByte(&OutBuf, '\0'); |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 88 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 89 | return UsefulOutBuf_GetError(&OutBuf) ? "" : StringMem.ptr; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 94 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 95 | typedef int (test_fun_t)(void); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 96 | typedef const char * (test_fun2_t)(void); |
| 97 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 98 | |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 99 | #define TEST_ENTRY(test_name) {#test_name, test_name, true} |
| 100 | #define TEST_ENTRY_DISABLED(test_name) {#test_name, test_name, false} |
| 101 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 102 | typedef struct { |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 103 | const char *szTestName; |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 104 | test_fun_t *test_fun; |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 105 | bool bEnabled; |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 106 | } test_entry; |
| 107 | |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 108 | typedef struct { |
| 109 | const char *szTestName; |
| 110 | test_fun2_t *test_fun; |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 111 | bool bEnabled; |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 112 | } test_entry2; |
| 113 | |
| 114 | test_entry2 s_tests2[] = { |
Laurence Lundblade | 7566b9f | 2018-10-12 09:13:32 +0800 | [diff] [blame] | 115 | TEST_ENTRY(UBUTest_CopyUtil), |
| 116 | TEST_ENTRY(UOBTest_NonAdversarial), |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 117 | TEST_ENTRY(TestBasicSanity), |
Laurence Lundblade | 7566b9f | 2018-10-12 09:13:32 +0800 | [diff] [blame] | 118 | TEST_ENTRY(UOBTest_BoundaryConditionsTest), |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 119 | TEST_ENTRY(UBMacroConversionsTest), |
| 120 | TEST_ENTRY(UBUtilTests), |
Laurence Lundblade | 7566b9f | 2018-10-12 09:13:32 +0800 | [diff] [blame] | 121 | TEST_ENTRY(UIBTest_IntegerFormat) |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 125 | test_entry s_tests[] = { |
Laurence Lundblade | ccfb8cd | 2018-12-07 21:11:30 +0900 | [diff] [blame] | 126 | TEST_ENTRY(ParseMapAsArrayTest), |
Laurence Lundblade | a44d506 | 2018-10-17 18:45:12 +0530 | [diff] [blame] | 127 | TEST_ENTRY(AllocAllStringsTest), |
| 128 | TEST_ENTRY(IndefiniteLengthNestTest), |
| 129 | TEST_ENTRY(NestedMapTestIndefLen), |
| 130 | TEST_ENTRY(ParseSimpleTest), |
Laurence Lundblade | 0fb6c6d | 2018-10-12 22:02:05 +0800 | [diff] [blame] | 131 | TEST_ENTRY(EncodeRawTest), |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 132 | TEST_ENTRY(RTICResultsTest), |
| 133 | TEST_ENTRY(MapEncodeTest), |
| 134 | TEST_ENTRY(ArrayNestingTest1), |
| 135 | TEST_ENTRY(ArrayNestingTest2), |
| 136 | TEST_ENTRY(ArrayNestingTest3), |
| 137 | TEST_ENTRY(EncodeDateTest), |
| 138 | TEST_ENTRY(SimpleValuesTest1), |
| 139 | TEST_ENTRY(IntegerValuesTest1), |
| 140 | TEST_ENTRY(AllAddMethodsTest), |
Laurence Lundblade | 9e3651c | 2018-10-10 11:49:55 +0800 | [diff] [blame] | 141 | TEST_ENTRY(ParseTooDeepArrayTest), |
| 142 | TEST_ENTRY(ComprehensiveInputTest), |
| 143 | TEST_ENTRY(ParseMapTest), |
Laurence Lundblade | a44d506 | 2018-10-17 18:45:12 +0530 | [diff] [blame] | 144 | TEST_ENTRY(IndefiniteLengthArrayMapTest), |
Laurence Lundblade | 369b90a | 2018-10-22 02:04:37 +0530 | [diff] [blame] | 145 | TEST_ENTRY(BasicEncodeTest), |
Laurence Lundblade | 9e3651c | 2018-10-10 11:49:55 +0800 | [diff] [blame] | 146 | TEST_ENTRY(NestedMapTest), |
| 147 | TEST_ENTRY(BignumParseTest), |
| 148 | TEST_ENTRY(OptTagParseTest), |
| 149 | TEST_ENTRY(DateParseTest), |
Laurence Lundblade | 9e3651c | 2018-10-10 11:49:55 +0800 | [diff] [blame] | 150 | TEST_ENTRY(ShortBufferParseTest2), |
| 151 | TEST_ENTRY(ShortBufferParseTest), |
| 152 | TEST_ENTRY(ParseDeepArrayTest), |
| 153 | TEST_ENTRY(SimpleArrayTest), |
| 154 | TEST_ENTRY(IntegerValuesParseTest), |
Laurence Lundblade | a44d506 | 2018-10-17 18:45:12 +0530 | [diff] [blame] | 155 | TEST_ENTRY(MemPoolTest), |
| 156 | TEST_ENTRY(IndefiniteLengthStringTest), |
Laurence Lundblade | bb474be | 2018-10-22 11:53:21 +0530 | [diff] [blame] | 157 | TEST_ENTRY(HalfPrecisionDecodeBasicTests), |
Laurence Lundblade | bb474be | 2018-10-22 11:53:21 +0530 | [diff] [blame] | 158 | TEST_ENTRY(DoubleAsSmallestTest), |
| 159 | TEST_ENTRY(HalfPrecisionAgainstRFCCodeTest), |
Laurence Lundblade | 369b90a | 2018-10-22 02:04:37 +0530 | [diff] [blame] | 160 | TEST_ENTRY(BstrWrapTest), |
| 161 | TEST_ENTRY(BstrWrapErrorTest), |
| 162 | TEST_ENTRY(BstrWrapNestTest), |
| 163 | TEST_ENTRY(CoseSign1TBSTest), |
Laurence Lundblade | ea567ac | 2018-12-09 14:03:21 -0800 | [diff] [blame] | 164 | TEST_ENTRY(StringDecoderModeFailTest), |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 165 | TEST_ENTRY_DISABLED(BigComprehensiveInputTest), |
Laurence Lundblade | 1ef8b2d | 2018-12-14 23:13:34 -0800 | [diff] [blame] | 166 | TEST_ENTRY(EncodeErrorTests), |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 167 | //TEST_ENTRY(fail_test), |
| 168 | }; |
| 169 | |
| 170 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 171 | int RunTests(const char *szTestNames[], OutputStringCB pfOutput, void *poutCtx, int *pNumTestsRun) |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 172 | { |
| 173 | int nTestsFailed = 0; |
| 174 | int nTestsRun = 0; |
Laurence Lundblade | 4fe9f31 | 2018-10-22 10:22:39 +0530 | [diff] [blame] | 175 | UsefulBuf_MAKE_STACK_UB(StringStorage, 5); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 176 | |
| 177 | test_entry2 *t2; |
| 178 | const test_entry2 *s_tests2_end = s_tests2 + sizeof(s_tests2)/sizeof(test_entry2); |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 179 | |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 180 | for(t2 = s_tests2; t2 < s_tests2_end; t2++) { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 181 | if(szTestNames[0]) { |
| 182 | // Some tests have been named |
| 183 | const char **szRequestedNames; |
| 184 | for(szRequestedNames = szTestNames; *szRequestedNames; szRequestedNames++) { |
| 185 | if(!strcmp(t2->szTestName, *szRequestedNames)) { |
| 186 | break; // Name matched |
| 187 | } |
| 188 | } |
| 189 | if(*szRequestedNames == NULL) { |
| 190 | // Didn't match this test |
| 191 | continue; |
| 192 | } |
| 193 | } else { |
| 194 | // no tests named, but don't run "disabled" tests |
| 195 | if(!t2->bEnabled) { |
| 196 | // Don't run disabled tests when all tests are being run |
| 197 | // as indicated by no specific test names being given |
| 198 | continue; |
| 199 | } |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 200 | } |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 201 | |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 202 | const char * szTestResult = (t2->test_fun)(); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 203 | nTestsRun++; |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 204 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 205 | (*pfOutput)(t2->szTestName, poutCtx, 0); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 206 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 207 | |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 208 | if(szTestResult) { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 209 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 210 | (*pfOutput)(" FAILED (returned ", poutCtx, 0); |
| 211 | (*pfOutput)(szTestResult, poutCtx, 0); |
Laurence Lundblade | df1c1cf | 2019-01-17 11:55:05 -0800 | [diff] [blame] | 212 | (*pfOutput)(")", poutCtx, 1); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 213 | } |
| 214 | nTestsFailed++; |
| 215 | } else { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 216 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 217 | (*pfOutput)( " PASSED", poutCtx, 1); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 221 | |
| 222 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 223 | test_entry *t; |
| 224 | const test_entry *s_tests_end = s_tests + sizeof(s_tests)/sizeof(test_entry); |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 225 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 226 | for(t = s_tests; t < s_tests_end; t++) { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 227 | if(szTestNames[0]) { |
| 228 | // Some tests have been named |
| 229 | const char **szRequestedNames; |
| 230 | for(szRequestedNames = szTestNames; *szRequestedNames; szRequestedNames++) { |
| 231 | if(!strcmp(t->szTestName, *szRequestedNames)) { |
| 232 | break; // Name matched |
| 233 | } |
| 234 | } |
| 235 | if(*szRequestedNames == NULL) { |
| 236 | // Didn't match this test |
| 237 | continue; |
| 238 | } |
| 239 | } else { |
| 240 | // no tests named, but don't run "disabled" tests |
| 241 | if(!t->bEnabled) { |
| 242 | // Don't run disabled tests when all tests are being run |
| 243 | // as indicated by no specific test names being given |
| 244 | continue; |
| 245 | } |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 246 | } |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 247 | |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 248 | int nTestResult = (t->test_fun)(); |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 249 | nTestsRun++; |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 250 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 251 | (*pfOutput)(t->szTestName, poutCtx, 0); |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 252 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 253 | |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 254 | if(nTestResult) { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 255 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 256 | (*pfOutput)(" FAILED (returned ", poutCtx, 0); |
| 257 | (*pfOutput)(NumToString(nTestResult, StringStorage), poutCtx, 0); |
| 258 | (*pfOutput)(")", poutCtx, 1); |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 259 | } |
| 260 | nTestsFailed++; |
| 261 | } else { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 262 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 263 | (*pfOutput)( " PASSED", poutCtx, 1); |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 267 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 268 | if(pNumTestsRun) { |
| 269 | *pNumTestsRun = nTestsRun; |
| 270 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 271 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 272 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 273 | (*pfOutput)( "SUMMARY: ", poutCtx, 0); |
| 274 | (*pfOutput)( NumToString(nTestsRun, StringStorage), poutCtx, 0); |
| 275 | (*pfOutput)( " tests run; ", poutCtx, 0); |
| 276 | (*pfOutput)( NumToString(nTestsFailed, StringStorage), poutCtx, 0); |
| 277 | (*pfOutput)( " tests failed", poutCtx, 1); |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 278 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 279 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 280 | return nTestsFailed; |
| 281 | } |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | static void PrintSize(const char *szWhat, uint32_t uSize, OutputStringCB pfOutput, void *pOutCtx) |
| 287 | { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 288 | UsefulBuf_MAKE_STACK_UB(buffer, 20); |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 289 | |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 290 | (*pfOutput)(szWhat, pOutCtx, 0); |
| 291 | (*pfOutput)(" ", pOutCtx, 0); |
| 292 | (*pfOutput)(NumToString(uSize, buffer), pOutCtx, 0); |
| 293 | (*pfOutput)("", pOutCtx, 1); |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void PrintSizes(OutputStringCB pfOutput, void *pOutCtx) |
| 297 | { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 298 | // Type and size of return from sizeof() varies. These will never be large so cast is safe |
| 299 | PrintSize("sizeof(QCBORTrackNesting)", (uint32_t)sizeof(QCBORTrackNesting), pfOutput, pOutCtx); |
| 300 | PrintSize("sizeof(QCBOREncodeContext)", (uint32_t)sizeof(QCBOREncodeContext), pfOutput, pOutCtx); |
| 301 | PrintSize("sizeof(QCBORDecodeNesting)", (uint32_t)sizeof(QCBORDecodeNesting), pfOutput, pOutCtx); |
| 302 | PrintSize("sizeof(QCBORDecodeContext)", (uint32_t)sizeof(QCBORDecodeContext), pfOutput, pOutCtx); |
| 303 | PrintSize("sizeof(QCBORItem)", (uint32_t)sizeof(QCBORItem), pfOutput, pOutCtx); |
| 304 | PrintSize("sizeof(QCBORStringAllocator)",(uint32_t)sizeof(QCBORStringAllocator), pfOutput, pOutCtx); |
| 305 | PrintSize("sizeof(QCBORTagListIn)", (uint32_t)sizeof(QCBORTagListIn), pfOutput, pOutCtx); |
| 306 | PrintSize("sizeof(QCBORTagListOut)", (uint32_t)sizeof(QCBORTagListOut), pfOutput, pOutCtx); |
| 307 | (*pfOutput)("", pOutCtx, 1); |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 308 | } |