Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-hash-sort.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2008-2009 Kouhei Sutou <kou@cozmixng.org>
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 <store.h>
20 #include "test-hash.h"
21 
22 void data_sort_by_uint_key(void);
23 void test_sort_by_uint_key(gconstpointer data);
24 void data_sort_by_int_key(void);
25 void test_sort_by_int_key(gconstpointer data);
27 void test_sort_by_variable_size_key(gconstpointer data);
28 void data_sort_by_value(void);
29 void test_sort_by_value(gconstpointer data);
30 
31 static GList *keys;
32 static GList *values;
33 static grn_array *sort_result;
34 
35 void
37 {
38  startup_hash_common();
39 }
40 
41 void
43 {
44  shutdown_hash_common();
45 }
46 
47 void
48 cut_setup(void)
49 {
50  setup_hash_common("hash-sort");
51  keys = NULL;
52  values = NULL;
53  sort_result = NULL;
54 }
55 
56 static void
57 keys_free(void)
58 {
59  if (keys) {
60  gcut_list_string_free(keys);
61  keys = NULL;
62  }
63 }
64 
65 static void
66 values_free(void)
67 {
68  if (values) {
69  gcut_list_string_free(values);
70  values = NULL;
71  }
72 }
73 
74 void
76 {
77  keys_free();
78  values_free();
79  if (sort_result)
80  grn_array_close(context, sort_result);
81  teardown_hash_common();
82 }
83 
84 
85 typedef int (*compare_func)(grn_ctx *ctx,
86  grn_obj *hash1, void *target1, uint32_t target1_size,
87  grn_obj *hash2, void *target2, uint32_t target2_size,
88  void *compare_arg);
89 
90 typedef struct _grn_sort_test_data
91 {
93  int limit;
96  const GList *strings;
98 
99 static grn_table_sort_optarg *
100 sort_options_new(int flags, compare_func _compare, void *compare_arg, int offset)
101 {
103 
104  options = g_new0(grn_table_sort_optarg, 1);
105  options->flags = flags;
106  options->compar = _compare;
107  options->compar_arg = compare_arg;
108  options->offset = offset;
109 
110  return options;
111 }
112 
113 static void
114 sort_options_free(grn_table_sort_optarg *options)
115 {
116  g_free(options);
117 }
118 
119 static grn_sort_test_data *
120 sort_test_data_new(GList *expected_strings,
121  int limit,
123  grn_test_set_parameters_func set_parameters,
124  const GList *strings)
125 {
126  grn_sort_test_data *test_data;
127 
128  test_data = g_new0(grn_sort_test_data, 1);
129  test_data->expected_strings = expected_strings;
130  test_data->limit = limit;
131  test_data->options = options;
132  test_data->set_parameters = set_parameters;
133  test_data->strings = strings;
134 
135  return test_data;
136 }
137 
138 static void
139 sort_test_data_free(grn_sort_test_data *test_data)
140 {
141  if (test_data->options)
142  sort_options_free(test_data->options);
143  g_free(test_data);
144 }
145 
146 static GList *
147 retrieve_all_keys (grn_array *array, grn_id n_entries)
148 {
149  grn_id id;
150  grn_array_cursor *cursor;
151 
152  keys_free();
153 
154  cursor = grn_array_cursor_open(context, array, 0, 0, 0, -1, GRN_CURSOR_ASCENDING);
155  id = grn_array_cursor_next(context, cursor);
156  while (id != GRN_ID_NIL) {
157  grn_id *hash_id;
158  void *array_value;
159  gchar key[GRN_HASH_MAX_KEY_SIZE];
160  int size;
161 
162  grn_array_cursor_get_value(context, cursor, &array_value);
163  hash_id = array_value;
164  size = grn_hash_get_key(context, hash, *hash_id, key, GRN_HASH_MAX_KEY_SIZE);
165  key[size] = '\0';
166  keys = g_list_append(keys, g_strdup(key));
167  id = grn_array_cursor_next(context, cursor);
168  }
170 
171  return keys;
172 }
173 
174 static GList *
175 retrieve_all_values (grn_array *array, grn_id n_entries)
176 {
177  grn_id id;
178  grn_array_cursor *cursor;
179 
180  values_free();
181 
182  cursor = grn_array_cursor_open(context, array, 0, 0, 0, -1, GRN_CURSOR_ASCENDING);
183  id = grn_array_cursor_next(context, cursor);
184  while (id != GRN_ID_NIL) {
185  grn_id *hash_id;
186  void *array_value;
188  int size;
189 
190  grn_array_cursor_get_value(context, cursor, &array_value);
191  hash_id = array_value;
192  size = grn_hash_get_value(context, hash, *hash_id, value);
193  values = g_list_append(values, g_strdup(value));
194  id = grn_array_cursor_next(context, cursor);
195  }
197 
198  return values;
199 }
200 
201 static void
202 add_sort_by_uint_key_data(const gchar *additional_label,
203  grn_test_set_parameters_func set_parameters_func)
204 {
205  int sort_by_unsigned_key_flags;
206 
207  sort_by_unsigned_key_flags = GRN_TABLE_SORT_AS_NUMBER;
208  sort_by_unsigned_key_flags |= GRN_TABLE_SORT_AS_UNSIGNED;
209 
210  cut_add_data(cut_take_printf("ascending%s", additional_label),
211  sort_test_data_new(gcut_list_string_new("セナセナ",
212  "セナ",
213  "ナセナセ",
214  "Senna",
215  "セナ + Ruby",
216  NULL),
217  -1,
218  sort_options_new(GRN_TABLE_SORT_ASC |
219  sort_by_unsigned_key_flags,
220  NULL, NULL,
221  0),
222  set_parameters_func,
223  NULL),
224  sort_test_data_free);
225 
226  cut_add_data(cut_take_printf("ascending - limit%s", additional_label),
227  sort_test_data_new(gcut_list_string_new("セナセナ",
228  "セナ",
229  "ナセナセ",
230  NULL),
231  3,
232  sort_options_new(GRN_TABLE_SORT_ASC |
233  sort_by_unsigned_key_flags,
234  NULL, NULL,
235  0),
236  set_parameters_func,
237  NULL),
238  sort_test_data_free);
239 
240  cut_add_data(cut_take_printf("descending%s", additional_label),
241  sort_test_data_new(gcut_list_string_new("セナ + Ruby",
242  "Senna",
243  "ナセナセ",
244  "セナ",
245  "セナセナ",
246  NULL),
247  -1,
248  sort_options_new(GRN_TABLE_SORT_DESC |
249  sort_by_unsigned_key_flags,
250  NULL, NULL,
251  0),
252  set_parameters_func,
253  NULL),
254  sort_test_data_free);
255 
256  cut_add_data(cut_take_printf("descending - limit%s", additional_label),
257  sort_test_data_new(gcut_list_string_new("セナ + Ruby",
258  "Senna",
259  "ナセナセ",
260  NULL),
261  3,
262  sort_options_new(GRN_TABLE_SORT_DESC |
263  sort_by_unsigned_key_flags,
264  NULL, NULL,
265  0),
266  set_parameters_func,
267  NULL),
268  sort_test_data_free);
269 
270  cut_add_data(cut_take_printf("no options%s", additional_label),
271  sort_test_data_new(gcut_list_string_new("セナセナ",
272  "Senna",
273  "セナ",
274  "セナ + Ruby",
275  "ナセナセ",
276  NULL),
277  -1,
278  NULL,
279  set_parameters_func,
280  NULL),
281  sort_test_data_free);
282 
283  cut_add_data(cut_take_printf("no options - limit%s", additional_label),
284  sort_test_data_new(gcut_list_string_new("セナセナ",
285  "Senna",
286  "セナ",
287  NULL),
288  3,
289  NULL,
290  set_parameters_func,
291  NULL),
292  sort_test_data_free);
293 }
294 
295 void
297 {
298  add_sort_by_uint_key_data("", NULL);
299  add_sort_by_uint_key_data(" - tiny", set_tiny_flags);
300 }
301 
302 void
303 test_sort_by_uint_key(gconstpointer data)
304 {
305  const grn_sort_test_data *test_data = data;
306  const uint32_t key1 = 100;
307  const uint32_t key2 = 2000000;
308  const uint32_t key3 = 30000;
309  const uint32_t key4 = 4000;
310  const uint32_t key5 = 5;
311  gchar value1[] = "セナ";
312  gchar value2[] = "セナ + Ruby";
313  gchar value3[] = "Senna";
314  gchar value4[] = "ナセナセ";
315  gchar value5[] = "セナセナ";
316  int n_entries;
317 
318  if (test_data->set_parameters)
319  test_data->set_parameters();
320 
322 
323  cut_assert_lookup_add_with_value(&key1, value1);
324  cut_assert_lookup_add_with_value(&key2, value2);
325  cut_assert_lookup_add_with_value(&key3, value3);
326  cut_assert_lookup_add_with_value(&key4, value4);
327  cut_assert_lookup_add_with_value(&key5, value5);
328 
329  sort_result = grn_array_create(context, NULL, sizeof(grn_id), GRN_ARRAY_TINY);
330  n_entries = grn_hash_sort(context, hash, test_data->limit,
331  sort_result, test_data->options);
332  gcut_assert_equal_list_string(test_data->expected_strings,
333  retrieve_all_values(sort_result, n_entries));
334 }
335 
336 static void
337 add_sort_by_int_key_data(const gchar *additional_label,
338  grn_test_set_parameters_func set_parameters_func)
339 {
340  int sort_by_number_key_flags;
341 
342  sort_by_number_key_flags = GRN_TABLE_SORT_AS_NUMBER;
343 
344  cut_add_data(cut_take_printf("ascending%s", additional_label),
345  sort_test_data_new(gcut_list_string_new("セナ + Ruby",
346  "ナセナセ",
347  "セナセナ",
348  "セナ",
349  "Senna",
350  NULL),
351  -1,
352  sort_options_new(GRN_TABLE_SORT_ASC |
353  sort_by_number_key_flags,
354  NULL, NULL,
355  0),
356  set_parameters_func,
357  NULL),
358  sort_test_data_free);
359 
360  cut_add_data(cut_take_printf("ascending - limit%s", additional_label),
361  sort_test_data_new(gcut_list_string_new("セナ + Ruby",
362  "ナセナセ",
363  "セナセナ",
364  NULL),
365  3,
366  sort_options_new(GRN_TABLE_SORT_ASC |
367  sort_by_number_key_flags,
368  NULL, NULL,
369  0),
370  set_parameters_func,
371  NULL),
372  sort_test_data_free);
373 
374  cut_add_data(cut_take_printf("descending%s", additional_label),
375  sort_test_data_new(gcut_list_string_new("Senna",
376  "セナ",
377  "セナセナ",
378  "ナセナセ",
379  "セナ + Ruby",
380  NULL),
381  -1,
382  sort_options_new(GRN_TABLE_SORT_DESC |
383  sort_by_number_key_flags,
384  NULL, NULL,
385  0),
386  set_parameters_func,
387  NULL),
388  sort_test_data_free);
389 
390  cut_add_data(cut_take_printf("descending - limit%s", additional_label),
391  sort_test_data_new(gcut_list_string_new("Senna",
392  "セナ",
393  "セナセナ",
394  NULL),
395  3,
396  sort_options_new(GRN_TABLE_SORT_DESC |
397  sort_by_number_key_flags,
398  NULL, NULL,
399  0),
400  set_parameters_func,
401  NULL),
402  sort_test_data_free);
403 
404  cut_add_data(cut_take_printf("no options%s", additional_label),
405  sort_test_data_new(gcut_list_string_new("セナセナ",
406  "Senna",
407  "ナセナセ",
408  "セナ",
409  "セナ + Ruby",
410  NULL),
411  -1,
412  NULL,
413  set_parameters_func,
414  NULL),
415  sort_test_data_free);
416 
417  cut_add_data(cut_take_printf("no options - limit%s", additional_label),
418  sort_test_data_new(gcut_list_string_new("セナセナ",
419  "Senna",
420  "ナセナセ",
421  NULL),
422  3,
423  NULL,
424  set_parameters_func,
425  NULL),
426  sort_test_data_free);
427 }
428 
429 void
431 {
432  add_sort_by_int_key_data("", NULL);
433  add_sort_by_int_key_data(" - tiny", set_tiny_flags);
434 }
435 
436 void
437 test_sort_by_int_key(gconstpointer data)
438 {
439  const grn_sort_test_data *test_data = data;
440  const int32_t key1 = 100;
441  const int32_t key2 = -2000000;
442  const int32_t key3 = 30000;
443  const int32_t key4 = -4000;
444  const int32_t key5 = 5;
445  gchar value1[] = "セナ";
446  gchar value2[] = "セナ + Ruby";
447  gchar value3[] = "Senna";
448  gchar value4[] = "ナセナセ";
449  gchar value5[] = "セナセナ";
450  int n_entries;
451 
452  key_size = sizeof(int32_t);
453  grn_test_hash_factory_set_key_size(factory, key_size);
454 
455  if (test_data->set_parameters)
456  test_data->set_parameters();
457 
459 
460  cut_assert_lookup_add_with_value(&key1, value1);
461  cut_assert_lookup_add_with_value(&key2, value2);
462  cut_assert_lookup_add_with_value(&key3, value3);
463  cut_assert_lookup_add_with_value(&key4, value4);
464  cut_assert_lookup_add_with_value(&key5, value5);
465 
466  sort_result = grn_array_create(context, NULL, sizeof(grn_id), GRN_ARRAY_TINY);
467  n_entries = grn_hash_sort(context, hash, test_data->limit,
468  sort_result, test_data->options);
469  gcut_assert_equal_list_string(test_data->expected_strings,
470  retrieve_all_values(sort_result, n_entries));
471 }
472 
473 static int
474 compare_string(grn_ctx *ctx,
475  grn_obj *hash1, void *target1, uint32_t target1_size,
476  grn_obj *hash2, void *target2, uint32_t target2_size,
477  void *user_data)
478 {
479  gchar *null_terminated_target1;
480  gchar *null_terminated_target2;
481 
482  null_terminated_target1 =
483  g_string_free(g_string_new_len(target1, target1_size), FALSE);
484  null_terminated_target2 =
485  g_string_free(g_string_new_len(target2, target2_size), FALSE);
486  return strcmp(cut_take_string(null_terminated_target1),
487  cut_take_string(null_terminated_target2)) > 0;
488 }
489 
490 static void
491 add_sort_by_variable_size_key_data(const gchar *additional_label,
492  grn_test_set_parameters_func set_parameters_func)
493 {
494  const GList *keys;
495 
496  keys = gcut_take_list(gcut_list_string_new("セナ",
497  "セナ + Ruby",
498  "Senna",
499  "ナセナセ",
500  "セナセナ",
501  NULL),
502  g_free);
503  cut_add_data(cut_take_printf("ascending%s", additional_label),
504  sort_test_data_new(gcut_list_string_new("Senna",
505  "セナ",
506  "セナ + Ruby",
507  "セナセナ",
508  "ナセナセ",
509  NULL),
510  -1,
511  sort_options_new(GRN_TABLE_SORT_ASC,
512  compare_string, NULL,
513  0),
514  set_parameters_func,
515  keys),
516  sort_test_data_free);
517 
518  cut_add_data(cut_take_printf("ascending - limit%s", additional_label),
519  sort_test_data_new(gcut_list_string_new("Senna",
520  "セナ",
521  "セナ + Ruby",
522  NULL),
523  3,
524  sort_options_new(GRN_TABLE_SORT_ASC,
525  compare_string, NULL,
526  0),
527  set_parameters_func,
528  keys),
529  sort_test_data_free);
530 
531  cut_add_data(cut_take_printf("descending%s", additional_label),
532  sort_test_data_new(gcut_list_string_new("ナセナセ",
533  "セナセナ",
534  "セナ + Ruby",
535  "セナ",
536  "Senna",
537  NULL),
538  -1,
539  sort_options_new(GRN_TABLE_SORT_DESC,
540  compare_string, NULL,
541  0),
542  set_parameters_func,
543  keys),
544  sort_test_data_free);
545 
546  cut_add_data(cut_take_printf("descending - limit%s", additional_label),
547  sort_test_data_new(gcut_list_string_new("ナセナセ",
548  "セナセナ",
549  "セナ + Ruby",
550  NULL),
551  3,
552  sort_options_new(GRN_TABLE_SORT_DESC,
553  compare_string, NULL,
554  0),
555  set_parameters_func,
556  keys),
557  sort_test_data_free);
558 }
559 
560 static void
561 add_sort_by_variable_size_key_data_many(const gchar *additional_label,
562  grn_test_set_parameters_func set_parameters_func)
563 {
564  const GList *keys;
565 
566  keys = gcut_take_list(gcut_list_string_new("セナ",
567  "セナ + Ruby",
568  "Senna",
569  "ナセナセ",
570  "セナセナ",
571  "Ruby",
572  "Tritton",
573  "ブラジル",
574  "Ludia",
575  NULL),
576  g_free);
577  cut_add_data(cut_take_printf("many - ascending%s", additional_label),
578  sort_test_data_new(gcut_list_string_new("Ludia",
579  "Ruby",
580  "Senna",
581  "Tritton",
582  "セナ",
583  "セナ + Ruby",
584  "セナセナ",
585  "ナセナセ",
586  "ブラジル",
587  NULL),
588  -1,
589  sort_options_new(GRN_TABLE_SORT_ASC,
590  compare_string, NULL,
591  0),
592  set_parameters_func,
593  keys),
594  sort_test_data_free);
595 
596  cut_add_data(cut_take_printf("many - ascending - limit%s", additional_label),
597  sort_test_data_new(gcut_list_string_new("Ludia",
598  "Ruby",
599  "Senna",
600  NULL),
601  3,
602  sort_options_new(GRN_TABLE_SORT_ASC,
603  compare_string, NULL,
604  0),
605  set_parameters_func,
606  keys),
607  sort_test_data_free);
608 
609  cut_add_data(cut_take_printf("many - descending%s", additional_label),
610  sort_test_data_new(gcut_list_string_new("ブラジル",
611  "ナセナセ",
612  "セナセナ",
613  "セナ + Ruby",
614  "セナ",
615  "Tritton",
616  "Senna",
617  "Ruby",
618  "Ludia",
619  NULL),
620  -1,
621  sort_options_new(GRN_TABLE_SORT_DESC,
622  compare_string, NULL,
623  0),
624  set_parameters_func,
625  keys),
626  sort_test_data_free);
627 
628  cut_add_data(cut_take_printf("many - descending - limit%s", additional_label),
629  sort_test_data_new(gcut_list_string_new("ブラジル",
630  "ナセナセ",
631  "セナセナ",
632  NULL),
633  3,
634  sort_options_new(GRN_TABLE_SORT_DESC,
635  compare_string, NULL,
636  0),
637  set_parameters_func,
638  keys),
639  sort_test_data_free);
640 }
641 
642 void
644 {
645  add_sort_by_variable_size_key_data("", NULL);
646  add_sort_by_variable_size_key_data(" - tiny", set_tiny_flags);
647 
648  add_sort_by_variable_size_key_data_many("", NULL);
649  add_sort_by_variable_size_key_data_many(" - tiny", set_tiny_flags);
650 }
651 
652 void
654 {
655  const grn_sort_test_data *test_data = data;
656  const GList *node;
657  int n_entries;
658 
661 
662  if (test_data->set_parameters)
663  test_data->set_parameters();
664 
666 
667  for (node = test_data->strings; node; node = g_list_next(node)) {
668  gchar *key = node->data;
670  }
671 
672  sort_result = grn_array_create(context, NULL, sizeof(grn_id), GRN_ARRAY_TINY);
673  n_entries = grn_hash_sort(context, hash, test_data->limit,
674  sort_result, test_data->options);
675  gcut_assert_equal_list_string(test_data->expected_strings,
676  retrieve_all_keys(sort_result, n_entries));
677 }
678 
679 static void
680 add_sort_by_value_data(const gchar *additional_label,
681  grn_test_set_parameters_func set_parameters_func)
682 {
683  const GList *values;
684 
685  values = gcut_take_list(gcut_list_string_new("セナ",
686  "セナ + Ruby",
687  "Senna",
688  "ナセナセ",
689  "セナセナ",
690  NULL),
691  g_free);
692 
693  cut_add_data(cut_take_printf("ascending%s", additional_label),
694  sort_test_data_new(gcut_list_string_new("Senna",
695  "セナ",
696  "セナ + Ruby",
697  "セナセナ",
698  "ナセナセ",
699  NULL),
700  -1,
701  sort_options_new(GRN_TABLE_SORT_ASC |
703  compare_string, NULL,
704  0),
705  set_parameters_func,
706  values),
707  sort_test_data_free);
708 
709  cut_add_data(cut_take_printf("ascending - limit%s", additional_label),
710  sort_test_data_new(gcut_list_string_new("Senna",
711  "セナ",
712  "セナ + Ruby",
713  NULL),
714  3,
715  sort_options_new(GRN_TABLE_SORT_ASC |
717  compare_string, NULL,
718  0),
719  set_parameters_func,
720  values),
721  sort_test_data_free);
722 
723  cut_add_data(cut_take_printf("descending%s", additional_label),
724  sort_test_data_new(gcut_list_string_new("ナセナセ",
725  "セナセナ",
726  "セナ + Ruby",
727  "セナ",
728  "Senna",
729  NULL),
730  -1,
731  sort_options_new(GRN_TABLE_SORT_DESC |
733  compare_string, NULL,
734  0),
735  set_parameters_func,
736  values),
737  sort_test_data_free);
738 
739  cut_add_data(cut_take_printf("descending - limit%s", additional_label),
740  sort_test_data_new(gcut_list_string_new("ナセナセ",
741  "セナセナ",
742  "セナ + Ruby",
743  NULL),
744  3,
745  sort_options_new(GRN_TABLE_SORT_DESC |
747  compare_string, NULL,
748  0),
749  set_parameters_func,
750  values),
751  sort_test_data_free);
752 }
753 
754 static void
755 add_sort_by_value_data_many(const gchar *additional_label,
756  grn_test_set_parameters_func set_parameters_func)
757 {
758  const GList *values;
759 
760  values = gcut_take_list(gcut_list_string_new("セナ",
761  "セナ + Ruby",
762  "Senna",
763  "ナセナセ",
764  "セナセナ",
765  "Ruby",
766  "Tritton",
767  "ブラジル",
768  "Ludia",
769  NULL),
770  g_free);
771 
772  cut_add_data(cut_take_printf("many - ascending%s", additional_label),
773  sort_test_data_new(gcut_list_string_new("Ludia",
774  "Ruby",
775  "Senna",
776  "Tritton",
777  "セナ",
778  "セナ + Ruby",
779  "セナセナ",
780  "ナセナセ",
781  "ブラジル",
782  NULL),
783  -1,
784  sort_options_new(GRN_TABLE_SORT_ASC |
786  compare_string, NULL,
787  0),
788  set_parameters_func,
789  values),
790  sort_test_data_free);
791 
792  cut_add_data(cut_take_printf("many - ascending - limit%s", additional_label),
793  sort_test_data_new(gcut_list_string_new("Ludia",
794  "Ruby",
795  "Senna",
796  NULL),
797  3,
798  sort_options_new(GRN_TABLE_SORT_ASC |
800  compare_string, NULL,
801  0),
802  set_parameters_func,
803  values),
804  sort_test_data_free);
805 
806  cut_add_data(cut_take_printf("many - descending%s", additional_label),
807  sort_test_data_new(gcut_list_string_new("ブラジル",
808  "ナセナセ",
809  "セナセナ",
810  "セナ + Ruby",
811  "セナ",
812  "Tritton",
813  "Senna",
814  "Ruby",
815  "Ludia",
816  NULL),
817  -1,
818  sort_options_new(GRN_TABLE_SORT_DESC |
820  compare_string, NULL,
821  0),
822  set_parameters_func,
823  values),
824  sort_test_data_free);
825 
826  cut_add_data(cut_take_printf("many - descending - limit%s", additional_label),
827  sort_test_data_new(gcut_list_string_new("ブラジル",
828  "ナセナセ",
829  "セナセナ",
830  NULL),
831  3,
832  sort_options_new(GRN_TABLE_SORT_DESC |
834  compare_string, NULL,
835  0),
836  set_parameters_func,
837  values),
838  sort_test_data_free);
839 }
840 
841 void
843 {
844  add_sort_by_value_data("", NULL);
845  add_sort_by_value_data(" - tiny", set_tiny_flags);
846 
847  add_sort_by_value_data_many("", NULL);
848  add_sort_by_value_data_many(" - tiny", set_tiny_flags);
849 }
850 
851 void
852 test_sort_by_value(gconstpointer data)
853 {
854  const grn_sort_test_data *test_data = data;
855  const GList *node;
856  int32_t key;
857  int n_entries;
858 
859  key_size = sizeof(key);
860  grn_test_hash_factory_set_key_size(factory, key_size);
861 
862  if (test_data->set_parameters)
863  test_data->set_parameters();
864 
866 
867  key = 1;
868  for (node = test_data->strings; node; node = g_list_next(node)) {
869  gchar *_value = node->data;
870  cut_assert_lookup_add_with_value(&key, _value);
871  key++;
872  }
873 
874  sort_result = grn_array_create(context, NULL, sizeof(grn_id), GRN_ARRAY_TINY);
875  n_entries = grn_hash_sort(context, hash, test_data->limit,
876  sort_result, test_data->options);
877  gcut_assert_equal_list_string(test_data->expected_strings,
878  retrieve_all_values(sort_result, n_entries));
879 }