Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-object.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 "../../../config.h"
20 
21 #include <groonga.h>
22 
23 #include <gcutter.h>
24 #include <glib/gstdio.h>
25 
26 #include "../lib/grn-assertions.h"
27 
28 void data_is_builtin(void);
29 void test_is_builtin(gconstpointer data);
30 
31 static gchar *tmp_directory;
32 static const gchar *database_path;
33 
34 static grn_ctx *context;
35 static grn_obj *database;
36 
37 void
39 {
40  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
41  "object",
42  NULL);
43 }
44 
45 void
47 {
48  g_free(tmp_directory);
49 }
50 
51 static void
52 remove_tmp_directory(void)
53 {
54  cut_remove_path(tmp_directory, NULL);
55 }
56 
57 void
58 cut_setup(void)
59 {
60  remove_tmp_directory();
61  g_mkdir_with_parents(tmp_directory, 0700);
62 
63  context = g_new0(grn_ctx, 1);
64  grn_ctx_init(context, 0);
65 
66  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
67  database = grn_db_create(context, database_path, NULL);
68 }
69 
70 void
72 {
73  if (context) {
74  grn_obj_close(context, database);
75  grn_ctx_fin(context);
76  g_free(context);
77  }
78 
79  remove_tmp_directory();
80 }
81 
82 void
84 {
85 #define ADD_DATUM(expected, name) \
86  gcut_add_datum((expected ? "built-in - " name : "custom - " name), \
87  "expected", G_TYPE_BOOLEAN, expected, \
88  "name", G_TYPE_STRING, name, \
89  NULL)
90 
91  ADD_DATUM(TRUE, "TokenBigram");
92 #ifdef GRN_WITH_MECAB
93  ADD_DATUM(TRUE, "TokenMecab");
94 #endif
95  ADD_DATUM(FALSE, "Users");
96  ADD_DATUM(FALSE, "Users.name");
97  ADD_DATUM(FALSE, "suggest");
98 
99 #undef ADD_DATUM
100 }
101 
102 void
103 test_is_builtin(gconstpointer data)
104 {
105  const gchar *name;
106  grn_obj *object;
107 
108  assert_send_command("register suggest/suggest");
109  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
110  assert_send_command("column_create Users name COLUMN_SCALAR ShortText");
111 
112  name = gcut_data_get_string(data, "name");
113  object = grn_ctx_get(context, name, strlen(name));
114  if (gcut_data_get_string(data, "expected")) {
115  cut_assert_true(grn_obj_is_builtin(context, object));
116  } else {
117  cut_assert_false(grn_obj_is_builtin(context, object));
118  }
119 }