2
0

testpath.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_errno.h"
  19. #include "fspr_pools.h"
  20. #include "fspr_tables.h"
  21. #if defined(WIN32) || defined(NETWARE) || defined(OS2)
  22. #define PSEP ";"
  23. #define DSEP "\\"
  24. #else
  25. #define PSEP ":"
  26. #define DSEP "/"
  27. #endif
  28. #define PX ""
  29. #define P1 "first path"
  30. #define P2 "second" DSEP "path"
  31. #define P3 "th ird" DSEP "path"
  32. #define P4 "fourth" DSEP "pa th"
  33. #define P5 "fifthpath"
  34. static const char *parts_in[] = { P1, P2, P3, PX, P4, P5 };
  35. static const char *path_in = P1 PSEP P2 PSEP P3 PSEP PX PSEP P4 PSEP P5;
  36. static const int parts_in_count = sizeof(parts_in)/sizeof(*parts_in);
  37. static const char *parts_out[] = { P1, P2, P3, P4, P5 };
  38. static const char *path_out = P1 PSEP P2 PSEP P3 PSEP P4 PSEP P5;
  39. static const int parts_out_count = sizeof(parts_out)/sizeof(*parts_out);
  40. static void list_split_multi(abts_case *tc, void *data)
  41. {
  42. int i;
  43. fspr_status_t rv;
  44. fspr_array_header_t *pathelts;
  45. pathelts = NULL;
  46. rv = fspr_filepath_list_split(&pathelts, path_in, p);
  47. ABTS_PTR_NOTNULL(tc, pathelts);
  48. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  49. ABTS_INT_EQUAL(tc, parts_out_count, pathelts->nelts);
  50. for (i = 0; i < pathelts->nelts; ++i)
  51. ABTS_STR_EQUAL(tc, parts_out[i], ((char**)pathelts->elts)[i]);
  52. }
  53. static void list_split_single(abts_case *tc, void *data)
  54. {
  55. int i;
  56. fspr_status_t rv;
  57. fspr_array_header_t *pathelts;
  58. for (i = 0; i < parts_in_count; ++i)
  59. {
  60. pathelts = NULL;
  61. rv = fspr_filepath_list_split(&pathelts, parts_in[i], p);
  62. ABTS_PTR_NOTNULL(tc, pathelts);
  63. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  64. if (parts_in[i][0] == '\0')
  65. ABTS_INT_EQUAL(tc, 0, pathelts->nelts);
  66. else
  67. {
  68. ABTS_INT_EQUAL(tc, 1, pathelts->nelts);
  69. ABTS_STR_EQUAL(tc, parts_in[i], *(char**)pathelts->elts);
  70. }
  71. }
  72. }
  73. static void list_merge_multi(abts_case *tc, void *data)
  74. {
  75. int i;
  76. char *liststr;
  77. fspr_status_t rv;
  78. fspr_array_header_t *pathelts;
  79. pathelts = fspr_array_make(p, parts_in_count, sizeof(const char*));
  80. for (i = 0; i < parts_in_count; ++i)
  81. *(const char**)fspr_array_push(pathelts) = parts_in[i];
  82. liststr = NULL;
  83. rv = fspr_filepath_list_merge(&liststr, pathelts, p);
  84. ABTS_PTR_NOTNULL(tc, liststr);
  85. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  86. ABTS_STR_EQUAL(tc, liststr, path_out);
  87. }
  88. static void list_merge_single(abts_case *tc, void *data)
  89. {
  90. int i;
  91. char *liststr;
  92. fspr_status_t rv;
  93. fspr_array_header_t *pathelts;
  94. pathelts = fspr_array_make(p, 1, sizeof(const char*));
  95. fspr_array_push(pathelts);
  96. for (i = 0; i < parts_in_count; ++i)
  97. {
  98. *(const char**)pathelts->elts = parts_in[i];
  99. liststr = NULL;
  100. rv = fspr_filepath_list_merge(&liststr, pathelts, p);
  101. if (parts_in[i][0] == '\0')
  102. ABTS_PTR_EQUAL(tc, NULL, liststr);
  103. else
  104. {
  105. ABTS_PTR_NOTNULL(tc, liststr);
  106. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  107. ABTS_STR_EQUAL(tc, liststr, parts_in[i]);
  108. }
  109. }
  110. }
  111. abts_suite *testpath(abts_suite *suite)
  112. {
  113. suite = ADD_SUITE(suite)
  114. abts_run_test(suite, list_split_multi, NULL);
  115. abts_run_test(suite, list_split_single, NULL);
  116. abts_run_test(suite, list_merge_multi, NULL);
  117. abts_run_test(suite, list_merge_single, NULL);
  118. return suite;
  119. }