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::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 ); }
void PagesTreeTest::testGetPages( PdfMemDocument & doc ) { for(int i=0; i<PODOFO_TEST_NUM_PAGES; i++) { PdfPage* pPage = doc.GetPage( i ); CPPUNIT_ASSERT_EQUAL( pPage != NULL, true ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, i ), true ); } // Now delete first page doc.GetPagesTree()->DeletePage( 0 ); for(int i=0; i<PODOFO_TEST_NUM_PAGES - 1; i++) { PdfPage* pPage = doc.GetPage( i ); CPPUNIT_ASSERT_EQUAL( pPage != NULL, true ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, i + 1 ), true ); } // Now delete any page const int DELETED_PAGE = 50; doc.GetPagesTree()->DeletePage( DELETED_PAGE ); for(int i=0; i<PODOFO_TEST_NUM_PAGES - 2; i++) { PdfPage* pPage = doc.GetPage( i ); CPPUNIT_ASSERT_EQUAL( pPage != NULL, true ); if( i < DELETED_PAGE ) { CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, i + 1 ), true ); } else { CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, i + 2 ), true ); } } }
void PagesTreeTest::testGetPagesReverse( PdfMemDocument & doc ) { for(int i=PODOFO_TEST_NUM_PAGES-1; i>=0; i--) { PdfPage* pPage = doc.GetPage( i ); CPPUNIT_ASSERT_EQUAL( pPage != NULL, true ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, i ), true ); } // Now delete first page doc.GetPagesTree()->DeletePage( 0 ); for(int i=PODOFO_TEST_NUM_PAGES-2; i>=0; i--) { PdfPage* pPage = doc.GetPage( i ); CPPUNIT_ASSERT_EQUAL( pPage != NULL, true ); CPPUNIT_ASSERT_EQUAL( IsPageNumber( pPage, i + 1 ), true ); } }