2
0

testtable.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.h"
  18. #include "fspr_strings.h"
  19. #include "fspr_general.h"
  20. #include "fspr_pools.h"
  21. #include "fspr_tables.h"
  22. #if APR_HAVE_STDIO_H
  23. #include <stdio.h>
  24. #endif
  25. #if APR_HAVE_STDLIB_H
  26. #include <stdlib.h>
  27. #endif
  28. #if APR_HAVE_STRING_H
  29. #include <string.h>
  30. #endif
  31. static fspr_table_t *t1 = NULL;
  32. static void table_make(abts_case *tc, void *data)
  33. {
  34. t1 = fspr_table_make(p, 5);
  35. ABTS_PTR_NOTNULL(tc, t1);
  36. }
  37. static void table_get(abts_case *tc, void *data)
  38. {
  39. const char *val;
  40. fspr_table_set(t1, "foo", "bar");
  41. val = fspr_table_get(t1, "foo");
  42. ABTS_STR_EQUAL(tc, val, "bar");
  43. }
  44. static void table_set(abts_case *tc, void *data)
  45. {
  46. const char *val;
  47. fspr_table_set(t1, "setkey", "bar");
  48. fspr_table_set(t1, "setkey", "2ndtry");
  49. val = fspr_table_get(t1, "setkey");
  50. ABTS_STR_EQUAL(tc, val, "2ndtry");
  51. }
  52. static void table_getnotthere(abts_case *tc, void *data)
  53. {
  54. const char *val;
  55. val = fspr_table_get(t1, "keynotthere");
  56. ABTS_PTR_EQUAL(tc, NULL, (void *)val);
  57. }
  58. static void table_add(abts_case *tc, void *data)
  59. {
  60. const char *val;
  61. fspr_table_add(t1, "addkey", "bar");
  62. fspr_table_add(t1, "addkey", "foo");
  63. val = fspr_table_get(t1, "addkey");
  64. ABTS_STR_EQUAL(tc, val, "bar");
  65. }
  66. static void table_nelts(abts_case *tc, void *data)
  67. {
  68. const char *val;
  69. fspr_table_t *t = fspr_table_make(p, 1);
  70. fspr_table_set(t, "abc", "def");
  71. fspr_table_set(t, "def", "abc");
  72. fspr_table_set(t, "foo", "zzz");
  73. val = fspr_table_get(t, "foo");
  74. ABTS_STR_EQUAL(tc, val, "zzz");
  75. val = fspr_table_get(t, "abc");
  76. ABTS_STR_EQUAL(tc, val, "def");
  77. val = fspr_table_get(t, "def");
  78. ABTS_STR_EQUAL(tc, val, "abc");
  79. ABTS_INT_EQUAL(tc, 3, fspr_table_elts(t)->nelts);
  80. }
  81. static void table_clear(abts_case *tc, void *data)
  82. {
  83. fspr_table_clear(t1);
  84. ABTS_INT_EQUAL(tc, 0, fspr_table_elts(t1)->nelts);
  85. }
  86. static void table_unset(abts_case *tc, void *data)
  87. {
  88. const char *val;
  89. fspr_table_t *t = fspr_table_make(p, 1);
  90. fspr_table_set(t, "a", "1");
  91. fspr_table_set(t, "b", "2");
  92. fspr_table_unset(t, "b");
  93. ABTS_INT_EQUAL(tc, 1, fspr_table_elts(t)->nelts);
  94. val = fspr_table_get(t, "a");
  95. ABTS_STR_EQUAL(tc, val, "1");
  96. val = fspr_table_get(t, "b");
  97. ABTS_PTR_EQUAL(tc, (void *)val, (void *)NULL);
  98. }
  99. static void table_overlap(abts_case *tc, void *data)
  100. {
  101. const char *val;
  102. fspr_table_t *t1 = fspr_table_make(p, 1);
  103. fspr_table_t *t2 = fspr_table_make(p, 1);
  104. fspr_table_addn(t1, "a", "0");
  105. fspr_table_addn(t1, "g", "7");
  106. fspr_table_addn(t2, "a", "1");
  107. fspr_table_addn(t2, "b", "2");
  108. fspr_table_addn(t2, "c", "3");
  109. fspr_table_addn(t2, "b", "2.0");
  110. fspr_table_addn(t2, "d", "4");
  111. fspr_table_addn(t2, "e", "5");
  112. fspr_table_addn(t2, "b", "2.");
  113. fspr_table_addn(t2, "f", "6");
  114. fspr_table_overlap(t1, t2, APR_OVERLAP_TABLES_SET);
  115. ABTS_INT_EQUAL(tc, fspr_table_elts(t1)->nelts, 7);
  116. val = fspr_table_get(t1, "a");
  117. ABTS_STR_EQUAL(tc, val, "1");
  118. val = fspr_table_get(t1, "b");
  119. ABTS_STR_EQUAL(tc, val, "2.");
  120. val = fspr_table_get(t1, "c");
  121. ABTS_STR_EQUAL(tc, val, "3");
  122. val = fspr_table_get(t1, "d");
  123. ABTS_STR_EQUAL(tc, val, "4");
  124. val = fspr_table_get(t1, "e");
  125. ABTS_STR_EQUAL(tc, val, "5");
  126. val = fspr_table_get(t1, "f");
  127. ABTS_STR_EQUAL(tc, val, "6");
  128. val = fspr_table_get(t1, "g");
  129. ABTS_STR_EQUAL(tc, val, "7");
  130. }
  131. static void table_overlap2(abts_case *tc, void *data)
  132. {
  133. fspr_pool_t *subp;
  134. fspr_table_t *t1, *t2;
  135. fspr_pool_create(&subp, p);
  136. t1 = fspr_table_make(subp, 1);
  137. t2 = fspr_table_make(p, 1);
  138. fspr_table_addn(t1, "t1", "one");
  139. fspr_table_addn(t2, "t2", "two");
  140. fspr_table_overlap(t1, t2, APR_OVERLAP_TABLES_SET);
  141. ABTS_INT_EQUAL(tc, 2, fspr_table_elts(t1)->nelts);
  142. ABTS_STR_EQUAL(tc, fspr_table_get(t1, "t1"), "one");
  143. ABTS_STR_EQUAL(tc, fspr_table_get(t1, "t2"), "two");
  144. }
  145. abts_suite *testtable(abts_suite *suite)
  146. {
  147. suite = ADD_SUITE(suite)
  148. abts_run_test(suite, table_make, NULL);
  149. abts_run_test(suite, table_get, NULL);
  150. abts_run_test(suite, table_set, NULL);
  151. abts_run_test(suite, table_getnotthere, NULL);
  152. abts_run_test(suite, table_add, NULL);
  153. abts_run_test(suite, table_nelts, NULL);
  154. abts_run_test(suite, table_clear, NULL);
  155. abts_run_test(suite, table_unset, NULL);
  156. abts_run_test(suite, table_overlap, NULL);
  157. abts_run_test(suite, table_overlap2, NULL);
  158. return suite;
  159. }