1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
15 #include <yaz/file_glob.h>
18 #include <yaz/wrbuf.h>
20 void tst_with_path(const char *tpath)
22 yaz_glob_res_t glob_res;
23 int ret = yaz_file_glob(tpath, &glob_res);
26 size_t n = yaz_file_glob_get_num(glob_res);
28 for (i = 0; i < n; i++)
30 yaz_log(YLOG_LOG, "match %s", yaz_file_glob_get_file(glob_res, i));
33 yaz_file_globfree(&glob_res);
36 static int check_file(const char *got, const char *expect)
39 size_t l_match = strlen(expect);
40 YAZ_CHECK(f && strlen(f) >= l_match);
41 if (f && strlen(f) >= l_match && !strcmp(f + strlen(f) - l_match, expect))
48 yaz_glob_res_t glob_res;
50 WRBUF tpath = wrbuf_alloc();
51 const char *srcdir = getenv("srcdir");
55 wrbuf_puts(tpath, srcdir);
56 wrbuf_puts(tpath, "/");
58 wrbuf_puts(tpath, "test_file*.c");
59 ret = yaz_file_glob(wrbuf_cstr(tpath), &glob_res);
62 YAZ_CHECK_EQ(2, yaz_file_glob_get_num(glob_res));
63 if (yaz_file_glob_get_num(glob_res) == 2)
65 YAZ_CHECK(check_file(yaz_file_glob_get_file(glob_res, 0),
67 YAZ_CHECK(check_file(yaz_file_glob_get_file(glob_res, 1),
71 yaz_file_globfree(&glob_res);
74 int main (int argc, char **argv)
76 YAZ_CHECK_INIT(argc, argv);
78 tst_with_path(argv[1]);
86 * c-file-style: "Stroustrup"
87 * indent-tabs-mode: nil
89 * vim: shiftwidth=4 tabstop=8 expandtab