Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-command-select-filter.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright(C) 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 "str.h"
20 #include <stdio.h>
21 
22 #include <gcutter.h>
23 
24 #include "../lib/grn-assertions.h"
25 
26 void test_prefix_search(void);
27 
28 static gchar *tmp_directory;
29 
30 static grn_ctx *context;
31 static grn_obj *database;
32 
33 void
35 {
36  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
37  "command-select-filter",
38  NULL);
39 }
40 
41 void
43 {
44  g_free(tmp_directory);
45 }
46 
47 static void
48 remove_tmp_directory(void)
49 {
50  cut_remove_path(tmp_directory, NULL);
51 }
52 
53 void
54 cut_setup(void)
55 {
56  const gchar *database_path;
57 
58  remove_tmp_directory();
59  g_mkdir_with_parents(tmp_directory, 0700);
60 
61  context = g_new0(grn_ctx, 1);
62  grn_ctx_init(context, 0);
63 
64  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
65  database = grn_db_create(context, database_path, NULL);
66 }
67 
68 void
70 {
71  if (context) {
72  grn_obj_unlink(context, database);
73  grn_ctx_fin(context);
74  g_free(context);
75  }
76 
77  remove_tmp_directory();
78 }
79 
80 void
82 {
83  assert_send_command("table_create Users TABLE_PAT_KEY ShortText");
84  assert_send_command("load --table Users\n"
85  "[\n"
86  "{\"_key\":\"mori\"},\n"
87  "{\"_key\":\"morita\"},\n"
88  "{\"_key\":\"mona\"}\n"
89  "]");
90  cut_assert_equal_string(
91  "[[[2],"
92  "[[\"_id\",\"UInt32\"],[\"_key\",\"ShortText\"]],"
93  "[2,\"morita\"],"
94  "[1,\"mori\"]]]",
95  send_command("select Users "
96  "--filter '_key @^ \"mor\"'"));
97 }