diff options
Diffstat (limited to 'src/google/protobuf/text_format_unittest.cc')
-rw-r--r-- | src/google/protobuf/text_format_unittest.cc | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index 53184130..d64cd2eb 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc @@ -44,20 +44,24 @@ #include <google/protobuf/stubs/logging.h> #include <google/protobuf/testing/file.h> #include <google/protobuf/testing/file.h> +#include <google/protobuf/map_unittest.pb.h> #include <google/protobuf/test_util.h> +#include <google/protobuf/test_util2.h> #include <google/protobuf/unittest.pb.h> #include <google/protobuf/unittest_mset.pb.h> #include <google/protobuf/unittest_mset_wire_format.pb.h> #include <google/protobuf/io/tokenizer.h> #include <google/protobuf/io/zero_copy_stream_impl.h> - #include <google/protobuf/stubs/strutil.h> + #include <google/protobuf/stubs/substitute.h> #include <google/protobuf/testing/googletest.h> #include <gtest/gtest.h> #include <google/protobuf/stubs/mathlimits.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { @@ -78,10 +82,11 @@ class TextFormatTest : public testing::Test { public: static void SetUpTestCase() { GOOGLE_CHECK_OK(File::GetContents( - TestSourceDir() + - "/google/protobuf/" - "testdata/text_format_unittest_data_oneof_implemented.txt", + TestUtil::GetTestDataPath( + "net/proto2/internal/" + "testdata/text_format_unittest_data_oneof_implemented.txt"), &static_proto_debug_string_, true)); + CleanStringLineEndings(&static_proto_debug_string_, false); } TextFormatTest() : proto_debug_string_(static_proto_debug_string_) {} @@ -99,10 +104,11 @@ string TextFormatTest::static_proto_debug_string_; class TextFormatExtensionsTest : public testing::Test { public: static void SetUpTestCase() { - GOOGLE_CHECK_OK(File::GetContents(TestSourceDir() + - "/google/protobuf/testdata/" - "text_format_unittest_extensions_data.txt", - &static_proto_debug_string_, true)); + GOOGLE_CHECK_OK(File::GetContents( + TestUtil::GetTestDataPath("net/proto2/internal/testdata/" + "text_format_unittest_extensions_data.txt"), + &static_proto_debug_string_, true)); + CleanStringLineEndings(&static_proto_debug_string_, false); } TextFormatExtensionsTest() @@ -484,7 +490,8 @@ TEST_F(TextFormatTest, ErrorCasesRegisteringFieldValuePrinterShouldFail) { class CustomMessageFieldValuePrinter : public TextFormat::FieldValuePrinter { public: virtual string PrintInt32(int32 v) const { - return StrCat(FieldValuePrinter::PrintInt32(v), " # x", strings::Hex(v)); + return StrCat(FieldValuePrinter::PrintInt32(v), " # x", + strings::Hex(v)); } virtual string PrintMessageStart(const Message& message, @@ -494,8 +501,8 @@ class CustomMessageFieldValuePrinter : public TextFormat::FieldValuePrinter { if (single_line_mode) { return " { "; } - return StrCat( - " { # ", message.GetDescriptor()->name(), ": ", field_index, "\n"); + return StrCat(" { # ", message.GetDescriptor()->name(), ": ", + field_index, "\n"); } }; @@ -575,10 +582,10 @@ class CompactRepeatedFieldPrinter : public TextFormat::FastFieldValuePrinter { } } // To prevent compiler complaining about Woverloaded-virtual - void PrintFieldName(const Message& message, - const Reflection* reflection, + void PrintFieldName(const Message& message, const Reflection* reflection, const FieldDescriptor* field, - TextFormat::BaseTextGenerator* generator) const override {} + TextFormat::BaseTextGenerator* generator) const override { + } void PrintMessageStart( const Message& message, int field_index, int field_count, bool single_line_mode, @@ -959,8 +966,8 @@ TEST_F(TextFormatTest, PrintExotic) { // 9223372036854775808 is outside the range of int64. However, it is not // outside the range of uint64. Confusingly, this means that everything // works if we make the literal unsigned, even though we are negating it. - message.add_repeated_int64(-GOOGLE_ULONGLONG(9223372036854775808)); - message.add_repeated_uint64(GOOGLE_ULONGLONG(18446744073709551615)); + message.add_repeated_int64(-PROTOBUF_ULONGLONG(9223372036854775808)); + message.add_repeated_uint64(PROTOBUF_ULONGLONG(18446744073709551615)); message.add_repeated_double(123.456); message.add_repeated_double(1.23e21); message.add_repeated_double(1.23e-18); @@ -996,6 +1003,7 @@ TEST_F(TextFormatTest, PrintExotic) { TEST_F(TextFormatTest, PrintFloatPrecision) { unittest::TestAllTypes message; + message.add_repeated_float(1.0); message.add_repeated_float(1.2); message.add_repeated_float(1.23); message.add_repeated_float(1.234); @@ -1036,6 +1044,7 @@ TEST_F(TextFormatTest, PrintFloatPrecision) { message.add_repeated_double(1.23456789876543e100); EXPECT_EQ( + "repeated_float: 1\n" "repeated_float: 1.2\n" "repeated_float: 1.23\n" "repeated_float: 1.234\n" @@ -1131,15 +1140,18 @@ TEST_F(TextFormatTest, ParseExotic) { // 9223372036854775808 is outside the range of int64. However, it is not // outside the range of uint64. Confusingly, this means that everything // works if we make the literal unsigned, even though we are negating it. - EXPECT_EQ(-GOOGLE_ULONGLONG(9223372036854775808), message.repeated_int64(1)); + EXPECT_EQ(-PROTOBUF_ULONGLONG(9223372036854775808), + message.repeated_int64(1)); ASSERT_EQ(2, message.repeated_uint32_size()); EXPECT_EQ(4294967295u, message.repeated_uint32(0)); EXPECT_EQ(2147483648u, message.repeated_uint32(1)); ASSERT_EQ(2, message.repeated_uint64_size()); - EXPECT_EQ(GOOGLE_ULONGLONG(18446744073709551615), message.repeated_uint64(0)); - EXPECT_EQ(GOOGLE_ULONGLONG(9223372036854775808), message.repeated_uint64(1)); + EXPECT_EQ(PROTOBUF_ULONGLONG(18446744073709551615), + message.repeated_uint64(0)); + EXPECT_EQ(PROTOBUF_ULONGLONG(9223372036854775808), + message.repeated_uint64(1)); ASSERT_EQ(13, message.repeated_double_size()); EXPECT_EQ(123.0 , message.repeated_double(0)); @@ -1272,7 +1284,8 @@ class TextFormatParserTest : public testing::Test { parser.RecordErrorsTo(&error_collector); EXPECT_EQ(expected_result, parser.ParseFromString(input, proto)) << input << " -> " << proto->DebugString(); - EXPECT_EQ(SimpleItoa(line) + ":" + SimpleItoa(col) + ": " + message + "\n", + EXPECT_EQ(SimpleItoa(line) + ":" + SimpleItoa(col) + + ": " + message + "\n", error_collector.text_); } |