testfnmatch.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "testutil.h"
  17. #include "fspr_file_info.h"
  18. #include "fspr_fnmatch.h"
  19. #include "fspr_tables.h"
  20. /* XXX NUM_FILES must be equal to the nummber of expected files with a
  21. * .txt extension in the data directory at the time testfnmatch
  22. * happens to be run (!?!). */
  23. #define NUM_FILES (5)
  24. static void test_glob(abts_case *tc, void *data)
  25. {
  26. int i;
  27. char **list;
  28. fspr_array_header_t *result;
  29. APR_ASSERT_SUCCESS(tc, "glob match against data/*.txt",
  30. fspr_match_glob("data\\*.txt", &result, p));
  31. ABTS_INT_EQUAL(tc, NUM_FILES, result->nelts);
  32. list = (char **)result->elts;
  33. for (i = 0; i < result->nelts; i++) {
  34. char *dot = strrchr(list[i], '.');
  35. ABTS_STR_EQUAL(tc, dot, ".txt");
  36. }
  37. }
  38. static void test_glob_currdir(abts_case *tc, void *data)
  39. {
  40. int i;
  41. char **list;
  42. fspr_array_header_t *result;
  43. fspr_filepath_set("data", p);
  44. APR_ASSERT_SUCCESS(tc, "glob match against *.txt with data as current",
  45. fspr_match_glob("*.txt", &result, p));
  46. ABTS_INT_EQUAL(tc, NUM_FILES, result->nelts);
  47. list = (char **)result->elts;
  48. for (i = 0; i < result->nelts; i++) {
  49. char *dot = strrchr(list[i], '.');
  50. ABTS_STR_EQUAL(tc, dot, ".txt");
  51. }
  52. fspr_filepath_set("..", p);
  53. }
  54. abts_suite *testfnmatch(abts_suite *suite)
  55. {
  56. suite = ADD_SUITE(suite)
  57. abts_run_test(suite, test_glob, NULL);
  58. abts_run_test(suite, test_glob_currdir, NULL);
  59. return suite;
  60. }