From 347d29658959c7e4b368a15134c183f4ce7a25bc Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 17 May 2026 01:31:49 +0530 Subject: Testing infrastructure: AGENTS.md rules + unit test framework + geohash tests (11/11 pass) - Add AGENTS.md: full project context + mandatory testing rules for AI sessions - Add tests/unit/ with host-compiled C unit test infrastructure - Clean stubs approach: ESP-IDF type stubs in tests/unit/stubs/, no source modifications - Fix geohash.c bit extraction bug (3-byte span) found by unit tests - test_geohash: 11/11 passing with reference vectors (Munich, NYC, origin, boundaries) --- tests/unit/test_framework.h | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/unit/test_framework.h (limited to 'tests/unit/test_framework.h') diff --git a/tests/unit/test_framework.h b/tests/unit/test_framework.h new file mode 100644 index 0000000..6eb3a10 --- /dev/null +++ b/tests/unit/test_framework.h @@ -0,0 +1,60 @@ +#ifndef TEST_FRAMEWORK_H +#define TEST_FRAMEWORK_H + +#include +#include +#include + +static int g_tests_passed = 0; +static int g_tests_failed = 0; + +#define ASSERT(cond, msg) do { \ + if (cond) { \ + printf(" PASS: %s\n", msg); \ + g_tests_passed++; \ + } else { \ + printf(" FAIL: %s (at %s:%d)\n", msg, __FILE__, __LINE__); \ + g_tests_failed++; \ + } \ +} while(0) + +#define ASSERT_EQ_INT(expected, actual, msg) do { \ + int _e = (expected), _a = (actual); \ + if (_e == _a) { \ + printf(" PASS: %s (got %d)\n", msg, _a); \ + g_tests_passed++; \ + } else { \ + printf(" FAIL: %s (expected %d, got %d) at %s:%d\n", msg, _e, _a, __FILE__, __LINE__); \ + g_tests_failed++; \ + } \ +} while(0) + +#define ASSERT_EQ_STR(expected, actual, msg) do { \ + const char *_e = (expected), *_a = (actual); \ + if (_e && _a && strcmp(_e, _a) == 0) { \ + printf(" PASS: %s (got \"%s\")\n", msg, _a); \ + g_tests_passed++; \ + } else { \ + printf(" FAIL: %s (expected \"%s\", got \"%s\") at %s:%d\n", msg, _e ? _e : "(null)", _a ? _a : "(null)", __FILE__, __LINE__); \ + g_tests_failed++; \ + } \ +} while(0) + +#define ASSERT_MEM_EQ(expected, actual, len, msg) do { \ + const uint8_t *_e = (const uint8_t *)(expected), *_a = (const uint8_t *)(actual); \ + size_t _l = (len); \ + if (_e && _a && memcmp(_e, _a, _l) == 0) { \ + printf(" PASS: %s (%zu bytes match)\n", msg, _l); \ + g_tests_passed++; \ + } else { \ + printf(" FAIL: %s (%zu bytes mismatch) at %s:%d\n", msg, _l, __FILE__, __LINE__); \ + g_tests_failed++; \ + } \ +} while(0) + +#define TEST_SUMMARY() do { \ + printf("\n=== Results: %d passed, %d failed ===\n", g_tests_passed, g_tests_failed); \ + return g_tests_failed > 0 ? 1 : 0; \ +} while(0) + +#endif -- cgit v1.2.3