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
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 51e66b9..1f17f24 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 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 @@
     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 0f57ecc..dfa51b2 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.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 @@
       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 bf91424..2326ed9 100755
--- a/python/google/protobuf/internal/message_test.py
+++ b/python/google/protobuf/internal/message_test.py
@@ -65,48 +65,6 @@
       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 @@
       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 @@
     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 91e71a2..e5510cb 100644
--- a/src/google/protobuf/BUILD.bazel
+++ b/src/google/protobuf/BUILD.bazel
@@ -1615,7 +1615,6 @@
         "message_unittest.inc",
         "message_unittest_legacy_apis.inc",
     ],
-    data = [":testdata"],
     deps = [
         ":arena",
         ":cc_lite_test_protos",
@@ -1648,7 +1647,6 @@
         "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 db21949..811c9dd 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 <typename T, bool use_arena>
-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<T>(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 75e1f83..857abf0 100644
--- a/src/google/protobuf/arena_unittest.cc
+++ b/src/google/protobuf/arena_unittest.cc
@@ -1607,13 +1607,6 @@
   arena.Reset();
 }
 
-TEST(ArenaTest, ParseCorruptedString) {
-  TestAllTypes message;
-  TestUtil::SetAllFields(&message);
-  TestParseCorruptedString<TestAllTypes, true>(message);
-  TestParseCorruptedString<TestAllTypes, false>(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 e9df8e4..ed0cf5a 100644
--- a/src/google/protobuf/compiler/BUILD.bazel
+++ b/src/google/protobuf/compiler/BUILD.bazel
@@ -432,6 +432,7 @@
         "//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 dda4190..fc30827 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 @@
   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 @@
   }
   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, 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 @@
   }
   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 b22c677..192fec3 100644
--- a/src/google/protobuf/io/BUILD.bazel
+++ b/src/google/protobuf/io/BUILD.bazel
@@ -192,9 +192,6 @@
         "zero_copy_stream_unittest.cc",
     ],
     copts = COPTS,
-    data = [
-        "//src/google/protobuf:testdata",
-    ],
     deps = [
         ":gzip_stream",
         ":io",
@@ -204,6 +201,7 @@
         "//: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 d4a39fd..21ffd16 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 @@
 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 14cd1eb..4b75234 100644
--- a/src/google/protobuf/map_test.inc
+++ b/src/google/protobuf/map_test.inc
@@ -3938,16 +3938,35 @@
   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<std::string> v;
   // Use multiple attempts to increase the chance of a failure if something is
@@ -3985,15 +4004,9 @@
   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 @@
   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<UNITTEST::TestMaps, true>(message);
-  TestParseCorruptedString<UNITTEST::TestMaps, false>(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 42c06ed..dfd6fe5 100644
--- a/src/google/protobuf/message_unittest.inc
+++ b/src/google/protobuf/message_unittest.inc
@@ -29,6 +29,8 @@
 #include <fstream>
 #include <sstream>
 
+#include "google/protobuf/testing/file.h"
+#include "google/protobuf/testing/file.h"
 #include "google/protobuf/descriptor.pb.h"
 #include <gmock/gmock.h>
 #include "google/protobuf/testing/googletest.h"
@@ -143,8 +145,12 @@
 }
 
 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, 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 5825975..0000000
--- a/src/google/protobuf/testdata/golden_message
+++ /dev/null
Binary files differ
diff --git a/src/google/protobuf/testdata/golden_message_maps b/src/google/protobuf/testdata/golden_message_maps
deleted file mode 100644
index c70a4d7..0000000
--- a/src/google/protobuf/testdata/golden_message_maps
+++ /dev/null
Binary files differ
diff --git a/src/google/protobuf/testdata/golden_message_oneof_implemented b/src/google/protobuf/testdata/golden_message_oneof_implemented
deleted file mode 100644
index 794ca5e..0000000
--- a/src/google/protobuf/testdata/golden_message_oneof_implemented
+++ /dev/null
Binary files differ
diff --git a/src/google/protobuf/testdata/golden_message_proto3 b/src/google/protobuf/testdata/golden_message_proto3
deleted file mode 100644
index bd646a0..0000000
--- a/src/google/protobuf/testdata/golden_message_proto3
+++ /dev/null
Binary files differ
diff --git a/src/google/protobuf/testdata/golden_packed_fields_message b/src/google/protobuf/testdata/golden_packed_fields_message
deleted file mode 100644
index ee28d38..0000000
--- a/src/google/protobuf/testdata/golden_packed_fields_message
+++ /dev/null
Binary files differ