Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-command-column-create.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2011-2012 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 
26 void test_invalid_name(void);
27 void test_missing_name(void);
28 void test_too_long_name(void);
29 void test_nonexistent_table(void);
30 void test_nonexistent_type(void);
31 
32 static gchar *tmp_directory;
33 static const gchar *database_path;
34 
35 static grn_ctx *context;
36 static grn_obj *database;
37 
38 void
40 {
41  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
42  "column-create",
43  NULL);
44 }
45 
46 void
48 {
49  g_free(tmp_directory);
50 }
51 
52 static void
53 remove_tmp_directory(void)
54 {
55  cut_remove_path(tmp_directory, NULL);
56 }
57 
58 void
59 cut_setup(void)
60 {
61  remove_tmp_directory();
62  g_mkdir_with_parents(tmp_directory, 0700);
63 
64  context = g_new0(grn_ctx, 1);
65  grn_ctx_init(context, 0);
66 
67  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
68  database = grn_db_create(context, database_path, NULL);
69 }
70 
71 void
73 {
74  if (context) {
75  grn_obj_close(context, database);
76  grn_ctx_fin(context);
77  g_free(context);
78  }
79 
80  remove_tmp_directory();
81 }
82 
83 void
85 {
86  assert_send_command("table_create Users");
88  context,
90  "[column][create] name can't start with '_' "
91  "and contains only 0-9, A-Z, a-z, #, @, - or _: <_name>",
92  "column_create Users _name COLUMN_SCALAR ShortText");
93 }
94 
95 void
97 {
98  assert_send_command("table_create Users");
100  context,
102  "[column][create] name is missing",
103  "column_create Users --flags COLUMN_SCALAR --type ShortText");
104 }
105 
106 void
108 {
109  GString *command, *long_name;
110 
111  long_name = grn_long_name_new(4096 - strlen("Users"));
112  gcut_take_string(long_name);
113  command = gcut_take_new_string("");
114  g_string_printf(command,
115  "column_create Users %s COLUMN_SCALAR ShortText",
116  long_name->str);
117 
118  assert_send_command("table_create Users");
120  context,
122  "[column][create] too long column name"
123  ": required name_size(4091) < 4090"
124  ": <Users>.<aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeee",
125  command->str);
126 }
127 
128 void
130 {
132  context,
134  "[column][create] table doesn't exist: <Users>",
135  "column_create Users name COLUMN_SCALAR ShortText");
136 }
137 
138 void
140 {
141  assert_send_command("table_create Users");
143  context,
145  "[column][create] type doesn't exist: <VeryShortText>",
146  "column_create Users name COLUMN_SCALAR VeryShortText");
147 }