• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "core/fxcrt/cfx_memorystream.h"
6 
7 #include "core/fxcrt/retain_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 
10 namespace {
11 
12 const char kSomeText[] = "Lets make holes in streams";
13 const size_t kSomeTextLen = sizeof(kSomeText) - 1;
14 
15 }  // namespace
16 
TEST(CFX_MemoryStreamTest,SparseBlockWrites)17 TEST(CFX_MemoryStreamTest, SparseBlockWrites) {
18   auto stream = pdfium::MakeRetain<CFX_MemoryStream>();
19   for (FX_FILESIZE offset = 0; offset <= 200000; offset += 100000)
20     stream->WriteBlockAtOffset(kSomeText, offset, kSomeTextLen);
21 
22   EXPECT_EQ(200000 + kSomeTextLen, static_cast<size_t>(stream->GetSize()));
23 }
24 
TEST(CFX_MemoryStreamTest,OverlappingBlockWrites)25 TEST(CFX_MemoryStreamTest, OverlappingBlockWrites) {
26   auto stream = pdfium::MakeRetain<CFX_MemoryStream>();
27   for (FX_FILESIZE offset = 0; offset <= 100; ++offset)
28     stream->WriteBlockAtOffset(kSomeText, offset, kSomeTextLen);
29 
30   EXPECT_EQ(100 + kSomeTextLen, static_cast<size_t>(stream->GetSize()));
31 }
32