Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-proc.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2013 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 <groonga.h>
20 
21 #include <gcutter.h>
22 #include <glib/gstdio.h>
23 
24 #include "../lib/grn-assertions.h"
25 
26 void data_path(void);
27 void test_path(gconstpointer data);
28 
29 static gchar *tmp_directory;
30 
31 static grn_logger_info *logger;
32 static grn_ctx *context;
33 static grn_obj *database, *proc;
34 
35 void
37 {
38  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
39  "test-proc",
40  NULL);
41 }
42 
43 void
45 {
46  g_free(tmp_directory);
47 }
48 
49 static void
50 remove_tmp_directory(void)
51 {
52  cut_remove_path(tmp_directory, NULL);
53 }
54 
55 void
56 cut_setup(void)
57 {
58  remove_tmp_directory();
59  g_mkdir_with_parents(tmp_directory, 0700);
60 
61  context = NULL;
62  logger = setup_grn_logger();
63 
64  context = g_new0(grn_ctx, 1);
65  grn_ctx_init(context, 0);
66 
67  database = grn_db_create(context,
68  cut_build_path(tmp_directory, "proc.db", NULL),
69  NULL);
70 
71  proc = NULL;
72 }
73 
74 void
76 {
77  if (proc) {
78  grn_obj_unlink(context, proc);
79  }
80 
81  grn_obj_close(context, database);
82  grn_ctx_fin(context);
83  g_free(context);
84 
85  teardown_grn_logger(logger);
86  cut_remove_path(tmp_directory, NULL);
87 }
88 
89 void
90 data_path(void)
91 {
92 #define ADD_DATA(label, expected, name) \
93  gcut_add_datum(label, \
94  "expected", G_TYPE_STRING, expected, \
95  "name", G_TYPE_STRING, name, \
96  NULL)
97 
98  ADD_DATA("built-in", NULL, "select");
99 
100 #undef ADD_DATA
101 }
102 
103 void
104 test_path(gconstpointer data)
105 {
106  const gchar *expected;
107  const gchar *name;
108 
109  expected = gcut_data_get_string(data, "expected");
110  name = gcut_data_get_string(data, "name");
111  proc = grn_ctx_get(context, name, -1);
112  cut_assert_equal_string(expected, grn_obj_path(context, proc));
113 }