|
| 1 | +/* test_framework.c |
| 2 | + * |
| 3 | + * Copyright (C) 2006-2026 wolfSSL Inc. |
| 4 | + * |
| 5 | + * This file is part of wolfMQTT. |
| 6 | + * |
| 7 | + * wolfMQTT is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * wolfMQTT is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 20 | + */ |
| 21 | + |
| 22 | +/* Pass-path smoke tests for every assertion macro defined by unit_test.h. |
| 23 | + * The fail paths call return after setting ut_current_test_failed, so they |
| 24 | + * cannot be exercised without the framework reporting the test as failed. |
| 25 | + * These tests ensure each macro at least compiles and evaluates its |
| 26 | + * non-failing branch correctly. */ |
| 27 | + |
| 28 | +#ifdef HAVE_CONFIG_H |
| 29 | + #include <config.h> |
| 30 | +#endif |
| 31 | + |
| 32 | +#include "tests/unit_test.h" |
| 33 | + |
| 34 | +void run_framework_tests(void); |
| 35 | + |
| 36 | +TEST(assert_true_pass) |
| 37 | +{ |
| 38 | + ASSERT_TRUE(1); |
| 39 | + ASSERT_TRUE(1 == 1); |
| 40 | +} |
| 41 | + |
| 42 | +TEST(assert_false_pass) |
| 43 | +{ |
| 44 | + ASSERT_FALSE(0); |
| 45 | + ASSERT_FALSE(1 == 2); |
| 46 | +} |
| 47 | + |
| 48 | +TEST(assert_eq_pass) |
| 49 | +{ |
| 50 | + ASSERT_EQ(0, 0); |
| 51 | + ASSERT_EQ(42, 42); |
| 52 | +} |
| 53 | + |
| 54 | +TEST(assert_ne_pass) |
| 55 | +{ |
| 56 | + ASSERT_NE(0, 1); |
| 57 | + ASSERT_NE(42, -1); |
| 58 | +} |
| 59 | + |
| 60 | +TEST(assert_null_pass) |
| 61 | +{ |
| 62 | + void* p = NULL; |
| 63 | + ASSERT_NULL(p); |
| 64 | +} |
| 65 | + |
| 66 | +TEST(assert_not_null_pass) |
| 67 | +{ |
| 68 | + int x; |
| 69 | + ASSERT_NOT_NULL(&x); |
| 70 | +} |
| 71 | + |
| 72 | +TEST(assert_str_eq_pass) |
| 73 | +{ |
| 74 | + ASSERT_STR_EQ("hello", "hello"); |
| 75 | +} |
| 76 | + |
| 77 | +TEST(assert_mem_eq_pass) |
| 78 | +{ |
| 79 | + const unsigned char a[] = {0x01, 0x02, 0x03, 0x04}; |
| 80 | + const unsigned char b[] = {0x01, 0x02, 0x03, 0x04}; |
| 81 | + ASSERT_MEM_EQ(a, b, sizeof(a)); |
| 82 | +} |
| 83 | + |
| 84 | +/* FAIL has no pass path; guard with a never-true condition so the macro |
| 85 | + * body is compiled but never executed. */ |
| 86 | +TEST(fail_compiles) |
| 87 | +{ |
| 88 | + if (0) { |
| 89 | + FAIL("unreachable"); |
| 90 | + } |
| 91 | + ASSERT_TRUE(1); |
| 92 | +} |
| 93 | + |
| 94 | +void run_framework_tests(void) |
| 95 | +{ |
| 96 | + TEST_SUITE_BEGIN("framework", NULL, NULL); |
| 97 | + |
| 98 | + RUN_TEST(assert_true_pass); |
| 99 | + RUN_TEST(assert_false_pass); |
| 100 | + RUN_TEST(assert_eq_pass); |
| 101 | + RUN_TEST(assert_ne_pass); |
| 102 | + RUN_TEST(assert_null_pass); |
| 103 | + RUN_TEST(assert_not_null_pass); |
| 104 | + RUN_TEST(assert_str_eq_pass); |
| 105 | + RUN_TEST(assert_mem_eq_pass); |
| 106 | + RUN_TEST(fail_compiles); |
| 107 | + |
| 108 | + TEST_SUITE_END(); |
| 109 | +} |
0 commit comments