22 #include <glib/gstdio.h>
24 #include "../lib/grn-assertions.h"
42 #define TYPE_SIZE 1024
46 static GList *expected_messages;
47 static GList *record_ids;
49 static gchar *tmp_directory;
55 static grn_ii *inverted_index;
68 g_free(tmp_directory);
73 remove_tmp_directory(
void)
75 cut_remove_path(tmp_directory, NULL);
82 const gchar *type_name, *table_name;
91 expected_messages = NULL;
94 remove_tmp_directory();
95 g_mkdir_with_parents(tmp_directory, 0700);
96 path = g_build_filename(tmp_directory,
"inverted-index", NULL);
109 table_name =
"lexicon";
110 table_path = g_build_filename(tmp_directory,
"lexicon-table", NULL);
112 table_name, strlen(table_name),
122 inverted_index = NULL;
126 inverted_index_free(
void)
128 if (inverted_index) {
130 inverted_index = NULL;
135 expected_messages_free(
void)
137 if (expected_messages) {
138 gcut_list_string_free(expected_messages);
139 expected_messages = NULL;
144 record_ids_free(
void)
147 gcut_list_string_free(record_ids);
156 inverted_index_free();
169 remove_tmp_directory();
173 expected_messages_free();
178 #define clear_messages() \
179 grn_collect_logger_clear_messages(logger)
182 grn_collect_logger_get_messages(logger)
184 #define cut_assert_create() do \
186 inverted_index = grn_ii_create(context, path, lexicon, 0); \
187 ((grn_db_obj *)inverted_index)->header.domain = GRN_DB_VOID; \
188 cut_assert_not_null(inverted_index); \
189 cut_assert_file_exist(cut_take_printf("%s.c", path)); \
203 cut_assert_not_null(inverted_index);
211 const gchar last_component[] = G_DIR_SEPARATOR_S
"index";
216 g_mkdir_with_parents(long_path->str, 0700);
217 g_string_append(long_path, last_component);
218 path = g_string_free(long_path,
FALSE);
220 cut_assert_equal_int(max_size, strlen(path) + 1);
223 inverted_index_free();
225 long_path = g_string_new(path);
228 g_string_append(long_path,
"X");
229 path = g_string_free(long_path,
FALSE);
232 cut_assert_null(inverted_index);
239 cut_assert_null(inverted_index);
246 inverted_index_free();
248 inverted_index =
grn_ii_open(context, path, lexicon);
249 cut_assert(inverted_index);
255 inverted_index =
grn_ii_open(context, path, lexicon);
256 cut_assert_null(inverted_index);
264 const gchar *expected_error_message =
"syscall error";
268 cut_assert_not_null(io);
270 strcpy(id_string,
"WRONG-ID");
274 inverted_index =
grn_ii_open(context, path, lexicon);
275 cut_assert_null(inverted_index);
277 cut_assert_equal_substring(expected_error_message,
279 strlen(expected_error_message));
287 gchar expected_error_message[] =
"file type unmatch";
290 cut_assert_not_null(io);
292 strcpy(id_string,
"WRONG-ID");
297 cut_assert_not_null(io);
301 inverted_index =
grn_ii_open(context, path, lexicon);
302 cut_assert_null(inverted_index);
304 cut_assert_equal_substring(expected_error_message,
306 strlen(expected_error_message));
313 inverted_index_free();
316 cut_assert_null(inverted_index);
321 update_data(
grn_id record_id,
unsigned int section,
322 const gchar *old_name,
const gchar *new_name)
325 const gchar *old_data, *new_data;
331 old_data = cut_get_fixture_data_string(old_name, NULL);
336 new_data = cut_get_fixture_data_string(new_name, NULL);
341 &old_value, &new_value, NULL);
347 add_data(
grn_id record_id,
unsigned int section,
const gchar *name)
349 update_data(record_id, section, NULL, name);
353 remove_data(
grn_id record_id,
unsigned int section,
const gchar *name)
355 update_data(record_id, section, name, NULL);
359 retrieve_record_ids(
const gchar *term)
365 term_id =
grn_table_get(context, lexicon, term, strlen(term));
377 record_ids = g_list_append(record_ids, g_strdup_printf(
"%d", posting->
rid));
389 add_data(1, 1,
"API.JA");
390 add_data(2, 1,
"CHECKINSTALL.JA");
391 add_data(3, 1,
"FUTUREWORKS.JA");
392 add_data(4, 1,
"INSTALL.JA");
393 gcut_assert_equal_list_string(gcut_take_new_list_string(
"1",
"2",
"3", NULL),
394 retrieve_record_ids(
"検索"));
396 remove_data(1, 1,
"API.JA");
397 gcut_assert_equal_list_string(gcut_take_new_list_string(
"2",
"3", NULL),
398 retrieve_record_ids(
"検索"));
400 update_data(3, 1,
"FUTUREWORKS.JA",
"Makefile.am");
401 gcut_assert_equal_list_string(gcut_take_new_list_string(
"2", NULL),
402 retrieve_record_ids(
"検索"));
404 remove_data(2, 1,
"CHECKINSTALL.JA");
405 add_data(3, 2,
"FUTUREWORKS.JA");
406 gcut_assert_equal_list_string(gcut_take_new_list_string(
"3", NULL),
407 retrieve_record_ids(
"検索"));
409 update_data(4, 1,
"INSTALL.JA",
"README.JA");
410 gcut_assert_equal_list_string(gcut_take_new_list_string(
"3",
"4", NULL),
411 retrieve_record_ids(
"検索"));
413 remove_data(4, 1,
"README.JA");
414 gcut_assert_equal_list_string(gcut_take_new_list_string(
"3", NULL),
415 retrieve_record_ids(
"検索"));
417 remove_data(3, 2,
"FUTUREWORKS.JA");
418 gcut_assert_equal_list_string(NULL, retrieve_record_ids(
"検索"),
419 cut_message(
"this assertion is wrong?"));
449 cut_assert_not_null(res);
467 grn_obj *users, *items, *checks, *checked;
471 remove_tmp_directory();
472 g_mkdir_with_parents(tmp_directory, 0700);
473 db_path = g_build_filename(tmp_directory,
"inverted-index", NULL);
480 cut_assert_not_null(users);
485 cut_assert_not_null(items);
490 cut_assert_not_null(checks);
495 cut_assert_not_null(checked);
499 insert_and_search(users, items, checks, checked);
512 grn_obj *users, *items, *checks, *checked;
516 remove_tmp_directory();
517 g_mkdir_with_parents(tmp_directory, 0700);
518 db_path = g_build_filename(tmp_directory,
"inverted-index", NULL);
525 cut_assert_not_null(users);
530 cut_assert_not_null(items);
535 cut_assert_not_null(checks);
540 cut_assert_not_null(checked);
544 insert_and_search(users, items, checks, checked);
557 grn_obj *users, *items, *checks, *checked, *int_type;
561 remove_tmp_directory();
562 g_mkdir_with_parents(tmp_directory, 0700);
563 db_path = g_build_filename(tmp_directory,
"inverted-index", NULL);
568 cut_assert_not_null(int_type);
573 cut_assert_not_null(users);
578 cut_assert_not_null(items);
583 cut_assert_not_null(checks);
588 cut_assert_not_null(checked);
601 cut_assert_not_null(res);
629 const gchar *mrn_dir;
631 mrn_dir = cut_build_path(tmp_directory,
"mrn", NULL);
632 g_mkdir_with_parents(mrn_dir, 0700);
636 cut_build_path(mrn_dir,
"mroonga.grn", NULL),
638 cut_assert_not_null(db);
642 cut_build_path(mrn_dir,
"t1.grn", NULL),
644 cut_assert_not_null(t1);
648 cut_build_path(mrn_dir,
"lc.grn", NULL),
651 cut_assert_not_null(lc);
657 cut_build_path(mrn_dir,
"t1.c1.grn", NULL),
660 cut_assert_not_null(c1);
664 cut_build_path(mrn_dir,
"lc.ft.grn", NULL),
666 cut_assert_not_null(ft);
677 cut_assert_equal_int(1,r1);
682 cut_assert_equal_int(2,r2);
687 cut_assert_equal_int(3,r3);
692 cut_assert_equal_int(4,r4);
714 cut_assert_equal_int(2, docid);
726 grn_obj *match_columns, *match_columns_variable;
727 grn_obj *expression, *expression_variable;
730 const char *match_columns_expression =
"c1";
731 const char *qstr =
"+22 -55";
734 match_columns, match_columns_variable);
736 match_columns_expression,
737 strlen(match_columns_expression),
753 cut_assert_equal_int(3, docid);
777 const gchar *mrn_dir;
779 mrn_dir = cut_build_path(tmp_directory,
"mrn", NULL);
780 g_mkdir_with_parents(mrn_dir, 0700);
784 cut_build_path(mrn_dir,
"mroonga.grn", NULL),
786 cut_assert_not_null(db);
790 cut_build_path(mrn_dir,
"t1.grn", NULL),
792 cut_assert_not_null(t1);
796 cut_build_path(mrn_dir,
"lc.grn", NULL),
799 cut_assert_not_null(lc);
805 cut_build_path(mrn_dir,
"t1.c1.grn", NULL),
808 cut_assert_not_null(c1);
812 cut_build_path(mrn_dir,
"lc.ft.grn", NULL),
814 cut_assert_not_null(ft);
824 cut_assert_equal_int(1,r1);
829 cut_assert_equal_int(2,r2);
834 cut_assert_equal_int(3,r3);
839 cut_assert_equal_int(4,r4);
865 cut_assert_equal_int(2, docid);
881 grn_obj *match_columns, *match_columns_variable;
882 grn_obj *expression, *expression_variable;
885 const char *match_columns_expression =
"c1 * 5";
886 const char *qstr =
"+22 -55";
889 match_columns, match_columns_variable);
891 match_columns_expression,
892 strlen(match_columns_expression),
911 cut_assert_equal_int(3, docid);