| Index: third_party/protobuf/src/google/protobuf/lite_arena_unittest.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/stubs/strutil_unittest.cc b/third_party/protobuf/src/google/protobuf/lite_arena_unittest.cc
|
| similarity index 52%
|
| copy from third_party/protobuf/src/google/protobuf/stubs/strutil_unittest.cc
|
| copy to third_party/protobuf/src/google/protobuf/lite_arena_unittest.cc
|
| index b9c9253b0483b7e85557484f8d78e220cea34fee..f0bee880aa669f00951b6d64ed618df34d7237e6 100644
|
| --- a/third_party/protobuf/src/google/protobuf/stubs/strutil_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,56 +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/stubs/strutil.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>
|
| -#include <locale.h>
|
|
|
| namespace google {
|
| namespace protobuf {
|
| namespace {
|
|
|
| -// TODO(kenton): Copy strutil tests from google3?
|
| -
|
| -TEST(StringUtilityTest, ImmuneToLocales) {
|
| - // Remember the old locale.
|
| - char* old_locale_cstr = setlocale(LC_NUMERIC, NULL);
|
| - ASSERT_TRUE(old_locale_cstr != NULL);
|
| - string old_locale = old_locale_cstr;
|
| +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);
|
|
|
| - // Set the locale to "C".
|
| - ASSERT_TRUE(setlocale(LC_NUMERIC, "C") != NULL);
|
| + {
|
| + // TODO(teboring): Enable no heap check when ArenaStringPtr is used in
|
| + // Map.
|
| + // google::protobuf::internal::NoHeapChecker no_heap;
|
|
|
| - EXPECT_EQ(1.5, NoLocaleStrtod("1.5", NULL));
|
| - EXPECT_EQ("1.5", SimpleDtoa(1.5));
|
| - EXPECT_EQ("1.5", SimpleFtoa(1.5));
|
| + protobuf_unittest::TestArenaMapLite* from =
|
| + google::protobuf::Arena::CreateMessage<protobuf_unittest::TestArenaMapLite>(&arena);
|
| + google::protobuf::MapLiteTestUtil::SetArenaMapFields(from);
|
| + from->SerializeToString(&data);
|
|
|
| - // Verify that the endptr is set correctly even if not all text was parsed.
|
| - const char* text = "1.5f";
|
| - char* endptr;
|
| - EXPECT_EQ(1.5, NoLocaleStrtod(text, &endptr));
|
| - EXPECT_EQ(3, endptr - text);
|
| -
|
| - if (setlocale(LC_NUMERIC, "es_ES") == NULL &&
|
| - setlocale(LC_NUMERIC, "es_ES.utf8") == NULL) {
|
| - // Some systems may not have the desired locale available.
|
| - GOOGLE_LOG(WARNING)
|
| - << "Couldn't set locale to es_ES. Skipping this test.";
|
| - } else {
|
| - EXPECT_EQ(1.5, NoLocaleStrtod("1.5", NULL));
|
| - EXPECT_EQ("1.5", SimpleDtoa(1.5));
|
| - EXPECT_EQ("1.5", SimpleFtoa(1.5));
|
| - EXPECT_EQ(1.5, NoLocaleStrtod(text, &endptr));
|
| - EXPECT_EQ(3, endptr - text);
|
| + protobuf_unittest::TestArenaMapLite* to =
|
| + google::protobuf::Arena::CreateMessage<protobuf_unittest::TestArenaMapLite>(&arena);
|
| + to->ParseFromString(data);
|
| + google::protobuf::MapLiteTestUtil::ExpectArenaMapFieldsSet(*to);
|
| }
|
| +}
|
|
|
| - // Return to original locale.
|
| - setlocale(LC_NUMERIC, old_locale.c_str());
|
| +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);
|
| }
|
|
|
| -} // anonymous namespace
|
| +} // namespace
|
| } // namespace protobuf
|
| } // namespace google
|
|
|