void PagesTreeTest::testDeleteAll( PdfMemDocument & doc ) { for(int i=0; i<PODOFO_TEST_NUM_PAGES; i++) { doc.GetPagesTree()->DeletePage(0); CPPUNIT_ASSERT_EQUAL( doc.GetPageCount(), PODOFO_TEST_NUM_PAGES - (i + 1) ); } CPPUNIT_ASSERT_EQUAL( doc.GetPageCount(), 0 ); }
void PagesTreeTest::testCreateDelete() { PdfMemDocument writer; PdfPage* pPage; PdfPainter painter; PdfFont * pFont; // create font pFont = writer.CreateFont( "Arial" ); if( !pFont ) { PODOFO_RAISE_ERROR( ePdfError_InvalidHandle ); } pFont->SetFontSize( 16.0 ); // write 1. page pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) ); painter.SetPage( pPage ); painter.SetFont( pFont ); painter.DrawText( 200, 200, "Page 1" ); painter.FinishPage(); CPPUNIT_ASSERT_EQUAL( writer.GetPageCount(), 1 ); // write 2. page pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) ); painter.SetPage( pPage ); painter.DrawText( 200, 200, "Page 2" ); painter.FinishPage(); CPPUNIT_ASSERT_EQUAL( writer.GetPageCount(), 2 ); // try to delete second page, index is 0 based writer.DeletePages( 1, 1 ); CPPUNIT_ASSERT_EQUAL( writer.GetPageCount(), 1 ); // write 3. page pPage = writer.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) ); painter.SetPage( pPage ); painter.DrawText( 200, 200, "Page 3" ); painter.FinishPage(); CPPUNIT_ASSERT_EQUAL( writer.GetPageCount(), 2 ); }
int count_pages( const char* pszFilename, const bool & bShortFormat ) { PdfMemDocument document; document.Load( pszFilename ); int nPages = document.GetPageCount(); if( bShortFormat ) printf("%i\n", nPages ); else printf("%s:\t%i\n", pszFilename, nPages ); return nPages; }
void PagesTreeTest::testEmptyDoc() { // PdfPagesTree does not throw exceptions but PdfDocument does PdfMemDocument writer; // Empty document must have page count == 0 CPPUNIT_ASSERT_EQUAL( writer.GetPageCount(), 0 ); // Retrieving any page from an empty document must be NULL CPPUNIT_ASSERT_THROW( writer.GetPage( 0 ), PdfError ); CPPUNIT_ASSERT_THROW( writer.GetPage( -1 ), PdfError ); CPPUNIT_ASSERT_THROW( writer.GetPage( 1 ), PdfError ); }
void PagesTreeTest::testEmptyTree() { PdfMemDocument writer; // Empty document must have page count == 0 CPPUNIT_ASSERT_EQUAL( writer.GetPageCount(), 0 ); // Retrieving any page from an empty document must be NULL PdfPage* pPage = writer.GetPagesTree()->GetPage( 0 ); CPPUNIT_ASSERT_EQUAL( pPage, static_cast<PdfPage*>(NULL) ); pPage = writer.GetPagesTree()->GetPage( -1 ); CPPUNIT_ASSERT_EQUAL( pPage, static_cast<PdfPage*>(NULL) ); pPage = writer.GetPagesTree()->GetPage( 1 ); CPPUNIT_ASSERT_EQUAL( pPage, static_cast<PdfPage*>(NULL) ); }
void PagesTreeTest::testInsert( PdfMemDocument & doc ) { const int INSERTED_PAGE_FLAG= 1234; const int INSERTED_PAGE_FLAG1= 1234 + 1; const int INSERTED_PAGE_FLAG2= 1234 + 2; PdfPage* pPage = new PdfPage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ), &(doc.GetObjects()) ); pPage->GetObject()->GetDictionary().AddKey( PODOFO_TEST_PAGE_KEY, static_cast<long long>(INSERTED_PAGE_FLAG) ); // Insert page at the beginning doc.GetPagesTree()->InsertPage( ePdfPageInsertionPoint_InsertBeforeFirstPage, pPage ); delete pPage; // Find inserted page (beginning) pPage = doc.GetPage( 0 ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, INSERTED_PAGE_FLAG ), true ); // Find old first page pPage = doc.GetPage( 1 ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, 0 ), true ); // Insert at end pPage = doc.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) ); pPage->GetObject()->GetDictionary().AddKey( PODOFO_TEST_PAGE_KEY, static_cast<long long>(INSERTED_PAGE_FLAG1) ); pPage = doc.GetPage( doc.GetPageCount() - 1 ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, INSERTED_PAGE_FLAG1 ), true ); // Insert in middle pPage = new PdfPage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ), &(doc.GetObjects()) ); pPage->GetObject()->GetDictionary().AddKey( PODOFO_TEST_PAGE_KEY, static_cast<long long>(INSERTED_PAGE_FLAG2) ); const int INSERT_POINT = 50; doc.GetPagesTree()->InsertPage( INSERT_POINT, pPage ); delete pPage; pPage = doc.GetPage( INSERT_POINT + 1 ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, INSERTED_PAGE_FLAG2 ), true ); }