null+****@clear*****
null+****@clear*****
2010年 8月 25日 (水) 18:36:45 JST
Kouhei Sutou 2010-08-25 09:36:45 +0000 (Wed, 25 Aug 2010) New Revision: 8d8dac6c5f654e366aca00fdc33e744859128e3a Log: don't call not command proc as command. #431 Added files: test/unit/core/test-function.c Modified files: lib/ctx.c test/unit/core/Makefile.am Modified: lib/ctx.c (+10 -2) =================================================================== --- lib/ctx.c 2010-08-25 08:17:29 +0000 (e7a4ad4) +++ lib/ctx.c 2010-08-25 09:36:45 +0000 (1d74c55) @@ -854,6 +854,13 @@ grn_str_get_mime_type(grn_ctx *ctx, const char *p, const char *pe, #define EXPR_MISSING "expr_missing" #define OUTPUT_TYPE_LEN (sizeof(OUTPUT_TYPE) - 1) +static inline int +command_proc_p(grn_obj *expr) +{ + return (expr->header.type == GRN_PROC && + ((grn_proc *)expr)->type == GRN_PROC_COMMAND); +} + grn_obj * grn_ctx_qe_exec_uri(grn_ctx *ctx, const char *path, uint32_t path_len) { @@ -865,7 +872,8 @@ grn_ctx_qe_exec_uri(grn_ctx *ctx, const char *path, uint32_t path_len) v = GRN_TEXT_VALUE(&buf); grn_str_get_mime_type(ctx, v, GRN_BULK_CURR(&buf), &key_end, &filename_end); if ((GRN_TEXT_LEN(&buf) >= 2 && v[0] == 'd' && v[1] == '/') && - (expr = grn_ctx_get(ctx, v + 2, key_end - (v + 2)))) { + (expr = grn_ctx_get(ctx, v + 2, key_end - (v + 2))) && + command_proc_p(expr)) { while (p < e) { int l; GRN_BULK_REWIND(&buf); @@ -948,7 +956,7 @@ grn_ctx_qe_exec(grn_ctx *ctx, const char *str, uint32_t str_len) } } ctx->impl->curr_expr = expr; - if (expr) { + if (expr && command_proc_p(expr)) { grn_expr_exec(ctx, expr, 0); } else { GRN_BULK_REWIND(&buf); Modified: test/unit/core/Makefile.am (+2 -0) =================================================================== --- test/unit/core/Makefile.am 2010-08-25 08:17:29 +0000 (dd15446) +++ test/unit/core/Makefile.am 2010-08-25 09:36:45 +0000 (f1d7e1a) @@ -34,6 +34,7 @@ noinst_LTLIBRARIES = \ test-view.la \ test-view-operations.la \ test-register.la \ + test-function.la \ test-function-cast.la \ test-function-edit-distance.la \ test-store-ja.la \ @@ -108,6 +109,7 @@ test_encoding_la_SOURCES = test-encoding.c test_view_la_SOURCES = test-view.c test_view_operations_la_SOURCES = test-view-operations.c test_register_la_SOURCES = test-register.c +test_function_la_SOURCES = test-function.c test_function_cast_la_SOURCES = test-function-cast.c test_function_edit_distance_la_SOURCES = test-function-edit-distance.c test_store_ja_la_SOURCES = test-store-ja.c Added: test/unit/core/test-function.c (+85 -0) 100644 =================================================================== --- /dev/null +++ test/unit/core/test-function.c 2010-08-25 09:36:45 +0000 (0434f1d) @@ -0,0 +1,85 @@ +/* -*- 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_call_as_command(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(), + "function", + 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_ctx_fin(context); + g_free(context); + } + + remove_tmp_directory(); +} + +void +test_call_as_command(void) +{ + assert_send_command_error(GRN_INVALID_ARGUMENT, + "invalid command name: rand", + "rand"); +}