Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-log.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2010 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_char(void);
27 
28 static grn_logger_info *logger;
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  "log",
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 void
55 cut_setup(void)
56 {
57  const gchar *database_path;
58 
59  remove_tmp_directory();
60  g_mkdir_with_parents(tmp_directory, 0700);
61 
62  logger = setup_grn_logger();
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  grn_obj_close(context, database);
75  grn_ctx_fin(context);
76  g_free(context);
77 
78  teardown_grn_logger(logger);
79 
80  remove_tmp_directory();
81 }
82 
83 void
85 {
86  GList *log = NULL;
87 
88  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
89  assert_send_command("column_create Users name COLUMN_SCALAR ShortText");
90  assert_send_command("column_create Users desc COLUMN_SCALAR ShortText");
92  assert_send_command("load --table Users --input_type json\n"
93  "{\"name\": \"groonga\" @ \"desc\" \"search engine\"}\n"
94  "");
95  log = (GList *)grn_collect_logger_get_messages(logger);
96  cut_assert_equal_string("ignored invalid char('@') at",
97  g_list_nth_data(log, 0));
98  cut_assert_equal_string("{\"name\": \"groonga\" @",
99  g_list_nth_data(log, 1));
100  cut_assert_equal_string(" ^",
101  g_list_nth_data(log, 2));
102 }
103 
104 void
106 {
107  GList *log = NULL;
108 
109  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
110  assert_send_command("column_create Users desc COLUMN_SCALAR ShortText");
112  assert_send_command("load --table Users --input_type json\n"
113  "{\"info\" \"search engine\"}\n"
114  "");
115  log = (GList *)grn_collect_logger_get_messages(logger);
116  cut_assert_equal_string("neither _key nor _id is assigned",
117  g_list_nth_data(log, 0));
118 }
119 
120 void
122 {
123  GList *log = NULL;
124 
125  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
126  assert_send_command("column_create Users desc COLUMN_SCALAR ShortText");
128  assert_send_command("load --table Users --input_type json\n"
129  "{\"_key\": \"groonga\", \"_id\": 1}\n"
130  "");
131  log = (GList *)grn_collect_logger_get_messages(logger);
132  cut_assert_equal_string("duplicated key columns: _key and _id",
133  g_list_nth_data(log, 0));
134 }
135 
136 void
138 {
139  GList *log = NULL;
140 
141  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
142  assert_send_command("column_create Users desc COLUMN_SCALAR ShortText");
144  assert_send_command("load --table Users --input_type json\n"
145  "{\"_key\": \"groonga\", \"info\" \"search engine\"}\n"
146  "");
147  log = (GList *)grn_collect_logger_get_messages(logger);
148  cut_assert_equal_string("invalid column('info')", g_list_nth_data(log, 0));
149 }