blob: 5a269a3cf65f50a568ee0db57af7145741756327 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef TESTING_FX_STRING_TESTHELPERS_H_
#define TESTING_FX_STRING_TESTHELPERS_H_
#include <ostream>
#include "core/fxcrt/cfx_datetime.h"
#include "core/fxcrt/fx_stream.h"
// Output stream operator so GTEST macros work with CFX_DateTime objects.
std::ostream& operator<<(std::ostream& os, const CFX_DateTime& dt);
class CFX_InvalidSeekableReadStream : public IFX_SeekableReadStream {
public:
template <typename T, typename... Args>
friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
// IFX_SeekableReadStream overrides:
bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
return false;
}
FX_FILESIZE GetSize() override { return data_size_; }
private:
explicit CFX_InvalidSeekableReadStream(FX_FILESIZE data_size)
: data_size_(data_size) {}
FX_FILESIZE data_size_;
};
class CFX_BufferSeekableReadStream : public IFX_SeekableReadStream {
public:
template <typename T, typename... Args>
friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
// IFX_SeekableReadStream:
bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
if (offset < 0 || static_cast<size_t>(offset) >= data_size_)
return false;
if (static_cast<size_t>(offset) + size > data_size_)
size = data_size_ - static_cast<size_t>(offset);
if (size == 0)
return false;
memcpy(buffer, data_ + offset, size);
return true;
}
FX_FILESIZE GetSize() override {
return static_cast<FX_FILESIZE>(data_size_);
}
private:
CFX_BufferSeekableReadStream(const unsigned char* src, size_t src_size)
: data_(src), data_size_(src_size) {}
const unsigned char* data_;
size_t data_size_;
};
#endif // TESTING_FX_STRING_TESTHELPERS_H_
|