Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-database-create.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2008-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 <store.h>
20 
21 #include <gcutter.h>
22 #include <glib/gstdio.h>
23 
24 #include "../lib/grn-assertions.h"
25 
26 void test_simple(void);
27 void test_with_long_path(void);
28 
29 static gchar *tmp_directory;
30 
31 static grn_ctx *context;
32 static grn_obj *database;
33 
34 static gchar *path;
36 
37 void
39 {
40  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
41  "function-cast",
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 = NULL;
67 
68  path = NULL;
69  options = NULL;
70 }
71 
72 void
74 {
75  if (path) {
76  g_free(path);
77  }
78 
79  if (options) {
80  g_free(options);
81  }
82 
83  if (database) {
84  grn_obj_close(context, database);
85  }
86 
87  if (context) {
88  grn_ctx_fin(context);
89  g_free(context);
90  }
91 
92  remove_tmp_directory();
93 }
94 
95 void
97 {
98  database = grn_db_create(context, NULL, NULL);
99  grn_test_assert_context(context);
100  cut_assert_not_null(database);
101 }
102 
103 void
105 {
106  gssize max_path = PATH_MAX - 14;
107  GString *long_path;
108  const gchar last_component[] = G_DIR_SEPARATOR_S "db";
109 
110  long_path = grn_long_path_new(tmp_directory,
111  max_path - strlen(last_component));
112  g_mkdir_with_parents(long_path->str, 0700);
113  g_string_append(long_path, last_component);
114 
115  path = g_string_free(long_path, FALSE);
116  database = grn_db_create(context, path, NULL);
117  grn_test_assert_context(context);
118  cut_assert_not_null(database);
119  grn_obj_close(context, database);
120  database = NULL;
121 
122  long_path = g_string_new(path);
123  g_free(path);
124  g_string_append(long_path, "X");
125  path = g_string_free(long_path, FALSE);
126  database = grn_db_create(context, path, NULL);
127  grn_test_assert_error(GRN_INVALID_ARGUMENT, "too long path", context);
128 }