Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-command-select-filter-invalid.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright(C) 2010-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 
28 
29 static gchar *tmp_directory;
30 
31 static grn_ctx *context;
32 static grn_obj *database;
33 
34 void
36 {
37  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
38  "command-select-filter-invalid",
39  NULL);
40 }
41 
42 void
44 {
45  g_free(tmp_directory);
46 }
47 
48 static void
49 remove_tmp_directory(void)
50 {
51  cut_remove_path(tmp_directory, NULL);
52 }
53 
54 static void
55 setup_data(void)
56 {
57  assert_send_commands("table_create Sites TABLE_HASH_KEY ShortText\n"
58  "column_create Sites uri COLUMN_SCALAR ShortText\n"
59  "load --table Sites\n"
60  "[\n"
61  "[\"_key\",\"uri\"],\n"
62  "[\"groonga\",\"http://groonga.org/\"],\n"
63  "[\"razil\",\"http://razil.jp/\"]\n"
64  "]");
65 }
66 
67 void
68 cut_setup(void)
69 {
70  const gchar *database_path;
71 
72  remove_tmp_directory();
73  g_mkdir_with_parents(tmp_directory, 0700);
74 
75  context = g_new0(grn_ctx, 1);
76  grn_ctx_init(context, 0);
77 
78  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
79  database = grn_db_create(context, database_path, NULL);
80 
81  setup_data();
82 }
83 
84 void
86 {
87  if (context) {
88  grn_obj_unlink(context, database);
89  grn_ctx_fin(context);
90  g_free(context);
91  }
92 
93  remove_tmp_directory();
94 }
95 
96 void
98 {
100  context,
102  "invalid function: <\"groonga\">",
103  "select Sites --filter \"_key != \\\"groonga\\\" ()\"");
104 }
105 
106 void
108 {
110  context,
112  "invalid expression: can't use column as a value: "
113  "<Sites.uri>: "
114  "<noname($1:\"\"){2_key GET_VALUE,0uri GET_VALUE,0MATCH}>",
115  "select Sites --filter \"_key @ uri");
116 }