Index: third_party/protobuf/src/google/protobuf/any_test.cc |
diff --git a/third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc b/third_party/protobuf/src/google/protobuf/any_test.cc |
similarity index 50% |
copy from third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc |
copy to third_party/protobuf/src/google/protobuf/any_test.cc |
index 28b6d8b49e4996cf7d9df2569a5240a27b07996b..1bfaa63d879e9a2cc9426382b1e705adf5fe7f74 100644 |
--- a/third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc |
+++ b/third_party/protobuf/src/google/protobuf/any_test.cc |
@@ -1,6 +1,6 @@ |
// Protocol Buffers - Google's data interchange format |
// Copyright 2008 Google Inc. All rights reserved. |
-// http://code.google.com/p/protobuf/ |
+// https://developers.google.com/protocol-buffers/ |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -28,39 +28,62 @@ |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-// Author: kenton@google.com (Kenton Varda) |
- |
-#include <google/protobuf/compiler/java/java_doc_comment.h> |
- |
+#include <google/protobuf/any_test.pb.h> |
#include <gtest/gtest.h> |
namespace google { |
namespace protobuf { |
-namespace compiler { |
-namespace java { |
namespace { |
-TEST(JavaDocCommentTest, Escaping) { |
- EXPECT_EQ("foo /* bar */ baz", EscapeJavadoc("foo /* bar */ baz")); |
- EXPECT_EQ("foo /*/ baz", EscapeJavadoc("foo /*/ baz")); |
- EXPECT_EQ("{@foo}", EscapeJavadoc("{@foo}")); |
- EXPECT_EQ("<i>&</i>", EscapeJavadoc("<i>&</i>")); |
- EXPECT_EQ("foo\u1234bar", EscapeJavadoc("foo\\u1234bar")); |
+TEST(AnyTest, TestPackAndUnpack) { |
+ protobuf_unittest::TestAny submessage; |
+ submessage.set_int32_value(12345); |
+ protobuf_unittest::TestAny message; |
+ message.mutable_any_value()->PackFrom(submessage); |
+ |
+ string data = message.SerializeAsString(); |
+ |
+ ASSERT_TRUE(message.ParseFromString(data)); |
+ EXPECT_TRUE(message.has_any_value()); |
+ ASSERT_TRUE(message.any_value().UnpackTo(&submessage)); |
+ EXPECT_EQ(12345, submessage.int32_value()); |
} |
-// TODO(kenton): It's hard to write a robust test of the doc comments -- we |
-// can only really compare the output against a golden value, which is a |
-// fairly tedious and fragile testing strategy. If we want to go that route, |
-// it probably makes sense to bite the bullet and write a test that compares |
-// the whole generated output for unittest.proto against a golden value, with |
-// a very simple script that can be run to regenerate it with the latest code. |
-// This would mean that updates to the golden file would have to be included |
-// in any change to the code generator, which would actually be fairly useful |
-// as it allows the reviewer to see clearly how the generated code is |
-// changing. |
+TEST(AnyTest, TestPackAndUnpackAny) { |
+ // We can pack a Any message inside another Any message. |
+ protobuf_unittest::TestAny submessage; |
+ submessage.set_int32_value(12345); |
+ google::protobuf::Any any; |
+ any.PackFrom(submessage); |
+ protobuf_unittest::TestAny message; |
+ message.mutable_any_value()->PackFrom(any); |
+ |
+ string data = message.SerializeAsString(); |
+ |
+ ASSERT_TRUE(message.ParseFromString(data)); |
+ EXPECT_TRUE(message.has_any_value()); |
+ ASSERT_TRUE(message.any_value().UnpackTo(&any)); |
+ ASSERT_TRUE(any.UnpackTo(&submessage)); |
+ EXPECT_EQ(12345, submessage.int32_value()); |
+} |
+ |
+TEST(AnyTest, TestIs) { |
+ protobuf_unittest::TestAny submessage; |
+ submessage.set_int32_value(12345); |
+ google::protobuf::Any any; |
+ any.PackFrom(submessage); |
+ ASSERT_TRUE(any.ParseFromString(any.SerializeAsString())); |
+ EXPECT_TRUE(any.Is<protobuf_unittest::TestAny>()); |
+ EXPECT_FALSE(any.Is<google::protobuf::Any>()); |
+ |
+ protobuf_unittest::TestAny message; |
+ message.mutable_any_value()->PackFrom(any); |
+ ASSERT_TRUE(message.ParseFromString(message.SerializeAsString())); |
+ EXPECT_FALSE(message.any_value().Is<protobuf_unittest::TestAny>()); |
+ EXPECT_TRUE(message.any_value().Is<google::protobuf::Any>()); |
+} |
} // namespace |
-} // namespace java |
-} // namespace compiler |
} // namespace protobuf |
+ |
} // namespace google |