Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-store-ja.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 #include "store.h"
24 
25 #include <str.h>
26 
27 void test_vector_empty_load(void);
28 
29 static gchar *tmp_directory;
30 
31 static grn_ctx *context;
32 static grn_ja *ja;
33 static grn_obj *vector;
34 
35 void
37 {
38  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
39  "store-ja",
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 = g_new0(grn_ctx, 1);
62  grn_ctx_init(context, 0);
63  ja = grn_ja_create(context, NULL, 65536, 0);
64  vector = grn_obj_open(context, GRN_BULK, GRN_OBJ_VECTOR, GRN_DB_VOID);
65 }
66 
67 void
69 {
70  if (vector) {
71  grn_obj_unlink(context, vector);
72  }
73 
74  if (ja) {
75  grn_ja_close(context, ja);
76  }
77 
78  if (context) {
79  grn_ctx_fin(context);
80  g_free(context);
81  }
82 
83  remove_tmp_directory();
84 }
85 
86 void
88 {
89  void *ptr;
90  uint32_t len;
91  grn_io_win iw;
92 
93  cut_assert_equal_int(0, grn_ja_size(context, ja, 1));
94  ptr = grn_ja_ref(context, ja, 1, &iw, &len);
95  grn_ja_unref(context, &iw);
96  cut_assert_null(ptr);
97  cut_assert_equal_uint(0, len);
98 
99  grn_test_assert(grn_ja_putv(context, ja, 1, vector, 0));
100 
101  cut_assert_equal_int(1, grn_ja_size(context, ja, 1));
102  ptr = grn_ja_ref(context, ja, 1, &iw, &len);
103  grn_ja_unref(context, &iw);
104  cut_assert_not_null(ptr);
105  cut_assert_equal_uint(1, len);
106 }