Kouhei Sutou
null+****@clear*****
Mon Feb 16 18:00:02 JST 2015
Kouhei Sutou 2015-02-16 18:00:02 +0900 (Mon, 16 Feb 2015) New Revision: bc182a32875dfead500d43320da9bf826763dffc https://github.com/groonga/groonga/commit/bc182a32875dfead500d43320da9bf826763dffc Message: Add grn_obj_is_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:48:10 +0900 (692407f) +++ include/groonga/obj.h 2015-02-16 18:00:02 +0900 (e97d3d5) @@ -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_proc(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); Modified: lib/obj.c (+10 -4) =================================================================== --- lib/obj.c 2015-02-16 17:48:10 +0900 (7964da1) +++ lib/obj.c 2015-02-16 18:00:02 +0900 (0905537) @@ -57,15 +57,21 @@ grn_obj_is_table(grn_ctx *ctx, grn_obj *obj) } grn_bool -grn_obj_is_function_proc(grn_ctx *ctx, grn_obj *obj) +grn_obj_is_proc(grn_ctx *ctx, grn_obj *obj) { - grn_proc *proc; - if (!obj) { return GRN_FALSE; } - if (obj->header.type != GRN_PROC) { + return obj->header.type == GRN_PROC; +} + +grn_bool +grn_obj_is_function_proc(grn_ctx *ctx, grn_obj *obj) +{ + grn_proc *proc; + + if (!grn_obj_is_proc(ctx, obj)) { return GRN_FALSE; } Modified: test/unit/core/test-object.c (+34 -0) =================================================================== --- test/unit/core/test-object.c 2015-02-16 17:48:10 +0900 (af13f94) +++ test/unit/core/test-object.c 2015-02-16 18:00:02 +0900 (998acc6) @@ -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_proc(void); +void test_is_proc(gconstpointer data); void data_is_function_proc(void); void test_is_function_proc(gconstpointer data); void data_is_selector_proc(void); @@ -158,6 +160,38 @@ test_is_table(gconstpointer data) } void +data_is_proc(void) +{ +#define ADD_DATUM(expected, name) \ + gcut_add_datum((expected ? \ + "proc - " name : \ + "not proc - " name), \ + "expected", G_TYPE_BOOLEAN, expected, \ + "name", G_TYPE_STRING, name, \ + NULL) + + ADD_DATUM(TRUE, "status"); + ADD_DATUM(FALSE, "TokenBigram"); + +#undef ADD_DATUM +} + +void +test_is_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_proc(context, object)); + } else { + cut_assert_false(grn_obj_is_proc(context, object)); + } +} + +void data_is_function_proc(void) { #define ADD_DATUM(expected, name) \ -------------- next part -------------- HTML����������������������������...Download