Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: third_party/protobuf/src/google/protobuf/lite_arena_unittest.cc

Issue 1842653006: Update //third_party/protobuf to version 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update defines Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 /&#42; bar *&#47; baz", EscapeJavadoc("foo /* bar */ baz"));
- EXPECT_EQ("foo /&#42;&#47; baz", EscapeJavadoc("foo /*/ baz"));
- EXPECT_EQ("{&#64;foo}", EscapeJavadoc("{@foo}"));
- EXPECT_EQ("&lt;i&gt;&amp;&lt;/i&gt;", EscapeJavadoc("<i>&</i>"));
- EXPECT_EQ("foo&#92;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

Powered by Google App Engine
This is Rietveld 408576698