Kouhei Sutou
null+****@clear*****
Mon Oct 19 14:28:53 JST 2015
Kouhei Sutou 2015-10-19 14:28:53 +0900 (Mon, 19 Oct 2015) New Revision: 106b5646069e83d141c0eb87e1f16224199e5c0e https://github.com/groonga/groonga/commit/106b5646069e83d141c0eb87e1f16224199e5c0e Message: Add grn_obj_is_type() 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-10-19 14:28:43 +0900 (f1053d2) +++ include/groonga/obj.h 2015-10-19 14:28:53 +0900 (4036ab3) @@ -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_type(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 -0) =================================================================== --- lib/obj.c 2015-10-19 14:28:43 +0900 (bca1597) +++ lib/obj.c 2015-10-19 14:28:53 +0900 (5cbcbab) @@ -57,6 +57,16 @@ grn_obj_is_table(grn_ctx *ctx, grn_obj *obj) } grn_bool +grn_obj_is_type(grn_ctx *ctx, grn_obj *obj) +{ + if (!obj) { + return GRN_FALSE; + } + + return obj->header.type == GRN_TYPE; +} + +grn_bool grn_obj_is_proc(grn_ctx *ctx, grn_obj *obj) { if (!obj) { Modified: test/unit/core/test-object.c (+36 -0) =================================================================== --- test/unit/core/test-object.c 2015-10-19 14:28:43 +0900 (896fe52) +++ test/unit/core/test-object.c 2015-10-19 14:28:53 +0900 (6585f9c) @@ -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_type(void); +void test_is_type(gconstpointer data); void data_is_proc(void); void test_is_proc(gconstpointer data); void data_is_function_proc(void); @@ -162,6 +164,40 @@ test_is_table(gconstpointer data) } void +data_is_type(void) +{ +#define ADD_DATUM(expected, name) \ + gcut_add_datum((expected ? \ + "type - " name : \ + "not type - " name), \ + "expected", G_TYPE_BOOLEAN, expected, \ + "name", G_TYPE_STRING, name, \ + NULL) + + ADD_DATUM(TRUE, "ShortText"); + ADD_DATUM(FALSE, "Users"); + +#undef ADD_DATUM +} + +void +test_is_type(gconstpointer data) +{ + const gchar *name; + grn_obj *object; + + assert_send_command("table_create Users TABLE_HASH_KEY ShortText"); + + 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_type(context, object)); + } else { + cut_assert_false(grn_obj_is_type(context, object)); + } +} + +void data_is_proc(void) { #define ADD_DATUM(expected, name) \ -------------- next part -------------- HTML����������������������������...Download