Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-command-column-rename.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 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 #define get(name) grn_ctx_get(context, name, strlen(name))
27 
28 void test_success(void);
29 void test_error_no_argument(void);
34 
35 static gchar *tmp_directory;
36 static const gchar *database_path;
37 
38 static grn_ctx *context;
39 static grn_obj *database;
40 
41 void
43 {
44  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
45  "column-rename",
46  NULL);
47 }
48 
49 void
51 {
52  g_free(tmp_directory);
53 }
54 
55 static void
56 remove_tmp_directory(void)
57 {
58  cut_remove_path(tmp_directory, NULL);
59 }
60 
61 void
62 cut_setup(void)
63 {
64  remove_tmp_directory();
65  g_mkdir_with_parents(tmp_directory, 0700);
66 
67  context = g_new0(grn_ctx, 1);
68  grn_ctx_init(context, 0);
69 
70  database_path = cut_build_path(tmp_directory,
71  "command-column-rename",
72  NULL);
73  database = grn_db_create(context, database_path, NULL);
74 }
75 
76 void
78 {
79  grn_obj_close(context, database);
80  grn_ctx_fin(context);
81  g_free(context);
82 
83  remove_tmp_directory();
84 }
85 
86 static void
87 populate(void)
88 {
89  assert_send_commands("table_create Users TABLE_HASH_KEY ShortText\n"
90  "column_create Users name COLUMN_SCALAR ShortText\n"
91  "load --table Users\n"
92  "[\n"
93  "[\"_key\",\"name\"],\n"
94  "[\"morita\",\"Daijiro MORI\"],\n"
95  "[\"yata\",\"Susumu Yata\"]\n"
96  "]");
97 }
98 
99 void
101 {
102  populate();
103  assert_send_command("column_rename Users name full_name");
104  cut_assert_equal_string(
105  "table_create Users TABLE_HASH_KEY ShortText\n"
106  "column_create Users full_name COLUMN_SCALAR ShortText\n"
107  "load --table Users\n"
108  "[\n"
109  "[\"_key\",\"full_name\"],\n"
110  "[\"morita\",\"Daijiro MORI\"],\n"
111  "[\"yata\",\"Susumu Yata\"]\n"
112  "]",
113  send_command("dump"));
114 }
115 
116 void
118 {
119  populate();
121  context,
123  "[column][rename] table name isn't specified",
124  "column_rename");
125 }
126 
127 void
129 {
130  populate();
132  context,
134  "[column][rename] table isn't found: <nonexistent>",
135  "column_rename nonexistent");
136 }
137 
138 void
140 {
141  populate();
143  context,
145  "[column][rename] column name isn't specified: <Users>",
146  "column_rename Users");
147 }
148 
149 void
151 {
152  populate();
154  context,
156  "[column][rename] column isn't found: <Users.nonexistent>",
157  "column_rename Users nonexistent");
158 }
159 
160 void
162 {
163  populate();
165  context,
167  "[column][rename] new column name isn't specified: <Users.name>",
168  "column_rename Users name");
169 }