5#include "core/fpdfapi/parser/cpdf_page_object_avail.h"
10#include "core/fpdfapi/parser/cpdf_array.h"
11#include "core/fpdfapi/parser/cpdf_dictionary.h"
12#include "core/fpdfapi/parser/cpdf_indirect_object_holder.h"
13#include "core/fpdfapi/parser/cpdf_name.h"
14#include "core/fpdfapi/parser/cpdf_read_validator.h"
15#include "core/fpdfapi/parser/cpdf_reference.h"
16#include "core/fpdfapi/parser/cpdf_string.h"
17#include "core/fxcrt/fx_stream.h"
18#include "testing/gtest/include/gtest/gtest.h"
19#include "testing/invalid_seekable_read_stream.h"
20#include "third_party/base/check.h"
34 ~TestReadValidator()
override =
default;
39 enum class ObjectState {
43 TestHolder() : validator_(pdfium::MakeRetain<TestReadValidator>()) {}
44 ~TestHolder()
override =
default;
48 auto it = objects_data_.find(objnum);
49 if (it == objects_data_.end())
52 ObjectData& obj_data = it->second;
53 if (obj_data.state == ObjectState::Unavailable) {
54 validator_->SimulateReadError();
57 return obj_data.object;
62 void AddObject(uint32_t objnum,
65 ObjectData object_data;
66 object_data.object =
std::move(object);
67 object_data.state = state;
68 DCHECK(objects_data_.find(objnum) == objects_data_.end());
69 objects_data_[objnum] = std::move(object_data);
72 void SetObjectState(uint32_t objnum, ObjectState state) {
73 auto it = objects_data_.find(objnum);
74 DCHECK(it != objects_data_.end());
75 ObjectData& obj_data = it->second;
76 obj_data.state = state;
80 auto it = objects_data_.find(objnum);
81 if (it == objects_data_.end())
83 return it->second.object.Get();
89 ObjectState state = ObjectState::Unavailable;
91 std::map<uint32_t, ObjectData> objects_data_;
99 holder.AddObject(1, pdfium::MakeRetain<CPDF_Dictionary>(),
100 TestHolder::ObjectState::Available);
101 holder.GetTestObject(1)->GetMutableDict()->SetNewFor<CPDF_Reference>(
103 holder.AddObject(2, pdfium::MakeRetain<CPDF_Array>(),
104 TestHolder::ObjectState::Available);
108 holder.AddObject(3, pdfium::MakeRetain<CPDF_Dictionary>(),
109 TestHolder::ObjectState::Available);
110 holder.GetTestObject(3)->GetMutableDict()->SetFor(
111 "Type", pdfium::MakeRetain<CPDF_Name>(
nullptr,
"Page"));
112 holder.GetTestObject(3)->GetMutableDict()->SetNewFor<CPDF_Reference>(
113 "OtherPageData", &holder, 4);
116 4, pdfium::MakeRetain<CPDF_String>(
nullptr,
"Other page data",
false),
117 TestHolder::ObjectState::Unavailable);
119 CPDF_PageObjectAvail avail(holder.GetValidator(), &holder, 1);
CPDF_DataAvail::DocAvailStatus CheckAvail()
virtual CPDF_Array * AsMutableArray()
bool ReadBlockAtOffset(pdfium::span< uint8_t > buffer, FX_FILESIZE offset) override
TEST(FXCRYPT, MD5GenerateEmtpyData)
#define CONSTRUCT_VIA_MAKE_RETAIN