null+****@clear*****
null+****@clear*****
2011年 11月 22日 (火) 13:53:51 JST
Kouhei Sutou 2011-11-22 04:53:51 +0000 (Tue, 22 Nov 2011)
New Revision: f88ccf7bdce4d9f8c928364e1c6bbc1862facf9c
Log:
[test] add a test about grn_column_rename(). refs #1167
Also add a grn_table_rename() but it's omitted for now.
Added files:
test/unit/core/test-rename.c
Modified files:
test/unit/core/Makefile.am
Modified: test/unit/core/Makefile.am (+3 -1)
===================================================================
--- test/unit/core/Makefile.am 2011-11-22 01:20:04 +0000 (1b3ed0e)
+++ test/unit/core/Makefile.am 2011-11-22 04:53:51 +0000 (9cd5e56)
@@ -63,7 +63,8 @@ noinst_LTLIBRARIES = \
test-geo-in-rectangle.la \
test-geo-in-rectangle-border.la \
test-accessor.la \
- test-object.la
+ test-object.la \
+ test-rename.la
endif
INCLUDES = \
@@ -148,3 +149,4 @@ test_geo_in_rectangle_la_SOURCES = test-geo-in-rectangle.c
test_geo_in_rectangle_border_la_SOURCES = test-geo-in-rectangle-border.c
test_accessor_la_SOURCES = test-accessor.c
test_object_la_SOURCES = test-object.c
+test_rename_la_SOURCES = test-rename.c
Added: test/unit/core/test-rename.c (+160 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/test-rename.c 2011-11-22 04:53:51 +0000 (6c163cf)
@@ -0,0 +1,160 @@
+/* -*- 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 <stdio.h>
+
+#include <gcutter.h>
+
+#include "../lib/grn-assertions.h"
+
+void test_table(void);
+void test_column(void);
+
+static gchar *tmp_directory;
+
+static grn_ctx *context;
+static grn_obj *database, *table, *column;
+
+void
+cut_startup(void)
+{
+ tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
+ "rename",
+ 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);
+
+ table = NULL;
+ column = NULL;
+}
+
+void
+cut_teardown(void)
+{
+ if (context) {
+ grn_obj_unlink(context, column);
+ grn_obj_unlink(context, table);
+ grn_obj_unlink(context, database);
+ grn_ctx_fin(context);
+ g_free(context);
+ }
+
+ remove_tmp_directory();
+}
+
+void
+test_table(void)
+{
+ const gchar *actual;
+
+ cut_omit("grn_table_rename() isn't implemented yet.");
+
+ assert_send_commands("table_create Sites TABLE_PAT_KEY ShortText\n"
+ "column_create Sites link COLUMN_SCALAR Sites\n"
+ "load --table Sites\n"
+ "[\n"
+ "[\"_key\",\"link\"],\n"
+ "[\"groonga.org\",\"razil.jp\"],\n"
+ "[\"razil.jp\",\"qwik.jp/senna/\"]\n"
+ "]");
+ actual = send_command("select Sites");
+ cut_assert_equal_string("[[[3],"
+ "[[\"_id\",\"UInt32\"],"
+ "[\"_key\",\"ShortText\"],"
+ "[\"link\",\"Sites\"]],"
+ "[1,\"groonga.org\",\"razil.jp\"],"
+ "[3,\"qwik.jp/senna/\",\"\"],"
+ "[2,\"razil.jp\",\"qwik.jp/senna/\"]]]",
+ actual);
+
+ table = grn_ctx_get(context, "Sites", strlen("Sites"));
+ grn_test_assert(grn_table_rename(context, table, "URLs", strlen("URLs")));
+ grn_test_assert_context(context);
+
+ actual = send_command("select URLs");
+ cut_assert_equal_string("[[[3],"
+ "[[\"_id\",\"UInt32\"],"
+ "[\"_key\",\"ShortText\"],"
+ "[\"link\",\"Sites\"]],"
+ "[1,\"groonga.org\",\"razil.jp\"],"
+ "[3,\"qwik.jp/senna/\",\"\"],"
+ "[2,\"razil.jp\",\"qwik.jp/senna/\"]]]",
+ actual);
+}
+
+void
+test_column(void)
+{
+ const gchar *actual;
+
+ assert_send_commands("table_create Users TABLE_PAT_KEY ShortText\n"
+ "column_create Users nick COLUMN_SCALAR ShortText\n"
+ "load --table Users\n"
+ "[\n"
+ "[\"_key\",\"nick\"],\n"
+ "[\"Daijiro MORI\",\"daijiro\"],\n"
+ "[\"Kouhei Sutou\",\"kou\"]\n"
+ "]");
+ actual = send_command("select Users");
+ cut_assert_equal_string("[[[2],"
+ "[[\"_id\",\"UInt32\"],"
+ "[\"_key\",\"ShortText\"],"
+ "[\"nick\",\"ShortText\"]],"
+ "[1,\"Daijiro MORI\",\"daijiro\"],"
+ "[2,\"Kouhei Sutou\",\"kou\"]]]",
+ actual);
+
+ column = grn_ctx_get(context, "Users.nick", strlen("Users.nick"));
+ grn_test_assert(grn_column_rename(context, column,
+ "account", strlen("account")));
+ grn_test_assert_context(context);
+
+ actual = send_command("select Users");
+ cut_assert_equal_string("[[[2],"
+ "[[\"_id\",\"UInt32\"],"
+ "[\"_key\",\"ShortText\"],"
+ "[\"account\",\"ShortText\"]],"
+ "[1,\"Daijiro MORI\",\"daijiro\"],"
+ "[2,\"Kouhei Sutou\",\"kou\"]]]",
+ actual);
+}