You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2015/01/25 23:20:53 UTC

[2/3] mesos git commit: Added a protobuf unit test for RepeatedPtrField.

Added a protobuf unit test for RepeatedPtrField.

Review: https://reviews.apache.org/r/30112


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5110dc10
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5110dc10
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5110dc10

Branch: refs/heads/master
Commit: 5110dc10fe3f133c0246639bada8a1633340a825
Parents: 7633982
Author: Michael Park <mc...@gmail.com>
Authored: Sun Jan 25 14:13:18 2015 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Sun Jan 25 14:13:18 2015 -0800

----------------------------------------------------------------------
 src/tests/protobuf_io_tests.cpp | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/5110dc10/src/tests/protobuf_io_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/protobuf_io_tests.cpp b/src/tests/protobuf_io_tests.cpp
index c6ce293..d5d788c 100644
--- a/src/tests/protobuf_io_tests.cpp
+++ b/src/tests/protobuf_io_tests.cpp
@@ -36,6 +36,10 @@ using namespace mesos;
 using namespace mesos::internal;
 using namespace mesos::internal::tests;
 
+using std::string;
+
+using google::protobuf::RepeatedPtrField;
+
 
 class ProtobufIOTest : public TemporaryDirectoryTest {};
 
@@ -43,7 +47,7 @@ class ProtobufIOTest : public TemporaryDirectoryTest {};
 // TODO(bmahler): Move this file into stout.
 TEST_F(ProtobufIOTest, Basic)
 {
-  const std::string file = ".protobuf_io_test_basic";
+  const string file = ".protobuf_io_test_basic";
 
   Try<int> result = os::open(
       file,
@@ -94,7 +98,7 @@ TEST_F(ProtobufIOTest, Basic)
 
 TEST_F(ProtobufIOTest, Append)
 {
-  const std::string file = ".protobuf_io_test_append";
+  const string file = ".protobuf_io_test_append";
 
   const size_t writes = 10;
   for (size_t i = 0; i < writes; i++) {
@@ -130,3 +134,31 @@ TEST_F(ProtobufIOTest, Append)
 
   os::close(fd.get());
 }
+
+TEST_F(ProtobufIOTest, RepeatedPtrField)
+{
+  const string file = ".protobuf_io_test_repeated_ptr_field";
+
+  RepeatedPtrField<FrameworkID> expected;
+
+  const size_t size = 10;
+  for (size_t i = 0; i < size; i++) {
+    FrameworkID frameworkId;
+    frameworkId.set_value(stringify(i));
+    expected.Add()->CopyFrom(frameworkId);
+  }
+
+  Try<Nothing> write = ::protobuf::write(file, expected);
+  ASSERT_SOME(write);
+
+  Result<RepeatedPtrField<FrameworkID>> read =
+    ::protobuf::read<RepeatedPtrField<FrameworkID>>(file);
+  ASSERT_SOME(read);
+
+  RepeatedPtrField<FrameworkID> actual = read.get();
+
+  ASSERT_EQ(expected.size(), actual.size());
+  for (size_t i = 0; i < size; i++) {
+    EXPECT_EQ(expected.Get(i), actual.Get(i));
+  }
+}