| Index: third_party/protobuf/src/google/protobuf/lite_arena_unittest.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc b/third_party/protobuf/src/google/protobuf/lite_arena_unittest.cc
|
| similarity index 51%
|
| rename from third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc
|
| rename to third_party/protobuf/src/google/protobuf/lite_arena_unittest.cc
|
| index 28b6d8b49e4996cf7d9df2569a5240a27b07996b..f0bee880aa669f00951b6d64ed618df34d7237e6 100644
|
| --- a/third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/lite_arena_unittest.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,56 @@
|
| // (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/arena_test_util.h>
|
| +#include <google/protobuf/map_lite_test_util.h>
|
| +#include <google/protobuf/testing/googletest.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(LiteArenaTest, MapNoHeapAllocation) {
|
| + // Allocate a large initial block to avoid mallocs during hooked test.
|
| + std::vector<char> arena_block(128 * 1024);
|
| + google::protobuf::ArenaOptions options;
|
| + options.initial_block = &arena_block[0];
|
| + options.initial_block_size = arena_block.size();
|
| + google::protobuf::Arena arena(options);
|
| + string data;
|
| + data.reserve(128 * 1024);
|
| +
|
| + {
|
| + // TODO(teboring): Enable no heap check when ArenaStringPtr is used in
|
| + // Map.
|
| + // google::protobuf::internal::NoHeapChecker no_heap;
|
| +
|
| + protobuf_unittest::TestArenaMapLite* from =
|
| + google::protobuf::Arena::CreateMessage<protobuf_unittest::TestArenaMapLite>(&arena);
|
| + google::protobuf::MapLiteTestUtil::SetArenaMapFields(from);
|
| + from->SerializeToString(&data);
|
| +
|
| + protobuf_unittest::TestArenaMapLite* to =
|
| + google::protobuf::Arena::CreateMessage<protobuf_unittest::TestArenaMapLite>(&arena);
|
| + to->ParseFromString(data);
|
| + google::protobuf::MapLiteTestUtil::ExpectArenaMapFieldsSet(*to);
|
| + }
|
| }
|
|
|
| -// 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(LiteArenaTest, UnknownFieldMemLeak) {
|
| + google::protobuf::Arena arena;
|
| + protobuf_unittest::ForeignMessageArenaLite* message =
|
| + google::protobuf::Arena::CreateMessage<protobuf_unittest::ForeignMessageArenaLite>(
|
| + &arena);
|
| + string data = "\012\000";
|
| + int original_capacity = data.capacity();
|
| + while (data.capacity() <= original_capacity) {
|
| + data.append("a");
|
| + }
|
| + data[1] = data.size() - 2;
|
| + message->ParseFromString(data);
|
| +}
|
|
|
| } // namespace
|
| -} // namespace java
|
| -} // namespace compiler
|
| } // namespace protobuf
|
| } // namespace google
|
|
|