Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-command-define-selector.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /* Copyright(C) 2010 Brazil
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License version 2.1 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Lesser General Public License for more details.
12 
13  You should have received a copy of the GNU Lesser General Public
14  License along with this library; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "str.h"
19 #include <stdio.h>
20 
21 #include <gcutter.h>
22 
23 #include "../lib/grn-assertions.h"
24 
25 void test_table(void);
26 
27 static gchar *tmp_directory;
28 
29 static grn_ctx *context;
30 static grn_obj *database;
31 
32 void
34 {
35  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
36  "command-select",
37  NULL);
38 }
39 
40 void
42 {
43  g_free(tmp_directory);
44 }
45 
46 static void
47 remove_tmp_directory(void)
48 {
49  cut_remove_path(tmp_directory, NULL);
50 }
51 
52 void
53 cut_setup(void)
54 {
55  const gchar *database_path;
56 
57  remove_tmp_directory();
58  g_mkdir_with_parents(tmp_directory, 0700);
59 
60  context = g_new0(grn_ctx, 1);
61  grn_ctx_init(context, 0);
62 
63  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
64  database = grn_db_create(context, database_path, NULL);
65 }
66 
67 void
69 {
70  if (context) {
71  grn_obj_unlink(context, database);
72  grn_ctx_fin(context);
73  g_free(context);
74  }
75 
76  remove_tmp_directory();
77 }
78 
79 void
81 {
82  const gchar *actual;
83 
84  assert_send_commands("table_create Sites TABLE_PAT_KEY ShortText Int32\n"
85  "column_create Sites link COLUMN_SCALAR Sites\n"
86  "load --table Sites\n"
87  "[\n"
88  "[\"_key\",\"_value\"],\n"
89  "[\"groonga.org\",0],\n"
90  "[\"razil.jp\",0]\n"
91  "]");
92  assert_send_commands("define_selector select_sites Sites "
93  "--output_columns \"_id, _key, _value, *\"");
94  actual = send_command("select_sites");
95  cut_assert_equal_string("[[[2],"
96  "[[\"_id\",\"UInt32\"],"
97  "[\"_key\",\"ShortText\"],"
98  "[\"_value\",\"Int32\"],"
99  "[\"link\",\"Sites\"]],"
100  "[1,\"groonga.org\",0,\"\"],"
101  "[2,\"razil.jp\",0,\"\"]]]", actual);
102 }