|
|
|
@ -63,6 +63,42 @@ TEST_F(SliceTest, StaticBuf) { |
|
|
|
|
CheckSlice(spp, kContent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(SliceTest, SliceNew) { |
|
|
|
|
char* x = new char[strlen(kContent) + 1]; |
|
|
|
|
strcpy(x, kContent); |
|
|
|
|
Slice spp(x, strlen(x), [](void* p) { delete[] reinterpret_cast<char*>(p); }); |
|
|
|
|
CheckSlice(spp, kContent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(SliceTest, SliceNewDoNothing) { |
|
|
|
|
Slice spp(const_cast<char*>(kContent), strlen(kContent), [](void* p) {}); |
|
|
|
|
CheckSlice(spp, kContent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(SliceTest, SliceNewWithUserData) { |
|
|
|
|
struct stest { |
|
|
|
|
char* x; |
|
|
|
|
int y; |
|
|
|
|
}; |
|
|
|
|
auto* t = new stest; |
|
|
|
|
t->x = new char[strlen(kContent) + 1]; |
|
|
|
|
strcpy(t->x, kContent); |
|
|
|
|
Slice spp(t->x, strlen(t->x), |
|
|
|
|
[](void* p) { |
|
|
|
|
auto* t = reinterpret_cast<stest*>(p); |
|
|
|
|
delete[] t->x; |
|
|
|
|
delete t; |
|
|
|
|
}, |
|
|
|
|
t); |
|
|
|
|
CheckSlice(spp, kContent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(SliceTest, SliceNewLen) { |
|
|
|
|
Slice spp(const_cast<char*>(kContent), strlen(kContent), |
|
|
|
|
[](void* p, size_t l) { EXPECT_EQ(l, strlen(kContent)); }); |
|
|
|
|
CheckSlice(spp, kContent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(SliceTest, Steal) { |
|
|
|
|
grpc_slice s = grpc_slice_from_copied_string(kContent); |
|
|
|
|
Slice spp(s, Slice::STEAL_REF); |
|
|
|
|