25 #include "../lib/grn-assertions.h"
49 static gchar *tmp_directory;
65 g_free(tmp_directory);
69 remove_tmp_directory(
void)
71 cut_remove_path(tmp_directory, NULL);
77 const gchar *database_path;
79 remove_tmp_directory();
80 g_mkdir_with_parents(tmp_directory, 0700);
85 database_path = cut_build_path(tmp_directory,
"database.groonga", NULL);
98 remove_tmp_directory();
112 "[\"_key\",\"value\"],"
118 "[\"_key\",\"answer\"],"
119 "[\"universe\",\"ultimate\"]"
120 "[\"mankind\",\"\"],"
123 cut_assert_equal_string(
"[["
126 "[\"_key\",\"ShortText\"],"
127 "[\"num\",\"UInt32\"],"
128 "[\"answer.value\",\"UInt32\"]"
130 "[\"universe\",0,42],"
135 " \"_key, num, answer.value\""));
144 cut_assert_equal_string(
"1",
146 "[{\"_key\": \"Daijiro MORI\", "
147 "\"scores\": [5, 5, 5]}]"));
148 cut_assert_equal_string(
"[[[1],"
149 "[[\"_id\",\"UInt32\"],"
150 "[\"_key\",\"ShortText\"],"
151 "[\"scores\",\"Int32\"]],"
152 "[1,\"Daijiro MORI\",[5,5,5]]]]",
162 "TABLE_PAT_KEY|KEY_NORMALIZE ShortText "
163 "--default_tokenizer TokenBigram");
165 "COLUMN_INDEX|WITH_POSITION Blogs articles");
169 " [\"gunya-gunya\", "
171 " \"hello groonga!\", "
172 " \"hello Senna!\"]],\n"
175 " \"My name is groonga!\"]],\n"
178 " \"My name is Senna!\"]]\n"
180 cut_assert_equal_string(
"[[[2],"
181 "[[\"_key\",\"ShortText\"],"
182 "[\"articles\",\"Text\"]],"
185 "\"hello groonga!\","
186 "\"hello Senna!\"]],"
189 "\"My name is groonga!\"]]]]",
191 "--output_columns _key,articles "
192 "--match_columns articles "
205 cut_assert_equal_string(
"2",
208 " [\"_id\", \"name\"],\n"
209 " [1, \"ryoqun\"],\n"
210 " [2, \"hayamiz\"]\n"
212 cut_assert_equal_string(
"1",
215 " [\"_key\", \"text\", \"authors\"],\n"
216 " [\"groonga\", \"it is fast\", [1, 2]]\n"
218 cut_assert_equal_string(
"[[[1],"
219 "[[\"_id\",\"UInt32\"],"
220 "[\"_key\",\"ShortText\"],"
221 "[\"authors\",\"Users\"],"
222 "[\"text\",\"ShortText\"]],"
223 "[1,\"groonga\",[1,2],\"it is fast\"]]]",
236 cut_assert_equal_string(
"2",
239 "[\"_key\",\"name\"],\n"
240 "[1000,\"ryoqun\"],\n"
241 "[1001,\"hayamiz\"]\n"
244 cut_assert_equal_string(
248 "[\"_key\",\"text\",\"authors\"],\n"
249 "[\"groonga\",\"it is fast\",[1000,1001]]\n"
252 cut_assert_equal_string(
"[[[1],"
253 "[[\"_id\",\"UInt32\"],"
254 "[\"_key\",\"ShortText\"],"
255 "[\"authors\",\"Users\"],"
256 "[\"text\",\"ShortText\"]],"
257 "[1,\"groonga\",[1000,1001],\"it is fast\"]]]",
265 "column_create Sites link COLUMN_SCALAR Sites\n"
266 "load --table Sites\n"
269 "[\"groonga.org\"],\n"
272 cut_assert_equal_string(
"[[[0],"
273 "[[\"_id\",\"UInt32\"],"
274 "[\"_key\",\"ShortText\"]]]]",
276 "--output_columns '_id _key' "
277 "--filter '_id == 100'"));
284 "column_create Sites link COLUMN_SCALAR Sites\n"
285 "load --table Sites\n"
288 "[\"groonga.org\"],\n"
291 cut_assert_equal_string(
"[[[2],"
292 "[[\"_id\",\"UInt32\"],"
293 "[\"_key\",\"ShortText\"]],"
294 "[1,\"groonga.org\"],[2,\"razil.jp\"]]]",
296 "--output_columns '_id _key' "
304 "column_create Sites link COLUMN_SCALAR Sites\n"
305 "load --table Sites\n"
308 "[\"groonga.org\"],\n"
311 cut_assert_equal_string(
"[[[0],"
312 "[[\"_id\",\"UInt32\"],"
313 "[\"_key\",\"ShortText\"]]]]",
315 "--output_columns '_id _key' "
323 "column_create Sites link COLUMN_SCALAR Sites\n"
324 "load --table Sites\n"
327 "[\"groonga.org\"],\n"
330 cut_assert_equal_string(
"[[[0],"
331 "[[\"_id\",\"UInt32\"],"
332 "[\"_key\",\"ShortText\"]]]]",
334 "--output_columns '_id _key' "
342 "column_create Softwares comment "
343 "COLUMN_SCALAR ShortText\n"
344 "table_create Terms TABLE_PAT_KEY ShortText "
345 "--default_tokenizer TokenBigramSplitSymbol\n"
346 "column_create Terms Softwares_comment "
347 "COLUMN_INDEX|WITH_POSITION Softwares comment\n"
348 "load --table Softwares\n"
350 "[\"_key\", \"comment\"],\n"
351 "[\"groonga\", \"うむ上々な仕上がりだね。\"],\n"
352 "[\"Cutter\", \"使いやすいじゃないか。\"]\n"
353 "[\"Senna\", \"悪くないね。上々だよ。\"]\n"
355 cut_assert_equal_string(
"[[[2],"
356 "[[\"_key\",\"ShortText\"]],"
360 "--output_columns '_key' "
361 "--match_columns comment "
368 const gchar *command =
"select nonexistent";
372 "invalid table name: <nonexistent>",
384 " [\"groonga 1.0\", true],\n"
385 " [\"groonga 2.0\", false]\n"
387 cut_assert_equal_string(
"[[[1],"
388 "[[\"_key\",\"ShortText\"],"
389 "[\"public\",\"Bool\"]],"
390 "[\"groonga 1.0\",true]]]",
392 "--output_columns _key,public "
393 "--filter public==true"));
403 "COLUMN_INDEX Blogs title");
407 " [\"groonga-1-0\", \"groonga 1.0 release!\"],\n"
408 " [\"groonga-2-0\", \"groonga 2.0 release!\"]\n"
410 cut_assert_equal_string(
412 "[[\"_key\",\"ShortText\"],"
413 "[\"title\",\"Titles\"]],"
414 "[\"groonga-1-0\",\"groonga 1.0 release!\"]]]",
416 "--output_columns _key,title "
417 "--filter 'title == \"groonga 1.0 release!\"'"));
423 #define ADD_DATA(type) \
424 gcut_add_datum(type, \
425 "type", G_TYPE_STRING, type, \
445 type = gcut_data_get_string(data,
"type");
449 cut_take_printf(
"column_create Sites score COLUMN_SCALAR %s", type));
451 cut_assert_equal_string(
453 send_command(
"load --table Sites --columns '_key, score' \n"
455 " [\"groonga.org\", 5],\n"
456 " [\"ruby-lang.org\", 4],\n"
457 " [\"qwik.jp/senna/\", 3]\n"
459 cut_assert_equal_string(
460 cut_take_printf(
"[[[1],"
461 "[[\"_key\",\"ShortText\"],"
462 "[\"score\",\"%s\"]],"
463 "[\"groonga.org\",5]]]",
467 "--output_columns _key,score "
468 "--filter 'score > 4'"));
474 #define ADD_DATA(type) \
475 gcut_add_datum(type, \
476 "type", G_TYPE_STRING, type, \
496 type = gcut_data_get_string(data,
"type");
500 cut_take_printf(
"column_create Sites score COLUMN_SCALAR %s", type));
502 cut_assert_equal_string(
504 send_command(
"load --table Sites --columns '_key, score' \n"
506 " [\"groonga.org\", 5],\n"
507 " [\"ruby-lang.org\", 4],\n"
508 " [\"qwik.jp/senna/\", 3]\n"
510 cut_assert_equal_string(
511 cut_take_printf(
"[[[2],"
512 "[[\"_key\",\"ShortText\"],"
513 "[\"score\",\"%s\"]],"
514 "[\"groonga.org\",5],"
515 "[\"ruby-lang.org\",4]]]",
519 "--output_columns _key,score "
520 "--filter 'score >= 4'"));
526 #define ADD_DATA(type) \
527 gcut_add_datum(type, \
528 "type", G_TYPE_STRING, type, \
548 type = gcut_data_get_string(data,
"type");
552 cut_take_printf(
"column_create Sites score COLUMN_SCALAR %s", type));
554 cut_assert_equal_string(
556 send_command(
"load --table Sites --columns '_key, score' \n"
558 " [\"groonga.org\", 5],\n"
559 " [\"ruby-lang.org\", 4],\n"
560 " [\"qwik.jp/senna/\", 3]\n"
562 cut_assert_equal_string(
563 cut_take_printf(
"[[[1],"
564 "[[\"_key\",\"ShortText\"],"
565 "[\"score\",\"%s\"]],"
566 "[\"ruby-lang.org\",4]]]",
570 "--output_columns _key,score "
571 "--filter 'score == 4'"));
577 #define ADD_DATA(label, error_message, command) \
578 gcut_add_datum(label, \
579 "error-message", G_TYPE_STRING, error_message, \
580 "command", G_TYPE_STRING, command, \
584 "invalid table name: <Sites --output_columns>",
587 "--output_columns _key");
590 "invalid table name: < Sites>",
594 "--output_columns _key");
602 const gchar *error_message;
603 const gchar *command;
605 error_message = gcut_data_get_string(data,
"error-message");
606 command = gcut_data_get_string(data,
"command");
609 cut_assert_equal_string(
613 " [\"groonga.org\"],\n"
614 " [\"ruby-lang.org\"],\n"
615 " [\"qwik.jp/senna/\"]\n"