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,416 @@
|
|
1
|
+
#ifndef TEST_H
|
2
|
+
#define TEST_H
|
3
|
+
|
4
|
+
#include "frt_global.h"
|
5
|
+
#include "frt_search.h"
|
6
|
+
#include <stdarg.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <stdlib.h>
|
9
|
+
#include <string.h>
|
10
|
+
|
11
|
+
/**
|
12
|
+
* A test suite is a linked-list of sub-suites that are made up of test cases
|
13
|
+
* which contain a list of assertions.
|
14
|
+
*/
|
15
|
+
typedef struct TestSubSuite
|
16
|
+
{
|
17
|
+
char *name;
|
18
|
+
int num_test;
|
19
|
+
int failed;
|
20
|
+
int not_run;
|
21
|
+
int not_impl;
|
22
|
+
struct TestSubSuite *next;
|
23
|
+
} TestSubSuite;
|
24
|
+
|
25
|
+
typedef struct TestSuite
|
26
|
+
{
|
27
|
+
TestSubSuite *head;
|
28
|
+
TestSubSuite *tail;
|
29
|
+
} TestSuite;
|
30
|
+
|
31
|
+
typedef struct TestCase
|
32
|
+
{
|
33
|
+
const char *name;
|
34
|
+
int failed;
|
35
|
+
TestSubSuite *suite;
|
36
|
+
} TestCase;
|
37
|
+
|
38
|
+
/* a test function needs to match this signature */
|
39
|
+
typedef void (*test_func)(TestCase *tc, void *data);
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Add a sub-suite to the linked-list of test suites. This function is usually
|
43
|
+
* used like this;
|
44
|
+
*
|
45
|
+
* TestSuite *ts_<sub-suite-name>(TestSuite *suite)
|
46
|
+
* {
|
47
|
+
* suite = ADD_SUITE(suite);
|
48
|
+
*
|
49
|
+
* tst_run_test(suite, test_<test-name>, NULL);
|
50
|
+
*
|
51
|
+
* return suite;
|
52
|
+
* }
|
53
|
+
*
|
54
|
+
* This function then needs to be included in the test_list in test/all_tests.h
|
55
|
+
*
|
56
|
+
* @param the previous suite that was added to which we will add this suite
|
57
|
+
* @param the suites name. This will be displayed in the test output. Use the
|
58
|
+
* ADD_SUITE macro if you want the file_name to be used as the name for the
|
59
|
+
* suite. This will suffice in most cases.
|
60
|
+
* @return the current suite
|
61
|
+
*/
|
62
|
+
extern TestSuite *tst_add_suite(TestSuite *suite, const char *suite_name);
|
63
|
+
#define ADD_SUITE(suite) tst_add_suite(suite, __FILE__);
|
64
|
+
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Run a test function. This function should be run from within
|
68
|
+
* ts_<sub-suite-name> function. See tst_add_suite.
|
69
|
+
*
|
70
|
+
* @param suite the test suite to include this test in
|
71
|
+
* @param func the test function to call
|
72
|
+
* @param value a parameter to pass to the test function. If you need to pass
|
73
|
+
* more than one value to the function use an argument struct
|
74
|
+
* @param test_name the name of the test which will be displayed in the error
|
75
|
+
* output. Use the tst_run_tests macro if you just want the name of the
|
76
|
+
* function to be used. This will suffice in most cases.
|
77
|
+
*/
|
78
|
+
extern void tst_run_test_with_name(TestSuite *suite, test_func func, void *value, const char *test_name);
|
79
|
+
#define tst_run_test(ts, f, val) tst_run_test_with_name(ts, f, (val), (char *)#f)
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Add a message to the test output diagnostics. This function should be used
|
83
|
+
* like this;
|
84
|
+
*
|
85
|
+
* static void test_something(TestCase *tc, void *data)
|
86
|
+
* {
|
87
|
+
* // do some stuff
|
88
|
+
*
|
89
|
+
* if (!Atrue(a->eq(b)) {
|
90
|
+
* // Error diagnostics will already be logged, now we just want to add a
|
91
|
+
* //little more information
|
92
|
+
* TMsg("%s != %s", a->to_s(a), b->to_s(b));
|
93
|
+
* }
|
94
|
+
* ///...
|
95
|
+
* }
|
96
|
+
*
|
97
|
+
* @param fmt the format for the message. This is exactly the same as the
|
98
|
+
* format you would pass to printf.
|
99
|
+
* @param ... the arguments to print in the format
|
100
|
+
*/
|
101
|
+
extern void Tmsg(const char *fmt, ...);
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Same as Tmsg but you must add your own new-lines and formatting.
|
105
|
+
*
|
106
|
+
* @param fmt the format for the message. This is exactly the same as the
|
107
|
+
* format you would pass to printf.
|
108
|
+
* @param ... the arguments to print in the format
|
109
|
+
*/
|
110
|
+
extern void Tmsg_nf(const char *fmt, ...);
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Add a message to the test output diagnostics. See Tmsg for usage. vTmsg is
|
114
|
+
* to Tmsg want vprintf is to printf
|
115
|
+
*/
|
116
|
+
extern void vTmsg(const char *fmt, va_list args);
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Test that a function raises a particular exception. Pass a function to call
|
120
|
+
* that should raise the exception if everything is working as expected. You
|
121
|
+
* can use the _args_ parameter to pass arguments to the function.
|
122
|
+
*
|
123
|
+
* @param line_num the line number this function is called from
|
124
|
+
* @param tc the test case to record the diagnostics
|
125
|
+
* @param err_code the exception you expect to be raised
|
126
|
+
* @param func the function to call that is supposed to raise the exception
|
127
|
+
* @param args the args to pass to the function
|
128
|
+
* @return true if the test passed
|
129
|
+
*/
|
130
|
+
extern bool tst_raise(int line_num, TestCase *tc, const int err_code,
|
131
|
+
void (*func)(void *args), void *args);
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Test that two integers are equal. If they are not equal then add an error
|
135
|
+
* test diagnostics. You should use the Aiequal(expected, actual) macro to
|
136
|
+
* call this function so that the line number will be added automatically.
|
137
|
+
*
|
138
|
+
* @param line_num the line number this function is called from
|
139
|
+
* @param tc the test case to record the diagnostics
|
140
|
+
* @param expected the expected value
|
141
|
+
* @param actual the actual value
|
142
|
+
* @return true if the test passed
|
143
|
+
*/
|
144
|
+
extern bool tst_int_equal(int line_num, TestCase *tc, const frt_u64 expected,
|
145
|
+
const frt_u64 actual);
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Test that two floats (or doubles) are equal (within 0.001%). If they are
|
149
|
+
* not equal then add an error test diagnostics. You should use the
|
150
|
+
* Afequal(expected, actual) macro to call this function so that the
|
151
|
+
* line number will be added automatically. A delta is used to account for
|
152
|
+
* floating point error. The test for equality is;
|
153
|
+
*
|
154
|
+
* <pre>
|
155
|
+
*
|
156
|
+
* diff = (expected - actual) / expected;
|
157
|
+
* if (abs(diff) < 0.00001) {
|
158
|
+
* return true;
|
159
|
+
* }
|
160
|
+
*
|
161
|
+
* </pre>
|
162
|
+
*
|
163
|
+
* To use a different delta value use tst_flt_delta_equal or the macro
|
164
|
+
* Afdequal.
|
165
|
+
*
|
166
|
+
* @param line_num the line number this function is called from
|
167
|
+
* @param tc the test case to record the diagnostics
|
168
|
+
* @param expected the expected value
|
169
|
+
* @param actual the actual value
|
170
|
+
* @return true if the test passed
|
171
|
+
*/
|
172
|
+
extern bool tst_flt_equal(int line_num, TestCase *tc, const double expected,
|
173
|
+
const double actual);
|
174
|
+
|
175
|
+
/**
|
176
|
+
* Test that two floats (or doubles) are equal (within +delta+/100%). If they
|
177
|
+
* are not equal then add an error test diagnostics. You should use the
|
178
|
+
* Afdequal(expected, actual, delta) macro to call this function so that the
|
179
|
+
* line number will be added automatically. The test for equality is;
|
180
|
+
*
|
181
|
+
* <pre>
|
182
|
+
*
|
183
|
+
* diff = (expected - actual) / expected;
|
184
|
+
* if (abs(diff) < delta) {
|
185
|
+
* return true;
|
186
|
+
* }
|
187
|
+
*
|
188
|
+
* </pre>
|
189
|
+
*
|
190
|
+
* To use the default delta value use tst_flt_equal or the macro Afequal.
|
191
|
+
*
|
192
|
+
* @param line_num the line number this function is called from
|
193
|
+
* @param tc the test case to record the diagnostics
|
194
|
+
* @param expected the expected value
|
195
|
+
* @param actual the actual value
|
196
|
+
* @param delta the allowed fraction of difference
|
197
|
+
* @return true if the test passed
|
198
|
+
*/
|
199
|
+
extern bool tst_flt_delta_equal(int line_num, TestCase *tc, const double expected,
|
200
|
+
const double actual, const double delta);
|
201
|
+
|
202
|
+
/**
|
203
|
+
* Test that two strings are equal. If they are not equal then add an error to
|
204
|
+
* the test diagnostics. You should use the Asequal(expected, actual) macro to
|
205
|
+
* call this function so that the line number will be added automatically.
|
206
|
+
*
|
207
|
+
* @param line_num the line number this function is called from
|
208
|
+
* @param tc the test case to record the diagnostics
|
209
|
+
* @param expected the expected value
|
210
|
+
* @param actual the actual value
|
211
|
+
* @return true if the test passed
|
212
|
+
*/
|
213
|
+
extern bool tst_str_equal(int line_num, TestCase *tc, const char *expected,
|
214
|
+
const char *actual);
|
215
|
+
|
216
|
+
/**
|
217
|
+
* Test one string contains another string. This test is similar to the
|
218
|
+
* Standard C strstr function. If haystack doesn't contain needle then add an
|
219
|
+
* error to the test diagnostics. You should use the Astrstr(haystack, needle)
|
220
|
+
* macro to call this function so that the line number will be added
|
221
|
+
* automatically.
|
222
|
+
*
|
223
|
+
* @param line_num the line number this function is called from
|
224
|
+
* @param tc the test case to record the diagnostics
|
225
|
+
* @param haystack the string to search in
|
226
|
+
* @param needle the string to search for
|
227
|
+
* @return true if the test passed
|
228
|
+
*/
|
229
|
+
extern bool tst_strstr(int line_num, TestCase *tc, const char *haystack,
|
230
|
+
const char *needle);
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Test that two arrays of integers are equal, ie the have the same elements
|
234
|
+
* for up to +size+ elements. If they are not equal then add an error to the
|
235
|
+
* test diagnostics. You should use the Aaiequal(expected, actual, size) macro
|
236
|
+
* to call this function so that the line number will be added automatically.
|
237
|
+
*
|
238
|
+
* @param line_num the line number this function is called from
|
239
|
+
* @param tc the test case to record the diagnostics
|
240
|
+
* @param expected the expected value
|
241
|
+
* @param actual the actual value
|
242
|
+
* @param size the number of elements in the array. Both arrays should have at
|
243
|
+
* least this number of elements allocated or you will get memory overflow
|
244
|
+
* @return true if the test passed
|
245
|
+
*/
|
246
|
+
extern bool tst_arr_int_equal(int line_num, TestCase *tc, const int *expected,
|
247
|
+
const int *actual, int size);
|
248
|
+
|
249
|
+
/**
|
250
|
+
* Test that two arrays of strings are equal, ie the have the same elements
|
251
|
+
* for up to +size+ elements. If they are not equal then add an error to the
|
252
|
+
* test diagnostics. You should use the Aasequal(expected, actual, size) macro
|
253
|
+
* to call this function so that the line number will be added automatically.
|
254
|
+
*
|
255
|
+
* @param line_num the line number this function is called from
|
256
|
+
* @param tc the test case to record the diagnostics
|
257
|
+
* @param expected the expected value
|
258
|
+
* @param actual the actual value
|
259
|
+
* @param size the number of elements in the array. Both arrays should have at
|
260
|
+
* least this number of elements allocated or you will get memory overflow
|
261
|
+
* @return true if the test passed
|
262
|
+
*/
|
263
|
+
extern bool tst_arr_str_equal(int line_num, TestCase *tc, const char **expected,
|
264
|
+
const char **actual, int size);
|
265
|
+
|
266
|
+
/**
|
267
|
+
* Test that two strings are equal up to +n+ bytes. If they are not equal then
|
268
|
+
* add an error to the test diagnostics. You should use the Asnequal(expected,
|
269
|
+
* actual, bytes) macro to call this function so that the line number will be
|
270
|
+
* added automatically. For example Asnequal("Discovery", "Discotheque", 5)
|
271
|
+
* will pass and return try but Asnequal("Discovery", "Discotheque", 6) will
|
272
|
+
* fail and return false.
|
273
|
+
*
|
274
|
+
* @param line_num the line number this function is called from
|
275
|
+
* @param tc the test case to record the diagnostics
|
276
|
+
* @param expected the expected value
|
277
|
+
* @param actual the actual value
|
278
|
+
* @param bytes the number of bytes in the strings. Both strings should have at
|
279
|
+
* least this number of bytes allocated or you will get memory overflow
|
280
|
+
* @return true if the test passed
|
281
|
+
*/
|
282
|
+
extern bool tst_str_nequal(int line_num, TestCase *tc, const char *expected,
|
283
|
+
const char *actual, size_t n);
|
284
|
+
|
285
|
+
/**
|
286
|
+
* Test that +ptr+ is NULL. If it is not NULL then add an error to the test
|
287
|
+
* diagnostics. You should use the Apnull(ptr) macro to call this function so
|
288
|
+
* that the line number will be added automatically.
|
289
|
+
*
|
290
|
+
* @param line_num the line number this function is called from
|
291
|
+
* @param tc the test case to record the diagnostics
|
292
|
+
* @param ptr fail if this is NULL
|
293
|
+
* @return true if the test passed, ie +ptr+ was NULL.
|
294
|
+
*/
|
295
|
+
extern bool tst_ptr_null(int line_num, TestCase *tc, const void *ptr);
|
296
|
+
|
297
|
+
/**
|
298
|
+
* Test that +ptr+ is not NULL. If it is NULL then add an error to the test
|
299
|
+
* diagnostics. You should use the Apnotnull(ptr) macro to call this function so
|
300
|
+
* that the line number will be added automatically.
|
301
|
+
*
|
302
|
+
* @param line_num the line number this function is called from
|
303
|
+
* @param tc the test case to record the diagnostics
|
304
|
+
* @param ptr fail if this is NULL
|
305
|
+
* @return true if the test passed, ie +ptr+ was NULL.
|
306
|
+
*/
|
307
|
+
extern bool tst_ptr_notnull(int line_num, TestCase *tc, const void *ptr);
|
308
|
+
|
309
|
+
/**
|
310
|
+
* Test that two ptrs point to the same memory (ie, they are equal). If they
|
311
|
+
* are not equal then add an error to the test diagnostics. You should use the
|
312
|
+
* Apequal(expected, actual) macro to call this function so that the line
|
313
|
+
* number will be added automatically.
|
314
|
+
*
|
315
|
+
* @param line_num the line number this function is called from
|
316
|
+
* @param tc the test case to record the diagnostics
|
317
|
+
* @param expected the expected value
|
318
|
+
* @param actual the actual value
|
319
|
+
* @return true if the test passed
|
320
|
+
*/
|
321
|
+
extern bool tst_ptr_equal(int line_num, TestCase *tc, const void *expected,
|
322
|
+
const void *actual);
|
323
|
+
|
324
|
+
/**
|
325
|
+
* Test that the +condition+ is true. If it is false, add an error to the test
|
326
|
+
* diagnostics. You should use the Atrue(condition) macro to call this
|
327
|
+
* function so that the line number will be added automatically.
|
328
|
+
*
|
329
|
+
* @param line_num the line number this function is called from
|
330
|
+
* @param tc the test case to record the diagnostics
|
331
|
+
* @param expected the expected value
|
332
|
+
* @param actual the actual value
|
333
|
+
* @return true if the test passed
|
334
|
+
*/
|
335
|
+
extern bool tst_true(int line_num, TestCase *tc, int condition);
|
336
|
+
|
337
|
+
/**
|
338
|
+
* Fail. Add an error to the test diagnostics. You should use the Afail(msg)
|
339
|
+
* macro to call this function so that the line number will be added
|
340
|
+
* automatically.
|
341
|
+
*
|
342
|
+
* @param line_num the line number this function is called from
|
343
|
+
* @param tc the test case to record the diagnostics
|
344
|
+
* @param fmt message to display. It can contain the same formatting options
|
345
|
+
* as printf
|
346
|
+
* @param ... variables to interpolate into the format
|
347
|
+
* @return false always (for consistency with other test functions)
|
348
|
+
*/
|
349
|
+
extern bool tst_fail(int line_num, TestCase *tc, const char *fmt, ...);
|
350
|
+
|
351
|
+
/**
|
352
|
+
* Add an error to the test diagnotistics specifying that this test has not
|
353
|
+
* yet been implemented. You should use the Anotimpl(message) macro to call
|
354
|
+
* this function so that the line number will be added automatically.
|
355
|
+
*
|
356
|
+
* @param line_num the line number this function is called from
|
357
|
+
* @param tc the test case to record the diagnostics
|
358
|
+
* @param message message to be added to the test diagnostics along with the
|
359
|
+
* "Not Implemented" message
|
360
|
+
* @return true if the test passed
|
361
|
+
*/
|
362
|
+
extern bool tst_not_impl(int line_num, TestCase *tc, const char *message);
|
363
|
+
|
364
|
+
/**
|
365
|
+
* Test that +condition+ is true. If it isn't, add an error to the test
|
366
|
+
* diagnostics along with the message in +fmt+, .... You can use the
|
367
|
+
* Assert(condition, fmt, ...) macro but note that it is not ANSI C compatible
|
368
|
+
* because of the variadic arguments. Instead you can use Atrue without the
|
369
|
+
* error message or an of the other Assertions along with Tmsg like this;
|
370
|
+
*
|
371
|
+
* <pre>
|
372
|
+
*
|
373
|
+
* if (!Aiequal(int1, int2)) {
|
374
|
+
* Tmsg("int1:%d should have been equal to int2:%d\n", int1, int2);
|
375
|
+
* }
|
376
|
+
*
|
377
|
+
* </pre>
|
378
|
+
*
|
379
|
+
* @param line_num the line number this function is called from
|
380
|
+
* @param tc the test case to record the diagnostics
|
381
|
+
* @param condition condition to test
|
382
|
+
* @param fmt message to display. It can contain the same formatting options
|
383
|
+
* as printf
|
384
|
+
* @param ... variables to interpolate into the format
|
385
|
+
* @return true if the test passed
|
386
|
+
*/
|
387
|
+
extern bool tst_assert(int line_num, TestCase *tc, int condition,
|
388
|
+
const char *fmt, ...);
|
389
|
+
|
390
|
+
#define Araise(e, f, b)\
|
391
|
+
tst_raise(__LINE__, tc, e, (void (*)(void *))(f), (void *)(b))
|
392
|
+
#define Aiequal(a, b) tst_int_equal(__LINE__, tc, (frt_u64)(a), (frt_u64)(b))
|
393
|
+
#define Afequal(a, b) tst_flt_equal(__LINE__, tc, (a), (b))
|
394
|
+
#define Afdequal(a, b, d) tst_flt_delta_equal(__LINE__, tc, (a), (b), (d))
|
395
|
+
#define Asequal(a, b) tst_str_equal(__LINE__, tc, (const char *)(a), (const char *)(b))
|
396
|
+
#define Astrstr(a, b) tst_strstr(__LINE__, tc, (const char *)(a), (const char *)(b))
|
397
|
+
#define Aaiequal(a, b, n) tst_arr_int_equal(__LINE__, tc, (const int *)(a), (const int *)(b), (n))
|
398
|
+
#define Aasequal(a, b, n) tst_arr_str_equal(__LINE__, tc, (const char **)(a), (const char **)(b), (n))
|
399
|
+
#define Asnequal(a, b, n) tst_str_nequal(__LINE__, tc, (const char *)(a), (const char *)(b), (n))
|
400
|
+
#define Apnull(a) tst_ptr_null(__LINE__, tc, (a))
|
401
|
+
#define Apnotnull(a) tst_ptr_notnull(__LINE__, tc, (a))
|
402
|
+
#define Apequal(a, b) tst_ptr_equal(__LINE__, tc, (a), (b))
|
403
|
+
#define Atrue(a) tst_true(__LINE__, tc, (a))
|
404
|
+
#define Afail(a) tst_fail(__LINE__, tc, (a))
|
405
|
+
#define Anotimpl(a) tst_not_impl(__LINE__, tc, (a))
|
406
|
+
#ifdef FRT_HAS_ISO_VARARGS
|
407
|
+
#define Assert(a, ...) tst_assert(__LINE__, tc, (a), __VA_ARGS__)
|
408
|
+
#elif defined(FRT_HAS_GNUC_VARARGS)
|
409
|
+
#define Assert(a, args...) tst_assert(__LINE__, tc, (a), ##args)
|
410
|
+
#else
|
411
|
+
extern bool Assert(int condition, const char *fmt, ...);
|
412
|
+
#endif
|
413
|
+
|
414
|
+
extern void tst_check_hits(TestCase *tc, FrtSearcher *searcher, FrtQuery *query, const char *expected_hits, int top);
|
415
|
+
|
416
|
+
#endif
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#include "frt_index.h"
|
2
|
+
#include "test.h"
|
3
|
+
#include "testhelper.h"
|
4
|
+
#include <stdio.h>
|
5
|
+
|
6
|
+
static FrtFieldInfos *create_fis()
|
7
|
+
{
|
8
|
+
FrtFieldInfos *fis = frt_fis_new(FRT_STORE_YES, FRT_INDEX_YES,
|
9
|
+
FRT_TERM_VECTOR_WITH_POSITIONS_OFFSETS);
|
10
|
+
return fis;
|
11
|
+
}
|
12
|
+
|
13
|
+
static FrtIndexWriter *create_iw(FrtStore *store)
|
14
|
+
{
|
15
|
+
FrtFieldInfos *fis = create_fis();
|
16
|
+
frt_index_create(store, fis);
|
17
|
+
frt_fis_deref(fis);
|
18
|
+
return frt_iw_open(store, frt_standard_analyzer_new(true), &frt_default_config);
|
19
|
+
}
|
20
|
+
|
21
|
+
static FrtDocument *prep_doc()
|
22
|
+
{
|
23
|
+
FrtDocument *doc = frt_doc_new();
|
24
|
+
frt_doc_add_field(
|
25
|
+
doc,
|
26
|
+
frt_df_add_data(
|
27
|
+
frt_df_new(rb_intern("content")),
|
28
|
+
frt_estrdup("http://_____________________________________________________")
|
29
|
+
)
|
30
|
+
)->destroy_data = true;
|
31
|
+
return doc;
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
static void test_problem_text(TestCase *tc, void *data)
|
36
|
+
{
|
37
|
+
FrtStore *store = (FrtStore *)data;
|
38
|
+
FrtIndexWriter *iw = create_iw(store);
|
39
|
+
FrtDocument *problem_text = prep_doc();
|
40
|
+
|
41
|
+
frt_iw_add_doc(iw, problem_text);
|
42
|
+
Aiequal(1, frt_iw_doc_count(iw));
|
43
|
+
Assert(!store->exists(store, "_0.cfs"),
|
44
|
+
"data shouldn't have been written yet");
|
45
|
+
frt_iw_commit(iw);
|
46
|
+
Assert(store->exists(store, "_0.cfs"), "data should now be written");
|
47
|
+
frt_iw_close(iw);
|
48
|
+
Assert(store->exists(store, "_0.cfs"), "data should still be there");
|
49
|
+
}
|
50
|
+
|
51
|
+
TestSuite *ts_1710(TestSuite *suite)
|
52
|
+
{
|
53
|
+
FrtStore *store = frt_open_ram_store();
|
54
|
+
|
55
|
+
suite = ADD_SUITE(suite);
|
56
|
+
|
57
|
+
tst_run_test(suite, test_problem_text, store);
|
58
|
+
|
59
|
+
frt_store_deref(store);
|
60
|
+
|
61
|
+
return suite;
|
62
|
+
}
|
63
|
+
|