Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-patricia-trie-cursor.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2008-2011 Kouhei Sutou <kou@clear-code.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License version 2.1 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "test-patricia-trie.h"
20 
21 void data_next_with_no_entry(void);
22 void test_next_with_no_entry(gconstpointer data);
23 void data_next_with_one_entry(void);
24 void test_next_with_one_entry(gconstpointer data);
26 void test_next_with_multi_entries(gconstpointer data);
28 void test_by_id_over_offset(void);
29 void data_value(void);
30 void test_value(gconstpointer data);
31 void data_delete(void);
32 void test_delete(gconstpointer data);
33 
34 static GList *keys;
35 static GList *keys_and_values;
36 
37 void
38 cut_setup(void)
39 {
40  setup_trie_common("patricia-trie-cursor");
41 
42  keys = NULL;
43  keys_and_values = NULL;
44 
45  default_encoding = GRN_ENC_UTF8;
46 
47  sample_value = NULL;
48 }
49 
50 static void
51 keys_free(void)
52 {
53  if (keys) {
54  gcut_list_string_free(keys);
55  keys = NULL;
56  }
57 }
58 
59 static void
60 keys_and_values_free(void)
61 {
62  if (keys_and_values) {
63  gcut_list_string_free(keys_and_values);
64  keys_and_values = NULL;
65  }
66 }
67 
68 void
70 {
71  keys_free();
72  keys_and_values_free();
73  teardown_trie_common();
74 }
75 
76 static GList *
77 retrieve_all_keys(void)
78 {
79  keys_free();
81  return keys;
82 }
83 
84 static GList *
85 retrieve_all_keys_and_values(void)
86 {
87  keys_and_values_free();
88  keys_and_values = grn_test_pat_cursor_get_pairs(context,
89  (grn_table_cursor *)cursor);
90  return keys_and_values;
91 }
92 
93 static grn_trie_test_data *test_data_new(GList *expected_strings,
94  grn_test_set_parameters_func set_parameters,
95  ...) G_GNUC_NULL_TERMINATED;
96 static grn_trie_test_data *
97 test_data_new(GList *expected_strings,
98  grn_test_set_parameters_func set_parameters,
99  ...)
100 {
101  grn_trie_test_data *test_data;
102  va_list args;
103 
104  va_start(args, set_parameters);
105  test_data = trie_test_data_newv(NULL, NULL, NULL, GRN_SUCCESS,
106  expected_strings, NULL,
107  set_parameters, &args);
108  va_end(args);
109 
110  return test_data;
111 }
112 
113 static void
114 test_data_free(grn_trie_test_data *test_data)
115 {
116  trie_test_data_free(test_data);
117 }
118 
119 static void
120 set_ascending(void)
121 {
122  default_cursor_flags |= GRN_CURSOR_ASCENDING;
123 }
124 
125 static void
126 set_descending(void)
127 {
128  default_cursor_flags |= GRN_CURSOR_DESCENDING;
129 }
130 
131 void
133 {
134  cut_add_data("ascending",
135  test_data_new(NULL, set_ascending, NULL),
136  test_data_free,
137  "ascending - sis",
138  test_data_new(NULL, set_ascending, set_sis, NULL),
139  test_data_free,
140  "descending",
141  test_data_new(NULL, set_descending, NULL),
142  test_data_free,
143  "descending - sis",
144  test_data_new(NULL, set_descending, set_sis, NULL),
145  test_data_free);
146 }
147 
148 void
149 test_next_with_no_entry(gconstpointer data)
150 {
151  const grn_trie_test_data *test_data = data;
152 
153  trie_test_data_set_parameters(test_data);
154 
157  gcut_assert_equal_list_string(NULL, retrieve_all_keys());
158 }
159 
160 void
162 {
163  cut_add_data("ascending",
164  test_data_new(gcut_list_string_new("セナ", NULL),
165  set_ascending, NULL),
166  test_data_free,
167  "ascending - sis",
168  test_data_new(gcut_list_string_new("セナ", "ナ", NULL),
169  set_ascending, set_sis, NULL),
170  test_data_free,
171  "descending",
172  test_data_new(gcut_list_string_new("セナ", NULL),
173  set_descending, NULL),
174  test_data_free,
175  "descending - sis",
176  test_data_new(gcut_list_string_new("ナ", "セナ", NULL),
177  set_descending, set_sis, NULL),
178  test_data_free);
179 }
180 
181 void
182 test_next_with_one_entry(gconstpointer data)
183 {
184  const grn_trie_test_data *test_data = data;
185  const gchar key[] = "セナ";
186 
187  trie_test_data_set_parameters(test_data);
188 
190 
192 
194  gcut_assert_equal_list_string(test_data->expected_strings,
195  retrieve_all_keys());
196 }
197 
198 static void
199 set_max(void)
200 {
201  default_cursor_max = g_strdup("セナセナ");
202  default_cursor_max_size = strlen(default_cursor_max);
203 }
204 
205 static void
206 set_max_low(void)
207 {
208  default_cursor_max = g_strdup("セナ");
209  default_cursor_max_size = strlen(default_cursor_max);
210 }
211 
212 static void
213 set_min(void)
214 {
215  default_cursor_min = g_strdup("セナ");
216  default_cursor_min_size = strlen(default_cursor_min);
217 }
218 
219 static void
220 set_min_high(void)
221 {
222  default_cursor_min = g_strdup("セナセナ");
223  default_cursor_min_size = strlen(default_cursor_min);
224 }
225 
226 static void
227 set_gt(void)
228 {
229  default_cursor_flags |= GRN_CURSOR_GT;
230 }
231 
232 static void
233 set_lt(void)
234 {
235  default_cursor_flags |= GRN_CURSOR_LT;
236 }
237 
238 static void
239 add_data_ascending(void)
240 {
241  cut_add_data("ascending",
242  test_data_new(gcut_list_string_new("Groonga",
243  "セナ",
244  "セナ + Ruby",
245  "セナセナ",
246  "ナセナセ",
247  NULL),
248  set_ascending, NULL),
249  test_data_free,
250  "ascending - max",
251  test_data_new(gcut_list_string_new("Groonga",
252  "セナ",
253  "セナ + Ruby",
254  "セナセナ",
255  NULL),
256  set_ascending, set_max, NULL),
257  test_data_free,
258  "ascending - max - gt",
259  test_data_new(gcut_list_string_new("Groonga",
260  "セナ",
261  "セナ + Ruby",
262  "セナセナ",
263  NULL),
264  set_ascending, set_max, set_gt, NULL),
265  test_data_free,
266  "ascending - max - lt",
267  test_data_new(gcut_list_string_new("Groonga",
268  "セナ",
269  "セナ + Ruby",
270  NULL),
271  set_ascending, set_max, set_lt, NULL),
272  test_data_free,
273  "ascending - max - gt - lt",
274  test_data_new(gcut_list_string_new("Groonga",
275  "セナ",
276  "セナ + Ruby",
277  NULL),
278  set_ascending, set_max, set_gt, set_lt, NULL),
279  test_data_free,
280  "ascending - min",
281  test_data_new(gcut_list_string_new("セナ",
282  "セナ + Ruby",
283  "セナセナ",
284  "ナセナセ",
285  NULL),
286  set_ascending, set_min, NULL),
287  test_data_free,
288  "ascending - min - gt",
289  test_data_new(gcut_list_string_new("セナ + Ruby",
290  "セナセナ",
291  "ナセナセ",
292  NULL),
293  set_ascending, set_min, set_gt, NULL),
294  test_data_free,
295  "ascending - min - lt",
296  test_data_new(gcut_list_string_new("セナ",
297  "セナ + Ruby",
298  "セナセナ",
299  "ナセナセ",
300  NULL),
301  set_ascending, set_min, set_lt, NULL),
302  test_data_free,
303  "ascending - min - gt - lt",
304  test_data_new(gcut_list_string_new("セナ + Ruby",
305  "セナセナ",
306  "ナセナセ",
307  NULL),
308  set_ascending, set_min, set_gt, set_lt, NULL),
309  test_data_free,
310  "ascending - max - min",
311  test_data_new(gcut_list_string_new("セナ",
312  "セナ + Ruby",
313  "セナセナ",
314  NULL),
315  set_ascending, set_max, set_min, NULL),
316  test_data_free,
317  "ascending - max - min - gt",
318  test_data_new(gcut_list_string_new("セナ + Ruby",
319  "セナセナ",
320  NULL),
321  set_ascending, set_max, set_min, set_gt,
322  NULL),
323  test_data_free,
324  "ascending - max - min - lt",
325  test_data_new(gcut_list_string_new("セナ",
326  "セナ + Ruby",
327  NULL),
328  set_ascending, set_max, set_min, set_lt,
329  NULL),
330  test_data_free,
331  "ascending - max - min - gt - lt",
332  test_data_new(gcut_list_string_new("セナ + Ruby",
333  NULL),
334  set_ascending, set_max, set_min, set_gt,
335  set_lt, NULL),
336  test_data_free,
337  "ascending - high-min",
338  test_data_new(gcut_list_string_new("セナセナ",
339  "ナセナセ",
340  NULL),
341  set_ascending, set_min_high, NULL),
342  test_data_free,
343  "ascending - low-max",
344  test_data_new(gcut_list_string_new("Groonga",
345  "セナ",
346  NULL),
347  set_ascending, set_max_low, NULL),
348  test_data_free,
349  "ascending - high-min - low-max",
350  test_data_new(NULL,
351  set_ascending, set_min_high, set_max_low, NULL),
352  test_data_free);
353 }
354 
355 static void
356 add_data_ascending_sis(void)
357 {
358  cut_add_data("ascending - sis",
359  test_data_new(gcut_list_string_new("Groonga",
360  "セ",
361  "セナ",
362  "セナ + Ruby",
363  "セナセ",
364  "セナセナ",
365  "ナ",
366  "ナ + Ruby",
367  "ナセ",
368  "ナセナ",
369  "ナセナセ",
370  NULL),
371  set_ascending, set_sis, NULL),
372  test_data_free,
373  "ascending - max - sis",
374  test_data_new(gcut_list_string_new("Groonga",
375  "セ",
376  "セナ",
377  "セナ + Ruby",
378  "セナセ",
379  "セナセナ",
380  NULL),
381  set_ascending, set_max, set_sis, NULL),
382  test_data_free,
383  "ascending - max - gt - sis",
384  test_data_new(gcut_list_string_new("Groonga",
385  "セ",
386  "セナ",
387  "セナ + Ruby",
388  "セナセ",
389  "セナセナ",
390  NULL),
391  set_ascending, set_max, set_gt, set_sis, NULL),
392  test_data_free,
393  "ascending - max - lt - sis",
394  test_data_new(gcut_list_string_new("Groonga",
395  "セ",
396  "セナ",
397  "セナ + Ruby",
398  "セナセ",
399  NULL),
400  set_ascending, set_max, set_lt, set_sis, NULL),
401  test_data_free,
402  "ascending - max - gt - lt - sis",
403  test_data_new(gcut_list_string_new("Groonga",
404  "セ",
405  "セナ",
406  "セナ + Ruby",
407  "セナセ",
408  NULL),
409  set_ascending, set_max, set_gt, set_lt, set_sis,
410  NULL),
411  test_data_free,
412  "ascending - min - sis",
413  test_data_new(gcut_list_string_new("セナ",
414  "セナ + Ruby",
415  "セナセ",
416  "セナセナ",
417  "ナ",
418  "ナ + Ruby",
419  "ナセ",
420  "ナセナ",
421  "ナセナセ",
422  NULL),
423  set_ascending, set_min, set_sis, NULL),
424  test_data_free,
425  "ascending - min - gt - sis",
426  test_data_new(gcut_list_string_new("セナ + Ruby",
427  "セナセ",
428  "セナセナ",
429  "ナ",
430  "ナ + Ruby",
431  "ナセ",
432  "ナセナ",
433  "ナセナセ",
434  NULL),
435  set_ascending, set_min, set_gt, set_sis, NULL),
436  test_data_free,
437  "ascending - min - lt - sis",
438  test_data_new(gcut_list_string_new("セナ",
439  "セナ + Ruby",
440  "セナセ",
441  "セナセナ",
442  "ナ",
443  "ナ + Ruby",
444  "ナセ",
445  "ナセナ",
446  "ナセナセ",
447  NULL),
448  set_ascending, set_min, set_lt, set_sis, NULL),
449  test_data_free,
450  "ascending - min - gt - lt - sis",
451  test_data_new(gcut_list_string_new("セナ + Ruby",
452  "セナセ",
453  "セナセナ",
454  "ナ",
455  "ナ + Ruby",
456  "ナセ",
457  "ナセナ",
458  "ナセナセ",
459  NULL),
460  set_ascending, set_min, set_gt, set_lt,
461  set_sis, NULL),
462  test_data_free,
463  "ascending - max - min - sis",
464  test_data_new(gcut_list_string_new("セナ",
465  "セナ + Ruby",
466  "セナセ",
467  "セナセナ",
468  NULL),
469  set_ascending, set_max, set_min, set_sis,
470  NULL),
471  test_data_free,
472  "ascending - max - min - gt - sis",
473  test_data_new(gcut_list_string_new("セナ + Ruby",
474  "セナセ",
475  "セナセナ",
476  NULL),
477  set_ascending, set_max, set_min, set_gt,
478  set_sis, NULL),
479  test_data_free,
480  "ascending - max - min - lt - sis",
481  test_data_new(gcut_list_string_new("セナ",
482  "セナ + Ruby",
483  "セナセ",
484  NULL),
485  set_ascending, set_max, set_min, set_lt,
486  set_sis, NULL),
487  test_data_free,
488  "ascending - max - min - gt - lt - sis",
489  test_data_new(gcut_list_string_new("セナ + Ruby",
490  "セナセ",
491  NULL),
492  set_ascending, set_max, set_min, set_gt,
493  set_lt, set_sis, NULL),
494  test_data_free,
495  "ascending - high-min - sis",
496  test_data_new(gcut_list_string_new("セナセナ",
497  "ナ",
498  "ナ + Ruby",
499  "ナセ",
500  "ナセナ",
501  "ナセナセ",
502  NULL),
503  set_ascending, set_min_high, set_sis, NULL),
504  test_data_free,
505  "ascending - low-max - sis",
506  test_data_new(gcut_list_string_new("Groonga",
507  "セ",
508  "セナ",
509  NULL),
510  set_ascending, set_max_low, set_sis, NULL),
511  test_data_free,
512  "ascending - high-min - low-max - sis",
513  test_data_new(NULL,
514  set_ascending, set_min_high, set_max_low, set_sis,
515  NULL),
516  test_data_free);
517 }
518 
519 static void
520 add_data_descending(void)
521 {
522  cut_add_data("descending",
523  test_data_new(gcut_list_string_new("ナセナセ",
524  "セナセナ",
525  "セナ + Ruby",
526  "セナ",
527  "Groonga",
528  NULL),
529  set_descending, NULL),
530  test_data_free,
531  "descending - max",
532  test_data_new(gcut_list_string_new("セナセナ",
533  "セナ + Ruby",
534  "セナ",
535  "Groonga",
536  NULL),
537  set_descending, set_max, NULL),
538  test_data_free,
539  "descending - max - gt",
540  test_data_new(gcut_list_string_new("セナセナ",
541  "セナ + Ruby",
542  "セナ",
543  "Groonga",
544  NULL),
545  set_descending, set_max, set_gt, NULL),
546  test_data_free,
547  "descending - max - lt",
548  test_data_new(gcut_list_string_new("セナ + Ruby",
549  "セナ",
550  "Groonga",
551  NULL),
552  set_descending, set_max, set_lt, NULL),
553  test_data_free,
554  "descending - max - gt - lt",
555  test_data_new(gcut_list_string_new("セナ + Ruby",
556  "セナ",
557  "Groonga",
558  NULL),
559  set_descending, set_max, set_gt, set_lt, NULL),
560  test_data_free,
561  "descending - min",
562  test_data_new(gcut_list_string_new("ナセナセ",
563  "セナセナ",
564  "セナ + Ruby",
565  "セナ",
566  NULL),
567  set_descending, set_min, NULL),
568  test_data_free,
569  "descending - min - gt",
570  test_data_new(gcut_list_string_new("ナセナセ",
571  "セナセナ",
572  "セナ + Ruby",
573  NULL),
574  set_descending, set_min, set_gt, NULL),
575  test_data_free,
576  "descending - min - lt",
577  test_data_new(gcut_list_string_new("ナセナセ",
578  "セナセナ",
579  "セナ + Ruby",
580  "セナ",
581  NULL),
582  set_descending, set_min, set_lt, NULL),
583  test_data_free,
584  "descending - min - gt - lt",
585  test_data_new(gcut_list_string_new("ナセナセ",
586  "セナセナ",
587  "セナ + Ruby",
588  NULL),
589  set_descending, set_min, set_gt, set_lt, NULL),
590  test_data_free,
591  "descending - max - min",
592  test_data_new(gcut_list_string_new("セナセナ",
593  "セナ + Ruby",
594  "セナ",
595  NULL),
596  set_descending, set_max, set_min, NULL),
597  test_data_free,
598  "descending - max - min - gt",
599  test_data_new(gcut_list_string_new("セナセナ",
600  "セナ + Ruby",
601  NULL),
602  set_descending, set_max, set_min, set_gt,
603  NULL),
604  test_data_free,
605  "descending - max - min - lt",
606  test_data_new(gcut_list_string_new("セナ + Ruby",
607  "セナ",
608  NULL),
609  set_descending, set_max, set_min, set_lt,
610  NULL),
611  test_data_free,
612  "descending - max - min - gt - lt",
613  test_data_new(gcut_list_string_new("セナ + Ruby",
614  NULL),
615  set_descending, set_max, set_min, set_gt,
616  set_lt, NULL),
617  test_data_free,
618  "descending - high-min",
619  test_data_new(gcut_list_string_new("ナセナセ",
620  "セナセナ",
621  NULL),
622  set_descending, set_min_high, NULL),
623  test_data_free,
624  "descending - low-max",
625  test_data_new(gcut_list_string_new("セナ",
626  "Groonga",
627  NULL),
628  set_descending, set_max_low, NULL),
629  test_data_free,
630  "descending - high-min - low-max",
631  test_data_new(NULL,
632  set_descending, set_min_high, set_max_low, NULL),
633  test_data_free);
634 }
635 
636 static void
637 add_data_descending_sis(void)
638 {
639  cut_add_data("descending - sis",
640  test_data_new(gcut_list_string_new("ナセナセ",
641  "ナセナ",
642  "ナセ",
643  "ナ + Ruby",
644  "ナ",
645  "セナセナ",
646  "セナセ",
647  "セナ + Ruby",
648  "セナ",
649  "セ",
650  "Groonga",
651  NULL),
652  set_descending, set_sis, NULL),
653  test_data_free,
654  "descending - max - sis",
655  test_data_new(gcut_list_string_new("セナセナ",
656  "セナセ",
657  "セナ + Ruby",
658  "セナ",
659  "セ",
660  "Groonga",
661  NULL),
662  set_descending, set_max, set_sis, NULL),
663  test_data_free,
664  "descending - max - gt - sis",
665  test_data_new(gcut_list_string_new("セナセナ",
666  "セナセ",
667  "セナ + Ruby",
668  "セナ",
669  "セ",
670  "Groonga",
671  NULL),
672  set_descending, set_max, set_gt, set_sis,
673  NULL),
674  test_data_free,
675  "descending - max - lt - sis",
676  test_data_new(gcut_list_string_new("セナセ",
677  "セナ + Ruby",
678  "セナ",
679  "セ",
680  "Groonga",
681  NULL),
682  set_descending, set_max, set_lt, set_sis,
683  NULL),
684  test_data_free,
685  "descending - max - gt - lt - sis",
686  test_data_new(gcut_list_string_new("セナセ",
687  "セナ + Ruby",
688  "セナ",
689  "セ",
690  "Groonga",
691  NULL),
692  set_descending, set_max, set_gt, set_lt,
693  set_sis, NULL),
694  test_data_free,
695  "descending - min - sis",
696  test_data_new(gcut_list_string_new("ナセナセ",
697  "ナセナ",
698  "ナセ",
699  "ナ + Ruby",
700  "ナ",
701  "セナセナ",
702  "セナセ",
703  "セナ + Ruby",
704  "セナ",
705  NULL),
706  set_descending, set_min, set_sis, NULL),
707  test_data_free,
708  "descending - min - gt - sis",
709  test_data_new(gcut_list_string_new("ナセナセ",
710  "ナセナ",
711  "ナセ",
712  "ナ + Ruby",
713  "ナ",
714  "セナセナ",
715  "セナセ",
716  "セナ + Ruby",
717  NULL),
718  set_descending, set_min, set_gt, set_sis,
719  NULL),
720  test_data_free,
721  "descending - min - lt - sis",
722  test_data_new(gcut_list_string_new("ナセナセ",
723  "ナセナ",
724  "ナセ",
725  "ナ + Ruby",
726  "ナ",
727  "セナセナ",
728  "セナセ",
729  "セナ + Ruby",
730  "セナ",
731  NULL),
732  set_descending, set_min, set_lt, set_sis,
733  NULL),
734  test_data_free,
735  "descending - min - gt - lt - sis",
736  test_data_new(gcut_list_string_new("ナセナセ",
737  "ナセナ",
738  "ナセ",
739  "ナ + Ruby",
740  "ナ",
741  "セナセナ",
742  "セナセ",
743  "セナ + Ruby",
744  NULL),
745  set_descending, set_min, set_gt, set_lt,
746  set_sis, NULL),
747  test_data_free,
748  "descending - max - min - sis",
749  test_data_new(gcut_list_string_new("セナセナ",
750  "セナセ",
751  "セナ + Ruby",
752  "セナ",
753  NULL),
754  set_descending, set_max, set_min,
755  set_sis, NULL),
756  test_data_free,
757  "descending - max - min - gt - sis",
758  test_data_new(gcut_list_string_new("セナセナ",
759  "セナセ",
760  "セナ + Ruby",
761  NULL),
762  set_descending, set_max, set_min, set_gt,
763  set_sis, NULL),
764  test_data_free,
765  "descending - max - min - lt - sis",
766  test_data_new(gcut_list_string_new("セナセ",
767  "セナ + Ruby",
768  "セナ",
769  NULL),
770  set_descending, set_max, set_min, set_lt,
771  set_sis, NULL),
772  test_data_free,
773  "descending - max - min - gt - lt - sis",
774  test_data_new(gcut_list_string_new("セナセ",
775  "セナ + Ruby",
776  NULL),
777  set_descending, set_max, set_min, set_gt,
778  set_lt, set_sis, NULL),
779  test_data_free,
780  "descending - high-min - sis",
781  test_data_new(gcut_list_string_new("ナセナセ",
782  "ナセナ",
783  "ナセ",
784  "ナ + Ruby",
785  "ナ",
786  "セナセナ",
787  NULL),
788  set_descending, set_min_high, set_sis, NULL),
789  test_data_free,
790  "descending - low-max - sis",
791  test_data_new(gcut_list_string_new("セナ",
792  "セ",
793  "Groonga",
794  NULL),
795  set_descending, set_max_low, set_sis, NULL),
796  test_data_free,
797  "descending - high-min - low-max - sis",
798  test_data_new(NULL,
799  set_descending, set_min_high, set_max_low, set_sis,
800  NULL),
801  test_data_free);
802 }
803 
804 void
806 {
807  add_data_ascending();
808  add_data_ascending_sis();
809  add_data_descending();
810  add_data_descending_sis();
811 }
812 
813 void
814 test_next_with_multi_entries(gconstpointer data)
815 {
816  const grn_trie_test_data *test_data = data;
817  const gchar key1[] = "セナ";
818  const gchar key2[] = "ナセナセ";
819  const gchar key3[] = "Groonga";
820  const gchar key4[] = "セナ + Ruby";
821  const gchar key5[] = "セナセナ";
822 
823  trie_test_data_set_parameters(test_data);
824 
826 
827  cut_assert_lookup_add(key1);
828  cut_assert_lookup_add(key2);
829  cut_assert_lookup_add(key3);
830  cut_assert_lookup_add(key4);
831  cut_assert_lookup_add(key5);
832 
834  gcut_assert_equal_list_string(test_data->expected_strings,
835  retrieve_all_keys());
836 }
837 
838 void
840 {
841  default_cursor_min = g_strdup("0");
842  default_cursor_min_size = strlen(default_cursor_min);
843  default_cursor_max = g_strdup("9989");
844  default_cursor_max_size = strlen(default_cursor_max);
845  default_cursor_flags |= GRN_CURSOR_DESCENDING;
846 
848 
849  cut_assert_lookup_add("997");
850  cut_assert_lookup_add("999");
851  cut_assert_lookup_add("9998");
852 
854  gcut_assert_equal_list_string(gcut_take_new_list_string("997", NULL),
855  retrieve_all_keys());
856 }
857 
858 void
860 {
861  default_cursor_flags |= GRN_CURSOR_BY_ID;
862  default_cursor_offset = 1;
863 
865 
867  gcut_assert_equal_list_string(NULL,
868  retrieve_all_keys());
869 }
870 
871 static void
872 set_value_size(void)
873 {
874  default_value_size = strlen("上書きされた値 -");
875 }
876 
877 void
878 data_value(void)
879 {
880  cut_add_data("default",
881  test_data_new(gcut_list_string_new("Groonga",
882  "",
883  "セナ",
884  "",
885  "セナ + Ruby",
886  "",
887  /* should be set two values */
888  "セナセナ",
889  "上書きされた値 -",
890  "ナセナセ",
891  "VALUE2",
892  NULL),
893  set_ascending, set_value_size, NULL),
894  test_data_free,
895 
896  "sis",
897  test_data_new(gcut_list_string_new("Groonga",
898  "",
899  "セ",
900  "",
901  "セナ",
902  "",
903  "セナ + Ruby",
904  "",
905  /* should be set two values */
906  "セナセ",
907  "",
908  "セナセナ",
909  "上書きされた値 -",
910  "ナ",
911  "",
912  "ナ + Ruby",
913  "",
914  "ナセ",
915  "",
916  "ナセナ",
917  "",
918  "ナセナセ",
919  "VALUE2",
920  NULL),
921  set_ascending, set_value_size, set_sis, NULL),
922  test_data_free);
923 }
924 
925 void
926 test_value(gconstpointer data)
927 {
928  const grn_trie_test_data *test_data = data;
929  const gchar key1[] = "セナ";
930  const gchar key2[] = "ナセナセ";
931  const gchar key3[] = "Groonga";
932  const gchar key4[] = "セナ + Ruby";
933  const gchar key5[] = "セナセナ";
934  gchar value2[] = "VALUE2";
935  gchar value4_1[] = "Groonga";
936  gchar value4_2[] = "るびい";
937  gchar value5_1[] = "上書きされる値 - overridden value";
938  gchar value5_2[] = "上書きされた値 - override value";
939 
940  trie_test_data_set_parameters(test_data);
941 
943 
944  cut_assert_lookup_add(key1);
945  cut_assert_lookup_add(key2);
946  cut_assert_lookup_add(key3);
947  cut_assert_lookup_add(key4);
948  cut_assert_lookup_add(key5);
949 
951  while (grn_pat_cursor_next(context, cursor) != GRN_ID_NIL) {
952  void *key;
953  gchar *null_terminated_key;
954  int size;
955 
956  size = grn_pat_cursor_get_key(context, cursor, &key);
957  null_terminated_key = g_string_free(g_string_new_len(key, size), FALSE);
958  if (g_str_equal(null_terminated_key, key2)) {
959  grn_pat_cursor_set_value(context, cursor, value2, GRN_OBJ_SET);
960  } else if (g_str_equal(null_terminated_key, key4)) {
961  grn_pat_cursor_set_value(context, cursor, value4_1, GRN_OBJ_INCR);
962  grn_pat_cursor_set_value(context, cursor, value4_2, GRN_OBJ_INCR);
963  } else if (g_str_equal(null_terminated_key, key5)) {
964  grn_pat_cursor_set_value(context, cursor, value5_1, GRN_OBJ_SET);
965  grn_pat_cursor_set_value(context, cursor, value5_2, GRN_OBJ_SET);
966  }
967  }
968  cursor_free();
969 
971  gcut_assert_equal_list_string(test_data->expected_strings,
972  retrieve_all_keys_and_values());
973 }
974 
975 void
976 data_delete(void)
977 {
978  cut_add_data("default",
979  test_data_new(gcut_list_string_new("Groonga",
980  "セナ + Ruby",
981  "ナセナセ",
982  NULL),
983  set_ascending, NULL),
984  test_data_free,
985  "sis",
986  test_data_new(gcut_list_string_new("Groonga",
987  "セ",
988  "セナ + Ruby",
989  "セナセ",
990  "ナ + Ruby",
991  "ナセ",
992  "ナセナセ",
993  NULL),
994  set_ascending, set_sis, NULL),
995  test_data_free);
996 }
997 
998 void
999 test_delete(gconstpointer data)
1000 {
1001  const grn_trie_test_data *test_data = data;
1002  const gchar key1[] = "セナ";
1003  const gchar key2[] = "ナセナセ";
1004  const gchar key3[] = "Groonga";
1005  const gchar key4[] = "セナ + Ruby";
1006  const gchar key5[] = "セナセナ";
1007 
1008  trie_test_data_set_parameters(test_data);
1009 
1011 
1012  cut_assert_lookup_add(key1);
1013  cut_assert_lookup_add(key2);
1014  cut_assert_lookup_add(key3);
1015  cut_assert_lookup_add(key4);
1016  cut_assert_lookup_add(key5);
1017 
1019  while (grn_pat_cursor_next(context, cursor) != GRN_ID_NIL) {
1020  void *key;
1021  gchar *null_terminated_key;
1022  int size;
1023 
1024  size = grn_pat_cursor_get_key(context, cursor, &key);
1025  null_terminated_key = g_string_free(g_string_new_len(key, size), FALSE);
1026  if (g_str_equal(null_terminated_key, key1) ||
1027  g_str_equal(null_terminated_key, key5)) {
1028  grn_pat_cursor_delete(context, cursor, NULL);
1029  }
1030  }
1031  cursor_free();
1032 
1034  gcut_assert_equal_list_string(test_data->expected_strings,
1035  retrieve_all_keys());
1036 }