Test split with changes

This commit is contained in:
Svetlana Kulikova
2025-04-29 11:02:51 +03:00
parent 4f38f17bd1
commit 2cbc83b389
2 changed files with 37 additions and 8 deletions

View File

@ -1548,10 +1548,8 @@ bool CPdfEditor::EditPage(int _nPageIndex, bool bSet, bool bActualPos)
}
bool CPdfEditor::SplitPages(const int* arrPageIndex, unsigned int unLength, PDFDoc* _pDoc, int nStartRefID)
{
if (m_nMode == Mode::WriteNew)
return false;
if (m_nMode == Mode::Unknown)
m_nMode = Mode::WriteNew;
return false;
PDFDoc* pPDFDocument = _pDoc;
XRef* xref = pPDFDocument->getXRef();
PdfWriter::CDocument* pDoc = m_pWriter->GetDocument();
@ -1913,8 +1911,10 @@ bool CPdfEditor::SplitPages(const int* arrPageIndex, unsigned int unLength, PDFD
}
bool CPdfEditor::SplitPages(const int* arrPageIndex, unsigned int unLength)
{
if (m_nMode != Mode::Unknown)
if (m_nMode == Mode::WriteNew)
return false;
if (m_nMode == Mode::Unknown)
m_nMode = Mode::WriteNew;
PdfWriter::CDocument* pDoc = m_pWriter->GetDocument();
if (!pDoc)
return false;
@ -2675,7 +2675,7 @@ bool CPdfEditor::DeleteAnnot(int nID, Object* oAnnots)
}
bool CPdfEditor::EditWidgets(IAdvancedCommand* pCommand)
{
if (m_nMode != Mode::WriteAppend && !IncrementalUpdates())
if (m_nMode == Mode::Unknown && !IncrementalUpdates())
return false;
CWidgetsInfo* pFieldInfo = (CWidgetsInfo*)pCommand;

View File

@ -355,11 +355,39 @@ TEST_F(CPdfFileTest, SplitPdf)
//GTEST_SKIP();
LoadFromFile();
std::vector<int> arrPages = { 0, 1, 2 };
BYTE* pFile = pdfFile->SplitPages(arrPages.data(), arrPages.size());
int nBufferLen = NULL;
BYTE* pBuffer = NULL;
NSFile::CFileBinary oFile;
if (oFile.OpenFile(NSFile::GetProcessDirectory() + L"/base64.txt"))
{
DWORD dwFileSize = oFile.GetFileSize();
BYTE* pFileContent = new BYTE[dwFileSize];
if (!pFileContent)
{
oFile.CloseFile();
FAIL();
}
DWORD dwReaded;
EXPECT_TRUE(oFile.ReadFile(pFileContent, dwFileSize, dwReaded));
nBufferLen = NSBase64::Base64DecodeGetRequiredLength(dwFileSize);
pBuffer = new BYTE[nBufferLen];
if (!pBuffer)
{
RELEASEARRAYOBJECTS(pFileContent);
FAIL();
}
EXPECT_TRUE(NSBase64::Base64Decode((const char*)pFileContent, dwFileSize, pBuffer, &nBufferLen));
}
oFile.CloseFile();
std::vector<int> arrPages = { 1 };
BYTE* pFile = pdfFile->SplitPages(arrPages.data(), arrPages.size(), pBuffer, nBufferLen);
ASSERT_TRUE(pFile != NULL);
NSFile::CFileBinary oFile;
std::wstring wsSplitFile = NSFile::GetProcessDirectory() + L"/test_split.pdf";
if (oFile.CreateFileW(wsSplitFile))
{
@ -369,6 +397,7 @@ TEST_F(CPdfFileTest, SplitPdf)
oFile.CloseFile();
RELEASEARRAYOBJECTS(pFile);
RELEASEARRAYOBJECTS(pBuffer);
}
TEST_F(CPdfFileTest, MergePdf)