Kouhei Sutou
null+****@clear*****
Mon Feb 16 17:37:57 JST 2015
Kouhei Sutou 2015-02-16 17:37:57 +0900 (Mon, 16 Feb 2015) New Revision: a1d064ec490c22552a5f36528e8c7581b03c7538 https://github.com/groonga/groonga/commit/a1d064ec490c22552a5f36528e8c7581b03c7538 Message: Add grn_obj_is_selector_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:35:08 +0900 (a9a5b5d) +++ include/groonga/obj.h 2015-02-16 17:37:57 +0900 (692407f) @@ -26,6 +26,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); +GRN_API grn_bool grn_obj_is_selector_proc(grn_ctx *ctx, grn_obj *obj); #ifdef __cplusplus } Modified: lib/obj.c (+13 -0) =================================================================== --- lib/obj.c 2015-02-16 17:35:08 +0900 (224cced) +++ lib/obj.c 2015-02-16 17:37:57 +0900 (7964da1) @@ -72,3 +72,16 @@ grn_obj_is_function_proc(grn_ctx *ctx, grn_obj *obj) proc = (grn_proc *)obj; return proc->type == GRN_PROC_FUNCTION; } + +grn_bool +grn_obj_is_selector_proc(grn_ctx *ctx, grn_obj *obj) +{ + grn_proc *proc; + + if (!grn_obj_is_function_proc(ctx, obj)) { + return GRN_FALSE; + } + + proc = (grn_proc *)obj; + return proc->selector != NULL; +} Modified: test/unit/core/test-object.c (+34 -0) =================================================================== --- test/unit/core/test-object.c 2015-02-16 17:35:08 +0900 (667b4a7) +++ test/unit/core/test-object.c 2015-02-16 17:37:57 +0900 (af13f94) @@ -31,6 +31,8 @@ void data_is_table(void); void test_is_table(gconstpointer data); void data_is_function_proc(void); void test_is_function_proc(gconstpointer data); +void data_is_selector_proc(void); +void test_is_selector_proc(gconstpointer data); static gchar *tmp_directory; static const gchar *database_path; @@ -186,3 +188,35 @@ test_is_function_proc(gconstpointer data) cut_assert_false(grn_obj_is_function_proc(context, object)); } } + +void +data_is_selector_proc(void) +{ +#define ADD_DATUM(expected, name) \ + gcut_add_datum((expected ? \ + "selector-proc - " name : \ + "not selector-proc - " name), \ + "expected", G_TYPE_BOOLEAN, expected, \ + "name", G_TYPE_STRING, name, \ + NULL) + + ADD_DATUM(TRUE, "geo_in_circle"); + ADD_DATUM(FALSE, "now"); + +#undef ADD_DATUM +} + +void +test_is_selector_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_selector_proc(context, object)); + } else { + cut_assert_false(grn_obj_is_selector_proc(context, object)); + } +} -------------- next part -------------- HTML����������������������������... Download