#include #include #include #ifdef __cplusplus extern "C" { #endif typedef int (*apr_fnmatch_test_t)(const char *pattern); apr_fnmatch_test_t apr_fnmatch_test; #ifdef __cplusplus } #endif static void* get_sym(void *lib_handle, const char *symbol); static void test_fnmatch_test(); int main(int argc, char **argv) { void *lib_handle; lib_handle = dlopen("/lib64/libapr-1.so.0", RTLD_LAZY); if (!lib_handle) { fprintf(stderr, "%s\n", dlerror()); exit(1); } apr_fnmatch_test = (apr_fnmatch_test_t) get_sym(lib_handle, "apr_fnmatch_test"); test_fnmatch_test(); dlclose(lib_handle); return 0; } static void* get_sym(void *lib_handle, const char *symbol) { void *result = dlsym(lib_handle, symbol); char *error; if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(1); } return result; } static void test_fnmatch_test() { static const struct test { const char *pattern; int result; } ft_tests[] = { { "a*b", 1 }, { "a?", 1 }, { "a\\b?", 1 }, { "a[b-c]", 1 }, { "a", 0 }, { "a\\", 0 }, // My tests. { "foo\\*bar", 1 }, { "foo\\bar", 1 }, { NULL, 0 } }; const struct test *t; for (t = ft_tests; t->pattern != NULL; t++) { int res = apr_fnmatch_test(t->pattern); if (res != t->result) { printf("apr_fnmatch_test(\"%s\") returns %d, expected %d\n", t->pattern, res, t->result); } } printf("done test_fnmatch_test\n"); }