Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-command-table-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);
32 
33 static gchar *tmp_directory;
34 static const gchar *database_path;
35 
36 static grn_ctx *context;
37 static grn_obj *database;
38 
39 void
41 {
42  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
43  "table-rename",
44  NULL);
45 }
46 
47 void
49 {
50  g_free(tmp_directory);
51 }
52 
53 static void
54 remove_tmp_directory(void)
55 {
56  cut_remove_path(tmp_directory, NULL);
57 }
58 
59 void
60 cut_setup(void)
61 {
62  remove_tmp_directory();
63  g_mkdir_with_parents(tmp_directory, 0700);
64 
65  context = g_new0(grn_ctx, 1);
66  grn_ctx_init(context, 0);
67 
68  database_path = cut_build_path(tmp_directory,
69  "command-table-rename",
70  NULL);
71  database = grn_db_create(context, database_path, NULL);
72 }
73 
74 void
76 {
77  grn_obj_close(context, database);
78  grn_ctx_fin(context);
79  g_free(context);
80 
81  remove_tmp_directory();
82 }
83 
84 static void
85 populate(void)
86 {
87  assert_send_commands("table_create Users TABLE_HASH_KEY ShortText\n"
88  "column_create Users name COLUMN_SCALAR ShortText\n"
89  "load --table Users\n"
90  "[\n"
91  "[\"_key\",\"name\"],\n"
92  "[\"morita\",\"Daijiro MORI\"],\n"
93  "[\"yata\",\"Susumu Yata\"]\n"
94  "]");
95 }
96 
97 void
98 test_success(void)
99 {
100  populate();
101  assert_send_command("table_rename Users People");
102  cut_assert_equal_string(
103  "table_create People TABLE_HASH_KEY ShortText\n"
104  "column_create People name COLUMN_SCALAR ShortText\n"
105  "load --table People\n"
106  "[\n"
107  "[\"_key\",\"name\"],\n"
108  "[\"morita\",\"Daijiro MORI\"],\n"
109  "[\"yata\",\"Susumu Yata\"]\n"
110  "]",
111  send_command("dump"));
112 }
113 
114 void
116 {
117  populate();
119  context,
121  "[table][rename] table name isn't specified",
122  "table_rename");
123 }
124 
125 void
127 {
128  populate();
130  context,
132  "[table][rename] table isn't found: <nonexistent>",
133  "table_rename nonexistent");
134 }
135 
136 void
138 {
139  populate();
141  context,
143  "[table][rename] new table name isn't specified: <Users>",
144  "table_rename Users");
145 }
146 
147 void
149 {
150  populate();
152  context,
154  "[table][rename] isn't table: <Users.name> -> <People>",
155  "table_rename Users.name People");
156 }