isomorfeus-ferret 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +612 -0
- data/README.md +44 -0
- data/ext/isomorfeus_ferret_ext/benchmark.c +223 -0
- data/ext/isomorfeus_ferret_ext/benchmark.h +45 -0
- data/ext/isomorfeus_ferret_ext/benchmarks_all.h +25 -0
- data/ext/isomorfeus_ferret_ext/bm_bitvector.c +123 -0
- data/ext/isomorfeus_ferret_ext/bm_hash.c +118 -0
- data/ext/isomorfeus_ferret_ext/bm_micro_string.c +40 -0
- data/ext/isomorfeus_ferret_ext/bm_store.c +93 -0
- data/ext/isomorfeus_ferret_ext/email.rl +21 -0
- data/ext/isomorfeus_ferret_ext/extconf.rb +5 -0
- data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -0
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +2577 -0
- data/ext/isomorfeus_ferret_ext/frb_index.c +3457 -0
- data/ext/isomorfeus_ferret_ext/frb_lang.c +9 -0
- data/ext/isomorfeus_ferret_ext/frb_lang.h +17 -0
- data/ext/isomorfeus_ferret_ext/frb_qparser.c +629 -0
- data/ext/isomorfeus_ferret_ext/frb_search.c +4460 -0
- data/ext/isomorfeus_ferret_ext/frb_store.c +515 -0
- data/ext/isomorfeus_ferret_ext/frb_threading.h +30 -0
- data/ext/isomorfeus_ferret_ext/frb_utils.c +1127 -0
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +1644 -0
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +247 -0
- data/ext/isomorfeus_ferret_ext/frt_array.c +124 -0
- data/ext/isomorfeus_ferret_ext/frt_array.h +54 -0
- data/ext/isomorfeus_ferret_ext/frt_bitvector.c +95 -0
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +586 -0
- data/ext/isomorfeus_ferret_ext/frt_compound_io.c +374 -0
- data/ext/isomorfeus_ferret_ext/frt_config.h +44 -0
- data/ext/isomorfeus_ferret_ext/frt_document.c +134 -0
- data/ext/isomorfeus_ferret_ext/frt_document.h +52 -0
- data/ext/isomorfeus_ferret_ext/frt_except.c +95 -0
- data/ext/isomorfeus_ferret_ext/frt_except.h +188 -0
- data/ext/isomorfeus_ferret_ext/frt_field_index.c +233 -0
- data/ext/isomorfeus_ferret_ext/frt_field_index.h +42 -0
- data/ext/isomorfeus_ferret_ext/frt_filter.c +157 -0
- data/ext/isomorfeus_ferret_ext/frt_fs_store.c +502 -0
- data/ext/isomorfeus_ferret_ext/frt_global.c +427 -0
- data/ext/isomorfeus_ferret_ext/frt_global.h +290 -0
- data/ext/isomorfeus_ferret_ext/frt_hash.c +518 -0
- data/ext/isomorfeus_ferret_ext/frt_hash.h +466 -0
- data/ext/isomorfeus_ferret_ext/frt_hashset.c +191 -0
- data/ext/isomorfeus_ferret_ext/frt_hashset.h +206 -0
- data/ext/isomorfeus_ferret_ext/frt_helper.c +62 -0
- data/ext/isomorfeus_ferret_ext/frt_helper.h +13 -0
- data/ext/isomorfeus_ferret_ext/frt_ind.c +353 -0
- data/ext/isomorfeus_ferret_ext/frt_ind.h +54 -0
- data/ext/isomorfeus_ferret_ext/frt_index.c +6377 -0
- data/ext/isomorfeus_ferret_ext/frt_index.h +880 -0
- data/ext/isomorfeus_ferret_ext/frt_lang.c +104 -0
- data/ext/isomorfeus_ferret_ext/frt_lang.h +44 -0
- data/ext/isomorfeus_ferret_ext/frt_mempool.c +87 -0
- data/ext/isomorfeus_ferret_ext/frt_mempool.h +33 -0
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +349 -0
- data/ext/isomorfeus_ferret_ext/frt_multimapper.h +52 -0
- data/ext/isomorfeus_ferret_ext/frt_posh.c +1006 -0
- data/ext/isomorfeus_ferret_ext/frt_posh.h +973 -0
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +147 -0
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +147 -0
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +1612 -0
- data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +157 -0
- data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +209 -0
- data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +281 -0
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +147 -0
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +672 -0
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +3084 -0
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +1182 -0
- data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +98 -0
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +665 -0
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +2386 -0
- data/ext/isomorfeus_ferret_ext/frt_q_term.c +311 -0
- data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +166 -0
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +460 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner.c +899 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner.h +28 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +6705 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +4419 -0
- data/ext/isomorfeus_ferret_ext/frt_search.c +1824 -0
- data/ext/isomorfeus_ferret_ext/frt_search.h +924 -0
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +150 -0
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +79 -0
- data/ext/isomorfeus_ferret_ext/frt_sort.c +796 -0
- data/ext/isomorfeus_ferret_ext/frt_stopwords.c +395 -0
- data/ext/isomorfeus_ferret_ext/frt_store.c +680 -0
- data/ext/isomorfeus_ferret_ext/frt_store.h +789 -0
- data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +72 -0
- data/ext/isomorfeus_ferret_ext/frt_threading.h +23 -0
- data/ext/isomorfeus_ferret_ext/frt_win32.h +54 -0
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +409 -0
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +95 -0
- data/ext/isomorfeus_ferret_ext/libstemmer.c +93 -0
- data/ext/isomorfeus_ferret_ext/libstemmer.h +73 -0
- data/ext/isomorfeus_ferret_ext/q_parser.y +1366 -0
- data/ext/isomorfeus_ferret_ext/scanner.h +28 -0
- data/ext/isomorfeus_ferret_ext/scanner.in +43 -0
- data/ext/isomorfeus_ferret_ext/scanner.rl +84 -0
- data/ext/isomorfeus_ferret_ext/scanner_mb.rl +200 -0
- data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +85 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +324 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +610 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +1104 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +749 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +1233 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +490 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +1217 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +1052 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +283 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +735 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +1003 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +1079 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +293 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +984 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +686 -0
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.c +325 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.c +620 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.c +1111 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.c +754 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.c +1242 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.c +495 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.c +1220 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.c +1059 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.c +285 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.c +741 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.c +1009 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.c +990 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.c +680 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.c +1083 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.c +294 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.c +2191 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_api.c +66 -0
- data/ext/isomorfeus_ferret_ext/stem_api.h +26 -0
- data/ext/isomorfeus_ferret_ext/stem_header.h +57 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.h +190 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.txt +50 -0
- data/ext/isomorfeus_ferret_ext/stem_utilities.c +478 -0
- data/ext/isomorfeus_ferret_ext/test.c +850 -0
- data/ext/isomorfeus_ferret_ext/test.h +416 -0
- data/ext/isomorfeus_ferret_ext/test_1710.c +63 -0
- data/ext/isomorfeus_ferret_ext/test_analysis.c +1221 -0
- data/ext/isomorfeus_ferret_ext/test_array.c +272 -0
- data/ext/isomorfeus_ferret_ext/test_bitvector.c +600 -0
- data/ext/isomorfeus_ferret_ext/test_compound_io.c +170 -0
- data/ext/isomorfeus_ferret_ext/test_document.c +156 -0
- data/ext/isomorfeus_ferret_ext/test_except.c +244 -0
- data/ext/isomorfeus_ferret_ext/test_fields.c +522 -0
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +185 -0
- data/ext/isomorfeus_ferret_ext/test_filter.c +331 -0
- data/ext/isomorfeus_ferret_ext/test_fs_store.c +25 -0
- data/ext/isomorfeus_ferret_ext/test_global.c +299 -0
- data/ext/isomorfeus_ferret_ext/test_hash.c +485 -0
- data/ext/isomorfeus_ferret_ext/test_hashset.c +288 -0
- data/ext/isomorfeus_ferret_ext/test_helper.c +47 -0
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +548 -0
- data/ext/isomorfeus_ferret_ext/test_index.c +2323 -0
- data/ext/isomorfeus_ferret_ext/test_lang.c +74 -0
- data/ext/isomorfeus_ferret_ext/test_mempool.c +102 -0
- data/ext/isomorfeus_ferret_ext/test_multimapper.c +64 -0
- data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +213 -0
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +84 -0
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +61 -0
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +241 -0
- data/ext/isomorfeus_ferret_ext/test_q_parser.c +464 -0
- data/ext/isomorfeus_ferret_ext/test_q_span.c +575 -0
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +77 -0
- data/ext/isomorfeus_ferret_ext/test_search.c +1874 -0
- data/ext/isomorfeus_ferret_ext/test_segments.c +167 -0
- data/ext/isomorfeus_ferret_ext/test_similarity.c +25 -0
- data/ext/isomorfeus_ferret_ext/test_sort.c +333 -0
- data/ext/isomorfeus_ferret_ext/test_store.c +591 -0
- data/ext/isomorfeus_ferret_ext/test_store.h +3 -0
- data/ext/isomorfeus_ferret_ext/test_term.c +351 -0
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +373 -0
- data/ext/isomorfeus_ferret_ext/test_test.c +83 -0
- data/ext/isomorfeus_ferret_ext/test_threading.c +188 -0
- data/ext/isomorfeus_ferret_ext/testhelper.c +561 -0
- data/ext/isomorfeus_ferret_ext/testhelper.h +25 -0
- data/ext/isomorfeus_ferret_ext/tests_all.h +87 -0
- data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +1854 -0
- data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +1999 -0
- data/ext/isomorfeus_ferret_ext/url.rl +27 -0
- data/ext/isomorfeus_ferret_ext/word_list.h +15156 -0
- data/lib/isomorfeus/ferret/document.rb +132 -0
- data/lib/isomorfeus/ferret/field_symbol.rb +85 -0
- data/lib/isomorfeus/ferret/index/field_infos.rb +48 -0
- data/lib/isomorfeus/ferret/index/index.rb +970 -0
- data/lib/isomorfeus/ferret/monitor.rb +323 -0
- data/lib/isomorfeus/ferret/stdlib_patches.rb +151 -0
- data/lib/isomorfeus/ferret/version.rb +5 -0
- data/lib/isomorfeus-ferret.rb +8 -0
- metadata +307 -0
@@ -0,0 +1,170 @@
|
|
1
|
+
#include "frt_store.h"
|
2
|
+
#include "frt_index.h"
|
3
|
+
#include "testhelper.h"
|
4
|
+
#include "test.h"
|
5
|
+
|
6
|
+
void test_compound_reader(TestCase *tc, void *data)
|
7
|
+
{
|
8
|
+
FrtStore *store = (FrtStore *)data;
|
9
|
+
char *p;
|
10
|
+
FrtOutStream *os = store->new_output(store, "cfile");
|
11
|
+
FrtInStream *is1;
|
12
|
+
FrtInStream *is2;
|
13
|
+
FrtStore *c_reader;
|
14
|
+
frt_os_write_vint(os, 2);
|
15
|
+
frt_os_write_u64(os, 29);
|
16
|
+
frt_os_write_string(os, "file1");
|
17
|
+
frt_os_write_u64(os, 33);
|
18
|
+
frt_os_write_string(os, "file2");
|
19
|
+
frt_os_write_u32(os, 20);
|
20
|
+
frt_os_write_string(os, "this is file 2");
|
21
|
+
frt_os_close(os);
|
22
|
+
|
23
|
+
c_reader = frt_open_cmpd_store(store, "cfile");
|
24
|
+
Aiequal(4, c_reader->length(c_reader, "file1"));
|
25
|
+
Aiequal(15, c_reader->length(c_reader, "file2"));
|
26
|
+
is1 = c_reader->open_input(c_reader, "file1");
|
27
|
+
is2 = c_reader->open_input(c_reader, "file2");
|
28
|
+
Aiequal(20, frt_is_read_u32(is1));
|
29
|
+
Asequal("this is file 2", p = frt_is_read_string(is2)); free(p);
|
30
|
+
frt_is_close(is1);
|
31
|
+
frt_is_close(is2);
|
32
|
+
frt_store_deref(c_reader);
|
33
|
+
}
|
34
|
+
|
35
|
+
void test_compound_writer(TestCase *tc, void *data)
|
36
|
+
{
|
37
|
+
FrtStore *store = (FrtStore *)data;
|
38
|
+
char *p;
|
39
|
+
FrtOutStream *os1 = store->new_output(store, "file1");
|
40
|
+
FrtOutStream *os2 = store->new_output(store, "file2");
|
41
|
+
FrtCompoundWriter *cw;
|
42
|
+
FrtInStream *is;
|
43
|
+
|
44
|
+
frt_os_write_u32(os1, 20);
|
45
|
+
frt_os_write_string(os2,"this is file2");
|
46
|
+
frt_os_close(os1);
|
47
|
+
frt_os_close(os2);
|
48
|
+
cw = frt_open_cw(store, (char *)"cfile");
|
49
|
+
frt_cw_add_file(cw, (char *)"file1");
|
50
|
+
frt_cw_add_file(cw, (char *)"file2");
|
51
|
+
frt_cw_close(cw);
|
52
|
+
|
53
|
+
is = store->open_input(store, "cfile");
|
54
|
+
Aiequal(2, frt_is_read_vint(is));
|
55
|
+
Aiequal(29, frt_is_read_u64(is));
|
56
|
+
Asequal("file1", p = frt_is_read_string(is)); free(p);
|
57
|
+
Aiequal(33, frt_is_read_u64(is));
|
58
|
+
Asequal("file2", p = frt_is_read_string(is)); free(p);
|
59
|
+
Aiequal(20, frt_is_read_u32(is));
|
60
|
+
Asequal("this is file2", p = frt_is_read_string(is)); free(p);
|
61
|
+
|
62
|
+
frt_is_close(is);
|
63
|
+
}
|
64
|
+
|
65
|
+
void test_compound_io(TestCase *tc, void *data)
|
66
|
+
{
|
67
|
+
FrtStore *c_reader;
|
68
|
+
FrtInStream *is1, *is2, *is3;
|
69
|
+
FrtStore *store = (FrtStore *)data;
|
70
|
+
FrtCompoundWriter *cw;
|
71
|
+
char *p;
|
72
|
+
FrtOutStream *os1 = store->new_output(store, "file1");
|
73
|
+
FrtOutStream *os2 = store->new_output(store, "file2");
|
74
|
+
FrtOutStream *os3 = store->new_output(store, "file3");
|
75
|
+
char long_string[10000];
|
76
|
+
const char *short_string = "this is a short string";
|
77
|
+
int slen = (int)strlen(short_string);
|
78
|
+
int i;
|
79
|
+
|
80
|
+
for (i = 0; i < 20; i++) {
|
81
|
+
frt_os_write_u32(os1, rand()%10000);
|
82
|
+
}
|
83
|
+
|
84
|
+
for (i = 0; i < 10000 - slen; i += slen) {
|
85
|
+
sprintf(long_string + i, "%s", short_string);
|
86
|
+
}
|
87
|
+
long_string[i] = 0;
|
88
|
+
frt_os_write_string(os2, long_string);
|
89
|
+
frt_os_write_string(os3, short_string);
|
90
|
+
frt_os_close(os1);
|
91
|
+
frt_os_close(os2);
|
92
|
+
frt_os_close(os3);
|
93
|
+
cw = frt_open_cw(store, (char *)"cfile");
|
94
|
+
frt_cw_add_file(cw, (char *)"file1");
|
95
|
+
frt_cw_add_file(cw, (char *)"file2");
|
96
|
+
frt_cw_add_file(cw, (char *)"file3");
|
97
|
+
frt_cw_close(cw);
|
98
|
+
|
99
|
+
c_reader = frt_open_cmpd_store(store, "cfile");
|
100
|
+
is1 = c_reader->open_input(c_reader, "file1");
|
101
|
+
for (i = 0; i < 20; i++) {
|
102
|
+
Assert(frt_is_read_u32(is1) < 10000, "should be a rand between 0 and 10000");
|
103
|
+
}
|
104
|
+
frt_is_close(is1);
|
105
|
+
is2 = c_reader->open_input(c_reader, "file2");
|
106
|
+
Asequal(long_string, p = frt_is_read_string(is2)); free(p);
|
107
|
+
frt_is_close(is2);
|
108
|
+
is3 = c_reader->open_input(c_reader, "file3");
|
109
|
+
Asequal(short_string, p = frt_is_read_string(is3)); free(p);
|
110
|
+
frt_is_close(is3);
|
111
|
+
|
112
|
+
frt_store_deref(c_reader);
|
113
|
+
}
|
114
|
+
|
115
|
+
#define MAX_TEST_WORDS 50
|
116
|
+
#define TEST_FILE_CNT 100
|
117
|
+
|
118
|
+
void test_compound_io_many_files(TestCase *tc, void *data)
|
119
|
+
{
|
120
|
+
static const int MAGIC = 250777;
|
121
|
+
|
122
|
+
FrtStore *store = (FrtStore *)data;
|
123
|
+
char buf[MAX_TEST_WORDS * (TEST_WORD_LIST_MAX_LEN + 1)];
|
124
|
+
char *str;
|
125
|
+
int i;
|
126
|
+
FrtOutStream *os;
|
127
|
+
FrtInStream *is;
|
128
|
+
FrtCompoundWriter *cw;
|
129
|
+
FrtStore *c_reader;
|
130
|
+
|
131
|
+
cw = frt_open_cw(store, (char *)"_.cfs");
|
132
|
+
for (i = 0; i < TEST_FILE_CNT; i++) {
|
133
|
+
sprintf(buf, "_%d.txt", i);
|
134
|
+
frt_cw_add_file(cw, buf);
|
135
|
+
os = store->new_output(store, buf);
|
136
|
+
frt_os_write_string(os, make_random_string(buf, MAX_TEST_WORDS));
|
137
|
+
frt_os_write_vint(os, MAGIC);
|
138
|
+
frt_os_close(os);
|
139
|
+
}
|
140
|
+
frt_cw_close(cw);
|
141
|
+
|
142
|
+
c_reader = frt_open_cmpd_store(store, "_.cfs");
|
143
|
+
for (i = 0; i < TEST_FILE_CNT; i++) {
|
144
|
+
sprintf(buf, "_%d.txt", i);
|
145
|
+
is = c_reader->open_input(c_reader, buf);
|
146
|
+
str = frt_is_read_string(is);
|
147
|
+
|
148
|
+
free(str);
|
149
|
+
Aiequal(MAGIC, frt_is_read_vint(is));
|
150
|
+
Aiequal(frt_is_length(is), frt_is_pos(is));
|
151
|
+
frt_is_close(is);
|
152
|
+
}
|
153
|
+
frt_store_deref(c_reader);
|
154
|
+
}
|
155
|
+
|
156
|
+
TestSuite *ts_compound_io(TestSuite *suite)
|
157
|
+
{
|
158
|
+
FrtStore *store = frt_open_ram_store();
|
159
|
+
|
160
|
+
suite = ADD_SUITE(suite);
|
161
|
+
|
162
|
+
tst_run_test(suite, test_compound_reader, store);
|
163
|
+
tst_run_test(suite, test_compound_writer, store);
|
164
|
+
tst_run_test(suite, test_compound_io, store);
|
165
|
+
tst_run_test(suite, test_compound_io_many_files, store);
|
166
|
+
|
167
|
+
frt_store_deref(store);
|
168
|
+
|
169
|
+
return suite;
|
170
|
+
}
|
@@ -0,0 +1,156 @@
|
|
1
|
+
#include "frt_document.h"
|
2
|
+
#include "test.h"
|
3
|
+
|
4
|
+
void test_df_standard(TestCase *tc, void *data)
|
5
|
+
{
|
6
|
+
char *s;
|
7
|
+
FrtDocField *df;
|
8
|
+
(void)data;
|
9
|
+
|
10
|
+
df = frt_df_add_data(frt_df_new(rb_intern("title")), frt_estrdup("Life of Pi"));
|
11
|
+
df->destroy_data = true;
|
12
|
+
Aiequal(1, df->size);
|
13
|
+
Asequal("title", rb_id2name(df->name));
|
14
|
+
Asequal("Life of Pi", df->data[0]);
|
15
|
+
Aiequal(strlen("Life of Pi"), df->lengths[0]);
|
16
|
+
Asequal("title: \"Life of Pi\"", s = frt_df_to_s(df));
|
17
|
+
Afequal(1.0, df->boost);
|
18
|
+
free(s);
|
19
|
+
frt_df_destroy(df);
|
20
|
+
|
21
|
+
df = frt_df_add_data_len(frt_df_new(rb_intern("title")), (char *)"new title", 9);
|
22
|
+
Aiequal(1, df->size);
|
23
|
+
Asequal("title", rb_id2name(df->name));
|
24
|
+
Asequal("new title", df->data[0]);
|
25
|
+
Aiequal(9, df->lengths[0]);
|
26
|
+
frt_df_destroy(df);
|
27
|
+
}
|
28
|
+
|
29
|
+
void test_df_multi_fields(TestCase *tc, void *data)
|
30
|
+
{
|
31
|
+
int i;
|
32
|
+
char *s;
|
33
|
+
FrtDocField *df;
|
34
|
+
(void)data;
|
35
|
+
|
36
|
+
df = frt_df_add_data(frt_df_new(rb_intern("title")), frt_estrdup("Vernon God Little"));
|
37
|
+
df->destroy_data = true;
|
38
|
+
Aiequal(1, df->size);
|
39
|
+
Asequal("title", rb_id2name(df->name));
|
40
|
+
Asequal("Vernon God Little", df->data[0]);
|
41
|
+
Aiequal(strlen("Vernon God Little"), df->lengths[0]);
|
42
|
+
|
43
|
+
frt_df_add_data(df, frt_estrdup("some more data"));
|
44
|
+
Aiequal(2, df->size);
|
45
|
+
Asequal("title: [\"Vernon God Little\", \"some more data\"]",
|
46
|
+
s = frt_df_to_s(df));
|
47
|
+
free(s);
|
48
|
+
frt_df_add_data_len(df, frt_estrdup("and more data"), 14);
|
49
|
+
Aiequal(3, df->size);
|
50
|
+
Asequal("title", rb_id2name(df->name));
|
51
|
+
Asequal("Vernon God Little", df->data[0]);
|
52
|
+
Asequal("some more data", df->data[1]);
|
53
|
+
Asequal("and more data", df->data[2]);
|
54
|
+
|
55
|
+
frt_df_destroy(df);
|
56
|
+
|
57
|
+
df = frt_df_add_data(frt_df_new(rb_intern("data")), frt_estrdup("start"));
|
58
|
+
df->destroy_data = true;
|
59
|
+
Aiequal(1, df->size);
|
60
|
+
for (i = 0; i < 1000; i++) {
|
61
|
+
char buf[100];
|
62
|
+
sprintf(buf, "<<%d>>", i);
|
63
|
+
frt_df_add_data(df, frt_estrdup(buf));
|
64
|
+
Aiequal(i + 2, df->size);
|
65
|
+
}
|
66
|
+
frt_df_destroy(df);
|
67
|
+
}
|
68
|
+
|
69
|
+
void test_doc(TestCase *tc, void *data)
|
70
|
+
{
|
71
|
+
int i;
|
72
|
+
FrtDocument *doc;
|
73
|
+
FrtDocField *df;
|
74
|
+
(void)data;
|
75
|
+
|
76
|
+
doc = frt_doc_new();
|
77
|
+
frt_doc_add_field(doc, frt_df_add_data(frt_df_new(rb_intern("title")), (char *)"title"));
|
78
|
+
Aiequal(1, doc->size);
|
79
|
+
df = frt_df_add_data(frt_df_new(rb_intern("data")), (char *)"data1");
|
80
|
+
frt_df_add_data(df, (char *)"data2");
|
81
|
+
frt_df_add_data(df, (char *)"data3");
|
82
|
+
frt_df_add_data(df, (char *)"data4");
|
83
|
+
frt_doc_add_field(doc, df);
|
84
|
+
Aiequal(2, doc->size);
|
85
|
+
Asequal("title", rb_id2name(frt_doc_get_field(doc, rb_intern("title"))->name));
|
86
|
+
Aiequal(1, frt_doc_get_field(doc, rb_intern("title"))->size);
|
87
|
+
Asequal("title", frt_doc_get_field(doc, rb_intern("title"))->data[0]);
|
88
|
+
Asequal("data", rb_id2name(frt_doc_get_field(doc, rb_intern("data"))->name));
|
89
|
+
Aiequal(4, frt_doc_get_field(doc, rb_intern("data"))->size);
|
90
|
+
Asequal("data1", frt_doc_get_field(doc, rb_intern("data"))->data[0]);
|
91
|
+
Asequal("data2", frt_doc_get_field(doc, rb_intern("data"))->data[1]);
|
92
|
+
Asequal("data3", frt_doc_get_field(doc, rb_intern("data"))->data[2]);
|
93
|
+
Asequal("data4", frt_doc_get_field(doc, rb_intern("data"))->data[3]);
|
94
|
+
Afequal(1.0, doc->boost);
|
95
|
+
frt_doc_destroy(doc);
|
96
|
+
|
97
|
+
doc = frt_doc_new();
|
98
|
+
for (i = 0; i < 1000; i++) {
|
99
|
+
char buf[100];
|
100
|
+
char *bufc;
|
101
|
+
sprintf(buf, "<<%d>>", i);
|
102
|
+
bufc = frt_estrdup(buf);
|
103
|
+
df = frt_df_add_data(frt_df_new(rb_intern(bufc)), bufc);
|
104
|
+
df->destroy_data = true;
|
105
|
+
frt_doc_add_field(doc, df);
|
106
|
+
Aiequal(i + 1, doc->size);
|
107
|
+
}
|
108
|
+
|
109
|
+
for (i = 0; i < 1000; i++) {
|
110
|
+
char buf[100];
|
111
|
+
sprintf(buf, "<<%d>>", i);
|
112
|
+
Aiequal(1, frt_doc_get_field(doc, rb_intern(buf))->size);
|
113
|
+
Aiequal(strlen(buf), frt_doc_get_field(doc, rb_intern(buf))->lengths[0]);
|
114
|
+
Asequal(buf, frt_doc_get_field(doc, rb_intern(buf))->data[0]);
|
115
|
+
}
|
116
|
+
frt_doc_destroy(doc);
|
117
|
+
}
|
118
|
+
|
119
|
+
void test_double_field_exception(TestCase *tc, void *data)
|
120
|
+
{
|
121
|
+
volatile bool exception_thrown = false;
|
122
|
+
FrtDocument *doc;
|
123
|
+
FrtDocField *volatile df = NULL;
|
124
|
+
(void)data;
|
125
|
+
|
126
|
+
doc = frt_doc_new();
|
127
|
+
frt_doc_add_field(doc, frt_df_add_data(frt_df_new(rb_intern("title")), (char *)"title"));
|
128
|
+
|
129
|
+
FRT_TRY
|
130
|
+
df = frt_df_add_data_len(frt_df_new(rb_intern("title")), (char *)"title", 5);
|
131
|
+
frt_doc_add_field(doc, df);
|
132
|
+
case FRT_EXCEPTION:
|
133
|
+
exception_thrown = true;
|
134
|
+
FRT_HANDLED();
|
135
|
+
break;
|
136
|
+
case FRT_FINALLY:
|
137
|
+
frt_df_destroy(df);
|
138
|
+
break;
|
139
|
+
FRT_ENDTRY
|
140
|
+
|
141
|
+
Atrue(exception_thrown);
|
142
|
+
|
143
|
+
frt_doc_destroy(doc);
|
144
|
+
}
|
145
|
+
|
146
|
+
TestSuite *ts_document(TestSuite *suite)
|
147
|
+
{
|
148
|
+
suite = ADD_SUITE(suite);
|
149
|
+
|
150
|
+
tst_run_test(suite, test_df_standard, NULL);
|
151
|
+
tst_run_test(suite, test_df_multi_fields, NULL);
|
152
|
+
tst_run_test(suite, test_doc, NULL);
|
153
|
+
tst_run_test(suite, test_double_field_exception, NULL);
|
154
|
+
|
155
|
+
return suite;
|
156
|
+
}
|
@@ -0,0 +1,244 @@
|
|
1
|
+
#include "frt_except.h"
|
2
|
+
#include "test.h"
|
3
|
+
#include "fio_tmpfile.h"
|
4
|
+
|
5
|
+
static const char *msg1 = "Message One";
|
6
|
+
static const char *msg2 = "Message Two";
|
7
|
+
|
8
|
+
static void raise_exception()
|
9
|
+
{
|
10
|
+
FRT_RAISE(FRT_EXCEPTION, "%s", msg1);
|
11
|
+
}
|
12
|
+
|
13
|
+
static void inner_try(TestCase *tc)
|
14
|
+
{
|
15
|
+
volatile bool exception_handled = false;
|
16
|
+
volatile bool ioerror_called = false;
|
17
|
+
|
18
|
+
FRT_TRY
|
19
|
+
raise_exception();
|
20
|
+
Assert(false, "Exception should have been raised");
|
21
|
+
break;
|
22
|
+
case FRT_EXCEPTION:
|
23
|
+
/* This should be called */
|
24
|
+
Astrstr(xcontext.msg, msg1);
|
25
|
+
exception_handled = true;
|
26
|
+
FRT_HANDLED();
|
27
|
+
FRT_RAISE(FRT_IO_ERROR, "%s", msg2);
|
28
|
+
Assert(false, "Exception should have been raised");
|
29
|
+
break;
|
30
|
+
case FRT_IO_ERROR:
|
31
|
+
ioerror_called = true;
|
32
|
+
break;
|
33
|
+
default:
|
34
|
+
Assert(false, "Exception should have been known");
|
35
|
+
break;
|
36
|
+
case FRT_FINALLY:
|
37
|
+
Assert(exception_handled, "%s", "Exception wasn't handled");
|
38
|
+
Assert(ioerror_called, "IO_ERROR wasn't called");
|
39
|
+
FRT_ENDTRY
|
40
|
+
}
|
41
|
+
|
42
|
+
static void test_nested_except(TestCase *tc, void *data)
|
43
|
+
{
|
44
|
+
volatile bool ioerror_handled = false;
|
45
|
+
bool finally_handled = false;
|
46
|
+
(void)data;
|
47
|
+
|
48
|
+
FRT_TRY
|
49
|
+
inner_try(tc);
|
50
|
+
Assert(false, "Exception should have been raised");
|
51
|
+
break;
|
52
|
+
case FRT_IO_ERROR:
|
53
|
+
/* This should be called */
|
54
|
+
Astrstr(xcontext.msg, msg2);
|
55
|
+
ioerror_handled = true;
|
56
|
+
FRT_HANDLED();
|
57
|
+
break;
|
58
|
+
case FRT_EXCEPTION:
|
59
|
+
/* This should be called */
|
60
|
+
Assert(false, "Exception should not have been raised");
|
61
|
+
break;
|
62
|
+
default:
|
63
|
+
Assert(false, "Exception should have been known");
|
64
|
+
break;
|
65
|
+
case FRT_FINALLY:
|
66
|
+
finally_handled = true;
|
67
|
+
FRT_ENDTRY
|
68
|
+
Assert(ioerror_handled, "Exception wasn't handled");
|
69
|
+
Assert(finally_handled, "Finally wasn't handled");
|
70
|
+
}
|
71
|
+
|
72
|
+
static void test_function_except(TestCase *tc, void *data)
|
73
|
+
{
|
74
|
+
volatile bool exception_handled = false;
|
75
|
+
bool finally_handled = false;
|
76
|
+
(void)data; /* suppress warning */
|
77
|
+
|
78
|
+
FRT_TRY
|
79
|
+
raise_exception();
|
80
|
+
Assert(false, "Exception should have been raised");
|
81
|
+
break;
|
82
|
+
case FRT_EXCEPTION:
|
83
|
+
/* This should be called */
|
84
|
+
Astrstr(xcontext.msg, msg1);
|
85
|
+
#if defined(__func__) && defined(FRT_HAS_VARARGS)
|
86
|
+
Astrstr("raise_exception", msg1);
|
87
|
+
#endif
|
88
|
+
exception_handled = true;
|
89
|
+
FRT_HANDLED();
|
90
|
+
break;
|
91
|
+
default:
|
92
|
+
Assert(false, "Exception should have been known");
|
93
|
+
break;
|
94
|
+
case FRT_FINALLY:
|
95
|
+
finally_handled = true;
|
96
|
+
FRT_ENDTRY
|
97
|
+
Assert(exception_handled, "Exception wasn't handled");
|
98
|
+
Assert(finally_handled, "Finally wasn't handled");
|
99
|
+
}
|
100
|
+
|
101
|
+
static void test_simple_except(TestCase *tc, void *data)
|
102
|
+
{
|
103
|
+
volatile bool exception_handled = false;
|
104
|
+
bool finally_handled = false;
|
105
|
+
(void)data; /* suppress warning */
|
106
|
+
|
107
|
+
FRT_TRY
|
108
|
+
FRT_RAISE(FRT_EXCEPTION, "error message %s %d", "string", 20);
|
109
|
+
Assert(false, "Exception should have been raised");
|
110
|
+
break;
|
111
|
+
case FRT_EXCEPTION:
|
112
|
+
/* This should be called */
|
113
|
+
Astrstr(xcontext.msg, "error message string 20");
|
114
|
+
#if defined(__func__) && defined(FRT_HAS_VARARGS)
|
115
|
+
Astrstr(xcontext.msg, __func__);
|
116
|
+
#endif
|
117
|
+
#if defined(FRT_HAS_VARARGS)
|
118
|
+
Astrstr(xcontext.msg, __FILE__);
|
119
|
+
#endif
|
120
|
+
exception_handled = true;
|
121
|
+
FRT_HANDLED();
|
122
|
+
break;
|
123
|
+
default:
|
124
|
+
Assert(false, "Exception should have been known");
|
125
|
+
break;
|
126
|
+
case FRT_FINALLY:
|
127
|
+
finally_handled = true;
|
128
|
+
FRT_ENDTRY
|
129
|
+
Assert(exception_handled, "Exception wasn't handled");
|
130
|
+
Assert(finally_handled, "Finally wasn't handled");
|
131
|
+
}
|
132
|
+
|
133
|
+
static void try_xfinally1(TestCase *tc)
|
134
|
+
{
|
135
|
+
bool finally_handled = false;
|
136
|
+
|
137
|
+
FRT_TRY
|
138
|
+
Assert(true, "No exception raised");
|
139
|
+
FRT_XFINALLY
|
140
|
+
FRT_RAISE(EXCEPTION, "%s", msg1);
|
141
|
+
finally_handled = true;
|
142
|
+
FRT_XENDTRY
|
143
|
+
Assert(finally_handled, "Finally wasn't handled");
|
144
|
+
Atrue(finally_handled);
|
145
|
+
}
|
146
|
+
|
147
|
+
static void try_xfinally2(TestCase *tc)
|
148
|
+
{
|
149
|
+
bool finally_handled = false;
|
150
|
+
|
151
|
+
FRT_TRY
|
152
|
+
FRT_RAISE(EXCEPTION, "%s", msg1);
|
153
|
+
Assert(false, "Exception should have been raised");
|
154
|
+
FRT_XFINALLY
|
155
|
+
FRT_RAISE(EXCEPTION, "%s", msg1);
|
156
|
+
finally_handled = true;
|
157
|
+
FRT_XENDTRY
|
158
|
+
Assert(finally_handled, "Finally wasn't handled");
|
159
|
+
Atrue(finally_handled);
|
160
|
+
}
|
161
|
+
|
162
|
+
static void try_xcatchall(TestCase *tc)
|
163
|
+
{
|
164
|
+
bool catchall_handled = false;
|
165
|
+
|
166
|
+
FRT_TRY
|
167
|
+
FRT_RAISE(EXCEPTION, "%s", msg1);
|
168
|
+
Assert(false, "Exception should have been raised");
|
169
|
+
FRT_XCATCHALL
|
170
|
+
FRT_HANDLED();
|
171
|
+
FRT_RAISE(EXCEPTION, "%s", msg1);
|
172
|
+
catchall_handled = true;
|
173
|
+
FRT_XENDTRY
|
174
|
+
Assert(catchall_handled, "Finally wasn't handled");
|
175
|
+
Atrue(catchall_handled);
|
176
|
+
}
|
177
|
+
|
178
|
+
static void test_xfinally(TestCase *tc, void *data)
|
179
|
+
{
|
180
|
+
volatile bool exception_handled = false;
|
181
|
+
bool finally_handled = false;
|
182
|
+
(void)data; /* suppress warning */
|
183
|
+
|
184
|
+
FRT_TRY
|
185
|
+
try_xfinally1(tc);
|
186
|
+
try_xfinally2(tc);
|
187
|
+
try_xcatchall(tc);
|
188
|
+
Assert(false, "Exception should have been raised");
|
189
|
+
break;
|
190
|
+
case FRT_EXCEPTION:
|
191
|
+
/* This should be called */
|
192
|
+
Astrstr(xcontext.msg, msg1);
|
193
|
+
exception_handled = true;
|
194
|
+
FRT_HANDLED();
|
195
|
+
break;
|
196
|
+
default:
|
197
|
+
Assert(false, "Exception should have been known");
|
198
|
+
break;
|
199
|
+
case FRT_FINALLY:
|
200
|
+
finally_handled = true;
|
201
|
+
FRT_ENDTRY
|
202
|
+
Assert(exception_handled, "Exception wasn't handled");
|
203
|
+
Assert(finally_handled, "Finally wasn't handled");
|
204
|
+
}
|
205
|
+
|
206
|
+
static void test_uncaught_except(TestCase *tc, void *data)
|
207
|
+
{
|
208
|
+
bool old_abort_setting = frt_x_abort_on_exception;
|
209
|
+
FILE *old_stream_setting = frt_x_exception_stream;
|
210
|
+
int tfd = fio_tmpfile();
|
211
|
+
FILE *exception_output = fdopen(tfd, "w+");
|
212
|
+
(void)data, (void)tc; /* suppress warning */
|
213
|
+
|
214
|
+
|
215
|
+
frt_x_abort_on_exception = false;
|
216
|
+
frt_x_exception_stream = exception_output;
|
217
|
+
|
218
|
+
/* Unhandled exception in try block */
|
219
|
+
FRT_TRY
|
220
|
+
raise_exception();
|
221
|
+
FRT_ENDTRY
|
222
|
+
Assert(frt_x_has_aborted, "Unhandled exception in try block didn't abort");
|
223
|
+
|
224
|
+
/* Unhandled exception outside of try block */
|
225
|
+
frt_x_has_aborted = false;
|
226
|
+
FRT_RAISE(FRT_EXCEPTION, "%s:", msg1);
|
227
|
+
Assert(frt_x_has_aborted, "Unhandled exception didn't cause an abort");
|
228
|
+
|
229
|
+
frt_x_abort_on_exception = old_abort_setting;
|
230
|
+
frt_x_exception_stream = old_stream_setting;
|
231
|
+
fclose(exception_output);
|
232
|
+
}
|
233
|
+
|
234
|
+
TestSuite *ts_except(TestSuite *suite)
|
235
|
+
{
|
236
|
+
suite = ADD_SUITE(suite);
|
237
|
+
|
238
|
+
tst_run_test(suite, test_simple_except, NULL);
|
239
|
+
tst_run_test(suite, test_function_except, NULL);
|
240
|
+
tst_run_test(suite, test_nested_except, NULL);
|
241
|
+
tst_run_test(suite, test_xfinally, NULL);
|
242
|
+
tst_run_test(suite, test_uncaught_except, NULL);
|
243
|
+
return suite;
|
244
|
+
}
|