19 #include <gtest/gtest.h>
34 const char* kContent =
"hello xxxxxxxxxxxxxxxxxxxx world";
38 static void SetUpTestCase() {
grpc_init(); }
48 std::string(
reinterpret_cast<const char*
>(s.begin()), s.size()));
54 CheckSlice(empty_slice,
"");
58 Slice sized_slice(strlen(kContent));
59 CheckSliceSize(sized_slice, kContent);
62 TEST_F(SliceTest, String) {
64 CheckSlice(spp, kContent);
68 Slice spp(kContent, strlen(kContent));
69 CheckSlice(spp, kContent);
72 TEST_F(SliceTest, StaticBuf) {
74 CheckSlice(spp, kContent);
77 TEST_F(SliceTest, SliceNew) {
78 char*
x =
new char[strlen(kContent) + 1];
80 Slice spp(
x, strlen(
x), [](
void* p) {
delete[]
static_cast<char*
>(p); });
81 CheckSlice(spp, kContent);
84 TEST_F(SliceTest, SliceNewDoNothing) {
85 Slice spp(
const_cast<char*
>(kContent), strlen(kContent), [](
void* ) {});
86 CheckSlice(spp, kContent);
89 TEST_F(SliceTest, SliceNewWithUserData) {
95 t->x =
new char[strlen(kContent) + 1];
96 strcpy(t->x, kContent);
100 auto* t = static_cast<stest*>(p);
105 CheckSlice(spp, kContent);
108 TEST_F(SliceTest, SliceNewLen) {
109 Slice spp(
const_cast<char*
>(kContent), strlen(kContent),
110 [](
void* ,
size_t l) {
EXPECT_EQ(l, strlen(kContent)); });
111 CheckSlice(spp, kContent);
114 TEST_F(SliceTest, Steal) {
117 CheckSlice(spp, kContent);
124 CheckSlice(spp, kContent);
128 Slice spp(
"0123456789");
130 CheckSlice(sub,
"12345678");
133 TEST_F(SliceTest, Cslice) {
136 CheckSlice(spp, kContent);
146 int main(
int argc,
char** argv) {