|
|
@ -34,33 +34,30 @@ const char* kContent2 = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy world"; |
|
|
|
class ByteBufferTest : public ::testing::Test {}; |
|
|
|
class ByteBufferTest : public ::testing::Test {}; |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ByteBufferTest, CreateFromSingleSlice) { |
|
|
|
TEST_F(ByteBufferTest, CreateFromSingleSlice) { |
|
|
|
grpc_slice hello = grpc_slice_from_copied_string(kContent1); |
|
|
|
Slice s(kContent1); |
|
|
|
Slice s(hello, Slice::STEAL_REF); |
|
|
|
|
|
|
|
ByteBuffer buffer(&s, 1); |
|
|
|
ByteBuffer buffer(&s, 1); |
|
|
|
|
|
|
|
EXPECT_EQ(strlen(kContent1), buffer.Length()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ByteBufferTest, CreateFromVector) { |
|
|
|
TEST_F(ByteBufferTest, CreateFromVector) { |
|
|
|
grpc_slice hello = grpc_slice_from_copied_string(kContent1); |
|
|
|
|
|
|
|
grpc_slice world = grpc_slice_from_copied_string(kContent2); |
|
|
|
|
|
|
|
std::vector<Slice> slices; |
|
|
|
std::vector<Slice> slices; |
|
|
|
slices.push_back(Slice(hello, Slice::STEAL_REF)); |
|
|
|
slices.emplace_back(kContent1); |
|
|
|
slices.push_back(Slice(world, Slice::STEAL_REF)); |
|
|
|
slices.emplace_back(kContent2); |
|
|
|
ByteBuffer buffer(&slices[0], 2); |
|
|
|
ByteBuffer buffer(&slices[0], 2); |
|
|
|
|
|
|
|
EXPECT_EQ(strlen(kContent1) + strlen(kContent2), buffer.Length()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ByteBufferTest, Clear) { |
|
|
|
TEST_F(ByteBufferTest, Clear) { |
|
|
|
grpc_slice hello = grpc_slice_from_copied_string(kContent1); |
|
|
|
Slice s(kContent1); |
|
|
|
Slice s(hello, Slice::STEAL_REF); |
|
|
|
|
|
|
|
ByteBuffer buffer(&s, 1); |
|
|
|
ByteBuffer buffer(&s, 1); |
|
|
|
buffer.Clear(); |
|
|
|
buffer.Clear(); |
|
|
|
|
|
|
|
EXPECT_EQ(static_cast<size_t>(0), buffer.Length()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ByteBufferTest, Length) { |
|
|
|
TEST_F(ByteBufferTest, Length) { |
|
|
|
grpc_slice hello = grpc_slice_from_copied_string(kContent1); |
|
|
|
|
|
|
|
grpc_slice world = grpc_slice_from_copied_string(kContent2); |
|
|
|
|
|
|
|
std::vector<Slice> slices; |
|
|
|
std::vector<Slice> slices; |
|
|
|
slices.push_back(Slice(hello, Slice::STEAL_REF)); |
|
|
|
slices.emplace_back(kContent1); |
|
|
|
slices.push_back(Slice(world, Slice::STEAL_REF)); |
|
|
|
slices.emplace_back(kContent2); |
|
|
|
ByteBuffer buffer(&slices[0], 2); |
|
|
|
ByteBuffer buffer(&slices[0], 2); |
|
|
|
EXPECT_EQ(strlen(kContent1) + strlen(kContent2), buffer.Length()); |
|
|
|
EXPECT_EQ(strlen(kContent1) + strlen(kContent2), buffer.Length()); |
|
|
|
} |
|
|
|
} |
|
|
|