Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfx_memorystream_unittest.cpp
Go to the documentation of this file.
1// Copyright 2019 The PDFium Authors
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/gmock/include/gmock/gmock.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11namespace {
12
13const char kSomeText[] = "Lets make holes in streams";
14const size_t kSomeTextLen = sizeof(kSomeText) - 1;
15
16} // namespace
17
19 auto stream = pdfium::MakeRetain<CFX_MemoryStream>();
20 for (FX_FILESIZE offset = 0; offset <= 200000; offset += 100000) {
21 stream->WriteBlockAtOffset(
22 {reinterpret_cast<const uint8_t*>(kSomeText), kSomeTextLen}, offset);
23 }
24 EXPECT_EQ(200000 + kSomeTextLen, static_cast<size_t>(stream->GetSize()));
25}
26
28 auto stream = pdfium::MakeRetain<CFX_MemoryStream>();
29 for (FX_FILESIZE offset = 0; offset <= 100; ++offset) {
30 stream->WriteBlockAtOffset(
31 {reinterpret_cast<const uint8_t*>(kSomeText), kSomeTextLen}, offset);
32 }
33 EXPECT_EQ(100 + kSomeTextLen, static_cast<size_t>(stream->GetSize()));
34}
35
37 auto stream = pdfium::MakeRetain<CFX_MemoryStream>();
38 const uint8_t kData1[] = {'a', 'b', 'c'};
39 ASSERT_TRUE(stream->WriteBlock(kData1));
40 ASSERT_THAT(stream->GetSpan(), testing::ElementsAre('a', 'b', 'c'));
41
42 ASSERT_TRUE(stream->WriteBlockAtOffset(kData1, 5));
43 ASSERT_THAT(stream->GetSpan(),
44 testing::ElementsAre('a', 'b', 'c', '\0', '\0', 'a', 'b', 'c'));
45
46 uint8_t buffer[4];
47 ASSERT_TRUE(stream->ReadBlockAtOffset(buffer, 2));
48 ASSERT_THAT(buffer, testing::ElementsAre('c', '\0', '\0', 'a'));
49}
50
52 auto stream = pdfium::MakeRetain<CFX_MemoryStream>();
53 const uint8_t kData1[] = {'a', 'b', 'c'};
54 ASSERT_TRUE(stream->WriteBlock(kData1));
55 ASSERT_THAT(stream->GetSpan(), testing::ElementsAre('a', 'b', 'c'));
56
57 ASSERT_TRUE(stream->WriteBlock({}));
58 ASSERT_THAT(stream->GetSpan(), testing::ElementsAre('a', 'b', 'c'));
59}
TEST(FXCRYPT, MD5GenerateEmtpyData)
#define FX_FILESIZE
Definition fx_types.h:19