Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-public-context.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2008-2009 Kouhei Sutou <kou@cozmixng.org>
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 test_load(void);
27 
28 static grn_obj *db;
29 static grn_ctx *context;
30 static const gchar *base_dir;
31 static gchar *default_path;
32 static int default_context_flags;
33 static grn_encoding default_encoding;
34 static gchar *sample_ql_program;
35 
36 void
37 cut_setup(void)
38 {
39  db = NULL;
40  context = g_new0(grn_ctx, 1);
41 
42  base_dir = grn_test_get_tmp_dir();
43  default_path = g_build_filename(base_dir, "db", NULL);
44  default_encoding = GRN_ENC_DEFAULT;
45  default_context_flags = GRN_CTX_USE_QL;
46 
47  cut_remove_path(base_dir, NULL);
48  g_mkdir_with_parents(base_dir, 0755);
49 
50  sample_ql_program = g_build_filename(grn_test_get_base_dir(),
51  "..", "ql", "bookmark.scm", NULL);
52 }
53 
54 void
56 {
57  if (context) {
58  if (db) {
59  grn_obj_close(context, db);
60  }
61  grn_ctx_fin(context);
62  g_free(context);
63  }
64 
65  if (default_path) {
66  g_free(default_path);
67  }
68 
69  if (base_dir) {
70  cut_remove_path(base_dir, NULL);
71  }
72 
73  if (sample_ql_program) {
74  g_free(sample_ql_program);
75  }
76 }
77 
78 #define create_db() do \
79 { \
80  grn_db_create_optarg option; \
81  \
82  option.builtin_type_names = NULL; \
83  option.n_builtin_type_names = 0; \
84  db = grn_db_create(context, default_path, &option); \
85 } while (0)
86 
87 #define open_context() do \
88 { \
89  grn_test_assert(grn_ctx_init(context, default_context_flags)); \
90  GRN_CTX_SET_ENCODING(context, default_encoding); \
91 } while (0)
92 
93 #define cut_assert_open_context() do \
94 { \
95  create_db(); \
96  cut_assert(db); \
97  open_context(); \
98  cut_assert(context); \
99 } while (0)