1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
14 #include <yaz/file_glob.h>
17 #include <yaz/wrbuf.h>
19 void tst_with_path(const char *tpath)
21 yaz_glob_res_t glob_res;
22 int ret = yaz_file_glob(tpath, &glob_res);
25 size_t n = yaz_file_glob_get_num(glob_res);
27 for (i = 0; i < n; i++)
29 yaz_log(YLOG_LOG, "match %s", yaz_file_glob_get_file(glob_res, i));
32 yaz_file_globfree(&glob_res);
35 static int check_file(const char *got, const char *expect)
38 size_t l_match = strlen(expect);
39 YAZ_CHECK(f && strlen(f) >= l_match);
40 if (f && strlen(f) >= l_match && !strcmp(f + strlen(f) - l_match, expect))
47 yaz_glob_res_t glob_res;
49 WRBUF tpath = wrbuf_alloc();
50 const char *srcdir = getenv("srcdir");
54 wrbuf_puts(tpath, srcdir);
55 wrbuf_puts(tpath, "/");
57 wrbuf_puts(tpath, "test_file*.c");
58 ret = yaz_file_glob(wrbuf_cstr(tpath), &glob_res);
61 YAZ_CHECK_EQ(2, yaz_file_glob_get_num(glob_res));
62 if (yaz_file_glob_get_num(glob_res) == 2)
64 YAZ_CHECK(check_file(yaz_file_glob_get_file(glob_res, 0),
66 YAZ_CHECK(check_file(yaz_file_glob_get_file(glob_res, 1),
70 yaz_file_globfree(&glob_res);
73 int main (int argc, char **argv)
75 YAZ_CHECK_INIT(argc, argv);
77 tst_with_path(argv[1]);
85 * c-file-style: "Stroustrup"
86 * indent-tabs-mode: nil
88 * vim: shiftwidth=4 tabstop=8 expandtab