37TEST(ParserUtilityTest, ValidateDictType) {
38 auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
41 EXPECT_FALSE(ValidateDictType(dict.Get(),
"foo"));
42 EXPECT_FALSE(ValidateDictType(dict.Get(),
"bar"));
45 dict->SetNewFor<CPDF_String>(
"Type", L"foo");
46 EXPECT_FALSE(ValidateDictType(dict.Get(),
"foo"));
47 EXPECT_FALSE(ValidateDictType(dict.Get(),
"bar"));
50 dict->SetNewFor<CPDF_Name>(
"Type",
"foo");
51 EXPECT_TRUE(ValidateDictType(dict.Get(),
"foo"));
52 EXPECT_FALSE(ValidateDictType(dict.Get(),
"bar"));
55TEST(ParserUtilityTest, ValidateDictAllResourcesOfType) {
56 CPDF_PageModule::Create();
60 auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
63 EXPECT_TRUE(ValidateDictAllResourcesOfType(dict.Get(),
"foo"));
64 EXPECT_TRUE(ValidateDictAllResourcesOfType(dict.Get(),
"bar"));
67 EXPECT_FALSE(ValidateDictAllResourcesOfType(
nullptr,
"foo"));
68 EXPECT_FALSE(ValidateDictAllResourcesOfType(
nullptr,
"bar"));
71 auto new_dict = dict->SetNewFor<CPDF_Dictionary>(
"f1");
72 new_dict->SetNewFor<CPDF_Name>(
"Type",
"foo");
73 new_dict = dict->SetNewFor<CPDF_Dictionary>(
"f2");
74 new_dict->SetNewFor<CPDF_Name>(
"Type",
"foo");
75 dict->SetNewFor<CPDF_String>(
"f3", L"foo");
76 EXPECT_FALSE(ValidateDictAllResourcesOfType(dict.Get(),
"foo"));
77 EXPECT_FALSE(ValidateDictAllResourcesOfType(dict.Get(),
"bar"));
80 new_dict = dict->SetNewFor<CPDF_Dictionary>(
"f3");
81 new_dict->SetNewFor<CPDF_Name>(
"Type",
"bar");
82 EXPECT_FALSE(ValidateDictAllResourcesOfType(dict.Get(),
"foo"));
83 EXPECT_FALSE(ValidateDictAllResourcesOfType(dict.Get(),
"bar"));
86 new_dict->SetNewFor<CPDF_Name>(
"Type",
"foo");
87 EXPECT_TRUE(ValidateDictAllResourcesOfType(dict.Get(),
"foo"));
88 EXPECT_FALSE(ValidateDictAllResourcesOfType(dict.Get(),
"bar"));
93 auto doc = std::make_unique<CPDF_TestDocument>();
94 auto dict = doc->New<CPDF_Dictionary>();
97 auto new_dict = doc->NewIndirect<CPDF_Dictionary>();
98 new_dict->SetNewFor<CPDF_Name>(
"Type",
"foo");
99 dict->SetNewFor<CPDF_Reference>(
"f1", doc.get(), new_dict->GetObjNum());
101 EXPECT_TRUE(ValidateDictAllResourcesOfType(dict.Get(),
"foo"));
102 EXPECT_FALSE(ValidateDictAllResourcesOfType(dict.Get(),
"bar"));
105 CPDF_PageModule::Destroy();
108TEST(ParserUtilityTest, ValidateDictOptionalType) {
109 auto dict = pdfium::MakeRetain<CPDF_Dictionary>();
112 EXPECT_TRUE(ValidateDictOptionalType(dict.Get(),
"foo"));
113 EXPECT_TRUE(ValidateDictOptionalType(dict.Get(),
"bar"));
116 dict->SetNewFor<CPDF_String>(
"Type", L"foo");
117 EXPECT_FALSE(ValidateDictOptionalType(dict.Get(),
"foo"));
118 EXPECT_FALSE(ValidateDictOptionalType(dict.Get(),
"bar"));
121 dict->SetNewFor<CPDF_Name>(
"Type",
"foo");
122 EXPECT_TRUE(ValidateDictOptionalType(dict.Get(),
"foo"));
123 EXPECT_FALSE(ValidateDictOptionalType(dict.Get(),
"bar"));