null+****@clear*****
null+****@clear*****
2010年 6月 15日 (火) 16:20:46 JST
Kouhei Sutou 2010-06-15 07:20:46 +0000 (Tue, 15 Jun 2010) New Revision: a7daa26ae6fd1f2ef8b9e0be69553c770c6d7c34 Log: add a test for column_list. Added files: test/unit/core/test-command-column-list.c Modified files: test/unit/core/Makefile.am Modified: test/unit/core/Makefile.am (+3 -1) =================================================================== --- test/unit/core/Makefile.am 2010-06-15 00:06:26 +0000 (51ceb6e) +++ test/unit/core/Makefile.am 2010-06-15 07:20:46 +0000 (d8f6cbc) @@ -36,7 +36,8 @@ noinst_LTLIBRARIES = \ test-store-ja.la \ test-log.la \ test-table-sort-key.la \ - test-inspect.la + test-inspect.la \ + test-command-column-list.la endif INCLUDES = \ @@ -97,3 +98,4 @@ test_store_ja_la_SOURCES = test-store-ja.c test_log_la_SOURCES = test-log.c test_table_sort_key_la_SOURCES = test-table-sort-key.c test_inspect_la_SOURCES = test-inspect.c +test_command_column_list_la_SOURCES = test-command-column-list.c Added: test/unit/core/test-command-column-list.c (+118 -0) 100644 =================================================================== --- /dev/null +++ test/unit/core/test-command-column-list.c 2010-06-15 07:20:46 +0000 (a3105d5) @@ -0,0 +1,118 @@ +/* -*- c-basic-offset: 2; coding: utf-8 -*- */ +/* + Copyright (C) 2010 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 <gcutter.h> +#include <glib/gstdio.h> + +#include "../lib/grn-assertions.h" + +#include <str.h> + +void test_success(void); + +static gchar *tmp_directory; +static const gchar *database_path; + +static grn_ctx *context; +static grn_obj *database; + +void +cut_startup(void) +{ + tmp_directory = g_build_filename(grn_test_get_base_dir(), + "tmp", + "column-list", + 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) +{ + 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_ctx_fin(context); + g_free(context); + } + + remove_tmp_directory(); +} + +void +test_columns(void) +{ + assert_send_command("table_create Users TABLE_HASH_KEY ShortText"); + assert_send_command("column_create Users age COLUMN_SCALAR UInt32"); + assert_send_command("column_create Users comment COLUMN_SCALAR Text"); + cut_assert_equal_string( + cut_take_printf("[" + "[" + "[\"id\", \"UInt32\"]," + "[\"name\",\"ShortText\"]," + "[\"path\",\"ShortText\"]," + "[\"type\",\"ShortText\"]," + "[\"flags\",\"ShortText\"]," + "[\"domain\", \"ShortText\"]," + "[\"range\", \"ShortText\"]," + "[\"source\",\"ShortText\"]" + "]," + "[258," + "\"comment\"," + "\"%s.0000102\"," + "\"var\"," + "\"COLUMN_SCALAR|COMPRESS_NONE|PERSISTENT\"," + "\"Users\"," + "\"Text\"," + "[]" + "]," + "[257," + "\"age\"," + "\"%s.0000101\"," + "\"fix\"," + "\"COLUMN_SCALAR|COMPRESS_NONE|PERSISTENT\"," + "\"Users\"," + "\"UInt32\"," + "[]" + "]" + "]", + database_path, database_path), + send_command("column_list Users")); +}