TEST_F(FPDFDocEmbedderTest, GetPageLabels) { EXPECT_TRUE(OpenDocument("page_labels.pdf")); EXPECT_EQ(7, FPDF_GetPageCount(document())); // We do not request labels, when use FPDFAvail_IsXXXAvail. // Flush all data, to allow read labels. SetWholeFileAvailable(); unsigned short buf[128]; EXPECT_EQ(0u, FPDF_GetPageLabel(document(), -2, buf, sizeof(buf))); EXPECT_EQ(0u, FPDF_GetPageLabel(document(), -1, buf, sizeof(buf))); const wchar_t kExpectedPageLabel0[] = L"i"; ASSERT_EQ(4u, FPDF_GetPageLabel(document(), 0, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel0), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel0))); const wchar_t kExpectedPageLabel1[] = L"ii"; ASSERT_EQ(6u, FPDF_GetPageLabel(document(), 1, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel1), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel1))); const wchar_t kExpectedPageLabel2[] = L"1"; ASSERT_EQ(4u, FPDF_GetPageLabel(document(), 2, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel2), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel2))); const wchar_t kExpectedPageLabel3[] = L"2"; ASSERT_EQ(4u, FPDF_GetPageLabel(document(), 3, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel3), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel3))); const wchar_t kExpectedPageLabel4[] = L"zzA"; ASSERT_EQ(8u, FPDF_GetPageLabel(document(), 4, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel4), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel4))); const wchar_t kExpectedPageLabel5[] = L"zzB"; ASSERT_EQ(8u, FPDF_GetPageLabel(document(), 5, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel5), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel5))); const wchar_t kExpectedPageLabel6[] = L""; ASSERT_EQ(2u, FPDF_GetPageLabel(document(), 6, buf, sizeof(buf))); EXPECT_EQ(WideString(kExpectedPageLabel6), WideString::FromUTF16LE(buf, FXSYS_len(kExpectedPageLabel6))); ASSERT_EQ(0u, FPDF_GetPageLabel(document(), 7, buf, sizeof(buf))); ASSERT_EQ(0u, FPDF_GetPageLabel(document(), 8, buf, sizeof(buf))); }
TEST_F(CPDFSecurityHandlerEmbedderTest, PasswordAfterGenerateSave) { #if _FX_PLATFORM_ == _FX_PLATFORM_LINUX_ const char md5[] = "7048dca58e2ed8f93339008b91e4eb4e"; #elif _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ const char md5[] = "6951b6c9891dfe0332a5b1983e484400"; #else const char md5[] = "041c2fb541c8907cc22ce101b686c79e"; #endif // _FX_PLATFORM_ == _FX_PLATFORM_LINUX_ { ASSERT_TRUE(OpenDocumentWithOptions("encrypted.pdf", "5678", LinearizeOption::kMustLinearize, JavaScriptOption::kEnableJavaScript)); FPDF_PAGE page = LoadPage(0); ASSERT_TRUE(page); FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(10, 10, 20, 20); ASSERT_TRUE(red_rect); EXPECT_TRUE(FPDFPath_SetFillColor(red_rect, 255, 0, 0, 255)); EXPECT_TRUE(FPDFPath_SetDrawMode(red_rect, FPDF_FILLMODE_ALTERNATE, 0)); FPDFPage_InsertObject(page, red_rect); ScopedFPDFBitmap bitmap = RenderLoadedPage(page); CompareBitmap(bitmap.get(), 612, 792, md5); EXPECT_TRUE(FPDFPage_GenerateContent(page)); SetWholeFileAvailable(); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); UnloadPage(page); } std::string new_file = GetString(); FPDF_FILEACCESS file_access; memset(&file_access, 0, sizeof(file_access)); file_access.m_FileLen = new_file.size(); file_access.m_GetBlock = GetBlockFromString; file_access.m_Param = &new_file; EXPECT_FALSE(FPDF_LoadCustomDocument(&file_access, nullptr)); struct { const char* password; const unsigned long permissions; } tests[] = {{"1234", 0xFFFFF2C0}, {"5678", 0xFFFFFFFC}}; for (const auto& test : tests) { OpenSavedDocument(test.password); FPDF_PAGE page = LoadSavedPage(0); VerifySavedRendering(page, 612, 792, md5); EXPECT_EQ(test.permissions, FPDF_GetDocPermissions(saved_document_)); CloseSavedPage(page); CloseSavedDocument(); } }