From 0d9baf367f6acca336b07e46ba1743f244e98ecf Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Mon, 26 Aug 2024 09:07:59 -0700 Subject: [PATCH] Remove outdated conformance/fuzz tests. These are very old unit-tests that appear to have been written to provide some conformance and fuzzing capabilities before we had more comprehensive solutions. Today, they should be already covered by our conformance tests and fuzz tests and create unnecessary noise. The goal of this change is to remove the checked-in binary golden data that we no longer know how to regenerate. There is a lot of nearby code that could likely also be cleaned up in a follow-up PiperOrigin-RevId: 667604310 --- .../protobuf/CodedOutputStreamTest.java | 42 ---------- .../java/com/google/protobuf/TestUtil.java | 47 ----------- .../google/protobuf/internal/message_test.py | 76 +----------------- src/google/protobuf/BUILD.bazel | 2 - src/google/protobuf/arena_test_util.h | 40 --------- src/google/protobuf/arena_unittest.cc | 7 -- src/google/protobuf/compiler/BUILD.bazel | 1 + .../command_line_interface_unittest.cc | 28 +++++-- src/google/protobuf/io/BUILD.bazel | 4 +- .../protobuf/io/zero_copy_stream_unittest.cc | 8 +- src/google/protobuf/map_test.inc | 63 +++++++-------- src/google/protobuf/message_unittest.inc | 18 ++++- src/google/protobuf/testdata/golden_message | Bin 537 -> 0 bytes .../protobuf/testdata/golden_message_maps | Bin 13619 -> 0 bytes .../testdata/golden_message_oneof_implemented | Bin 521 -> 0 bytes .../protobuf/testdata/golden_message_proto3 | Bin 248 -> 0 bytes .../testdata/golden_packed_fields_message | Bin 142 -> 0 bytes 17 files changed, 72 insertions(+), 264 deletions(-) delete mode 100644 src/google/protobuf/testdata/golden_message delete mode 100644 src/google/protobuf/testdata/golden_message_maps delete mode 100644 src/google/protobuf/testdata/golden_message_oneof_implemented delete mode 100644 src/google/protobuf/testdata/golden_message_proto3 delete mode 100644 src/google/protobuf/testdata/golden_packed_fields_message diff --git a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java index 51e66b9759..1f17f24fe3 100644 --- a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +++ b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java @@ -13,7 +13,6 @@ import static com.google.common.truth.Truth.assertWithMessage; import com.google.protobuf.CodedOutputStream.OutOfSpaceException; import protobuf_unittest.UnittestProto.SparseEnumMessage; import protobuf_unittest.UnittestProto.TestAllTypes; -import protobuf_unittest.UnittestProto.TestPackedTypes; import protobuf_unittest.UnittestProto.TestSparseEnum; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -402,47 +401,6 @@ public class CodedOutputStreamTest { assertThat(CodedOutputStream.computeTagSize((1 << 30) + 1)).isEqualTo(1); } - /** Tests writing a whole message with every field type. */ - @Test - public void testWriteWholeMessage() throws Exception { - final byte[] expectedBytes = TestUtil.getGoldenMessage().toByteArray(); - TestAllTypes message = TestUtil.getAllSet(); - - for (OutputType outputType : OutputType.values()) { - Coder coder = outputType.newCoder(message.getSerializedSize()); - message.writeTo(coder.stream()); - coder.stream().flush(); - byte[] rawBytes = coder.toByteArray(); - assertEqualBytes(outputType, expectedBytes, rawBytes); - } - - // Try different block sizes. - for (int blockSize = 1; blockSize < 256; blockSize *= 2) { - Coder coder = OutputType.STREAM.newCoder(blockSize); - message.writeTo(coder.stream()); - coder.stream().flush(); - assertEqualBytes(OutputType.STREAM, expectedBytes, coder.toByteArray()); - } - } - - /** - * Tests writing a whole message with every packed field type. Ensures the wire format of packed - * fields is compatible with C++. - */ - @Test - public void testWriteWholePackedFieldsMessage() throws Exception { - byte[] expectedBytes = TestUtil.getGoldenPackedFieldsMessage().toByteArray(); - TestPackedTypes message = TestUtil.getPackedSet(); - - for (OutputType outputType : OutputType.values()) { - Coder coder = outputType.newCoder(message.getSerializedSize()); - message.writeTo(coder.stream()); - coder.stream().flush(); - byte[] rawBytes = coder.toByteArray(); - assertEqualBytes(outputType, expectedBytes, rawBytes); - } - } - /** * Test writing a message containing a negative enum value. This used to fail because the size was * not properly computed as a sign-extended varint. diff --git a/java/core/src/test/java/com/google/protobuf/TestUtil.java b/java/core/src/test/java/com/google/protobuf/TestUtil.java index 0f57ecc9ac..dfa51b2af3 100644 --- a/java/core/src/test/java/com/google/protobuf/TestUtil.java +++ b/java/core/src/test/java/com/google/protobuf/TestUtil.java @@ -212,7 +212,6 @@ import protobuf_unittest.UnittestProto.TestRequired; import protobuf_unittest.UnittestProto.TestUnpackedTypes; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.RandomAccessFile; import java.util.ArrayList; import java.util.Collections; @@ -3819,53 +3818,7 @@ public final class TestUtil { throw new IllegalArgumentException("Couldn't read file: " + fullPath.getPath(), e); } } - // END FULL-RUNTIME - - private static ByteString readBytesFromResource(String name) { - try { - InputStream in = TestUtil.class.getResourceAsStream(name); - if (in == null) { // - throw new RuntimeException("Tests data file " + name + " is missing."); - } - return ByteString.readFrom(in); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - /** - * Get the bytes of the "golden message". This is a serialized TestAllTypes with all fields set as - * they would be by {@link #setAllFields(TestAllTypes.Builder)}, but it is loaded from a file on - * disk rather than generated dynamically. The file is actually generated by C++ code, so testing - * against it verifies compatibility with C++. - */ - public static ByteString getGoldenMessage() { - if (goldenMessage == null) { - goldenMessage = - readBytesFromResource("/google/protobuf/testdata/golden_message_oneof_implemented"); - } - return goldenMessage; - } - - private static ByteString goldenMessage = null; - - /** - * Get the bytes of the "golden packed fields message". This is a serialized TestPackedTypes with - * all fields set as they would be by {@link #setPackedFields(TestPackedTypes.Builder)}, but it is - * loaded from a file on disk rather than generated dynamically. The file is actually generated by - * C++ code, so testing against it verifies compatibility with C++. - */ - public static ByteString getGoldenPackedFieldsMessage() { - if (goldenPackedFieldsMessage == null) { - goldenPackedFieldsMessage = - readBytesFromResource("/google/protobuf/testdata/golden_packed_fields_message"); - } - return goldenPackedFieldsMessage; - } - private static ByteString goldenPackedFieldsMessage = null; - - // BEGIN FULL-RUNTIME /** * Mock implementation of {@link GeneratedMessage.BuilderParent} for testing. * diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index bf91424cd5..2326ed9687 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -65,48 +65,6 @@ class MessageTest(unittest.TestCase): message_module.TestAllTypes.FromString(bad_utf8_data) self.assertIn('TestAllTypes.optional_string', str(context.exception)) - def testGoldenMessage(self, message_module): - # Proto3 doesn't have the "default_foo" members or foreign enums, - # and doesn't preserve unknown fields, so for proto3 we use a golden - # message that doesn't have these fields set. - if message_module is unittest_pb2: - golden_data = test_util.GoldenFileData('golden_message_oneof_implemented') - else: - golden_data = test_util.GoldenFileData('golden_message_proto3') - - golden_message = message_module.TestAllTypes() - golden_message.ParseFromString(golden_data) - if message_module is unittest_pb2: - test_util.ExpectAllFieldsSet(self, golden_message) - self.assertEqual(golden_data, golden_message.SerializeToString()) - golden_copy = copy.deepcopy(golden_message) - self.assertEqual(golden_data, golden_copy.SerializeToString()) - - def testGoldenMessageBytearray(self, message_module): - # bytearray was broken, test that it works again - if message_module is unittest_pb2: - golden_data = test_util.GoldenFileData('golden_message_oneof_implemented') - else: - golden_data = test_util.GoldenFileData('golden_message_proto3') - - golden_message = message_module.TestAllTypes() - golden_message.ParseFromString(bytearray(golden_data)) - if message_module is unittest_pb2: - test_util.ExpectAllFieldsSet(self, golden_message) - self.assertEqual(golden_data, golden_message.SerializeToString()) - - def testGoldenPackedMessage(self, message_module): - golden_data = test_util.GoldenFileData('golden_packed_fields_message') - golden_message = message_module.TestPackedTypes() - parsed_bytes = golden_message.ParseFromString(golden_data) - all_set = message_module.TestPackedTypes() - test_util.SetAllPackedFields(all_set) - self.assertEqual(parsed_bytes, len(golden_data)) - self.assertEqual(all_set, golden_message) - self.assertEqual(golden_data, all_set.SerializeToString()) - golden_copy = copy.deepcopy(golden_message) - self.assertEqual(golden_data, golden_copy.SerializeToString()) - def testParseErrors(self, message_module): msg = message_module.TestAllTypes() self.assertRaises(TypeError, msg.FromString, 0) @@ -162,7 +120,9 @@ class MessageTest(unittest.TestCase): golden_message.SerializeToString(deterministic=BadArg()) def testPickleSupport(self, message_module): - golden_data = test_util.GoldenFileData('golden_message') + golden_message = message_module.TestAllTypes() + test_util.SetAllFields(golden_message) + golden_data = golden_message.SerializeToString() golden_message = message_module.TestAllTypes() golden_message.ParseFromString(golden_data) pickled_message = pickle.dumps(golden_message) @@ -1537,36 +1497,6 @@ class Proto2Test(unittest.TestCase): all_set.Extensions[unittest_pb2.packed_float_extension].extend([61.0, 71.0]) self.assertNotEqual(all_set, copy) - def testGoldenExtensions(self): - golden_data = test_util.GoldenFileData('golden_message') - golden_message = unittest_pb2.TestAllExtensions() - golden_message.ParseFromString(golden_data) - all_set = unittest_pb2.TestAllExtensions() - test_util.SetAllExtensions(all_set) - self.assertEqual(all_set, golden_message) - self.assertEqual(golden_data, golden_message.SerializeToString()) - golden_copy = copy.deepcopy(golden_message) - self.assertEqual(golden_message, golden_copy) - # Depend on a specific serialization order for extensions is not - # reasonable to guarantee. - if api_implementation.Type() != 'upb': - self.assertEqual(golden_data, golden_copy.SerializeToString()) - - def testGoldenPackedExtensions(self): - golden_data = test_util.GoldenFileData('golden_packed_fields_message') - golden_message = unittest_pb2.TestPackedExtensions() - golden_message.ParseFromString(golden_data) - all_set = unittest_pb2.TestPackedExtensions() - test_util.SetAllPackedExtensions(all_set) - self.assertEqual(all_set, golden_message) - self.assertEqual(golden_data, all_set.SerializeToString()) - golden_copy = copy.deepcopy(golden_message) - self.assertEqual(golden_message, golden_copy) - # Depend on a specific serialization order for extensions is not - # reasonable to guarantee. - if api_implementation.Type() != 'upb': - self.assertEqual(golden_data, golden_copy.SerializeToString()) - def testPickleIncompleteProto(self): golden_message = unittest_pb2.TestRequired(a=1) pickled_message = pickle.dumps(golden_message) diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index 91e71a2205..e5510cb2e6 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -1615,7 +1615,6 @@ cc_test( "message_unittest.inc", "message_unittest_legacy_apis.inc", ], - data = [":testdata"], deps = [ ":arena", ":cc_lite_test_protos", @@ -1648,7 +1647,6 @@ cc_test( "edition_message_unittest.cc", "message_unittest.inc", ], - data = [":testdata"], deps = [ ":arena", ":cc_test_protos", diff --git a/src/google/protobuf/arena_test_util.h b/src/google/protobuf/arena_test_util.h index db21949d08..811c9dd820 100644 --- a/src/google/protobuf/arena_test_util.h +++ b/src/google/protobuf/arena_test_util.h @@ -21,46 +21,6 @@ namespace google { namespace protobuf { - -template -void TestParseCorruptedString(const T& message) { - int success_count = 0; - std::string s; - { - // Map order is not deterministic. To make the test deterministic we want - // to serialize the proto deterministically. - io::StringOutputStream output(&s); - io::CodedOutputStream out(&output); - out.SetSerializationDeterministic(true); - message.SerializePartialToCodedStream(&out); - } -#if defined(PROTOBUF_ASAN) || defined(PROTOBUF_TSAN) || defined(PROTOBUF_MSAN) - // Make the test smaller in sanitizer mode. - const int kMaxIters = 200; -#else - const int kMaxIters = 900; -#endif - const int stride = s.size() <= kMaxIters ? 1 : s.size() / kMaxIters; - const int start = stride == 1 || use_arena ? 0 : (stride + 1) / 2; - for (int i = start; i < s.size(); i += stride) { - for (int c = 1 + (i % 17); c < 256; c += 2 * c + (i & 3)) { - s[i] ^= c; - Arena arena; - T* message = Arena::Create(use_arena ? &arena : nullptr); - if (message->ParseFromString(s)) { - ++success_count; - } - if (!use_arena) { - delete message; - } - s[i] ^= c; // Restore s to its original state. - } - } - // This next line is a low bar. But getting through the test without crashing - // due to use-after-free or other bugs is a big part of what we're checking. - ABSL_CHECK_GT(success_count, 0); -} - namespace internal { struct ArenaTestPeer { diff --git a/src/google/protobuf/arena_unittest.cc b/src/google/protobuf/arena_unittest.cc index 75e1f83d53..857abf057d 100644 --- a/src/google/protobuf/arena_unittest.cc +++ b/src/google/protobuf/arena_unittest.cc @@ -1607,13 +1607,6 @@ TEST(ArenaTest, NoHeapAllocationsTest) { arena.Reset(); } -TEST(ArenaTest, ParseCorruptedString) { - TestAllTypes message; - TestUtil::SetAllFields(&message); - TestParseCorruptedString(message); - TestParseCorruptedString(message); -} - #if PROTOBUF_RTTI // Test construction on an arena via generic MessageLite interface. We should be // able to successfully deserialize on the arena without incurring heap diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index e9df8e4ffa..ed0cf5a16a 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -432,6 +432,7 @@ cc_test( "//src/google/protobuf:cc_test_protos", "//src/google/protobuf:port", "//src/google/protobuf:test_textproto", + "//src/google/protobuf:test_util", "//src/google/protobuf:test_util2", "//src/google/protobuf/compiler/cpp:names", "//src/google/protobuf/io", diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index dda4190d86..fc30827647 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -48,6 +48,7 @@ #include "google/protobuf/compiler/mock_code_generator.h" #include "google/protobuf/compiler/plugin.pb.h" #include "google/protobuf/test_textproto.h" +#include "google/protobuf/test_util.h" #include "google/protobuf/test_util2.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/unittest_custom_options.pb.h" @@ -4202,7 +4203,16 @@ class EncodeDecodeTest : public testing::TestWithParam { std::string unittest_proto_descriptor_set_filename_; }; +static void WriteGoldenMessage(const std::string& filename) { + protobuf_unittest::TestAllTypes message; + TestUtil::SetAllFields(&message); + std::string golden = message.SerializeAsString(); + ABSL_CHECK_OK(File::SetContents(filename, golden, true)); +} + TEST_P(EncodeDecodeTest, Encode) { + std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message"); + WriteGoldenMessage(golden_path); RedirectStdinFromFile(TestUtil::GetTestDataPath( "google/protobuf/" "testdata/text_format_unittest_data_oneof_implemented.txt")); @@ -4212,14 +4222,14 @@ TEST_P(EncodeDecodeTest, Encode) { } EXPECT_TRUE( Run(absl::StrCat(args, " --encode=protobuf_unittest.TestAllTypes"))); - ExpectStdoutMatchesBinaryFile(TestUtil::GetTestDataPath( - "google/protobuf/testdata/golden_message_oneof_implemented")); + ExpectStdoutMatchesBinaryFile(golden_path); ExpectStderrMatchesText(""); } TEST_P(EncodeDecodeTest, Decode) { - RedirectStdinFromFile(TestUtil::GetTestDataPath( - "google/protobuf/testdata/golden_message_oneof_implemented")); + std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message"); + WriteGoldenMessage(golden_path); + RedirectStdinFromFile(golden_path); EXPECT_TRUE( Run("google/protobuf/unittest.proto" " --decode=protobuf_unittest.TestAllTypes")); @@ -4272,6 +4282,8 @@ TEST_P(EncodeDecodeTest, ProtoParseError) { } TEST_P(EncodeDecodeTest, EncodeDeterministicOutput) { + std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message"); + WriteGoldenMessage(golden_path); RedirectStdinFromFile(TestUtil::GetTestDataPath( "google/protobuf/" "testdata/text_format_unittest_data_oneof_implemented.txt")); @@ -4281,14 +4293,14 @@ TEST_P(EncodeDecodeTest, EncodeDeterministicOutput) { } EXPECT_TRUE(Run(absl::StrCat( args, " --encode=protobuf_unittest.TestAllTypes --deterministic_output"))); - ExpectStdoutMatchesBinaryFile(TestUtil::GetTestDataPath( - "google/protobuf/testdata/golden_message_oneof_implemented")); + ExpectStdoutMatchesBinaryFile(golden_path); ExpectStderrMatchesText(""); } TEST_P(EncodeDecodeTest, DecodeDeterministicOutput) { - RedirectStdinFromFile(TestUtil::GetTestDataPath( - "google/protobuf/testdata/golden_message_oneof_implemented")); + std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message"); + WriteGoldenMessage(golden_path); + RedirectStdinFromFile(golden_path); EXPECT_FALSE( Run("google/protobuf/unittest.proto" " --decode=protobuf_unittest.TestAllTypes --deterministic_output")); diff --git a/src/google/protobuf/io/BUILD.bazel b/src/google/protobuf/io/BUILD.bazel index b22c677358..192fec3ab1 100644 --- a/src/google/protobuf/io/BUILD.bazel +++ b/src/google/protobuf/io/BUILD.bazel @@ -192,9 +192,6 @@ cc_test( "zero_copy_stream_unittest.cc", ], copts = COPTS, - data = [ - "//src/google/protobuf:testdata", - ], deps = [ ":gzip_stream", ":io", @@ -204,6 +201,7 @@ cc_test( "//:protobuf", "//src/google/protobuf", "//src/google/protobuf:port", + "//src/google/protobuf:test_util", "//src/google/protobuf:test_util2", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc index d4a39fd074..21ffd16ad3 100644 --- a/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -62,6 +62,7 @@ #include "google/protobuf/io/gzip_stream.h" #endif +#include "google/protobuf/test_util.h" // Must be included last. #include "google/protobuf/port_def.inc" @@ -557,10 +558,9 @@ std::string IoTest::Uncompress(const std::string& data) { TEST_F(IoTest, CompressionOptions) { // Some ad-hoc testing of compression options. - std::string golden_filename = - TestUtil::GetTestDataPath("google/protobuf/testdata/golden_message"); - std::string golden; - ABSL_CHECK_OK(File::GetContents(golden_filename, &golden, true)); + protobuf_unittest::TestAllTypes message; + TestUtil::SetAllFields(&message); + std::string golden = message.SerializeAsString(); GzipOutputStream::Options options; std::string gzip_compressed = Compress(golden, options); diff --git a/src/google/protobuf/map_test.inc b/src/google/protobuf/map_test.inc index 14cd1eb8f3..4b75234346 100644 --- a/src/google/protobuf/map_test.inc +++ b/src/google/protobuf/map_test.inc @@ -3938,16 +3938,35 @@ TEST(MapSerializationTest, Deterministic) { EXPECT_TRUE(util::MessageDifferencer::Equals(u, t)); } +static std::string GetGoldenMessageTextProto() { + static std::string* golden_message_textproto = [] { + std::string* textproto = new std::string; + ABSL_CHECK_OK(File::GetContents( + TestUtil::GetTestDataPath("google/protobuf/" + "testdata/map_test_data.txt"), + textproto, true)); + return textproto; + }(); + return *golden_message_textproto; +} + +static std::string GetGoldenMessageBinary() { + static std::string* golden_message_binary = [] { + UNITTEST::TestMaps t; + TextFormat::Parser parser; + parser.ParseFromString(GetGoldenMessageTextProto(), &t); + + std::string* result = new std::string; + t.SerializeToString(result); + return result; + }(); + return *golden_message_binary; +} + TEST(MapSerializationTest, DeterministicSubmessage) { UNITTEST::TestSubmessageMaps p; UNITTEST::TestMaps t; - const std::string filename = "golden_message_maps"; - std::string golden; - ABSL_CHECK_OK( - File::GetContents(TestUtil::GetTestDataPath(absl::StrCat( - "google/protobuf/testdata/", filename)), - &golden, true)); - t.ParseFromString(golden); + t.ParseFromString(GetGoldenMessageBinary()); *(p.mutable_m()) = t; std::vector v; // Use multiple attempts to increase the chance of a failure if something is @@ -3985,15 +4004,9 @@ TEST(TextFormatMapTest, DynamicMessage) { MapReflectionTester tester(message->GetDescriptor()); tester.SetMapFieldsViaReflection(message.get()); - std::string expected_text; - ABSL_CHECK_OK( - File::GetContents(TestUtil::GetTestDataPath("google/protobuf/" - "testdata/map_test_data.txt"), - &expected_text, true)); - std::string actual_text; TextFormat::PrintToString(*message, &actual_text); - EXPECT_EQ(actual_text, expected_text); + EXPECT_EQ(actual_text, GetGoldenMessageTextProto()); } TEST(TextFormatMapTest, Sorted) { @@ -4001,35 +4014,17 @@ TEST(TextFormatMapTest, Sorted) { MapReflectionTester tester(message.GetDescriptor()); tester.SetMapFieldsViaReflection(&message); - std::string expected_text; - ABSL_CHECK_OK( - File::GetContents(TestUtil::GetTestDataPath("google/protobuf/" - "testdata/map_test_data.txt"), - &expected_text, true)); - TextFormat::Printer printer; std::string actual_text; printer.PrintToString(message, &actual_text); - EXPECT_EQ(actual_text, expected_text); + EXPECT_EQ(actual_text, GetGoldenMessageTextProto()); // Test again on the reverse order. UNITTEST::TestMap message2; tester.SetMapFieldsViaReflection(&message2); tester.SwapMapsViaReflection(&message2); printer.PrintToString(message2, &actual_text); - EXPECT_EQ(actual_text, expected_text); -} - -TEST(TextFormatMapTest, ParseCorruptedString) { - std::string serialized_message; - ABSL_CHECK_OK(File::GetContents( - TestUtil::GetTestDataPath( - "google/protobuf/testdata/golden_message_maps"), - &serialized_message, true)); - UNITTEST::TestMaps message; - ABSL_CHECK(message.ParseFromString(serialized_message)); - TestParseCorruptedString(message); - TestParseCorruptedString(message); + EXPECT_EQ(actual_text, GetGoldenMessageTextProto()); } // Previously, serializing to text format will disable iterator from generated diff --git a/src/google/protobuf/message_unittest.inc b/src/google/protobuf/message_unittest.inc index 42c06ed820..dfd6fe5c9f 100644 --- a/src/google/protobuf/message_unittest.inc +++ b/src/google/protobuf/message_unittest.inc @@ -29,6 +29,8 @@ #include #include +#include "google/protobuf/testing/file.h" +#include "google/protobuf/testing/file.h" #include "google/protobuf/descriptor.pb.h" #include #include "google/protobuf/testing/googletest.h" @@ -143,8 +145,12 @@ TEST(MESSAGE_TEST_NAME, SerializeToBrokenOstream) { } TEST(MESSAGE_TEST_NAME, ParseFromFileDescriptor) { - std::string filename = - TestUtil::GetTestDataPath("google/protobuf/testdata/golden_message"); + std::string filename = absl::StrCat(TestTempDir(), "/golden_message"); + UNITTEST::TestAllTypes expected_message; + TestUtil::SetAllFields(&expected_message); + ABSL_CHECK_OK(File::SetContents( + filename, expected_message.SerializeAsString(), true)); + int file = open(filename.c_str(), O_RDONLY | O_BINARY); ASSERT_GE(file, 0); @@ -156,8 +162,12 @@ TEST(MESSAGE_TEST_NAME, ParseFromFileDescriptor) { } TEST(MESSAGE_TEST_NAME, ParsePackedFromFileDescriptor) { - std::string filename = TestUtil::GetTestDataPath( - "google/protobuf/testdata/golden_packed_fields_message"); + std::string filename = absl::StrCat(TestTempDir(), "/golden_message"); + UNITTEST::TestPackedTypes expected_message; + TestUtil::SetPackedFields(&expected_message); + ABSL_CHECK_OK(File::SetContents( + filename, expected_message.SerializeAsString(), true)); + int file = open(filename.c_str(), O_RDONLY | O_BINARY); ASSERT_GE(file, 0); diff --git a/src/google/protobuf/testdata/golden_message b/src/google/protobuf/testdata/golden_message deleted file mode 100644 index 5825975ce07bde310f5618aab42bc578739a65f0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 537 zcmXxfJxmlq6bJBm|2Mn0be5Kumh8uDXL5Qq1)?PEtPqJ%B(4+*LNb#9cY@vulDqNB$M^I{{ASSO0Cz7R-@%;ZZlRpEUL3O}^Z^Y0y zzip1i(2xJ3i*vew{Wfrc1!k{J*7sNvzmjzqCGi_s_mHtHuCP;Kx5{3X2X>f)AQHnM zdS|l{!@xA<{~u)ifM2}Kf4Ib5e$I)0!Kq$%i+aO-tzXI{Z*0jV)pfbwH?&HQ y3j4Y@+1_0KqgE}=k#E}8ICZG#=*-EjIUEJiy47^ubG?w0N%T^V_I^i;cA+cvq`u4VOJS%xYprl7H1=6px9w z%;U$`0bCY*>cZsUx%~J#=fV!gZ)v1p#27Pve0|KA?^{l9ADGmbIsEuK7;`dzv|@7b z!~FO<7<1xm%~c9UjA8llb!vAkFSrpoZeI& zH9V=y)A{jraJjwcK(_WwCD>sp`0;gcxv{q8E(Ig@oAcxA)EFyPrg(H>4oF#smyH2p z3%flO^Cn^}*qJ<8;T+k^gWS!p2F~EMOPmcm6kc0w zhC$@Kb_pPj9T|-%WHzr|0!Y%p?z2-cDYJO(57| z$!K;2B?bjZCOH38;KAZGe1IBOU4enq*YIu!g`-5|&Fl6S5AVe(J)uNPFTvg(Jb4Xgcd1 zJ4hvY(%jJ!T8T=fc?39;+nL#UevK%O=03PYnDk0eXExvvS{5=b2qlS?efaS9R#YfW zJjEhyRt1LD?1REXDpW7EKq{#Y|J*Y_Lo-3jlva4WQ^yL;c^d9pe5#d<2F|JojVL2iPG{mIEJ2vnyN?2txdw zt*uF4VMd7if~5@`RID=C87%GC#`b?1Q*G(M4yPQSg+*2`_beB&*W>&yqV+G15t!$f z7T1j?DJ4{Z?9VMqLK_7wO@M^eoGwHmG}XcUp}eTuW|*78g0ysG4}@R3XNLKymq8$~ zJT`O36ilEnEg>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#sj2rG)N1qawk*UlJZvgojn)HOhRZ(XYgw zAGWNfBR7w`!g7z;jj2!HWY-X*MKL}i!FNjV2?hM10@jeC#3_2ZjJI6IA6>&wc|i>U zDOJbr@M(2~(%WiaZ=jLBiO%56rf7KIhEi8@V!V>ulPneA%KlG_*#po4R1fTXMhrZ2 zVsj)0Ui1%r{Gv11Zv$s|!t8d*x`F57Az3$36pzTdg_LD+nVm9cs_a&Ibe-AvLox8f zFE$%7@J&np|4r6y{N)#X%0=$;OOEv`PV{P~pg&~Z>DMyJdz}vFsp&V8>bf-S8(PKf nTvHDw+j^AU(W;|4^i0)CYT+ diff --git a/src/google/protobuf/testdata/golden_message_proto3 b/src/google/protobuf/testdata/golden_message_proto3 deleted file mode 100644 index bd646a0dc85e0b8c7cfcfbea8bb9ae0a8987883d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 248 zcmXZSJ8r^25C-6xe>TCTkAio-u918M&X6W;E?`l*bm^pWiNr&c6o6=uoJavmpfag) zgjAVzGQ~IlJbqZ7W|+XVJVy!h&I?p9AG|~jQ%h$Wm^b+{Q$(Lcq1gdU SJG41$Vq;=t*u}=g$_4<-G94WN