proper init const char *

pull/2175/head
yang-g 10 years ago
parent 89c5a56233
commit b1bbc8764d
  1. 24
      test/cpp/util/byte_buffer_test.cc
  2. 4
      test/cpp/util/slice_test.cc

@ -43,21 +43,21 @@
namespace grpc { namespace grpc {
namespace { namespace {
const char* kContent1 = "hello xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const char* kContent2 = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy world";
class ByteBufferTest : public ::testing::Test { class ByteBufferTest : public ::testing::Test {
protected:
const char* kContent1_ = "hello xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const char* kContent2_ = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy world";
}; };
TEST_F(ByteBufferTest, CreateFromSingleSlice) { TEST_F(ByteBufferTest, CreateFromSingleSlice) {
gpr_slice hello = gpr_slice_from_copied_string(kContent1_); gpr_slice hello = gpr_slice_from_copied_string(kContent1);
Slice s(hello, Slice::STEAL_REF); Slice s(hello, Slice::STEAL_REF);
ByteBuffer buffer(&s, 1); ByteBuffer buffer(&s, 1);
} }
TEST_F(ByteBufferTest, CreateFromVector) { TEST_F(ByteBufferTest, CreateFromVector) {
gpr_slice hello = gpr_slice_from_copied_string(kContent1_); gpr_slice hello = gpr_slice_from_copied_string(kContent1);
gpr_slice world = gpr_slice_from_copied_string(kContent2_); gpr_slice world = gpr_slice_from_copied_string(kContent2);
std::vector<Slice> slices; std::vector<Slice> slices;
slices.push_back(Slice(hello, Slice::STEAL_REF)); slices.push_back(Slice(hello, Slice::STEAL_REF));
slices.push_back(Slice(world, Slice::STEAL_REF)); slices.push_back(Slice(world, Slice::STEAL_REF));
@ -65,20 +65,20 @@ TEST_F(ByteBufferTest, CreateFromVector) {
} }
TEST_F(ByteBufferTest, Clear) { TEST_F(ByteBufferTest, Clear) {
gpr_slice hello = gpr_slice_from_copied_string(kContent1_); gpr_slice hello = gpr_slice_from_copied_string(kContent1);
Slice s(hello, Slice::STEAL_REF); Slice s(hello, Slice::STEAL_REF);
ByteBuffer buffer(&s, 1); ByteBuffer buffer(&s, 1);
buffer.Clear(); buffer.Clear();
} }
TEST_F(ByteBufferTest, Length) { TEST_F(ByteBufferTest, Length) {
gpr_slice hello = gpr_slice_from_copied_string(kContent1_); gpr_slice hello = gpr_slice_from_copied_string(kContent1);
gpr_slice world = gpr_slice_from_copied_string(kContent2_); gpr_slice world = gpr_slice_from_copied_string(kContent2);
std::vector<Slice> slices; std::vector<Slice> slices;
slices.push_back(Slice(hello, Slice::STEAL_REF)); slices.push_back(Slice(hello, Slice::STEAL_REF));
slices.push_back(Slice(world, Slice::STEAL_REF)); slices.push_back(Slice(world, Slice::STEAL_REF));
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());
} }
bool SliceEqual(const Slice& a, gpr_slice b) { bool SliceEqual(const Slice& a, gpr_slice b) {
@ -94,8 +94,8 @@ bool SliceEqual(const Slice& a, gpr_slice b) {
} }
TEST_F(ByteBufferTest, Dump) { TEST_F(ByteBufferTest, Dump) {
gpr_slice hello = gpr_slice_from_copied_string(kContent1_); gpr_slice hello = gpr_slice_from_copied_string(kContent1);
gpr_slice world = gpr_slice_from_copied_string(kContent2_); gpr_slice world = gpr_slice_from_copied_string(kContent2);
std::vector<Slice> slices; std::vector<Slice> slices;
slices.push_back(Slice(hello, Slice::STEAL_REF)); slices.push_back(Slice(hello, Slice::STEAL_REF));
slices.push_back(Slice(world, Slice::STEAL_REF)); slices.push_back(Slice(world, Slice::STEAL_REF));

@ -39,6 +39,8 @@
namespace grpc { namespace grpc {
namespace { namespace {
const char* kContent = "hello xxxxxxxxxxxxxxxxxxxx world";
class SliceTest : public ::testing::Test { class SliceTest : public ::testing::Test {
protected: protected:
void CheckSlice(const Slice& s, const grpc::string& content) { void CheckSlice(const Slice& s, const grpc::string& content) {
@ -46,8 +48,6 @@ class SliceTest : public ::testing::Test {
EXPECT_EQ(content, EXPECT_EQ(content,
grpc::string(reinterpret_cast<const char*>(s.begin()), s.size())); grpc::string(reinterpret_cast<const char*>(s.begin()), s.size()));
} }
const char* kContent = "hello xxxxxxxxxxxxxxxxxxxx world";
}; };
TEST_F(SliceTest, Steal) { TEST_F(SliceTest, Steal) {

Loading…
Cancel
Save