Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 1 | /*============================================================================== |
| 2 | run_tests.c -- test aggregator and results reporting |
Laurence Lundblade | a3fd49f | 2019-01-21 10:16:22 -0800 | [diff] [blame^] | 3 | |
| 4 | Copyright (c) 2018-2019, Laurence Lundblade. All rights reserved. |
| 5 | |
| 6 | SPDX-License-Identifier: BSD-3-Clause |
| 7 | |
| 8 | See BSD-3-Clause license in README.md |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 9 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 10 | Created on 9/30/18 |
Laurence Lundblade | 88b6ece | 2018-12-04 12:27:19 +0900 | [diff] [blame] | 11 | ==============================================================================*/ |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 12 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 13 | #include "run_tests.h" |
| 14 | #include "UsefulBuf.h" |
| 15 | #include <stdbool.h> |
| 16 | |
Laurence Lundblade | 2d85ce4 | 2018-10-12 14:12:47 +0800 | [diff] [blame] | 17 | #include "float_tests.h" |
Laurence Lundblade | 9e3651c | 2018-10-10 11:49:55 +0800 | [diff] [blame] | 18 | #include "qcbor_decode_tests.h" |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 19 | #include "qcbor_encode_tests.h" |
| 20 | #include "UsefulBuf_Tests.h" |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 21 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 22 | |
| 23 | |
| 24 | // Used to test RunTests |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 25 | int fail_test() |
| 26 | { |
| 27 | return -44; |
| 28 | } |
| 29 | |
| 30 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 31 | |
| 32 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 33 | /* |
| 34 | Convert a number up to 999999999 to a string. This is so sprintf doesn't |
| 35 | 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] | 36 | */ |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 37 | const char *NumToString(int32_t nNum, UsefulBuf StringMem) |
| 38 | { |
Laurence Lundblade | 570fab5 | 2018-10-13 18:28:27 +0800 | [diff] [blame] | 39 | const int32_t nMax = 1000000000; |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 40 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 41 | UsefulOutBuf OutBuf; |
| 42 | UsefulOutBuf_Init(&OutBuf, StringMem); |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 43 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 44 | if(nNum < 0) { |
| 45 | UsefulOutBuf_AppendByte(&OutBuf, '-'); |
| 46 | nNum = -nNum; |
| 47 | } |
Laurence Lundblade | 570fab5 | 2018-10-13 18:28:27 +0800 | [diff] [blame] | 48 | if(nNum > nMax-1) { |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 49 | return "XXX"; |
| 50 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 51 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 52 | bool bDidSomeOutput = false; |
Laurence Lundblade | 570fab5 | 2018-10-13 18:28:27 +0800 | [diff] [blame] | 53 | for(int n = nMax; n > 0; n/=10) { |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 54 | int x = nNum/n; |
| 55 | if(x || bDidSomeOutput){ |
| 56 | bDidSomeOutput = true; |
| 57 | UsefulOutBuf_AppendByte(&OutBuf, '0' + x); |
| 58 | nNum -= x * n; |
| 59 | } |
| 60 | } |
| 61 | if(!bDidSomeOutput){ |
| 62 | UsefulOutBuf_AppendByte(&OutBuf, '0'); |
| 63 | } |
| 64 | UsefulOutBuf_AppendByte(&OutBuf, '\0'); |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 65 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 66 | return UsefulOutBuf_GetError(&OutBuf) ? "" : StringMem.ptr; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 71 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 72 | typedef int (test_fun_t)(void); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 73 | typedef const char * (test_fun2_t)(void); |
| 74 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 75 | |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 76 | #define TEST_ENTRY(test_name) {#test_name, test_name, true} |
| 77 | #define TEST_ENTRY_DISABLED(test_name) {#test_name, test_name, false} |
| 78 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 79 | typedef struct { |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 80 | const char *szTestName; |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 81 | test_fun_t *test_fun; |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 82 | bool bEnabled; |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 83 | } test_entry; |
| 84 | |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 85 | typedef struct { |
| 86 | const char *szTestName; |
| 87 | test_fun2_t *test_fun; |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 88 | bool bEnabled; |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 89 | } test_entry2; |
| 90 | |
| 91 | test_entry2 s_tests2[] = { |
Laurence Lundblade | 7566b9f | 2018-10-12 09:13:32 +0800 | [diff] [blame] | 92 | TEST_ENTRY(UBUTest_CopyUtil), |
| 93 | TEST_ENTRY(UOBTest_NonAdversarial), |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 94 | TEST_ENTRY(TestBasicSanity), |
Laurence Lundblade | 7566b9f | 2018-10-12 09:13:32 +0800 | [diff] [blame] | 95 | TEST_ENTRY(UOBTest_BoundaryConditionsTest), |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 96 | TEST_ENTRY(UBMacroConversionsTest), |
| 97 | TEST_ENTRY(UBUtilTests), |
Laurence Lundblade | 7566b9f | 2018-10-12 09:13:32 +0800 | [diff] [blame] | 98 | TEST_ENTRY(UIBTest_IntegerFormat) |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 102 | test_entry s_tests[] = { |
Laurence Lundblade | ccfb8cd | 2018-12-07 21:11:30 +0900 | [diff] [blame] | 103 | TEST_ENTRY(ParseMapAsArrayTest), |
Laurence Lundblade | a44d506 | 2018-10-17 18:45:12 +0530 | [diff] [blame] | 104 | TEST_ENTRY(AllocAllStringsTest), |
| 105 | TEST_ENTRY(IndefiniteLengthNestTest), |
| 106 | TEST_ENTRY(NestedMapTestIndefLen), |
| 107 | TEST_ENTRY(ParseSimpleTest), |
Laurence Lundblade | 0fb6c6d | 2018-10-12 22:02:05 +0800 | [diff] [blame] | 108 | TEST_ENTRY(EncodeRawTest), |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 109 | TEST_ENTRY(RTICResultsTest), |
| 110 | TEST_ENTRY(MapEncodeTest), |
| 111 | TEST_ENTRY(ArrayNestingTest1), |
| 112 | TEST_ENTRY(ArrayNestingTest2), |
| 113 | TEST_ENTRY(ArrayNestingTest3), |
| 114 | TEST_ENTRY(EncodeDateTest), |
| 115 | TEST_ENTRY(SimpleValuesTest1), |
| 116 | TEST_ENTRY(IntegerValuesTest1), |
| 117 | TEST_ENTRY(AllAddMethodsTest), |
Laurence Lundblade | 9e3651c | 2018-10-10 11:49:55 +0800 | [diff] [blame] | 118 | TEST_ENTRY(ParseTooDeepArrayTest), |
| 119 | TEST_ENTRY(ComprehensiveInputTest), |
| 120 | TEST_ENTRY(ParseMapTest), |
Laurence Lundblade | a44d506 | 2018-10-17 18:45:12 +0530 | [diff] [blame] | 121 | TEST_ENTRY(IndefiniteLengthArrayMapTest), |
Laurence Lundblade | 369b90a | 2018-10-22 02:04:37 +0530 | [diff] [blame] | 122 | TEST_ENTRY(BasicEncodeTest), |
Laurence Lundblade | 9e3651c | 2018-10-10 11:49:55 +0800 | [diff] [blame] | 123 | TEST_ENTRY(NestedMapTest), |
| 124 | TEST_ENTRY(BignumParseTest), |
| 125 | TEST_ENTRY(OptTagParseTest), |
| 126 | TEST_ENTRY(DateParseTest), |
Laurence Lundblade | 9e3651c | 2018-10-10 11:49:55 +0800 | [diff] [blame] | 127 | TEST_ENTRY(ShortBufferParseTest2), |
| 128 | TEST_ENTRY(ShortBufferParseTest), |
| 129 | TEST_ENTRY(ParseDeepArrayTest), |
| 130 | TEST_ENTRY(SimpleArrayTest), |
| 131 | TEST_ENTRY(IntegerValuesParseTest), |
Laurence Lundblade | a44d506 | 2018-10-17 18:45:12 +0530 | [diff] [blame] | 132 | TEST_ENTRY(MemPoolTest), |
| 133 | TEST_ENTRY(IndefiniteLengthStringTest), |
Laurence Lundblade | bb474be | 2018-10-22 11:53:21 +0530 | [diff] [blame] | 134 | TEST_ENTRY(HalfPrecisionDecodeBasicTests), |
Laurence Lundblade | bb474be | 2018-10-22 11:53:21 +0530 | [diff] [blame] | 135 | TEST_ENTRY(DoubleAsSmallestTest), |
| 136 | TEST_ENTRY(HalfPrecisionAgainstRFCCodeTest), |
Laurence Lundblade | 369b90a | 2018-10-22 02:04:37 +0530 | [diff] [blame] | 137 | TEST_ENTRY(BstrWrapTest), |
| 138 | TEST_ENTRY(BstrWrapErrorTest), |
| 139 | TEST_ENTRY(BstrWrapNestTest), |
| 140 | TEST_ENTRY(CoseSign1TBSTest), |
Laurence Lundblade | ea567ac | 2018-12-09 14:03:21 -0800 | [diff] [blame] | 141 | TEST_ENTRY(StringDecoderModeFailTest), |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 142 | TEST_ENTRY_DISABLED(BigComprehensiveInputTest), |
Laurence Lundblade | 1ef8b2d | 2018-12-14 23:13:34 -0800 | [diff] [blame] | 143 | TEST_ENTRY(EncodeErrorTests), |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 144 | //TEST_ENTRY(fail_test), |
| 145 | }; |
| 146 | |
| 147 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 148 | int RunTests(const char *szTestNames[], OutputStringCB pfOutput, void *poutCtx, int *pNumTestsRun) |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 149 | { |
| 150 | int nTestsFailed = 0; |
| 151 | int nTestsRun = 0; |
Laurence Lundblade | 4fe9f31 | 2018-10-22 10:22:39 +0530 | [diff] [blame] | 152 | UsefulBuf_MAKE_STACK_UB(StringStorage, 5); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 153 | |
| 154 | test_entry2 *t2; |
| 155 | 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] | 156 | |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 157 | for(t2 = s_tests2; t2 < s_tests2_end; t2++) { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 158 | if(szTestNames[0]) { |
| 159 | // Some tests have been named |
| 160 | const char **szRequestedNames; |
| 161 | for(szRequestedNames = szTestNames; *szRequestedNames; szRequestedNames++) { |
| 162 | if(!strcmp(t2->szTestName, *szRequestedNames)) { |
| 163 | break; // Name matched |
| 164 | } |
| 165 | } |
| 166 | if(*szRequestedNames == NULL) { |
| 167 | // Didn't match this test |
| 168 | continue; |
| 169 | } |
| 170 | } else { |
| 171 | // no tests named, but don't run "disabled" tests |
| 172 | if(!t2->bEnabled) { |
| 173 | // Don't run disabled tests when all tests are being run |
| 174 | // as indicated by no specific test names being given |
| 175 | continue; |
| 176 | } |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 177 | } |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 178 | |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 179 | const char * szTestResult = (t2->test_fun)(); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 180 | nTestsRun++; |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 181 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 182 | (*pfOutput)(t2->szTestName, poutCtx, 0); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 183 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 184 | |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 185 | if(szTestResult) { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 186 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 187 | (*pfOutput)(" FAILED (returned ", poutCtx, 0); |
| 188 | (*pfOutput)(szTestResult, poutCtx, 0); |
Laurence Lundblade | df1c1cf | 2019-01-17 11:55:05 -0800 | [diff] [blame] | 189 | (*pfOutput)(")", poutCtx, 1); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 190 | } |
| 191 | nTestsFailed++; |
| 192 | } else { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 193 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 194 | (*pfOutput)( " PASSED", poutCtx, 1); |
Laurence Lundblade | dc6e28e | 2018-10-11 19:19:27 +0530 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 198 | |
| 199 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 200 | test_entry *t; |
| 201 | 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] | 202 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 203 | for(t = s_tests; t < s_tests_end; t++) { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 204 | if(szTestNames[0]) { |
| 205 | // Some tests have been named |
| 206 | const char **szRequestedNames; |
| 207 | for(szRequestedNames = szTestNames; *szRequestedNames; szRequestedNames++) { |
| 208 | if(!strcmp(t->szTestName, *szRequestedNames)) { |
| 209 | break; // Name matched |
| 210 | } |
| 211 | } |
| 212 | if(*szRequestedNames == NULL) { |
| 213 | // Didn't match this test |
| 214 | continue; |
| 215 | } |
| 216 | } else { |
| 217 | // no tests named, but don't run "disabled" tests |
| 218 | if(!t->bEnabled) { |
| 219 | // Don't run disabled tests when all tests are being run |
| 220 | // as indicated by no specific test names being given |
| 221 | continue; |
| 222 | } |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 223 | } |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 224 | |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 225 | int nTestResult = (t->test_fun)(); |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 226 | nTestsRun++; |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 227 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 228 | (*pfOutput)(t->szTestName, poutCtx, 0); |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 229 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 230 | |
Laurence Lundblade | a2e2907 | 2018-12-30 09:20:06 -0800 | [diff] [blame] | 231 | if(nTestResult) { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 232 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 233 | (*pfOutput)(" FAILED (returned ", poutCtx, 0); |
| 234 | (*pfOutput)(NumToString(nTestResult, StringStorage), poutCtx, 0); |
| 235 | (*pfOutput)(")", poutCtx, 1); |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 236 | } |
| 237 | nTestsFailed++; |
| 238 | } else { |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 239 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 240 | (*pfOutput)( " PASSED", poutCtx, 1); |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 244 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 245 | if(pNumTestsRun) { |
| 246 | *pNumTestsRun = nTestsRun; |
| 247 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 248 | |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 249 | if(pfOutput) { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 250 | (*pfOutput)( "SUMMARY: ", poutCtx, 0); |
| 251 | (*pfOutput)( NumToString(nTestsRun, StringStorage), poutCtx, 0); |
| 252 | (*pfOutput)( " tests run; ", poutCtx, 0); |
| 253 | (*pfOutput)( NumToString(nTestsFailed, StringStorage), poutCtx, 0); |
| 254 | (*pfOutput)( " tests failed", poutCtx, 1); |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 255 | } |
Laurence Lundblade | 3aee3a3 | 2018-12-17 16:17:45 -0800 | [diff] [blame] | 256 | |
Laurence Lundblade | f156fb8 | 2018-10-01 09:47:03 -0700 | [diff] [blame] | 257 | return nTestsFailed; |
| 258 | } |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | static void PrintSize(const char *szWhat, uint32_t uSize, OutputStringCB pfOutput, void *pOutCtx) |
| 264 | { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 265 | UsefulBuf_MAKE_STACK_UB(buffer, 20); |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 266 | |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 267 | (*pfOutput)(szWhat, pOutCtx, 0); |
| 268 | (*pfOutput)(" ", pOutCtx, 0); |
| 269 | (*pfOutput)(NumToString(uSize, buffer), pOutCtx, 0); |
| 270 | (*pfOutput)("", pOutCtx, 1); |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | void PrintSizes(OutputStringCB pfOutput, void *pOutCtx) |
| 274 | { |
Laurence Lundblade | d396f62 | 2019-01-12 17:12:29 -0800 | [diff] [blame] | 275 | // Type and size of return from sizeof() varies. These will never be large so cast is safe |
| 276 | PrintSize("sizeof(QCBORTrackNesting)", (uint32_t)sizeof(QCBORTrackNesting), pfOutput, pOutCtx); |
| 277 | PrintSize("sizeof(QCBOREncodeContext)", (uint32_t)sizeof(QCBOREncodeContext), pfOutput, pOutCtx); |
| 278 | PrintSize("sizeof(QCBORDecodeNesting)", (uint32_t)sizeof(QCBORDecodeNesting), pfOutput, pOutCtx); |
| 279 | PrintSize("sizeof(QCBORDecodeContext)", (uint32_t)sizeof(QCBORDecodeContext), pfOutput, pOutCtx); |
| 280 | PrintSize("sizeof(QCBORItem)", (uint32_t)sizeof(QCBORItem), pfOutput, pOutCtx); |
| 281 | PrintSize("sizeof(QCBORStringAllocator)",(uint32_t)sizeof(QCBORStringAllocator), pfOutput, pOutCtx); |
| 282 | PrintSize("sizeof(QCBORTagListIn)", (uint32_t)sizeof(QCBORTagListIn), pfOutput, pOutCtx); |
| 283 | PrintSize("sizeof(QCBORTagListOut)", (uint32_t)sizeof(QCBORTagListOut), pfOutput, pOutCtx); |
| 284 | (*pfOutput)("", pOutCtx, 1); |
Laurence Lundblade | 1f8b5b0 | 2019-01-01 22:27:38 -0800 | [diff] [blame] | 285 | } |