isomorfeus-ferret 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +612 -0
  3. data/README.md +44 -0
  4. data/ext/isomorfeus_ferret_ext/benchmark.c +223 -0
  5. data/ext/isomorfeus_ferret_ext/benchmark.h +45 -0
  6. data/ext/isomorfeus_ferret_ext/benchmarks_all.h +25 -0
  7. data/ext/isomorfeus_ferret_ext/bm_bitvector.c +123 -0
  8. data/ext/isomorfeus_ferret_ext/bm_hash.c +118 -0
  9. data/ext/isomorfeus_ferret_ext/bm_micro_string.c +40 -0
  10. data/ext/isomorfeus_ferret_ext/bm_store.c +93 -0
  11. data/ext/isomorfeus_ferret_ext/email.rl +21 -0
  12. data/ext/isomorfeus_ferret_ext/extconf.rb +5 -0
  13. data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -0
  14. data/ext/isomorfeus_ferret_ext/frb_analysis.c +2577 -0
  15. data/ext/isomorfeus_ferret_ext/frb_index.c +3457 -0
  16. data/ext/isomorfeus_ferret_ext/frb_lang.c +9 -0
  17. data/ext/isomorfeus_ferret_ext/frb_lang.h +17 -0
  18. data/ext/isomorfeus_ferret_ext/frb_qparser.c +629 -0
  19. data/ext/isomorfeus_ferret_ext/frb_search.c +4460 -0
  20. data/ext/isomorfeus_ferret_ext/frb_store.c +515 -0
  21. data/ext/isomorfeus_ferret_ext/frb_threading.h +30 -0
  22. data/ext/isomorfeus_ferret_ext/frb_utils.c +1127 -0
  23. data/ext/isomorfeus_ferret_ext/frt_analysis.c +1644 -0
  24. data/ext/isomorfeus_ferret_ext/frt_analysis.h +247 -0
  25. data/ext/isomorfeus_ferret_ext/frt_array.c +124 -0
  26. data/ext/isomorfeus_ferret_ext/frt_array.h +54 -0
  27. data/ext/isomorfeus_ferret_ext/frt_bitvector.c +95 -0
  28. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +586 -0
  29. data/ext/isomorfeus_ferret_ext/frt_compound_io.c +374 -0
  30. data/ext/isomorfeus_ferret_ext/frt_config.h +44 -0
  31. data/ext/isomorfeus_ferret_ext/frt_document.c +134 -0
  32. data/ext/isomorfeus_ferret_ext/frt_document.h +52 -0
  33. data/ext/isomorfeus_ferret_ext/frt_except.c +95 -0
  34. data/ext/isomorfeus_ferret_ext/frt_except.h +188 -0
  35. data/ext/isomorfeus_ferret_ext/frt_field_index.c +233 -0
  36. data/ext/isomorfeus_ferret_ext/frt_field_index.h +42 -0
  37. data/ext/isomorfeus_ferret_ext/frt_filter.c +157 -0
  38. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +502 -0
  39. data/ext/isomorfeus_ferret_ext/frt_global.c +427 -0
  40. data/ext/isomorfeus_ferret_ext/frt_global.h +290 -0
  41. data/ext/isomorfeus_ferret_ext/frt_hash.c +518 -0
  42. data/ext/isomorfeus_ferret_ext/frt_hash.h +466 -0
  43. data/ext/isomorfeus_ferret_ext/frt_hashset.c +191 -0
  44. data/ext/isomorfeus_ferret_ext/frt_hashset.h +206 -0
  45. data/ext/isomorfeus_ferret_ext/frt_helper.c +62 -0
  46. data/ext/isomorfeus_ferret_ext/frt_helper.h +13 -0
  47. data/ext/isomorfeus_ferret_ext/frt_ind.c +353 -0
  48. data/ext/isomorfeus_ferret_ext/frt_ind.h +54 -0
  49. data/ext/isomorfeus_ferret_ext/frt_index.c +6377 -0
  50. data/ext/isomorfeus_ferret_ext/frt_index.h +880 -0
  51. data/ext/isomorfeus_ferret_ext/frt_lang.c +104 -0
  52. data/ext/isomorfeus_ferret_ext/frt_lang.h +44 -0
  53. data/ext/isomorfeus_ferret_ext/frt_mempool.c +87 -0
  54. data/ext/isomorfeus_ferret_ext/frt_mempool.h +33 -0
  55. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +349 -0
  56. data/ext/isomorfeus_ferret_ext/frt_multimapper.h +52 -0
  57. data/ext/isomorfeus_ferret_ext/frt_posh.c +1006 -0
  58. data/ext/isomorfeus_ferret_ext/frt_posh.h +973 -0
  59. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +147 -0
  60. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +147 -0
  61. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +1612 -0
  62. data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +157 -0
  63. data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +209 -0
  64. data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +281 -0
  65. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +147 -0
  66. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +672 -0
  67. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +3084 -0
  68. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +1182 -0
  69. data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +98 -0
  70. data/ext/isomorfeus_ferret_ext/frt_q_range.c +665 -0
  71. data/ext/isomorfeus_ferret_ext/frt_q_span.c +2386 -0
  72. data/ext/isomorfeus_ferret_ext/frt_q_term.c +311 -0
  73. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +166 -0
  74. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +460 -0
  75. data/ext/isomorfeus_ferret_ext/frt_scanner.c +899 -0
  76. data/ext/isomorfeus_ferret_ext/frt_scanner.h +28 -0
  77. data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +6705 -0
  78. data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +4419 -0
  79. data/ext/isomorfeus_ferret_ext/frt_search.c +1824 -0
  80. data/ext/isomorfeus_ferret_ext/frt_search.h +924 -0
  81. data/ext/isomorfeus_ferret_ext/frt_similarity.c +150 -0
  82. data/ext/isomorfeus_ferret_ext/frt_similarity.h +79 -0
  83. data/ext/isomorfeus_ferret_ext/frt_sort.c +796 -0
  84. data/ext/isomorfeus_ferret_ext/frt_stopwords.c +395 -0
  85. data/ext/isomorfeus_ferret_ext/frt_store.c +680 -0
  86. data/ext/isomorfeus_ferret_ext/frt_store.h +789 -0
  87. data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +72 -0
  88. data/ext/isomorfeus_ferret_ext/frt_threading.h +23 -0
  89. data/ext/isomorfeus_ferret_ext/frt_win32.h +54 -0
  90. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +409 -0
  91. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +95 -0
  92. data/ext/isomorfeus_ferret_ext/libstemmer.c +93 -0
  93. data/ext/isomorfeus_ferret_ext/libstemmer.h +73 -0
  94. data/ext/isomorfeus_ferret_ext/q_parser.y +1366 -0
  95. data/ext/isomorfeus_ferret_ext/scanner.h +28 -0
  96. data/ext/isomorfeus_ferret_ext/scanner.in +43 -0
  97. data/ext/isomorfeus_ferret_ext/scanner.rl +84 -0
  98. data/ext/isomorfeus_ferret_ext/scanner_mb.rl +200 -0
  99. data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +85 -0
  100. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +324 -0
  101. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +7 -0
  102. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +610 -0
  103. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +6 -0
  104. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +1104 -0
  105. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +6 -0
  106. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +749 -0
  107. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +7 -0
  108. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +1233 -0
  109. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +6 -0
  110. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +490 -0
  111. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +6 -0
  112. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +1217 -0
  113. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +7 -0
  114. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +1052 -0
  115. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +6 -0
  116. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +283 -0
  117. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +6 -0
  118. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +735 -0
  119. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +6 -0
  120. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +1003 -0
  121. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +7 -0
  122. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +1079 -0
  123. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +6 -0
  124. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +293 -0
  125. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +6 -0
  126. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +984 -0
  127. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +6 -0
  128. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +686 -0
  129. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +6 -0
  130. data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.c +325 -0
  131. data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.h +6 -0
  132. data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.c +620 -0
  133. data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.h +6 -0
  134. data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.c +1111 -0
  135. data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.h +6 -0
  136. data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.c +754 -0
  137. data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.h +6 -0
  138. data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.c +1242 -0
  139. data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.h +6 -0
  140. data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.c +495 -0
  141. data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.h +6 -0
  142. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.c +1220 -0
  143. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.h +6 -0
  144. data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.c +1059 -0
  145. data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.h +6 -0
  146. data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.c +285 -0
  147. data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.h +6 -0
  148. data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.c +741 -0
  149. data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.h +6 -0
  150. data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.c +1009 -0
  151. data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.h +6 -0
  152. data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.c +990 -0
  153. data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.h +6 -0
  154. data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.c +680 -0
  155. data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.h +6 -0
  156. data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.c +1083 -0
  157. data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.h +6 -0
  158. data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.c +294 -0
  159. data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.h +6 -0
  160. data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.c +2191 -0
  161. data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.h +6 -0
  162. data/ext/isomorfeus_ferret_ext/stem_api.c +66 -0
  163. data/ext/isomorfeus_ferret_ext/stem_api.h +26 -0
  164. data/ext/isomorfeus_ferret_ext/stem_header.h +57 -0
  165. data/ext/isomorfeus_ferret_ext/stem_modules.h +190 -0
  166. data/ext/isomorfeus_ferret_ext/stem_modules.txt +50 -0
  167. data/ext/isomorfeus_ferret_ext/stem_utilities.c +478 -0
  168. data/ext/isomorfeus_ferret_ext/test.c +850 -0
  169. data/ext/isomorfeus_ferret_ext/test.h +416 -0
  170. data/ext/isomorfeus_ferret_ext/test_1710.c +63 -0
  171. data/ext/isomorfeus_ferret_ext/test_analysis.c +1221 -0
  172. data/ext/isomorfeus_ferret_ext/test_array.c +272 -0
  173. data/ext/isomorfeus_ferret_ext/test_bitvector.c +600 -0
  174. data/ext/isomorfeus_ferret_ext/test_compound_io.c +170 -0
  175. data/ext/isomorfeus_ferret_ext/test_document.c +156 -0
  176. data/ext/isomorfeus_ferret_ext/test_except.c +244 -0
  177. data/ext/isomorfeus_ferret_ext/test_fields.c +522 -0
  178. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +185 -0
  179. data/ext/isomorfeus_ferret_ext/test_filter.c +331 -0
  180. data/ext/isomorfeus_ferret_ext/test_fs_store.c +25 -0
  181. data/ext/isomorfeus_ferret_ext/test_global.c +299 -0
  182. data/ext/isomorfeus_ferret_ext/test_hash.c +485 -0
  183. data/ext/isomorfeus_ferret_ext/test_hashset.c +288 -0
  184. data/ext/isomorfeus_ferret_ext/test_helper.c +47 -0
  185. data/ext/isomorfeus_ferret_ext/test_highlighter.c +548 -0
  186. data/ext/isomorfeus_ferret_ext/test_index.c +2323 -0
  187. data/ext/isomorfeus_ferret_ext/test_lang.c +74 -0
  188. data/ext/isomorfeus_ferret_ext/test_mempool.c +102 -0
  189. data/ext/isomorfeus_ferret_ext/test_multimapper.c +64 -0
  190. data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +213 -0
  191. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +84 -0
  192. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +61 -0
  193. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +241 -0
  194. data/ext/isomorfeus_ferret_ext/test_q_parser.c +464 -0
  195. data/ext/isomorfeus_ferret_ext/test_q_span.c +575 -0
  196. data/ext/isomorfeus_ferret_ext/test_ram_store.c +77 -0
  197. data/ext/isomorfeus_ferret_ext/test_search.c +1874 -0
  198. data/ext/isomorfeus_ferret_ext/test_segments.c +167 -0
  199. data/ext/isomorfeus_ferret_ext/test_similarity.c +25 -0
  200. data/ext/isomorfeus_ferret_ext/test_sort.c +333 -0
  201. data/ext/isomorfeus_ferret_ext/test_store.c +591 -0
  202. data/ext/isomorfeus_ferret_ext/test_store.h +3 -0
  203. data/ext/isomorfeus_ferret_ext/test_term.c +351 -0
  204. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +373 -0
  205. data/ext/isomorfeus_ferret_ext/test_test.c +83 -0
  206. data/ext/isomorfeus_ferret_ext/test_threading.c +188 -0
  207. data/ext/isomorfeus_ferret_ext/testhelper.c +561 -0
  208. data/ext/isomorfeus_ferret_ext/testhelper.h +25 -0
  209. data/ext/isomorfeus_ferret_ext/tests_all.h +87 -0
  210. data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +1854 -0
  211. data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +1999 -0
  212. data/ext/isomorfeus_ferret_ext/url.rl +27 -0
  213. data/ext/isomorfeus_ferret_ext/word_list.h +15156 -0
  214. data/lib/isomorfeus/ferret/document.rb +132 -0
  215. data/lib/isomorfeus/ferret/field_symbol.rb +85 -0
  216. data/lib/isomorfeus/ferret/index/field_infos.rb +48 -0
  217. data/lib/isomorfeus/ferret/index/index.rb +970 -0
  218. data/lib/isomorfeus/ferret/monitor.rb +323 -0
  219. data/lib/isomorfeus/ferret/stdlib_patches.rb +151 -0
  220. data/lib/isomorfeus/ferret/version.rb +5 -0
  221. data/lib/isomorfeus-ferret.rb +8 -0
  222. metadata +307 -0
@@ -0,0 +1,591 @@
1
+ #include "frt_store.h"
2
+ #include <string.h>
3
+ #include <limits.h>
4
+ #include "test.h"
5
+
6
+ #define TEST_LOCK_NAME "test"
7
+
8
+ typedef struct WithLockTestArg {
9
+ FrtLock *lock;
10
+ TestCase *tc;
11
+ } WithLockTestArg;
12
+
13
+ typedef struct WithLockNameTestArg {
14
+ const char *lock_name;
15
+ FrtStore *store;
16
+ TestCase *tc;
17
+ } WithLockNameTestArg;
18
+
19
+ static void with_lock_test(void *p)
20
+ {
21
+ WithLockTestArg *l = (WithLockTestArg *)p;
22
+ TestCase *tc = l->tc;
23
+ Assert(l->lock->is_locked(l->lock), "lock should be locked");
24
+ }
25
+
26
+ static void with_lock_name_test(void *p)
27
+ {
28
+ WithLockNameTestArg *l = (WithLockNameTestArg *)p;
29
+ TestCase *tc = l->tc;
30
+ FrtLock *lock = frt_open_lock(l->store, l->lock_name);
31
+ Assert(lock->is_locked(lock), "lock should be locked");
32
+ frt_close_lock(lock);
33
+ }
34
+
35
+ /**
36
+ * Test that the lock is created and deleted correctly
37
+ */
38
+ static void test_lock(TestCase *tc, void *data)
39
+ {
40
+ FrtStore *store = (FrtStore *)data;
41
+ FrtLock *lock, *lock1, *lock2;
42
+ bool handled;
43
+ WithLockTestArg wlta;
44
+ WithLockNameTestArg wlnta;
45
+
46
+ lock1 = frt_open_lock(store, TEST_LOCK_NAME);
47
+ Aiequal(false, lock1->is_locked(lock1));
48
+ Aiequal(true, lock1->obtain(lock1));
49
+ Aiequal(true, lock1->is_locked(lock1));
50
+ lock1->release(lock1);
51
+ Aiequal(false, lock1->is_locked(lock1));
52
+ Aiequal(true, lock1->obtain(lock1));
53
+ lock2 = frt_open_lock(store, TEST_LOCK_NAME);
54
+ Aiequal(true, lock2->is_locked(lock2));
55
+ lock1->release(lock1);
56
+ Aiequal(false, lock2->is_locked(lock2));
57
+ frt_close_lock(lock1);
58
+ frt_close_lock(lock2);
59
+
60
+ /* test with_lock */
61
+ lock = frt_open_lock(store, TEST_LOCK_NAME);
62
+ Assert(!lock->is_locked(lock), "lock shouldn't be locked yet");
63
+ wlta.lock = lock; wlta.tc = tc;
64
+ frt_with_lock(lock, &with_lock_test, &wlta);
65
+ Assert(!lock->is_locked(lock), "lock should be unlocked again");
66
+ Assert(lock->obtain(lock), "lock should be obtainable");
67
+ handled = false;
68
+ FRT_TRY
69
+ frt_with_lock(lock, &with_lock_test, &wlta);
70
+ Assert(false, "A locking exception should have been raised");
71
+ break;
72
+ case FRT_LOCK_ERROR:
73
+ handled = true;
74
+ FRT_HANDLED();
75
+ break;
76
+ default:
77
+ Assert(false, "This exception shouldn't have been raised");
78
+ break;
79
+ case FRT_FINALLY:
80
+ break;
81
+ FRT_XENDTRY
82
+ Assert(handled, "A LOCK_ERROR should have been raised");
83
+ lock->release(lock);
84
+ frt_close_lock(lock);
85
+
86
+ /* test with_lock_name */
87
+ lock = frt_open_lock(store, TEST_LOCK_NAME);
88
+ Assert(!lock->is_locked(lock), "lock shouldn't be locked yet");
89
+ wlnta.lock_name = TEST_LOCK_NAME; wlnta.tc = tc; wlnta.store = store;
90
+ frt_with_lock_name(store, TEST_LOCK_NAME, &with_lock_name_test, &wlnta);
91
+ Assert(!lock->is_locked(lock), "lock should be unlocked again");
92
+ Assert(lock->obtain(lock), "lock should be obtainable");
93
+ handled = false;
94
+ FRT_TRY
95
+ frt_with_lock_name(store, TEST_LOCK_NAME, &with_lock_name_test, &wlnta);
96
+ Assert(false, "A locking exception should have been raised");
97
+ break;
98
+ case FRT_LOCK_ERROR:
99
+ handled = true;
100
+ FRT_HANDLED();
101
+ break;
102
+ default:
103
+ Assert(false, "This exception shouldn't have been raised");
104
+ break;
105
+ case FRT_FINALLY:
106
+ break;
107
+ FRT_XENDTRY
108
+ Assert(handled, "A LOCK_ERROR should have been raised");
109
+ lock->release(lock);
110
+ frt_close_lock(lock);
111
+ }
112
+
113
+ /**
114
+ * Do basic file operations test.
115
+ */
116
+ static void test_basic_file_ops(TestCase *tc, void *data)
117
+ {
118
+ FrtStore *store = (FrtStore *)data;
119
+
120
+ store->clear_all(store); /* Make sure the test directory is empty. */
121
+ Assert(!store->exists(store, "_1.f1"),
122
+ "File1 should not been created yet");
123
+ store->touch(store, "_1.f1");
124
+ Aiequal(1, store->count(store));
125
+ Assert(store->count(store) == 1, "The store now contains one file");
126
+ Assert(store->exists(store, "_1.f1"), "File1 should now been created");
127
+ store->touch(store, "_1.f2");
128
+ Assert(store->count(store) == 2, "The store now contains two files");
129
+ Assert(store->exists(store, "_1.f2"), "File2 should now been created");
130
+ store->remove(store, "_1.f1");
131
+ Assert(store->count(store) == 1, "The store now contains one file");
132
+ Assert(!store->exists(store, "_1.f1"), "File1 should have been removed");
133
+ Assert(store->exists(store, "_1.f2"), "File2 should still exist");
134
+
135
+ /* test that lock files get deleted by clear_all */
136
+ store->touch(store, "ferret-write.lck");
137
+ Assert(store->exists(store, "ferret-write.lck"),"lock should still exist");
138
+ store->clear_all(store);
139
+ Assert(!store->exists(store, "ferret-write.lck"), "lock should be deleted");
140
+ }
141
+
142
+ /**
143
+ * Test argument used to test the store->each function
144
+ */
145
+ struct EachArg
146
+ {
147
+ char str[100];
148
+ char *p;
149
+ };
150
+
151
+ /**
152
+ * Test function used to test store->each function
153
+ */
154
+ static void concat_filenames(const char *fname, struct EachArg *ea)
155
+ {
156
+ strcpy(ea->p, fname);
157
+ ea->p += strlen(fname);
158
+ }
159
+
160
+ /**
161
+ * Test the store->each function
162
+ */
163
+ static void test_each(TestCase *tc, void *data)
164
+ {
165
+ FrtStore *store = (FrtStore *)data;
166
+
167
+ struct EachArg ea;
168
+ ea.p = ea.str;
169
+
170
+ store->clear_all(store); /* Make sure the test directory is empty. */
171
+ store->touch(store, "_1.f1");
172
+ store->touch(store, "_1.f2");
173
+ store->touch(store, "_1.f3");
174
+ store->touch(store, "_1.f4");
175
+ store->each(store, (void(*)(const char *fname, void *arg))&concat_filenames, &ea);
176
+ *(ea.p) = 0;
177
+ Assert(strstr(ea.str, "_1.f1") != NULL, "should contain this file");
178
+ Assert(strstr(ea.str, "_1.f2") != NULL, "should contain this file");
179
+ Assert(strstr(ea.str, "_1.f3") != NULL, "should contain this file");
180
+ Assert(strstr(ea.str, "_1.f4") != NULL, "should contain this file");
181
+ Aiequal(20, strlen(ea.str));
182
+ }
183
+
184
+ /**
185
+ * Test the store->rename function
186
+ */
187
+ static void test_rename(TestCase *tc, void *data)
188
+ {
189
+ int cnt_before, cnt_after;
190
+ FrtStore *store = (FrtStore *)data;
191
+ store->touch(store, "_from.f1");
192
+ Assert(store->exists(store, "_from.f1"), "File should exist");
193
+ Assert(!store->exists(store, "_to.f1"), "File should not exist");
194
+ cnt_before = store->count(store);
195
+ store->rename(store, "_from.f1", "_to.f1");
196
+ cnt_after = store->count(store);
197
+ Aiequal(cnt_before, cnt_after);
198
+ Assert(store->exists(store, "_to.f1"), "File should now exist");
199
+ Assert(!store->exists(store, "_from.f1"), "File should no longer exist");
200
+ }
201
+
202
+ /**
203
+ * Test the reading and writing of bytes (8 bit)
204
+ */
205
+ static void test_rw_bytes(TestCase *tc, void *data)
206
+ {
207
+ int i;
208
+ FrtStore *store = (FrtStore *)data;
209
+ frt_uchar bytes[6] = { 0x34, 0x87, 0xF9, 0xEA, 0x00, 0xFF };
210
+ FrtOutStream *ostream = store->new_output(store, "_rw_byte.cfs");
211
+ FrtInStream *istream;
212
+ Assert(store->exists(store, "_rw_byte.cfs"), "File should now exist");
213
+ for (i = 0; i < 6; i++) {
214
+ frt_os_write_byte(ostream, bytes[i]);
215
+ }
216
+ frt_os_close(ostream);
217
+
218
+ istream = store->open_input(store, "_rw_byte.cfs");
219
+ for (i = 0; i < 6; i++) {
220
+ Aiequal(bytes[i], frt_is_read_byte(istream));
221
+ }
222
+ frt_is_close(istream);
223
+ Aiequal(6, store->length(store, "_rw_byte.cfs"));
224
+ Assert(store->exists(store, "_rw_byte.cfs"), "File should now exist");
225
+ }
226
+
227
+ /**
228
+ * Test the reading and writing of 32-bit integers
229
+ */
230
+ static void test_rw_i32(TestCase *tc, void *data)
231
+ {
232
+ int i;
233
+ FrtStore *store = (FrtStore *)data;
234
+ FrtOutStream *ostream = store->new_output(store, "_rw_int.cfs");
235
+ FrtInStream *istream;
236
+ frt_i32 ints[4] = { POSH_I32_MAX, POSH_I32_MIN, -1, 0 };
237
+
238
+ for (i = 0; i < 4; i++) {
239
+ frt_os_write_i32(ostream, (int)ints[i]);
240
+ }
241
+ frt_os_close(ostream);
242
+
243
+ istream = store->open_input(store, "_rw_int.cfs");
244
+ for (i = 0; i < 4; i++) {
245
+ Aiequal(ints[i], frt_is_read_i32(istream));
246
+ }
247
+
248
+ frt_is_close(istream);
249
+ Aiequal(16, store->length(store, "_rw_int.cfs"));
250
+ }
251
+
252
+ /**
253
+ * Test the reading and writing of 64-bit integers
254
+ */
255
+ static void test_rw_i64(TestCase *tc, void *data)
256
+ {
257
+ int i;
258
+ FrtStore *store = (FrtStore *)data;
259
+ frt_u64 longs[4] =
260
+ { POSH_I64_MIN, POSH_I64_MAX, POSH_I64(-1), POSH_I64(0) };
261
+ FrtOutStream *ostream = store->new_output(store, "_rw_long.cfs");
262
+ FrtInStream *istream;
263
+
264
+ for (i = 0; i < 4; i++) {
265
+ frt_os_write_i64(ostream, longs[i]);
266
+ }
267
+ frt_os_close(ostream);
268
+
269
+ istream = store->open_input(store, "_rw_long.cfs");
270
+ for (i = 0; i < 4; i++) {
271
+ Aiequal(longs[i], frt_is_read_i64(istream));
272
+ }
273
+ frt_is_close(istream);
274
+ Aiequal(32, store->length(store, "_rw_long.cfs"));
275
+ }
276
+
277
+ /**
278
+ * Test the reading and writing of 32-bit unsigned integers
279
+ */
280
+ static void test_rw_u32(TestCase *tc, void *data)
281
+ {
282
+ int i;
283
+ FrtStore *store = (FrtStore *)data;
284
+ frt_u32 uints[4] = { POSH_U32_MAX, POSH_U32_MIN, 100000, 1 };
285
+ FrtOutStream *ostream = store->new_output(store, "_rw_uint.cfs");
286
+ FrtInStream *istream;
287
+
288
+ for (i = 0; i < 4; i++) {
289
+ frt_os_write_u32(ostream, uints[i]);
290
+ }
291
+ frt_os_close(ostream);
292
+
293
+ istream = store->open_input(store, "_rw_uint.cfs");
294
+ for (i = 0; i < 4; i++) {
295
+ Aiequal(uints[i], frt_is_read_u32(istream));
296
+ }
297
+ frt_is_close(istream);
298
+ Aiequal(16, store->length(store, "_rw_uint.cfs"));
299
+ }
300
+
301
+ /**
302
+ * Test the reading and writing of 64-bit unsigned integers
303
+ */
304
+ static void test_rw_u64(TestCase *tc, void *data)
305
+ {
306
+ int i;
307
+ FrtStore *store = (FrtStore *)data;
308
+ frt_u64 ulongs[4] =
309
+ { POSH_U64_MAX, POSH_U64_MIN, POSH_U64(100000000000000), POSH_U64(1) };
310
+ FrtOutStream *ostream = store->new_output(store, "_rw_ulong.cfs");
311
+ FrtInStream *istream;
312
+
313
+ for (i = 0; i < 4; i++) {
314
+ frt_os_write_u64(ostream, ulongs[i]);
315
+ }
316
+ frt_os_close(ostream);
317
+
318
+ istream = store->open_input(store, "_rw_ulong.cfs");
319
+ for (i = 0; i < 4; i++) {
320
+ Aiequal(ulongs[i], frt_is_read_u64(istream));
321
+ }
322
+ frt_is_close(istream);
323
+ Aiequal(32, store->length(store, "_rw_ulong.cfs"));
324
+ }
325
+
326
+ /**
327
+ * Test reading and writing of variable size integers
328
+ */
329
+ static void test_rw_vints(TestCase *tc, void *data)
330
+ {
331
+ int i;
332
+ FrtStore *store = (FrtStore *)data;
333
+ unsigned int vints[4] = { UINT_MAX, 0, 10000, 1 };
334
+ FrtOutStream *ostream = store->new_output(store, "_rw_vint.cfs");
335
+ FrtInStream *istream;
336
+
337
+ for (i = 0; i < 4; i++) {
338
+ frt_os_write_vint(ostream, vints[i]);
339
+ }
340
+ frt_os_close(ostream);
341
+
342
+ istream = store->open_input(store, "_rw_vint.cfs");
343
+ for (i = 0; i < 4; i++) {
344
+ Aiequal(vints[i], frt_is_read_vint(istream));
345
+ }
346
+ frt_is_close(istream);
347
+ }
348
+
349
+ /**
350
+ * Test reading and writing of variable size integers
351
+ */
352
+ static void test_rw_vlls(TestCase *tc, void *data)
353
+ {
354
+ int i;
355
+ FrtStore *store = (FrtStore *)data;
356
+ unsigned long long vlls[4] = { ULLONG_MAX, 0, 10000, 1 };
357
+ FrtOutStream *ostream = store->new_output(store, "_rw_vll.cfs");
358
+ FrtInStream *istream;
359
+
360
+ for (i = 0; i < 4; i++) {
361
+ frt_os_write_vll(ostream, vlls[i]);
362
+ }
363
+ frt_os_close(ostream);
364
+
365
+ istream = store->open_input(store, "_rw_vll.cfs");
366
+ for (i = 0; i < 4; i++) {
367
+ Aiequal(vlls[i], frt_is_read_vll(istream));
368
+ }
369
+ frt_is_close(istream);
370
+ }
371
+
372
+ /**
373
+ * Test reading and writing of variable size 64-bit integers
374
+ */
375
+ static void test_rw_voff_ts(TestCase *tc, void *data)
376
+ {
377
+ int i;
378
+ FrtStore *store = (FrtStore *)data;
379
+ FrtOutStream *ostream;
380
+ FrtInStream *istream;
381
+ frt_i64 voff_ts[4] =
382
+ { LONG_MAX, 0, 1000000, 1 };
383
+ if (sizeof(off_t) == 8) {
384
+ voff_ts[0] = POSH_I64_MAX;
385
+ }
386
+ else {
387
+ voff_ts[0] = POSH_I32_MAX;
388
+ }
389
+ ostream = store->new_output(store, "_rw_voff_t.cfs");
390
+
391
+ for (i = 0; i < 4; i++) {
392
+ frt_os_write_voff_t(ostream, (off_t)voff_ts[i]);
393
+ }
394
+ frt_os_close(ostream);
395
+
396
+ istream = store->open_input(store, "_rw_voff_t.cfs");
397
+ for (i = 0; i < 4; i++) {
398
+ Aiequal(voff_ts[i], frt_is_read_voff_t(istream));
399
+ }
400
+ frt_is_close(istream);
401
+ }
402
+
403
+ /**
404
+ * Test reading and writing of strings
405
+ */
406
+ static void test_rw_strings(TestCase *tc, void *data)
407
+ {
408
+ int i;
409
+ char *tmp;
410
+ FrtStore *store = (FrtStore *)data;
411
+ char str[60] =
412
+ "This is a c ferret test string ~!@#$%^&*()`123456790-=\\)_+|";
413
+ char buf[60000] = "";
414
+ FrtOutStream *ostream;
415
+ FrtInStream *istream;
416
+
417
+ for (i = 0; i < 1000; i++) {
418
+ strcat(buf, str);
419
+ }
420
+
421
+ ostream = store->new_output(store, "_rw_string.cfs");
422
+ frt_os_write_string(ostream, str);
423
+ frt_os_write_string(ostream, buf);
424
+ frt_os_close(ostream);
425
+
426
+ istream = store->open_input(store, "_rw_string.cfs");
427
+
428
+ tmp = frt_is_read_string(istream);
429
+ Asequal(str, tmp);
430
+ free(tmp);
431
+ tmp = frt_is_read_string(istream);
432
+ Asequal(buf, tmp);
433
+ free(tmp);
434
+ frt_is_close(istream);
435
+ Aiequal(59063, store->length(store, "_rw_string.cfs"));
436
+ }
437
+
438
+ /**
439
+ * Test reading and writing of non-ascii characters
440
+ */
441
+ static void test_rw_funny_strings(TestCase *tc, void *data)
442
+ {
443
+ int i;
444
+ char *tmp;
445
+ FrtStore *store = (FrtStore *)data;
446
+ char str[18] = "³³ ëêðïéÄ";
447
+ char buf[18000] = "";
448
+ FrtOutStream *ostream;
449
+ FrtInStream *istream;
450
+
451
+ for (i = 0; i < 1000; i++) {
452
+ strcat(buf, str);
453
+ }
454
+
455
+ ostream = store->new_output(store, "_funny_string.cfs");
456
+ frt_os_write_string(ostream, str);
457
+ frt_os_write_string(ostream, buf);
458
+ frt_os_close(ostream);
459
+
460
+ istream = store->open_input(store, "_funny_string.cfs");
461
+ tmp = frt_is_read_string(istream);
462
+ Asequal(str, tmp);
463
+ free(tmp);
464
+ tmp = frt_is_read_string(istream);
465
+ Asequal(buf, tmp);
466
+ free(tmp);
467
+ frt_is_close(istream);
468
+ Aiequal(17021, store->length(store, "_funny_string.cfs"));
469
+ }
470
+
471
+ /**
472
+ * Test seek in both input stream and output stream, ie test the frt_os_seek and
473
+ * frt_is_seek functions
474
+ */
475
+ static void test_buffer_seek(TestCase *tc, void *data)
476
+ {
477
+ int i;
478
+ FrtStore *store = (FrtStore *)data;
479
+
480
+ FrtOutStream *ostream = store->new_output(store, "_rw_seek.cfs");
481
+ char text[60] = "This is another int test string !@#$%#$%&%$*%^&*()(_";
482
+ FrtInStream *istream;
483
+
484
+ for (i = 0; i < 1000; i++) {
485
+ frt_os_write_i64(ostream, i);
486
+ frt_os_write_string(ostream, text);
487
+ }
488
+ frt_os_seek(ostream, 987);
489
+ Aiequal(987, frt_os_pos(ostream));
490
+ frt_os_write_vint(ostream, 555);
491
+ frt_os_seek(ostream, 56);
492
+ Aiequal(56, frt_os_pos(ostream));
493
+ frt_os_write_vint(ostream, 12345);
494
+ frt_os_seek(ostream, 4000);
495
+ Aiequal(4000, frt_os_pos(ostream));
496
+ frt_os_write_voff_t(ostream, 98763210);
497
+ frt_os_close(ostream);
498
+
499
+ istream = store->open_input(store, "_rw_seek.cfs");
500
+ frt_is_seek(istream, 56);
501
+ Aiequal(56, frt_is_pos(istream));
502
+ Aiequal(12345, frt_is_read_vint(istream));
503
+ frt_is_seek(istream, 4000);
504
+ Aiequal(4000, frt_is_pos(istream));
505
+ Aiequal(98763210, frt_is_read_voff_t(istream));
506
+ frt_is_seek(istream, 987);
507
+ Aiequal(987, frt_is_pos(istream));
508
+ Aiequal(555, frt_is_read_vint(istream));
509
+ frt_is_close(istream);
510
+ }
511
+
512
+ /**
513
+ * Test cloning of InputStream
514
+ */
515
+ static void test_is_clone(TestCase *tc, void *data)
516
+ {
517
+ int i;
518
+ FrtStore *store = (FrtStore *)data;
519
+ FrtOutStream *ostream = store->new_output(store, "_clone.cfs");
520
+ FrtInStream *istream, *alt_istream;
521
+
522
+ for (i = 0; i < 10; i++) {
523
+ frt_os_write_i64(ostream, i);
524
+ }
525
+ frt_os_close(ostream);
526
+ istream = store->open_input(store, "_clone.cfs");
527
+ frt_is_seek(istream, 24);
528
+ alt_istream = frt_is_clone(istream);
529
+ Aiequal(frt_is_pos(istream), frt_is_pos(alt_istream));
530
+ for (i = 3; i < 10; i++) {
531
+ Aiequal(i, frt_is_read_i64(alt_istream));
532
+ }
533
+ Aiequal(80, frt_is_pos(alt_istream));
534
+ Aiequal(24, frt_is_pos(istream));
535
+ for (i = 3; i < 10; i++) {
536
+ Aiequal(i, frt_is_read_i64(istream));
537
+ }
538
+ frt_is_close(alt_istream);
539
+ frt_is_close(istream);
540
+ }
541
+
542
+ /**
543
+ * Test the read_bytes method. This method reads a number of bytes into a
544
+ * buffer.
545
+ */
546
+ static void test_read_bytes(TestCase *tc, void *data)
547
+ {
548
+ char str[11] = "0000000000";
549
+ FrtStore *store = (FrtStore *)data;
550
+ FrtOutStream *ostream = store->new_output(store, "_read_bytes.cfs");
551
+ FrtInStream *istream;
552
+
553
+ frt_os_write_bytes(ostream, (frt_uchar *)"how are you doing?", 18);
554
+ frt_os_close(ostream);
555
+ istream = store->open_input(store, "_read_bytes.cfs");
556
+ frt_is_read_bytes(istream, (frt_uchar *)(str + 2), 4);
557
+ Asequal("00how 0000", str);
558
+ frt_is_read_bytes(istream, (frt_uchar *)(str + 1), 8);
559
+ Asequal("0are you 0", str);
560
+ frt_is_close(istream);
561
+ }
562
+
563
+ /**
564
+ * Create a test suite for a store. This function can be used to create a test
565
+ * suite for both a FileSystem store and a RAM store and any other type of
566
+ * store that you might want to create.
567
+ */
568
+ void create_test_store_suite(TestSuite *suite, FrtStore *store)
569
+ {
570
+ store->clear_all(store);
571
+
572
+ tst_run_test(suite, test_basic_file_ops, store);
573
+ tst_run_test(suite, test_rename, store);
574
+ tst_run_test(suite, test_each, store);
575
+ tst_run_test(suite, test_rw_bytes, store);
576
+ tst_run_test(suite, test_rw_i32, store);
577
+ tst_run_test(suite, test_rw_i64, store);
578
+ tst_run_test(suite, test_rw_u32, store);
579
+ tst_run_test(suite, test_rw_u64, store);
580
+ tst_run_test(suite, test_rw_vints, store);
581
+ tst_run_test(suite, test_rw_vlls, store);
582
+ tst_run_test(suite, test_rw_voff_ts, store);
583
+ tst_run_test(suite, test_rw_strings, store);
584
+ tst_run_test(suite, test_rw_funny_strings, store);
585
+ tst_run_test(suite, test_buffer_seek, store);
586
+ tst_run_test(suite, test_is_clone, store);
587
+ tst_run_test(suite, test_read_bytes, store);
588
+ tst_run_test(suite, test_lock, store);
589
+
590
+ store->clear_all(store);
591
+ }
@@ -0,0 +1,3 @@
1
+ #include "test.h"
2
+
3
+ void create_test_store_suite(TestSuite *suite, FrtStore *store);