/* Simple unit test framework for asfur */ #ifndef TEST_H #define TEST_H #include #include #include static int tests_run = 0; static int tests_passed = 0; static int tests_failed = 0; #define TEST_ASSERT(cond, msg) do { \ if (!(cond)) { \ printf(" FAIL: %s\n", msg); \ return 1; \ } \ } while(0) #define TEST_ASSERT_EQ(a, b, msg) do { \ if ((a) != (b)) { \ printf(" FAIL: %s (expected %d, got %d)\n", msg, (int)(b), (int)(a)); \ return 1; \ } \ } while(0) #define TEST_ASSERT_STR_EQ(a, b, msg) do { \ if (strcmp((a), (b)) != 0) { \ printf(" FAIL: %s (expected '%s', got '%s')\n", msg, (b), (a)); \ return 1; \ } \ } while(0) #define RUN_TEST(test_fn) do { \ tests_run++; \ printf("Running %s...\n", #test_fn); \ if (test_fn() == 0) { \ printf(" PASS\n"); \ tests_passed++; \ } else { \ tests_failed++; \ } \ } while(0) #define TEST_SUMMARY() do { \ printf("\n=== Test Summary ===\n"); \ printf("Total: %d\n", tests_run); \ printf("Passed: %d\n", tests_passed); \ printf("Failed: %d\n", tests_failed); \ return tests_failed > 0 ? 1 : 0; \ } while(0) #endif