Laurence Lundblade | d92a616 | 2018-11-01 11:38:35 +0700 | [diff] [blame] | 1 | /*============================================================================== |
Laurence Lundblade | 624405d | 2018-09-18 20:10:47 -0700 | [diff] [blame] | 2 | cmd_line_mainc.c -- basic tests for qcbor encoder / decoder |
| 3 | |
Laurence Lundblade | d92a616 | 2018-11-01 11:38:35 +0700 | [diff] [blame] | 4 | Copyright (c) 2018, Laurence Lundblade. |
| 5 | All rights reserved. |
Laurence Lundblade | 624405d | 2018-09-18 20:10:47 -0700 | [diff] [blame] | 6 | |
Laurence Lundblade | 0dbc917 | 2018-11-01 14:17:21 +0700 | [diff] [blame] | 7 | Redistribution and use in source and binary forms, with or without |
| 8 | modification, are permitted provided that the following conditions are |
| 9 | met: |
| 10 | * Redistributions of source code must retain the above copyright |
| 11 | notice, this list of conditions and the following disclaimer. |
| 12 | * Redistributions in binary form must reproduce the above |
| 13 | copyright notice, this list of conditions and the following |
| 14 | disclaimer in the documentation and/or other materials provided |
| 15 | with the distribution. |
| 16 | * Neither the name of The Linux Foundation nor the names of its |
| 17 | contributors, nor the name "Laurence Lundblade" may be used to |
| 18 | endorse or promote products derived from this software without |
| 19 | specific prior written permission. |
Laurence Lundblade | 624405d | 2018-09-18 20:10:47 -0700 | [diff] [blame] | 20 | |
Laurence Lundblade | 0dbc917 | 2018-11-01 14:17:21 +0700 | [diff] [blame] | 21 | THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 22 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 25 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 28 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 29 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 30 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 31 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Laurence Lundblade | d92a616 | 2018-11-01 11:38:35 +0700 | [diff] [blame] | 32 | ==============================================================================*/ |
Laurence Lundblade | 74f6841 | 2018-09-13 12:18:49 -0700 | [diff] [blame] | 33 | // Created by Laurence Lundblade on 9/13/18. |
Laurence Lundblade | 74f6841 | 2018-09-13 12:18:49 -0700 | [diff] [blame] | 34 | |
| 35 | #include <stdio.h> |
Laurence Lundblade | 781fd82 | 2018-10-01 09:37:52 -0700 | [diff] [blame] | 36 | #include "run_tests.h" |
Laurence Lundblade | d92a616 | 2018-11-01 11:38:35 +0700 | [diff] [blame] | 37 | #include "qcbor.h" // just to print sizes of the structures. |
Laurence Lundblade | 74f6841 | 2018-09-13 12:18:49 -0700 | [diff] [blame] | 38 | |
Laurence Lundblade | a954db9 | 2018-09-28 19:27:31 -0700 | [diff] [blame] | 39 | |
Laurence Lundblade | cc2ed34 | 2018-09-22 17:29:55 -0700 | [diff] [blame] | 40 | int fputs_wrapper(const char *szString, void *ctx) |
| 41 | { |
| 42 | return fputs(szString, (FILE *)ctx); |
| 43 | } |
Laurence Lundblade | 2300b56 | 2018-09-29 20:00:09 -0700 | [diff] [blame] | 44 | |
Laurence Lundblade | 2300b56 | 2018-09-29 20:00:09 -0700 | [diff] [blame] | 45 | |
Laurence Lundblade | 8ca1369 | 2018-12-04 14:35:53 +0900 | [diff] [blame^] | 46 | static void PrintSize(const char *szWhat, uint32_t uSize) |
| 47 | { |
| 48 | UsefulBuf_MAKE_STACK_UB(foo, 20); |
| 49 | |
| 50 | fputs_wrapper(szWhat, stdout); |
| 51 | fputs_wrapper(" ", stdout); |
| 52 | fputs_wrapper(NumToString(uSize,foo), stdout); |
| 53 | fputs_wrapper("\n", stdout); |
| 54 | } |
| 55 | |
| 56 | |
Laurence Lundblade | 570fab5 | 2018-10-13 18:28:27 +0800 | [diff] [blame] | 57 | int main(int argc, const char * argv[]) |
| 58 | { |
Laurence Lundblade | fab1b52 | 2018-10-19 13:40:52 +0530 | [diff] [blame] | 59 | // Type and size of return from sizeof() varies. These will never be large so cast is safe |
Laurence Lundblade | 8ca1369 | 2018-12-04 14:35:53 +0900 | [diff] [blame^] | 60 | PrintSize("sizeof(QCBORTrackNesting)", (uint32_t)sizeof(QCBORTrackNesting)); |
| 61 | PrintSize("sizeof(QCBORTrackNesting)", (uint32_t)sizeof(QCBORTrackNesting)); |
| 62 | PrintSize("sizeof(QCBOREncodeContext)", (uint32_t)sizeof(QCBOREncodeContext)); |
| 63 | PrintSize("sizeof(QCBORDecodeContext)", (uint32_t)sizeof(QCBORDecodeContext)); |
| 64 | PrintSize("sizeof(QCBORDecodeNesting)", (uint32_t)sizeof(QCBORDecodeNesting)); |
| 65 | PrintSize("sizeof(QCBORItem)", (uint32_t)sizeof(QCBORItem)); |
| 66 | PrintSize("sizeof(QCBORStringAllocator)", (uint32_t)sizeof(QCBORStringAllocator)); |
| 67 | fputs_wrapper("\n", stdout); |
Laurence Lundblade | a44d506 | 2018-10-17 18:45:12 +0530 | [diff] [blame] | 68 | |
Laurence Lundblade | 88b6ece | 2018-12-04 12:27:19 +0900 | [diff] [blame] | 69 | int nNumTestsFailed = 0; |
| 70 | |
| 71 | if(argc > 1) { |
| 72 | nNumTestsFailed += run_tests(argv[1], &fputs_wrapper, stdout, NULL); |
| 73 | } else { |
| 74 | nNumTestsFailed += run_tests(NULL, &fputs_wrapper, stdout, NULL); |
| 75 | } |
Laurence Lundblade | cc2ed34 | 2018-09-22 17:29:55 -0700 | [diff] [blame] | 76 | |
| 77 | return nNumTestsFailed; |
Laurence Lundblade | 74f6841 | 2018-09-13 12:18:49 -0700 | [diff] [blame] | 78 | } |