/* Include the main header first, to test it works */ #include /* Include the C files directly. */ #include #include #include #ifndef ARRAY_SIZE #define ARRAY_SIZE(array) (sizeof(array) / sizeof(*(array))) #endif struct foo { const char *string; int number; }; struct foo foo_structs[] = { {"apple", 1}, {"banana", 2}, {"banana", 4}, {"cherry", 4}, {"doughnut", 5}, }; struct foo *foo_base[ARRAY_SIZE(foo_structs)]; const unsigned int foo_count = ARRAY_SIZE(foo_structs); static void init_foo_pointers(void) { unsigned int i; for (i = 0; i < foo_count; i++) foo_base[i] = &foo_structs[i]; } /* Make sure forward declarations work */ btree_search_proto order_by_string, order_by_number; static void test_order_by_string(void) { struct { const char *key; int lr; unsigned int expect_offset; int expect_found; } test[] = { {"anchovies", 0, 0, 0}, {"anchovies", 1, 0, 0}, {"apple", 0, 0, 1}, {"apple", 1, 1, 1}, {"banana", 0, 1, 1}, {"banana", 1, 3, 1}, {"blueberry", 0, 3, 0}, {"blueberry", 1, 3, 0}, {"doughnut", 0, 4, 1}, {"doughnut", 1, 5, 1}, }; size_t i; for (i=0; istring, b->string), c == 0, c < 0 ) btree_search_implement ( order_by_number, const struct foo *, , a->number == b->number, a->number < b->number )