48 void test_at(gconstpointer data);
51 static GList *expected_keys, *actual_keys;
57 setup_trie_common(
"patricia-trie");
69 g_array_free(ids,
TRUE);
78 gcut_list_string_free(expected_keys);
80 gcut_list_string_free(actual_keys);
83 teardown_trie_common();
88 set_key_size_to_zero(
void)
94 set_value_size_to_zero(
void)
96 default_value_size = 0;
100 set_sis_and_utf8_encoding(
void)
109 cut_add_data(
"default", NULL, NULL,
110 "zero key size", set_key_size_to_zero, NULL,
111 "zero value size", set_value_size_to_zero, NULL);
128 cut_add_data(
"default", NULL, NULL,
129 "sis", set_sis, NULL);
147 cut_add_data(
"default", NULL, NULL,
148 "sis", set_sis, NULL);
155 const gchar *saved_default_path;
160 saved_default_path = cut_take_string(default_path);
163 cut_assert_path_not_exist(saved_default_path);
165 cut_assert_path_not_exist(saved_default_path);
167 cut_assert_path_not_exist(saved_default_path);
173 cut_assert_path_not_exist(default_path);
175 cut_assert_path_exist(default_path);
177 cut_assert_path_not_exist(default_path);
183 gchar expected_error_message[] =
"path is null";
186 gcut_assert_equal_list_string(NULL,
messages());
189 cut_assert_equal_substring(expected_error_message,
191 strlen(expected_error_message));
197 return trie_test_data_newv(key, NULL, NULL,
GRN_SUCCESS, NULL, NULL,
198 set_parameters, NULL);
204 trie_test_data_free(data);
210 cut_add_data(
"default",
211 test_data_new(
"Cutter", NULL),
214 test_data_new(
"Groonga", set_sis),
216 "sis - multi byte key",
217 test_data_new(
"セナ", set_sis_and_utf8_encoding),
226 trie_test_data_set_parameters(test_data);
235 cut_add_data(
"default",
236 test_data_new(
"Cutter", NULL),
239 test_data_new(
"Groonga", set_sis),
241 "sis - multi byte key",
242 test_data_new(
"セナ", set_sis_and_utf8_encoding),
253 trie_test_data_set_parameters(test_data);
263 key_size = strlen(test_data->
key);
279 grn_id short_term_id, long_term_id;
281 set_sis_and_utf8_encoding();
290 expected_keys = gcut_list_string_new(
"セナ",
"セナセナ",
"ナ",
"ナセナ", NULL);
292 gcut_assert_equal_list_string(expected_keys, actual_keys);
297 gcut_list_string_free(actual_keys);
299 gcut_assert_equal_list_string(expected_keys, actual_keys);
305 cut_set_attributes(
"ML",
"1010",
312 grn_id short_term_id, long_term_id;
314 set_sis_and_utf8_encoding();
323 expected_keys = gcut_list_string_new(
"セナ",
"セナセナ",
"ナ",
"ナセナ", NULL);
325 gcut_assert_equal_list_string(expected_keys, actual_keys);
329 gcut_list_string_free(actual_keys);
331 gcut_assert_equal_list_string(NULL, actual_keys);
334 #define cut_assert_delete(key) do \
337 uint32_t key_size = 0; \
338 grn_search_flags flags; \
342 key_size = strlen(_key); \
344 grn_test_assert(grn_pat_delete(context, trie, _key, key_size, NULL)); \
345 grn_test_assert_equal_rc(GRN_INVALID_ARGUMENT, \
346 grn_pat_delete(context, trie, \
347 _key, key_size, NULL)); \
350 cut_assert_lookup_failed(_key, key_size, &flags); \
356 cut_add_data(
"default",
357 test_data_new(
"29", NULL),
360 test_data_new(
"29", set_sis),
362 "sis - multi byte key",
363 test_data_new(
"肉ニク", set_sis_and_utf8_encoding),
372 trie_test_data_set_parameters(test_data);
382 cut_add_data(
"default", NULL, NULL,
383 "sis", set_sis, NULL);
391 const gchar key1[] =
"セナ + PostgreSQL";
392 const gchar key2[] =
"セナ + MySQL";
393 const gchar key3[] =
"セナ + Ruby";
420 const gchar key[] =
"Groonga";
421 const gchar initial_key[] =
"Ludia";
423 grn_id nonexistence_id = 12345;
429 strcpy(got_key, initial_key);
432 cut_assert_equal_string(initial_key, got_key);
437 strcpy(got_key, initial_key);
453 cut_assert_equal_int(strlen(key), got_key_size);
454 got_key[got_key_size] =
'\0';
455 cut_assert_equal_string(key, got_key);
461 cut_add_data(
"default",
462 test_data_new(
"Cutter", NULL),
465 test_data_new(
"Groonga", set_sis),
468 test_data_new(
"セナ", set_sis_and_utf8_encoding),
476 const gchar *set_value;
477 const gchar *initial_value;
479 grn_id nonexistence_id = 12345;
482 trie_test_data_set_parameters(test_data);
486 initial_value = cut_take_string(g_strjoin(
" - ",
490 strcpy(got_value, initial_value);
492 nonexistence_id, got_value));
493 cut_assert_equal_string(initial_value, got_value);
496 set_value = cut_take_string(g_strjoin(
" - ",
501 strcpy(value, set_value);
503 strcpy(got_value, initial_value);
505 nonexistence_id, got_value);
519 cut_assert_equal_string(set_value, got_value);
535 cut_assert_equal_string(
"XXX", got_value);
557 return trie_test_data_newv(key, NULL, NULL,
GRN_SUCCESS, NULL, increment,
558 set_parameters, NULL);
564 trie_test_data_free(data);
570 gchar *original_string = data->
key;
574 last = strlen(original_string);
575 if (original_string[last - 1] <
'X') {
576 original_string[last - 1]++;
578 string = g_strconcat(data->
key,
"A", NULL);
587 gchar *original_string = data->
key;
590 for (character = original_string;
592 character = g_utf8_next_char(character)) {
595 if (g_random_int_range(0, 100) < 99)
598 unicode = g_utf8_get_char(character);
599 if (unicode < g_utf8_get_char(
"ン")) {
603 length = g_unichar_to_utf8(unicode + 1, buffer);
604 for (i = 0; i < length; i++) {
605 character[
i] = buffer[
i];
613 gunichar new_unicode;
614 gchar new_character[6];
617 new_unicode = g_random_int_range(g_utf8_get_char(
"ア"),
618 g_utf8_get_char(
"ン"));
619 length = g_unichar_to_utf8(new_unicode, new_character);
620 new_character[length] =
'\0';
621 string = g_strconcat(data->
key, new_character, NULL);
630 gchar *original_string = data->
key;
633 for (character = original_string;
635 character = g_utf8_next_char(character)) {
638 unicode = g_utf8_get_char(character);
639 if (unicode < g_utf8_get_char(
"ン")) {
643 length = g_unichar_to_utf8(unicode + 1, buffer);
644 for (i = 0; i < length; i++) {
645 character[
i] = buffer[
i];
653 string = g_strconcat(data->
key,
"ア", NULL);
666 for (i = 0; i < n; i++) {
669 g_array_append_val(ids,
id);
676 return test_data->
increment == utf8_string_increment ||
677 test_data->
increment == utf8_string_same_prefix_increment;
681 add_increment_test_data(
void)
683 cut_add_data(
"default",
684 increment_test_data_new(
"Cutter", string_increment, NULL),
685 increment_test_data_free,
687 increment_test_data_new(
"Groonga", string_increment, set_sis),
688 increment_test_data_free,
689 "sis - multi byte key (katakana)",
690 increment_test_data_new(
"セナ", utf8_string_increment,
691 set_sis_and_utf8_encoding),
692 increment_test_data_free,
693 "sis - multi byte key (katakana) - many same prefix",
694 increment_test_data_new(
"セナ", utf8_string_same_prefix_increment,
695 set_sis_and_utf8_encoding),
696 increment_test_data_free);
702 add_increment_test_data();
710 const guint n_operations = 750;
711 gboolean sis_utf8_data =
FALSE;
714 if (is_sis_utf8_increment_test_data(test_data))
715 sis_utf8_data =
TRUE;
717 trie_test_data_set_parameters(test_data);
721 increment_test_data_add_n_data(n_operations, test_data);
728 for (i = 0; i < ids->len; i++) {
731 delete_id = g_array_index(ids,
grn_id, i);
736 cut_message(
"i = %d; id = %d", i, delete_id));
741 gcut_assert_equal_list_string(NULL, actual_keys);
744 #define cut_assert_truncate(key) do \
747 uint32_t key_size = 0; \
748 grn_search_flags flags; \
752 key_size = strlen(_key); \
754 grn_test_assert(grn_pat_truncate(context, trie, _key, key_size, NULL));\
755 grn_test_assert_equal_rc(GRN_INVALID_ARGUMENT, \
756 grn_pat_delete(context, trie, \
757 _key, key_size, NULL)); \
760 cut_assert_lookup_failed(_key, key_size, &flags); \
766 add_increment_test_data();
773 gboolean sis_utf8_data =
FALSE;
777 if (is_sis_utf8_increment_test_data(test_data))
778 sis_utf8_data =
TRUE;
780 trie_test_data_set_parameters(test_data);
784 increment_test_data_add_n_data(n_data, test_data);
798 #define ADD_DATUM(label, commands) \
799 gcut_add_datum(label, \
800 "commands", G_TYPE_STRING, commands, \
804 "table_create Pat TABLE_PAT_KEY Int32\n"
806 "[{\"_key\": -29}]");
808 "table_create Pat TABLE_PAT_KEY UInt32\n"
812 "table_create Pat TABLE_PAT_KEY TokyoGeoPoint\n"
814 "[{\"_key\": \"128467228x503222332\"}]");
816 "table_create Pat TABLE_PAT_KEY ShortText\n"
818 "[{\"_key\": \"niku\"}]");