diff options
Diffstat (limited to 'lib/x1000-installer/test/main.c')
-rw-r--r-- | lib/x1000-installer/test/main.c | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/lib/x1000-installer/test/main.c b/lib/x1000-installer/test/main.c deleted file mode 100644 index f9bff1b704..0000000000 --- a/lib/x1000-installer/test/main.c +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021 Aidan MacDonald | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | |||
24 | static int test_num_executed = 0; | ||
25 | static int test_num_failed = 0; | ||
26 | int test_num_asserts_executed = 0; | ||
27 | int test_num_asserts_failed = 0; | ||
28 | |||
29 | void test_failure(const char* file, int line, const char* msg) | ||
30 | { | ||
31 | fprintf(stderr, "%s:%d: ASSERTION FAILED: %s\n", file, line, msg); | ||
32 | ++test_num_asserts_failed; | ||
33 | } | ||
34 | |||
35 | typedef void(*test_t)(void); | ||
36 | |||
37 | struct test_info { | ||
38 | const char* name; | ||
39 | test_t func; | ||
40 | }; | ||
41 | |||
42 | extern void test_stream_read_lines(void); | ||
43 | extern void test_stream_read_line_too_long(void); | ||
44 | extern void test_flashmap_parseline(void); | ||
45 | |||
46 | #define TEST(x) {#x, x} | ||
47 | static const struct test_info all_tests[] = { | ||
48 | TEST(test_stream_read_lines), | ||
49 | TEST(test_stream_read_line_too_long), | ||
50 | TEST(test_flashmap_parseline), | ||
51 | }; | ||
52 | #undef TEST | ||
53 | |||
54 | void run_test(const struct test_info* tinfo) | ||
55 | { | ||
56 | int asserts_now = test_num_asserts_failed; | ||
57 | ++test_num_executed; | ||
58 | |||
59 | fprintf(stderr, "RUN %s\n", tinfo->name); | ||
60 | tinfo->func(); | ||
61 | |||
62 | if(test_num_asserts_failed > asserts_now) { | ||
63 | fprintf(stderr, " %s: FAILED!\n", tinfo->name); | ||
64 | ++test_num_failed; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | int main(int argc, char* argv[]) | ||
69 | { | ||
70 | (void)argc; | ||
71 | (void)argv; | ||
72 | |||
73 | size_t num_tests = sizeof(all_tests) / sizeof(struct test_info); | ||
74 | for(size_t i = 0; i < num_tests; ++i) | ||
75 | run_test(&all_tests[i]); | ||
76 | |||
77 | fprintf(stderr, "------------------------------------------\n"); | ||
78 | fprintf(stderr, "TEST COMPLETE\n"); | ||
79 | fprintf(stderr, " Tests %d failed / %d executed\n", | ||
80 | test_num_failed, test_num_executed); | ||
81 | fprintf(stderr, " Assertions %d failed / %d executed\n", | ||
82 | test_num_asserts_failed, test_num_asserts_executed); | ||
83 | |||
84 | if(test_num_failed > 0) | ||
85 | return 1; | ||
86 | } | ||