null+****@clear*****
null+****@clear*****
2011年 9月 11日 (日) 17:35:45 JST
Kouhei Sutou 2011-09-11 08:35:45 +0000 (Sun, 11 Sep 2011)
New Revision: 19daf32a2b94de260879e2efabf5f11df63c0d7d
Log:
[test][query-expansion] add a test for simple case.
Added files:
test/unit/core/test-command-select-query-expansion.c
Modified files:
test/unit/core/Makefile.am
Modified: test/unit/core/Makefile.am (+2 -0)
===================================================================
--- test/unit/core/Makefile.am 2011-09-11 06:17:43 +0000 (6200fb0)
+++ test/unit/core/Makefile.am 2011-09-11 08:35:45 +0000 (69aa809)
@@ -50,6 +50,7 @@ noinst_LTLIBRARIES = \
test-command-select-filter-invalid.la \
test-command-select-query.la \
test-command-select-filter.la \
+ test-command-select-query-expansion.la \
test-command-define-selector.la \
test-command-cache-limit.la \
test-command-delete.la \
@@ -131,6 +132,7 @@ test_command_select_prefix_search_la_SOURCES = test-command-select-prefix-search
test_command_select_filter_invalid_la_SOURCES = test-command-select-filter-invalid.c
test_command_select_query_la_SOURCES = test-command-select-query.c
test_command_select_filter_la_SOURCES = test-command-select-filter.c
+test_command_select_query_expansion_la_SOURCES = test-command-select-query-expansion.c
test_command_define_selector_la_SOURCES = test-command-define-selector.c
test_command_cache_limit_la_SOURCES = test-command-cache-limit.c
test_command_delete_la_SOURCES = test-command-delete.c
Added: test/unit/core/test-command-select-query-expansion.c (+112 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/test-command-select-query-expansion.c 2011-09-11 08:35:45 +0000 (6ba82b3)
@@ -0,0 +1,112 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+ Copyright(C) 2011 Kouhei Sutou <kou****@clear*****>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License version 2.1 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "str.h"
+#include <stdio.h>
+
+#include <gcutter.h>
+
+#include "../lib/grn-assertions.h"
+
+void test_expand(void);
+
+static gchar *tmp_directory;
+
+static grn_ctx *context;
+static grn_obj *database;
+
+void
+cut_startup(void)
+{
+ tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
+ "command-select-query-expansion",
+ NULL);
+}
+
+void
+cut_shutdown(void)
+{
+ g_free(tmp_directory);
+}
+
+static void
+remove_tmp_directory(void)
+{
+ cut_remove_path(tmp_directory, NULL);
+}
+
+void
+cut_setup(void)
+{
+ const gchar *database_path;
+
+ remove_tmp_directory();
+ g_mkdir_with_parents(tmp_directory, 0700);
+
+ context = g_new0(grn_ctx, 1);
+ grn_ctx_init(context, 0);
+
+ database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
+ database = grn_db_create(context, database_path, NULL);
+}
+
+void
+cut_teardown(void)
+{
+ if (context) {
+ grn_obj_unlink(context, database);
+ grn_ctx_fin(context);
+ g_free(context);
+ }
+
+ remove_tmp_directory();
+}
+
+void
+test_expand(void)
+{
+ assert_send_command("table_create Diaries TABLE_HASH_KEY Time");
+ assert_send_command("column_create Diaries content COLUMN_SCALAR Text");
+ assert_send_command("table_create Lexicon TABLE_PAT_KEY ShortText "
+ "--default_tokenizer TokenBigram");
+ assert_send_command("column_create Lexicon diary_content "
+ "COLUMN_INDEX|WITH_POSITION Diaries content");
+ assert_send_command("table_create Synonyms TABLE_PAT_KEY ShortText");
+ assert_send_command("column_create Synonyms words COLUMN_SCALAR ShortText");
+ assert_send_command("load --table Diaries\n"
+ "[\n"
+ "[\"_key\", \"content\"],\n"
+ "[\"2011-09-11 00:00:00\", \"Start groonga!\"],\n"
+ "[\"2011-09-12 00:00:00\", \"Start mroonga!\"],\n"
+ "[\"2011-09-13 00:00:00\", \"Start rroonga!\"]\n"
+ "]");
+ assert_send_command("load --table Synonyms\n"
+ "[\n"
+ "[\"_key\", \"words\"],\n"
+ "[\"groonga\", \"(groonga OR mroonga)\"]\n"
+ "]");
+ cut_assert_equal_string(
+ "[[[2],"
+ "[[\"_id\",\"UInt32\"],"
+ "[\"_key\",\"Time\"],"
+ "[\"content\",\"Text\"]],"
+ "[1,1315666800.0,\"Start groonga!\"],"
+ "[2,1315753200.0,\"Start mroonga!\"]]]",
+ send_command("select Diaries --match_columns content --query groonga "
+ "--query_expand Synonyms.words"));
+}