Add a test case for CFX_MemoryStream::{Read,Write}BlockAtOffset().

Make sure CFX_MemoryStream::ReadBlockAtOffset() and WriteBlockAtOffset()
work as expected for their normal use cases.

Rename CFXMemoryStreamTest to not have underscores along the way.

Change-Id: I875ea9fdafe64d3108ae0de1c68f9a4fb7be07b5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/98074
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/cfx_memorystream_unittest.cpp b/core/fxcrt/cfx_memorystream_unittest.cpp
index 8339e8e..da71e27 100644
--- a/core/fxcrt/cfx_memorystream_unittest.cpp
+++ b/core/fxcrt/cfx_memorystream_unittest.cpp
@@ -5,6 +5,7 @@
 #include "core/fxcrt/cfx_memorystream.h"
 
 #include "core/fxcrt/retain_ptr.h"
+#include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
@@ -14,7 +15,7 @@
 
 }  // namespace
 
-TEST(CFX_MemoryStreamTest, SparseBlockWrites) {
+TEST(CFXMemoryStreamTest, SparseBlockWrites) {
   auto stream = pdfium::MakeRetain<CFX_MemoryStream>();
   for (FX_FILESIZE offset = 0; offset <= 200000; offset += 100000)
     stream->WriteBlockAtOffset(kSomeText, offset, kSomeTextLen);
@@ -22,10 +23,28 @@
   EXPECT_EQ(200000 + kSomeTextLen, static_cast<size_t>(stream->GetSize()));
 }
 
-TEST(CFX_MemoryStreamTest, OverlappingBlockWrites) {
+TEST(CFXMemoryStreamTest, OverlappingBlockWrites) {
   auto stream = pdfium::MakeRetain<CFX_MemoryStream>();
   for (FX_FILESIZE offset = 0; offset <= 100; ++offset)
     stream->WriteBlockAtOffset(kSomeText, offset, kSomeTextLen);
 
   EXPECT_EQ(100 + kSomeTextLen, static_cast<size_t>(stream->GetSize()));
 }
+
+TEST(CFXMemoryStreamTest, ReadWriteBlockAtOffset) {
+  auto stream = pdfium::MakeRetain<CFX_MemoryStream>();
+  const uint8_t kData1[] = {'a', 'b', 'c'};
+  ASSERT_TRUE(stream->WriteBlock(kData1, sizeof(kData1)));
+  auto stream_contents =
+      pdfium::make_span(stream->GetBuffer(), stream->GetSize());
+  ASSERT_THAT(stream_contents, testing::ElementsAre('a', 'b', 'c'));
+
+  ASSERT_TRUE(stream->WriteBlockAtOffset(kData1, 5, sizeof(kData1)));
+  stream_contents = pdfium::make_span(stream->GetBuffer(), stream->GetSize());
+  ASSERT_THAT(stream_contents,
+              testing::ElementsAre('a', 'b', 'c', '\0', '\0', 'a', 'b', 'c'));
+
+  uint8_t buffer[4];
+  ASSERT_TRUE(stream->ReadBlockAtOffset(buffer, 2, sizeof(buffer)));
+  ASSERT_THAT(buffer, testing::ElementsAre('c', '\0', '\0', 'a'));
+}