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 | d92a616 | 2018-11-01 11:38:35 +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 | d92a616 | 2018-11-01 11:38:35 +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. |
| 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 | 570fab5 | 2018-10-13 18:28:27 +0800 | [diff] [blame] | 46 | int main(int argc, const char * argv[]) |
| 47 | { |
| 48 | (void)argc; // Suppress unused warning |
Laurence Lundblade | 742df4a | 2018-10-13 20:07:17 +0800 | [diff] [blame] | 49 | (void)argv; // Suppress unused warning |
Laurence Lundblade | fab1b52 | 2018-10-19 13:40:52 +0530 | [diff] [blame] | 50 | |
| 51 | // Type and size of return from sizeof() varies. These will never be large so cast is safe |
| 52 | // TODO: use fputs_wrapper to output these |
Laurence Lundblade | a44d506 | 2018-10-17 18:45:12 +0530 | [diff] [blame] | 53 | printf("sizeof(QCBOREncodeContext) %d\n", (uint32_t)sizeof(QCBOREncodeContext)); |
| 54 | printf("sizeof(QCBORDecodeContext) %d\n", (uint32_t)sizeof(QCBORDecodeContext)); |
Laurence Lundblade | fab1b52 | 2018-10-19 13:40:52 +0530 | [diff] [blame] | 55 | printf("sizeof(QCBORDecodeNesting) %d\n", (uint32_t)sizeof(QCBORDecodeNesting)); |
Laurence Lundblade | a44d506 | 2018-10-17 18:45:12 +0530 | [diff] [blame] | 56 | printf("sizeof(QCBORItem) %d\n", (uint32_t)sizeof(QCBORItem)); |
| 57 | printf("sizeof(QCBORStringAllocator) %d\n\n", (uint32_t)sizeof(QCBORStringAllocator)); |
| 58 | |
Laurence Lundblade | dbe6f21 | 2018-10-28 11:37:53 +0700 | [diff] [blame] | 59 | // TODO: command line arg to select test |
Laurence Lundblade | cc2ed34 | 2018-09-22 17:29:55 -0700 | [diff] [blame] | 60 | int nNumTestsFailed = run_tests(&fputs_wrapper, stdout, NULL); |
| 61 | |
| 62 | return nNumTestsFailed; |
Laurence Lundblade | 74f6841 | 2018-09-13 12:18:49 -0700 | [diff] [blame] | 63 | } |