Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-command-table-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_hash_key(void);
27 void test_pat_key(void);
28 void test_dat_key(void);
29 void test_no_key(void);
30 
31 void test_invalid_name(void);
32 
33 static gchar *tmp_directory;
34 static const gchar *database_path;
35 
36 static grn_ctx *context;
37 static grn_obj *database, *users;
38 
39 void
41 {
42  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
43  "table-create",
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, "database.groonga", NULL);
69  database = grn_db_create(context, database_path, NULL);
70  users = NULL;
71 }
72 
73 void
75 {
76  if (context) {
77  grn_obj_unlink(context, users);
78  grn_obj_close(context, database);
79  grn_ctx_fin(context);
80  g_free(context);
81  }
82 
83  remove_tmp_directory();
84 }
85 
86 static void
87 grn_test_assert_users_exist(void)
88 {
89  const gchar *users_name = "Users";
90  users = grn_ctx_get(context, users_name, strlen(users_name));
91 }
92 
93 void
95 {
96  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
97  grn_test_assert_users_exist();
99 }
100 
101 void
103 {
104  assert_send_command("table_create Users TABLE_PAT_KEY ShortText");
105  grn_test_assert_users_exist();
107 }
108 
109 void
111 {
112  assert_send_command("table_create Users TABLE_DAT_KEY ShortText");
113  grn_test_assert_users_exist();
115 }
116 
117 void
119 {
120  assert_send_command("table_create Users TABLE_NO_KEY");
121  grn_test_assert_users_exist();
123 }
124 
125 void
126 test_invalid_name(void)
127 {
129  context,
131  "[table][create] name can't start with '_' and "
132  "contains only 0-9, A-Z, a-z, #, @, - or _: <_Users>",
133  "table_create _Users");
134 }