Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-inspect.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2010-2013 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 <gcutter.h>
20 #include <glib/gstdio.h>
21 
22 #include "../lib/grn-assertions.h"
23 
24 #include <str.h>
25 #include <util.h>
26 
27 #define get(name) grn_ctx_get(context, name, strlen(name))
28 
29 void test_null(void);
30 void test_void(void);
31 void test_int8(void);
32 void test_int16(void);
33 void test_int32(void);
34 void test_int64(void);
35 void test_uint8(void);
36 void test_uint16(void);
37 void test_uint32(void);
38 void test_uint64(void);
39 void test_float(void);
40 void test_time(void);
41 void test_bool_true(void);
42 void test_bool_false(void);
43 void test_text(void);
44 void test_geo_point_tokyo(void);
45 void test_geo_point_wgs84(void);
46 void test_array_empty(void);
47 void test_array_with_records(void);
48 void test_hash_empty(void);
49 void test_hash_with_records(void);
50 void test_patricia_trie_empty(void);
54 void test_uvector_empty(void);
55 void test_uvector_with_records(void);
56 void test_uvector_bool(void);
57 void test_vector_empty(void);
58 void test_pvector_empty(void);
59 void test_pvector_with_records(void);
60 void data_accessor_column_name(void);
61 void test_accessor_column_name(gconstpointer data);
63 void test_accessor_dynamic_pseudo_column_name(gconstpointer data);
64 void test_column_fix_size(void);
65 void test_column_var_size(void);
66 void test_column_index(void);
67 void test_type(void);
68 void test_record(void);
69 void test_proc_command(void);
70 void test_proc_function(void);
71 
72 static gchar *tmp_directory;
73 
74 static grn_ctx *context;
75 static grn_obj *database;
76 
77 static grn_obj *inspected;
78 
79 static grn_obj *void_value;
80 static grn_obj *int8, *int16, *int32, *int64;
81 static grn_obj *uint8, *uint16, *uint32, *uint64;
82 static grn_obj *float_value;
83 static grn_obj *time_value;
84 static grn_obj *bool_value;
85 static grn_obj *text;
86 static grn_obj *geo_point_tokyo, *geo_point_wgs84;
87 static grn_obj *uvector;
88 static grn_obj *pvector;
89 static grn_obj *vector;
90 static grn_obj *record;
91 static grn_table_cursor *cursor;
92 
93 void
95 {
96  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
97  "inspect",
98  NULL);
99 }
100 
101 void
103 {
104  g_free(tmp_directory);
105 }
106 
107 static void
108 remove_tmp_directory(void)
109 {
110  cut_remove_path(tmp_directory, NULL);
111 }
112 
113 static void
114 setup_values(void)
115 {
116  void_value = NULL;
117  int8 = int16 = int32 = int64 = NULL;
118  uint8 = uint16 = uint32 = uint64 = NULL;
119  float_value = NULL;
120  time_value = NULL;
121  bool_value = NULL;
122  text = NULL;
123  geo_point_tokyo = geo_point_wgs84 = NULL;
124  uvector = NULL;
125  pvector = NULL;
126  vector = NULL;
127  record = NULL;
128  cursor = NULL;
129 }
130 
131 void
133 {
134  const gchar *database_path;
135 
136  inspected = NULL;
137  setup_values();
138 
139  remove_tmp_directory();
140  g_mkdir_with_parents(tmp_directory, 0700);
141 
142  context = g_new0(grn_ctx, 1);
143  grn_ctx_init(context, 0);
144 
145  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
146  database = grn_db_create(context, database_path, NULL);
147 }
148 
149 static void
150 teardown_values(void)
151 {
152  grn_obj_unlink(context, void_value);
153  grn_obj_unlink(context, int8);
154  grn_obj_unlink(context, int16);
155  grn_obj_unlink(context, int32);
156  grn_obj_unlink(context, int64);
157  grn_obj_unlink(context, uint8);
158  grn_obj_unlink(context, uint16);
159  grn_obj_unlink(context, uint32);
160  grn_obj_unlink(context, uint64);
161  grn_obj_unlink(context, float_value);
162  grn_obj_unlink(context, time_value);
163  grn_obj_unlink(context, bool_value);
164  grn_obj_unlink(context, text);
165  grn_obj_unlink(context, geo_point_tokyo);
166  grn_obj_unlink(context, geo_point_wgs84);
167  grn_obj_unlink(context, uvector);
168  grn_obj_unlink(context, pvector);
169  grn_obj_unlink(context, vector);
170  grn_obj_unlink(context, record);
171  grn_table_cursor_close(context, cursor);
172 }
173 
174 void
176 {
177  teardown_values();
178 
179  grn_obj_unlink(context, inspected);
180 
181  grn_obj_close(context, database);
182  grn_ctx_fin(context);
183  g_free(context);
184 
185  remove_tmp_directory();
186 }
187 
188 static const gchar *
189 inspected_string (void)
190 {
191  return cut_take_printf("%.*s",
192  (int)GRN_TEXT_LEN(inspected),
193  GRN_TEXT_VALUE(inspected));
194 }
195 
196 void
197 test_null(void)
198 {
199  inspected = grn_inspect(context, NULL, NULL);
200  cut_assert_equal_string("(NULL)", inspected_string());
201 }
202 
203 void
205 {
206  void_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_VOID);
207  GRN_TEXT_PUTS(context, void_value, "void");
208  inspected = grn_inspect(context, NULL, void_value);
209  cut_assert_equal_string("\"void\"", inspected_string());
210 }
211 
212 void
214 {
215  int8 = grn_obj_open(context, GRN_BULK, 0, GRN_DB_INT8);
216  GRN_INT8_SET(context, int8, G_MAXINT8);
217  inspected = grn_inspect(context, NULL, int8);
218  cut_assert_equal_string(cut_take_printf("%d", G_MAXINT8),
219  inspected_string());
220 }
221 
222 void
224 {
225  int16 = grn_obj_open(context, GRN_BULK, 0, GRN_DB_INT16);
226  GRN_INT16_SET(context, int16, G_MAXINT16);
227  inspected = grn_inspect(context, NULL, int16);
228  cut_assert_equal_string(cut_take_printf("%" G_GINT16_FORMAT, G_MAXINT16),
229  inspected_string());
230 }
231 
232 void
234 {
235  int32 = grn_obj_open(context, GRN_BULK, 0, GRN_DB_INT32);
236  GRN_INT32_SET(context, int32, G_MAXINT32);
237  inspected = grn_inspect(context, NULL, int32);
238  cut_assert_equal_string(cut_take_printf("%" G_GINT32_FORMAT, G_MAXINT32),
239  inspected_string());
240 }
241 
242 void
244 {
245  int64 = grn_obj_open(context, GRN_BULK, 0, GRN_DB_INT64);
246  GRN_INT64_SET(context, int64, G_MAXINT64);
247  inspected = grn_inspect(context, NULL, int64);
248  cut_assert_equal_string(cut_take_printf("%" G_GINT64_FORMAT, G_MAXINT64),
249  inspected_string());
250 }
251 
252 void
254 {
255  uint8 = grn_obj_open(context, GRN_BULK, 0, GRN_DB_UINT8);
256  GRN_UINT8_SET(context, uint8, G_MAXUINT8);
257  inspected = grn_inspect(context, NULL, uint8);
258  cut_assert_equal_string(cut_take_printf("%u", G_MAXUINT8),
259  inspected_string());
260 }
261 
262 void
264 {
265  uint16 = grn_obj_open(context, GRN_BULK, 0, GRN_DB_UINT16);
266  GRN_UINT16_SET(context, uint16, G_MAXUINT16);
267  inspected = grn_inspect(context, NULL, uint16);
268  cut_assert_equal_string(cut_take_printf("%" G_GUINT16_FORMAT, G_MAXUINT16),
269  inspected_string());
270 }
271 
272 void
274 {
275  uint32 = grn_obj_open(context, GRN_BULK, 0, GRN_DB_UINT32);
276  GRN_UINT32_SET(context, uint32, G_MAXUINT32);
277  inspected = grn_inspect(context, NULL, uint32);
278  cut_assert_equal_string(cut_take_printf("%" G_GUINT32_FORMAT, G_MAXUINT32),
279  inspected_string());
280 }
281 
282 void
283 test_uint64(void)
284 {
285  uint64 = grn_obj_open(context, GRN_BULK, 0, GRN_DB_UINT64);
286  GRN_UINT64_SET(context, uint64, G_MAXUINT64);
287  inspected = grn_inspect(context, NULL, uint64);
288  cut_assert_equal_string(cut_take_printf("%" G_GUINT64_FORMAT, G_MAXUINT64),
289  inspected_string());
290 }
291 
292 void
294 {
295  float_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_FLOAT);
296  GRN_FLOAT_SET(context, float_value, 0.29);
297  inspected = grn_inspect(context, NULL, float_value);
298  cut_assert_equal_string("0.29", inspected_string());
299 }
300 
301 void
303 {
304  GTimeVal g_time_value;
305 
306  g_time_val_from_iso8601("2010-05-31T11:50:29.29+0900", &g_time_value);
307  time_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_TIME);
308  GRN_TIME_SET(context, time_value,
309  (gint64)g_time_value.tv_sec * G_USEC_PER_SEC +
310  g_time_value.tv_usec);
311  inspected = grn_inspect(context, NULL, time_value);
312  cut_assert_equal_string(cut_take_printf("%ld.29", g_time_value.tv_sec),
313  inspected_string());
314 }
315 
316 void
318 {
319  bool_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_BOOL);
320  GRN_BOOL_SET(context, bool_value, GRN_TRUE);
321  inspected = grn_inspect(context, NULL, bool_value);
322  cut_assert_equal_string("true", inspected_string());
323 }
324 
325 void
327 {
328  bool_value = grn_obj_open(context, GRN_BULK, 0, GRN_DB_BOOL);
329  GRN_BOOL_SET(context, bool_value, GRN_FALSE);
330  inspected = grn_inspect(context, NULL, bool_value);
331  cut_assert_equal_string("false", inspected_string());
332 }
333 
334 void
336 {
337  text = grn_obj_open(context, GRN_BULK, 0, GRN_DB_TEXT);
338  GRN_TEXT_PUTS(context, text, "niku");
339  inspected = grn_inspect(context, NULL, text);
340  cut_assert_equal_string("\"niku\"", inspected_string());
341 }
342 
343 void
345 {
346  gint takane_latitude, takane_longitude;
347 
348  takane_latitude = grn_test_coordinate_in_milliseconds(35.6954581363924);
349  takane_longitude = grn_test_coordinate_in_milliseconds(139.564207350021);
350 
351  geo_point_tokyo = grn_obj_open(context, GRN_BULK, 0, GRN_DB_TOKYO_GEO_POINT);
352  GRN_GEO_POINT_SET(context, geo_point_tokyo, takane_latitude, takane_longitude);
353  inspected = grn_inspect(context, NULL, geo_point_tokyo);
354  cut_assert_equal_string("[(128503649,502431146) "
355  "((35, 41, 43, 649),(139, 33, 51, 146)) "
356  "[00000001 01111011 11011101 10000100 "
357  "10110101 11111011 01101100 01000110]]",
358  inspected_string());
359 }
360 
361 void
363 {
364  gint takane_latitude, takane_longitude;
365 
366  takane_latitude = grn_test_coordinate_in_milliseconds(35.6986901);
367  takane_longitude = grn_test_coordinate_in_milliseconds(139.56099);
368 
369  geo_point_wgs84 = grn_obj_open(context, GRN_BULK, 0, GRN_DB_WGS84_GEO_POINT);
370  GRN_GEO_POINT_SET(context, geo_point_wgs84, takane_latitude, takane_longitude);
371  inspected = grn_inspect(context, NULL, geo_point_wgs84);
372  cut_assert_equal_string("[(128515284,502419564) "
373  "((35, 41, 55, 284),(139, 33, 39, 564)) "
374  "[00000001 01111011 11011101 10000100 "
375  "10111011 10100000 10110110 01110000]]",
376  inspected_string());
377 }
378 
379 void
381 {
382  assert_send_command("table_create Sites TABLE_NO_KEY");
383  inspected = grn_inspect(context, NULL, get("Sites"));
384  cut_assert_equal_string("#<table:no_key "
385  "Sites "
386  "value:(nil) "
387  "size:0 "
388  "columns:[] "
389  "ids:[] "
390  "subrec:none"
391  ">",
392  inspected_string());
393 }
394 
395 void
397 {
398  assert_send_command("table_create Sites TABLE_NO_KEY");
399  assert_send_command("column_create Sites name COLUMN_SCALAR Text");
400  assert_send_command("load "
401  "'[[\"name\"],[\"groonga.org\"],[\"razil.jp\"]]' "
402  "Sites");
403  inspected = grn_inspect(context, NULL, get("Sites"));
404  cut_assert_equal_string("#<table:no_key "
405  "Sites "
406  "value:(nil) "
407  "size:2 "
408  "columns:[name] "
409  "ids:[1, 2] "
410  "subrec:none"
411  ">",
412  inspected_string());
413 }
414 
415 void
417 {
418  assert_send_command("table_create Sites TABLE_HASH_KEY ShortText");
419  inspected = grn_inspect(context, NULL, get("Sites"));
420  cut_assert_equal_string("#<table:hash "
421  "Sites "
422  "key:ShortText "
423  "value:(nil) "
424  "size:0 "
425  "columns:[] "
426  "default_tokenizer:(nil) "
427  "normalizer:(nil) "
428  "keys:[] "
429  "subrec:none"
430  ">",
431  inspected_string());
432 }
433 
434 void
436 {
437  assert_send_command("table_create Sites TABLE_HASH_KEY ShortText");
438  assert_send_command("column_create Sites name COLUMN_SCALAR Text");
439  assert_send_command("load "
440  "'["
441  "[\"_key\",\"name\"],"
442  "[\"groonga.org\",\"groonga\"],"
443  "[\"razil.jp\",\"Brazil\"]"
444  "]' "
445  "Sites");
446  inspected = grn_inspect(context, NULL, get("Sites"));
447  cut_assert_equal_string("#<table:hash "
448  "Sites "
449  "key:ShortText "
450  "value:(nil) "
451  "size:2 "
452  "columns:[name] "
453  "default_tokenizer:(nil) "
454  "normalizer:(nil) "
455  "keys:[\"groonga.org\", \"razil.jp\"] "
456  "subrec:none"
457  ">",
458  inspected_string());
459 }
460 
461 void
463 {
464  assert_send_command("table_create Sites TABLE_PAT_KEY ShortText");
465  inspected = grn_inspect(context, NULL, get("Sites"));
466  cut_assert_equal_string("#<table:pat "
467  "Sites "
468  "key:ShortText "
469  "value:(nil) "
470  "size:0 "
471  "columns:[] "
472  "default_tokenizer:(nil) "
473  "normalizer:(nil) "
474  "keys:[] "
475  "subrec:none "
476  "nodes:{}"
477  ">",
478  inspected_string());
479 }
480 
481 void
483 {
484  assert_send_command("table_create Sites TABLE_PAT_KEY ShortText");
485  assert_send_command("column_create Sites name COLUMN_SCALAR Text");
486  assert_send_command("load "
487  "'["
488  "[\"_key\",\"name\"],"
489  "[\"groonga.org\",\"groonga\"],"
490  "[\"razil.jp\",\"Brazil\"]"
491  "]' "
492  "Sites");
493  inspected = grn_inspect(context, NULL, get("Sites"));
494  cut_assert_equal_string(
495  "#<table:pat "
496  "Sites "
497  "key:ShortText "
498  "value:(nil) "
499  "size:2 "
500  "columns:[name] "
501  "default_tokenizer:(nil) "
502  "normalizer:(nil) "
503  "keys:[\"groonga.org\", \"razil.jp\"] "
504  "subrec:none "
505  "nodes:{\n"
506  "2(\"razil.jp\"){0,3,0}[01110010 01100001 01111010 01101001 "
507  "01101100 00101110 01101010 01110000]\n"
508  " L:1(\"groonga.org\"){10,7,0}[01100111 01110010 01101111 01101111 "
509  "01101110 01100111 01100001 00101110 "
510  "01101111 01110010 01100111]\n"
511  " L:0\n"
512  " R:1\n"
513  " R:2\n"
514  "}"
515  ">",
516  inspected_string());
517 }
518 
519 void
521 {
522  assert_send_command("table_create Sites TABLE_PAT_KEY ShortText");
523  cursor = grn_table_cursor_open(context, get("Sites"),
524  NULL, 0,
525  NULL, 0,
526  0, -1, GRN_CURSOR_ASCENDING);
527  inspected = grn_inspect(context, NULL, cursor);
528  cut_assert_equal_string("#<cursor:pat:Sites "
529  "current:0 "
530  "tail:0 "
531  "flags:ascending|greater|less "
532  "rest:0 "
533  "entries:[]"
534  ">",
535  inspected_string());
536 }
537 
538 void
540 {
541  assert_send_command("table_create Sites TABLE_PAT_KEY ShortText");
542  assert_send_command("column_create Sites name COLUMN_SCALAR Text");
543  assert_send_command("load "
544  "'["
545  "[\"_key\",\"name\"],"
546  "[\"groonga.org\",\"groonga\"],"
547  "[\"razil.jp\",\"Brazil\"]"
548  "]' "
549  "Sites");
550  cursor = grn_table_cursor_open(context, get("Sites"),
551  NULL, 0,
552  NULL, 0,
553  0, -1, GRN_CURSOR_ASCENDING);
554  inspected = grn_inspect(context, NULL, cursor);
555  cut_assert_equal_string("#<cursor:pat:Sites "
556  "current:0 "
557  "tail:0 "
558  "flags:ascending|greater|less "
559  "rest:2 "
560  "entries:[[2,{0,3,0}], [1,{0,3,0}]]"
561  ">",
562  inspected_string());
563 }
564 
565 void
567 {
568  assert_send_command("table_create Sites TABLE_PAT_KEY ShortText");
569  uvector = grn_obj_open(context, GRN_UVECTOR, 0,
570  grn_obj_id(context, get("Sites")));
571  inspected = grn_inspect(context, NULL, uvector);
572  cut_assert_equal_string("[]", inspected_string());
573 }
574 
575 void
577 {
578  assert_send_command("table_create Sites TABLE_PAT_KEY ShortText");
579  assert_send_command("load "
580  "'[[\"_key\"],[\"groonga.org\"],[\"razil.jp\"]]' "
581  "Sites");
582  uvector = grn_obj_open(context, GRN_UVECTOR, 0,
583  grn_obj_id(context, get("Sites")));
584  GRN_RECORD_PUT(context, uvector, 1);
585  GRN_RECORD_PUT(context, uvector, 2);
586  inspected = grn_inspect(context, NULL, uvector);
587  cut_assert_equal_string("["
588  "#<record:pat:Sites id:1 key:\"groonga.org\">, "
589  "#<record:pat:Sites id:2 key:\"razil.jp\">"
590  "]",
591  inspected_string());
592 }
593 
594 void
596 {
597  uvector = grn_obj_open(context, GRN_UVECTOR, 0, GRN_DB_BOOL);
598  GRN_BOOL_PUT(context, uvector, TRUE);
599  GRN_BOOL_PUT(context, uvector, FALSE);
600  inspected = grn_inspect(context, NULL, uvector);
601  cut_assert_equal_string("[true,false]", inspected_string());
602 }
603 
604 void
606 {
607  pvector = grn_obj_open(context, GRN_PVECTOR, 0, GRN_ID_NIL);
608  inspected = grn_inspect(context, NULL, pvector);
609  cut_assert_equal_string("[]", inspected_string());
610 }
611 
612 void
614 {
615  grn_obj *groonga, *razil;
616 
617  pvector = grn_obj_open(context, GRN_PVECTOR, 0, GRN_ID_NIL);
618  groonga = grn_obj_open(context, GRN_BULK, 0, GRN_DB_SHORT_TEXT);
619  razil = grn_obj_open(context, GRN_BULK, 0, GRN_DB_SHORT_TEXT);
620  GRN_TEXT_PUTS(context, groonga, "groonga");
621  GRN_TEXT_PUTS(context, razil, "razil");
622  GRN_PTR_PUT(context, pvector, groonga);
623  GRN_PTR_PUT(context, pvector, razil);
624  inspected = grn_inspect(context, NULL, pvector);
625  grn_obj_unlink(context, groonga);
626  grn_obj_unlink(context, razil);
627  cut_assert_equal_string("[\"groonga\",\"razil\"]", inspected_string());
628 }
629 
630 void
632 {
633  vector = grn_obj_open(context, GRN_VECTOR, 0, GRN_DB_TEXT);
634  inspected = grn_inspect(context, NULL, vector);
635  cut_assert_equal_string("[]", inspected_string());
636 }
637 
638 void
640 {
641 #define ADD_DATUM(table, accessor) \
642  gcut_add_datum(table "." accessor, \
643  "table", G_TYPE_STRING, table, \
644  "accessor", G_TYPE_STRING, accessor, \
645  NULL)
646 
647  ADD_DATUM("Sites", "_id");
648  ADD_DATUM("Sites", "_key");
649  ADD_DATUM("Sites", "_value");
650  ADD_DATUM("Sites", "name._id");
651  ADD_DATUM("Sites", "name._key");
652  ADD_DATUM("Sites", "name._value");
653  ADD_DATUM("Sites", "name.site");
654  ADD_DATUM("Sites", "name.site.name");
655  ADD_DATUM("Names", "site.name.site");
656 
657 #undef ADD_DATUM
658 }
659 
660 void
661 test_accessor_column_name(gconstpointer data)
662 {
663  const char *table_name = gcut_data_get_string(data, "table");
664  const char *accessor_name = gcut_data_get_string(data, "accessor");
665  grn_obj *object, *accessor;
666 
667  assert_send_command("table_create Sites TABLE_PAT_KEY ShortText Int32");
668  assert_send_command("table_create Names TABLE_PAT_KEY ShortText UInt32");
669  assert_send_command("column_create Sites name COLUMN_SCALAR Names");
670  assert_send_command("column_create Names site COLUMN_SCALAR Sites");
671 
672  object = get_object(table_name);
673  accessor = grn_obj_column(context, object,
674  accessor_name, strlen(accessor_name));
675  grn_obj_unlink(context, object);
676  cut_assert_not_null(accessor);
677  inspected = grn_inspect(context, NULL, accessor);
678  grn_obj_unlink(context, accessor);
679  cut_assert_equal_string(accessor_name, inspected_string());
680 }
681 
682 void
684 {
685 #define ADD_DATUM(accessor) \
686  gcut_add_datum(accessor, \
687  "accessor", G_TYPE_STRING, accessor, \
688  NULL)
689 
690  ADD_DATUM("_score");
691 
692 #undef ADD_DATUM
693 }
694 
695 void
697 {
698  const char *query, *accessor_name;
699  grn_obj *table, *result, *expression, *variable, *accessor;
700 
701  assert_send_command("table_create Sites TABLE_PAT_KEY ShortText");
702  assert_send_command("column_create Sites uri COLUMN_SCALAR ShortText");
703  assert_send_command("load "
704  "'["
705  "[\"_key\",\"uri\"],"
706  "[\"groonga\",\"http://groonga.org/\"]"
707  "]' "
708  "Sites");
709 
710  accessor_name = gcut_data_get_string(data, "accessor");
711 
712  table = get_object("Sites");
713  GRN_EXPR_CREATE_FOR_QUERY(context, table, expression, variable);
714  query = "_key:groonga";
715  grn_expr_parse(context, expression,
716  query, strlen(query),
717  NULL, GRN_OP_MATCH, GRN_OP_AND,
719  result = grn_table_select(context, table, expression, NULL, GRN_OP_AND);
720  accessor = grn_obj_column(context, result,
721  accessor_name, strlen(accessor_name));
722  cut_assert_not_null(accessor);
723  inspected = grn_inspect(context, NULL, accessor);
724  grn_obj_unlink(context, accessor);
725  cut_assert_equal_string(accessor_name, inspected_string());
726 }
727 
728 void
730 {
731  grn_obj *column;
732 
733  assert_send_command("table_create Sites TABLE_PAT_KEY ShortText");
734  assert_send_command("column_create Sites score COLUMN_SCALAR Int32");
735 
736  column = get_object("Sites.score");
737  inspected = grn_inspect(context, NULL, column);
738  cut_assert_equal_string("#<column:fix_size "
739  "Sites.score "
740  "range:Int32 "
741  "type:scalar "
742  "compress:none"
743  ">",
744  inspected_string());
745 }
746 
747 void
749 {
750  grn_obj *column;
751 
752  assert_send_command("table_create Sites TABLE_PAT_KEY ShortText");
753  assert_send_command("column_create Sites name COLUMN_SCALAR ShortText");
754 
755  column = get_object("Sites.name");
756  inspected = grn_inspect(context, NULL, column);
757  cut_assert_equal_string("#<column:var_size "
758  "Sites.name "
759  "range:ShortText "
760  "type:scalar "
761  "compress:none"
762  ">",
763  inspected_string());
764 }
765 
766 void
768 {
769  grn_obj *column;
770 
771  assert_send_command("table_create Sites TABLE_PAT_KEY ShortText");
772  assert_send_command("table_create Terms TABLE_PAT_KEY ShortText");
773  assert_send_command("column_create Terms Sites_key COLUMN_INDEX Sites _key");
774 
775  column = get_object("Terms.Sites_key");
776  inspected = grn_inspect(context, NULL, column);
777  cut_assert_equal_string("#<column:index "
778  "Terms.Sites_key "
779  "range:Sites "
780  "sources:[Sites] "
781  "flags:NONE "
782  "elements:[]>",
783  inspected_string());
784 }
785 
786 void
788 {
789  grn_obj *type;
790 
791  type = get_object("ShortText");
792  inspected = grn_inspect(context, NULL, type);
793  cut_assert_equal_string("#<type "
794  "ShortText "
795  "size:4096 "
796  "type:var_size"
797  ">",
798  inspected_string());
799 }
800 
801 void
803 {
804  assert_send_command("table_create Sites TABLE_HASH_KEY ShortText");
805  assert_send_command("column_create Sites name COLUMN_SCALAR Text");
806  assert_send_command("load "
807  "'["
808  "[\"_key\",\"name\"],"
809  "[\"groonga.org\",\"groonga\"],"
810  "[\"razil.jp\",\"Brazil\"]"
811  "]' "
812  "Sites");
813 
814  record = grn_obj_open(context, GRN_BULK, 0,
815  grn_obj_id(context, get_object("Sites")));
816  GRN_RECORD_SET(context, record, 1);
817  inspected = grn_inspect(context, NULL, record);
818  cut_assert_equal_string("#<record:hash:Sites "
819  "id:1 "
820  "key:\"groonga.org\" "
821  "name:\"groonga\""
822  ">",
823  inspected_string());
824 }
825 
826 void
828 {
829  grn_obj *proc;
830 
831  proc = get_object("column_remove");
832  inspected = grn_inspect(context, NULL, proc);
833  cut_assert_equal_string("#<proc:command "
834  "column_remove "
835  "arguments:[table, name]"
836  ">",
837  inspected_string());
838 }
839 
840 void
842 {
843  grn_obj *proc;
844 
845  proc = get_object("geo_distance");
846  inspected = grn_inspect(context, NULL, proc);
847  cut_assert_equal_string("#<proc:function "
848  "geo_distance "
849  "arguments:[]"
850  ">",
851  inspected_string());
852 }