diff options
-rw-r--r-- | src/core/support/slice.c | 7 | ||||
-rw-r--r-- | test/core/support/slice_test.c | 17 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/core/support/slice.c b/src/core/support/slice.c index 5b091f17b0..9f0ded4932 100644 --- a/src/core/support/slice.c +++ b/src/core/support/slice.c @@ -341,10 +341,3 @@ int gpr_slice_str_cmp(gpr_slice a, const char *b) { if (d != 0) return d; return memcmp(GPR_SLICE_START_PTR(a), b, b_length); } - -char *gpr_slice_to_cstring(gpr_slice slice) { - char *result = gpr_malloc(GPR_SLICE_LENGTH(slice) + 1); - memcpy(result, GPR_SLICE_START_PTR(slice), GPR_SLICE_LENGTH(slice)); - result[GPR_SLICE_LENGTH(slice)] = '\0'; - return result; -} diff --git a/test/core/support/slice_test.c b/test/core/support/slice_test.c index 1d202f0618..9e0e22c24b 100644 --- a/test/core/support/slice_test.c +++ b/test/core/support/slice_test.c @@ -94,12 +94,27 @@ static void do_nothing_with_len_1(void *ignored, size_t len) { static void test_slice_new_with_len_returns_something_sensible(void) { gpr_uint8 x; + int num_refs = 5; /* To test adding/removing an arbitrary number of refs */ + int i; gpr_slice slice = gpr_slice_new_with_len(&x, 1, do_nothing_with_len_1); - GPR_ASSERT(slice.refcount); + GPR_ASSERT(slice.refcount); /* ref count is initialized to 1 at this point */ GPR_ASSERT(slice.data.refcounted.bytes == &x); GPR_ASSERT(slice.data.refcounted.length == 1); GPR_ASSERT(do_nothing_with_len_1_calls == 0); + + /* Add an arbitrary number of refs to the slice and remoe the refs. This is to + make sure that that the destroy callback (i.e do_nothing_with_len_1()) is + not called until the last unref operation */ + for (i = 0; i < num_refs; i++) { + gpr_slice_ref(slice); + } + for (i = 0; i < num_refs; i++) { + gpr_slice_unref(slice); + } + GPR_ASSERT(do_nothing_with_len_1_calls == 0); /* Shouldn't be called yet */ + + /* last unref */ gpr_slice_unref(slice); GPR_ASSERT(do_nothing_with_len_1_calls == 1); } |