null+****@clear*****
null+****@clear*****
2010年 8月 16日 (月) 13:55:09 JST
Kouhei Sutou 2010-08-16 04:55:09 +0000 (Mon, 16 Aug 2010) New Revision: 0c5fd3d4b885ffd634fb84d0268f020fe3a1fcda Log: re-enable define_selector. Added files: test/unit/core/test-command-define-selector.c Modified files: lib/proc.c test/unit/core/Makefile.am Modified: lib/proc.c (+5 -1) =================================================================== --- lib/proc.c 2010-08-16 02:03:45 +0000 (f0392a6) +++ lib/proc.c 2010-08-16 04:55:09 +0000 (a4a221a) @@ -342,9 +342,13 @@ proc_select(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) static grn_obj * proc_define_selector(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) { - uint32_t nvars; + uint32_t i, nvars; grn_expr_var *vars; grn_proc_get_info(ctx, user_data, &vars, &nvars, NULL); + for (i = 1; i < nvars; i++) { + GRN_TEXT_SET(ctx, &((vars + i)->value), + GRN_TEXT_VALUE(VAR(i)), GRN_TEXT_LEN(VAR(i))); + } grn_proc_create(ctx, GRN_TEXT_VALUE(VAR(0)), GRN_TEXT_LEN(VAR(0)), GRN_PROC_COMMAND, proc_select, NULL, NULL, nvars - 1, vars + 1); Modified: test/unit/core/Makefile.am (+2 -0) =================================================================== --- test/unit/core/Makefile.am 2010-08-16 02:03:45 +0000 (e78914e) +++ test/unit/core/Makefile.am 2010-08-16 04:55:09 +0000 (679e39a) @@ -44,6 +44,7 @@ noinst_LTLIBRARIES = \ test-command-select.la \ test-command-select-sort.la \ test-command-select-prefix-search.la \ + test-command-define-selector.la \ test-command-cache-limit.la \ test-command-delete.la \ test-geo.la \ @@ -115,6 +116,7 @@ test_command_column_list_la_SOURCES = test-command-column-list.c test_command_select_la_SOURCES = test-command-select.c test_command_select_sort_la_SOURCES = test-command-select-sort.c test_command_select_prefix_search_la_SOURCES = test-command-select-prefix-search.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 test_geo_la_SOURCES = test-geo.c Added: test/unit/core/test-command-define-selector.c (+101 -0) 100644 =================================================================== --- /dev/null +++ test/unit/core/test-command-define-selector.c 2010-08-16 04:55:09 +0000 (476c0fa) @@ -0,0 +1,101 @@ +/* -*- c-basic-offset: 2; coding: utf-8 -*- */ +/* Copyright(C) 2010 Brazil + + 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_table(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", + 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_table(void) +{ + const gchar *actual; + + assert_send_commands("table_create Sites TABLE_PAT_KEY ShortText Int32\n" + "column_create Sites link COLUMN_SCALAR Sites\n" + "load --table Sites\n" + "[\n" + "[\"_key\",\"_value\"],\n" + "[\"groonga.org\",0],\n" + "[\"razil.jp\",0]\n" + "]"); + assert_send_commands("define_selector select_sites Sites"); + actual = send_command("select_sites"); + cut_assert_equal_string("[[[2]," + "[[\"_id\",\"UInt32\"]," + "[\"_key\",\"ShortText\"]," + "[\"_value\",\"Int32\"]," + "[\"link\",\"Sites\"]]," + "[1,\"groonga.org\",0,\"\"]," + "[2,\"razil.jp\",0,\"\"]]]", actual); +}