Kouhei Sutou
null+****@clear*****
Wed Aug 12 11:48:22 JST 2015
Kouhei Sutou 2015-08-12 11:48:22 +0900 (Wed, 12 Aug 2015) New Revision: 411ff1e2e44752f776028294d66f6cba2efcf4f9 https://github.com/groonga/groonga/commit/411ff1e2e44752f776028294d66f6cba2efcf4f9 Message: Support inspecting GRN_PTR Modified files: lib/util.c test/unit/core/test-inspect.c Modified: lib/util.c (+25 -1) =================================================================== --- lib/util.c 2015-08-11 14:26:52 +0900 (7096b06) +++ lib/util.c 2015-08-12 11:48:22 +0900 (80ad384) @@ -368,6 +368,30 @@ grn_expr_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *expr) } static grn_rc +grn_ptr_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *ptr) +{ + size_t size; + + GRN_TEXT_PUTS(ctx, buffer, "#<ptr:"); + + size = GRN_BULK_VSIZE(ptr); + if (size == 0) { + GRN_TEXT_PUTS(ctx, buffer, "(empty)"); + } else if (size >= sizeof(grn_obj *)) { + grn_obj *content = GRN_PTR_VALUE(ptr); + grn_inspect(ctx, buffer, content); + if (size > sizeof(grn_obj *)) { + grn_text_printf(ctx, buffer, + " (and more data: %" GRN_FMT_SIZE ")", + size - sizeof(grn_obj *)); + } + } + GRN_TEXT_PUTS(ctx, buffer, ">"); + + return GRN_SUCCESS; +} + +static grn_rc grn_pvector_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *pvector) { int i, n; @@ -1126,7 +1150,7 @@ grn_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj) } break; case GRN_PTR : - /* TODO */ + grn_ptr_inspect(ctx, buffer, obj); break; case GRN_UVECTOR : domain = grn_ctx_at(ctx, obj->header.domain); Modified: test/unit/core/test-inspect.c (+25 -0) =================================================================== --- test/unit/core/test-inspect.c 2015-08-11 14:26:52 +0900 (7a6a5fb) +++ test/unit/core/test-inspect.c 2015-08-12 11:48:22 +0900 (dcce6a3) @@ -51,6 +51,8 @@ void test_patricia_trie_empty(void); void test_patricia_trie_with_records(void); void test_patricia_trie_cursor_empty(void); void test_patricia_trie_cursor_with_records(void); +void test_ptr_empty(void); +void test_ptr_with_object(void); void test_uvector_empty(void); void test_uvector_with_records(void); void test_uvector_bool(void); @@ -84,6 +86,7 @@ static grn_obj *time_value; static grn_obj *bool_value; static grn_obj *text; static grn_obj *geo_point_tokyo, *geo_point_wgs84; +static grn_obj *ptr; static grn_obj *uvector; static grn_obj *pvector; static grn_obj *vector; @@ -121,6 +124,7 @@ setup_values(void) bool_value = NULL; text = NULL; geo_point_tokyo = geo_point_wgs84 = NULL; + ptr = NULL; uvector = NULL; pvector = NULL; vector = NULL; @@ -164,6 +168,7 @@ teardown_values(void) grn_obj_unlink(context, text); grn_obj_unlink(context, geo_point_tokyo); grn_obj_unlink(context, geo_point_wgs84); + grn_obj_unlink(context, ptr); grn_obj_unlink(context, uvector); grn_obj_unlink(context, pvector); grn_obj_unlink(context, vector); @@ -563,6 +568,26 @@ test_patricia_trie_cursor_with_records(void) } void +test_ptr_empty(void) +{ + ptr = grn_obj_open(context, GRN_PTR, 0, GRN_ID_NIL); + inspected = grn_inspect(context, NULL, ptr); + cut_assert_equal_string("#<ptr:(empty)>", inspected_string()); +} + +void +test_ptr_with_object(void) +{ + text = grn_obj_open(context, GRN_BULK, 0, GRN_DB_TEXT); + GRN_TEXT_PUTS(context, text, "niku"); + + ptr = grn_obj_open(context, GRN_PTR, 0, GRN_ID_NIL); + GRN_PTR_SET(context, ptr, text); + inspected = grn_inspect(context, NULL, ptr); + cut_assert_equal_string("#<ptr:\"niku\">", inspected_string()); +} + +void test_uvector_empty(void) { assert_send_command("table_create Sites TABLE_PAT_KEY ShortText"); -------------- next part -------------- HTML����������������������������...Download