Kouhei Sutou
null+****@clear*****
Mon Feb 16 17:35:08 JST 2015
Kouhei Sutou 2015-02-16 17:35:08 +0900 (Mon, 16 Feb 2015) New Revision: 8961ce8f926645c396a034374c68218a74fb680d https://github.com/groonga/groonga/commit/8961ce8f926645c396a034374c68218a74fb680d Message: Add grn_obj_is_function_proc() Modified files: include/groonga/obj.h lib/obj.c test/unit/core/test-object.c Modified: include/groonga/obj.h (+1 -0) =================================================================== --- include/groonga/obj.h 2015-02-16 17:23:26 +0900 (2a61f8c) +++ include/groonga/obj.h 2015-02-16 17:35:08 +0900 (a9a5b5d) @@ -25,6 +25,7 @@ extern "C" { GRN_API grn_bool grn_obj_is_builtin(grn_ctx *ctx, grn_obj *obj); GRN_API grn_bool grn_obj_is_table(grn_ctx *ctx, grn_obj *obj); +GRN_API grn_bool grn_obj_is_function_proc(grn_ctx *ctx, grn_obj *obj); #ifdef __cplusplus } Modified: lib/obj.c (+17 -0) =================================================================== --- lib/obj.c 2015-02-16 17:23:26 +0900 (036eeac) +++ lib/obj.c 2015-02-16 17:35:08 +0900 (224cced) @@ -55,3 +55,20 @@ grn_obj_is_table(grn_ctx *ctx, grn_obj *obj) return is_table; } + +grn_bool +grn_obj_is_function_proc(grn_ctx *ctx, grn_obj *obj) +{ + grn_proc *proc; + + if (!obj) { + return GRN_FALSE; + } + + if (obj->header.type != GRN_PROC) { + return GRN_FALSE; + } + + proc = (grn_proc *)obj; + return proc->type == GRN_PROC_FUNCTION; +} Modified: test/unit/core/test-object.c (+35 -1) =================================================================== --- test/unit/core/test-object.c 2015-02-16 17:23:26 +0900 (105cafc) +++ test/unit/core/test-object.c 2015-02-16 17:35:08 +0900 (667b4a7) @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2; coding: utf-8 -*- */ /* - Copyright (C) 2011-2012 Kouhei Sutou <kou �� clear-code.com> + Copyright (C) 2011-2015 Kouhei Sutou <kou �� clear-code.com> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -29,6 +29,8 @@ void data_is_builtin(void); void test_is_builtin(gconstpointer data); void data_is_table(void); void test_is_table(gconstpointer data); +void data_is_function_proc(void); +void test_is_function_proc(gconstpointer data); static gchar *tmp_directory; static const gchar *database_path; @@ -152,3 +154,35 @@ test_is_table(gconstpointer data) cut_assert_false(grn_obj_is_table(context, object)); } } + +void +data_is_function_proc(void) +{ +#define ADD_DATUM(expected, name) \ + gcut_add_datum((expected ? \ + "function-proc - " name : \ + "not function-proc - " name), \ + "expected", G_TYPE_BOOLEAN, expected, \ + "name", G_TYPE_STRING, name, \ + NULL) + + ADD_DATUM(TRUE, "now"); + ADD_DATUM(FALSE, "status"); + +#undef ADD_DATUM +} + +void +test_is_function_proc(gconstpointer data) +{ + const gchar *name; + grn_obj *object; + + name = gcut_data_get_string(data, "name"); + object = grn_ctx_get(context, name, strlen(name)); + if (gcut_data_get_string(data, "expected")) { + cut_assert_true(grn_obj_is_function_proc(context, object)); + } else { + cut_assert_false(grn_obj_is_function_proc(context, object)); + } +} -------------- next part -------------- HTML����������������������������... 下载