aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/util/slice_test.cc
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2017-07-18 10:42:33 -0700
committerGravatar Vijay Pai <vpai@google.com>2017-07-18 11:07:43 -0700
commit0f95fa4909ba6f65364cb0b5c8c37a27c09b67b4 (patch)
treea98b582aa9e26d6aca4a3e23e8a4ab9dfe883ec3 /test/cpp/util/slice_test.cc
parentc39d4c16a02d49a1e4b090309786643045287639 (diff)
Add idiomatic C++ API for grpc::Slice construction that doesn't
require using grpc_slice
Diffstat (limited to 'test/cpp/util/slice_test.cc')
-rw-r--r--test/cpp/util/slice_test.cc33
1 files changed, 28 insertions, 5 deletions
diff --git a/test/cpp/util/slice_test.cc b/test/cpp/util/slice_test.cc
index 0f80003580..9e3329fab0 100644
--- a/test/cpp/util/slice_test.cc
+++ b/test/cpp/util/slice_test.cc
@@ -28,6 +28,9 @@ const char* kContent = "hello xxxxxxxxxxxxxxxxxxxx world";
class SliceTest : public ::testing::Test {
protected:
+ void CheckSliceSize(const Slice& s, const grpc::string& content) {
+ EXPECT_EQ(content.size(), s.size());
+ }
void CheckSlice(const Slice& s, const grpc::string& content) {
EXPECT_EQ(content.size(), s.size());
EXPECT_EQ(content,
@@ -35,6 +38,31 @@ class SliceTest : public ::testing::Test {
}
};
+TEST_F(SliceTest, Empty) {
+ Slice empty_slice;
+ CheckSlice(empty_slice, "");
+}
+
+TEST_F(SliceTest, Sized) {
+ Slice sized_slice(strlen(kContent));
+ CheckSliceSize(sized_slice, kContent);
+}
+
+TEST_F(SliceTest, String) {
+ Slice spp(kContent);
+ CheckSlice(spp, kContent);
+}
+
+TEST_F(SliceTest, Buf) {
+ Slice spp(kContent, strlen(kContent));
+ CheckSlice(spp, kContent);
+}
+
+TEST_F(SliceTest, StaticBuf) {
+ Slice spp(kContent, strlen(kContent), Slice::STATIC_SLICE);
+ CheckSlice(spp, kContent);
+}
+
TEST_F(SliceTest, Steal) {
grpc_slice s = grpc_slice_from_copied_string(kContent);
Slice spp(s, Slice::STEAL_REF);
@@ -48,11 +76,6 @@ TEST_F(SliceTest, Add) {
CheckSlice(spp, kContent);
}
-TEST_F(SliceTest, Empty) {
- Slice empty_slice;
- CheckSlice(empty_slice, "");
-}
-
TEST_F(SliceTest, Cslice) {
grpc_slice s = grpc_slice_from_copied_string(kContent);
Slice spp(s, Slice::STEAL_REF);