c81121c3d5
Final residual translations found in code/comments/CI: - .doorstop.yml: config comments, traceability mapping comments - Doxyfile: header comment - tools/render_plantuml.py: docstring - tools/generate_test_report.py: docstring - tests/unit_test_framework.h: doxygen brief + body - tests/unit/test_safety_manager.c: section comment - src/stubs/*.h: doxygen briefs for diag/display/inclinometer/logger/service/wheel-speed - .gitea/workflows/release.yml: release notes 'Statische Analyse' + deploy error message
63 lines
2.4 KiB
C
63 lines
2.4 KiB
C
/**
|
|
* @file unit_test_framework.h
|
|
* @brief Minimal test runner for demo-epb.
|
|
*
|
|
* In production CppUTest or Google Test would go here
|
|
* (see docs/SWE-Plan.docx, section 7). For the demo, the framework
|
|
* stays small so it builds without external dependencies.
|
|
*/
|
|
#ifndef UNIT_TEST_FRAMEWORK_H
|
|
#define UNIT_TEST_FRAMEWORK_H
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
typedef struct {
|
|
int tests_run;
|
|
int tests_failed;
|
|
} TestStats;
|
|
|
|
extern TestStats g_test_stats;
|
|
|
|
#define TEST_BEGIN(name) \
|
|
do { \
|
|
++g_test_stats.tests_run; \
|
|
const char* _test_name = name; \
|
|
int _test_failed = 0; \
|
|
printf(" TEST %s ... ", _test_name);
|
|
|
|
#define TEST_END() \
|
|
if (_test_failed) { ++g_test_stats.tests_failed; \
|
|
printf("FAIL\n"); } \
|
|
else { printf("ok\n"); } \
|
|
} while (0)
|
|
|
|
#define ASSERT_TRUE(expr) \
|
|
do { if (!(expr)) { _test_failed = 1; \
|
|
printf("\n ASSERT_TRUE failed: %s (%s:%d)\n", \
|
|
#expr, __FILE__, __LINE__); } } while (0)
|
|
|
|
#define ASSERT_EQ(a, b) \
|
|
do { long long _a = (long long)(a), _b = (long long)(b); \
|
|
if (_a != _b) { _test_failed = 1; \
|
|
printf("\n ASSERT_EQ failed: %s=%lld != %s=%lld (%s:%d)\n", \
|
|
#a, _a, #b, _b, __FILE__, __LINE__); } \
|
|
} while (0)
|
|
|
|
#define ASSERT_NE(a, b) \
|
|
do { long long _a = (long long)(a), _b = (long long)(b); \
|
|
if (_a == _b) { _test_failed = 1; \
|
|
printf("\n ASSERT_NE failed: %s==%s==%lld (%s:%d)\n", \
|
|
#a, #b, _a, __FILE__, __LINE__); } \
|
|
} while (0)
|
|
|
|
#define TEST_SUMMARY() \
|
|
do { \
|
|
printf("\n%d tests run, %d failed.\n", \
|
|
g_test_stats.tests_run, g_test_stats.tests_failed); \
|
|
return (g_test_stats.tests_failed == 0) ? 0 : 1; \
|
|
} while (0)
|
|
|
|
#endif /* UNIT_TEST_FRAMEWORK_H */
|