blob: 927beee0ed5d14567d3bd2dcb0ded48575ebe740 [file] [log] [blame]
Laurence Lundbladed92a6162018-11-01 11:38:35 +07001/*==============================================================================
Laurence Lundblade624405d2018-09-18 20:10:47 -07002 cmd_line_mainc.c -- basic tests for qcbor encoder / decoder
Laurence Lundblade3aee3a32018-12-17 16:17:45 -08003
Laurence Lundbladed92a6162018-11-01 11:38:35 +07004 Copyright (c) 2018, Laurence Lundblade.
5 All rights reserved.
Laurence Lundblade3aee3a32018-12-17 16:17:45 -08006
Laurence Lundblade0dbc9172018-11-01 14:17:21 +07007Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions are
9met:
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 Lundblade3aee3a32018-12-17 16:17:45 -080020
Laurence Lundblade0dbc9172018-11-01 14:17:21 +070021THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
22WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
24ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
31IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Laurence Lundbladed92a6162018-11-01 11:38:35 +070032 ==============================================================================*/
Laurence Lundblade74f68412018-09-13 12:18:49 -070033// Created by Laurence Lundblade on 9/13/18.
Laurence Lundblade74f68412018-09-13 12:18:49 -070034
35#include <stdio.h>
Laurence Lundblade781fd822018-10-01 09:37:52 -070036#include "run_tests.h"
Laurence Lundbladed92a6162018-11-01 11:38:35 +070037#include "qcbor.h" // just to print sizes of the structures.
Laurence Lundblade74f68412018-09-13 12:18:49 -070038
Laurence Lundbladea954db92018-09-28 19:27:31 -070039
Laurence Lundbladecc2ed342018-09-22 17:29:55 -070040int fputs_wrapper(const char *szString, void *ctx)
41{
42 return fputs(szString, (FILE *)ctx);
43}
Laurence Lundblade2300b562018-09-29 20:00:09 -070044
Laurence Lundblade2300b562018-09-29 20:00:09 -070045
Laurence Lundblade8ca13692018-12-04 14:35:53 +090046static void PrintSize(const char *szWhat, uint32_t uSize)
47{
48 UsefulBuf_MAKE_STACK_UB(foo, 20);
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080049
Laurence Lundblade8ca13692018-12-04 14:35:53 +090050 fputs_wrapper(szWhat, stdout);
51 fputs_wrapper(" ", stdout);
52 fputs_wrapper(NumToString(uSize,foo), stdout);
53 fputs_wrapper("\n", stdout);
54}
55
56
Laurence Lundblade570fab52018-10-13 18:28:27 +080057int main(int argc, const char * argv[])
58{
Laurence Lundbladefab1b522018-10-19 13:40:52 +053059 // Type and size of return from sizeof() varies. These will never be large so cast is safe
Laurence Lundblade8ca13692018-12-04 14:35:53 +090060 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 Lundbladea44d5062018-10-17 18:45:12 +053068
Laurence Lundblade88b6ece2018-12-04 12:27:19 +090069 int nNumTestsFailed = 0;
Laurence Lundblade3aee3a32018-12-17 16:17:45 -080070
Laurence Lundblade88b6ece2018-12-04 12:27:19 +090071 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 Lundbladecc2ed342018-09-22 17:29:55 -070076
77 return nNumTestsFailed;
Laurence Lundblade74f68412018-09-13 12:18:49 -070078}