Show
Ignore:
Timestamp:
04/11/06 08:14:31 (3 years ago)
Author:
jordi
Message:

I added the dumb document and main view for testing.

I had to create a Document Interface (IDocument) to handle the dumb document for tests. I moved the Document.{cxx,h} files to PDFDocument.{cxx,h}. The rotation, page change and scaling functions remains in IDocument, as well as the error functions and enumerations. The PDF specific portions of the document has been kept in the PDFDocument class.

The test name is also updated to PDFDocumentTest, and all tests runs OK.

Files:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/tests/PDFDocumentTest.cxx

    r19 r21  
    1717 
    1818#include <epdfview.h> 
    19 #include "DocumentTest.h" 
     19#include "PDFDocumentTest.h" 
    2020 
    2121using namespace ePDFView; 
    22 static const double equalDelta = 0.0001; 
     22static const double DELTA = 0.0001; 
    2323 
    2424// Register the test suite into the `registry'. 
    25 CPPUNIT_TEST_SUITE_REGISTRATION (DocumentTest); 
     25CPPUNIT_TEST_SUITE_REGISTRATION (PDFDocumentTest); 
    2626 
    2727/// 
     
    2929/// 
    3030void 
    31 DocumentTest::setUp () 
    32 { 
    33     m_Document = new Document (); 
     31PDFDocumentTest::setUp () 
     32{ 
     33    m_Document = new PDFDocument (); 
    3434} 
    3535 
     
    3838/// 
    3939void 
    40 DocumentTest::tearDown () 
     40PDFDocumentTest::tearDown () 
    4141{ 
    4242    delete m_Document; 
     
    5252/// 
    5353void 
    54 DocumentTest::emptyDocument () 
     54PDFDocumentTest::emptyDocument () 
    5555{ 
    5656    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
     
    9494/// 
    9595void 
    96 DocumentTest::fileNotFound (void) 
     96PDFDocumentTest::fileNotFound (void) 
    9797{ 
    9898    GError *error = NULL;     
     
    101101    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
    102102     
    103     gchar *documentError = Document::getErrorMessage(DocumentErrorOpenFile); 
     103    gchar *documentError = IDocument::getErrorMessage(DocumentErrorOpenFile); 
    104104    gchar *errorMessage = g_strdup_printf ( 
    105105            "Failed to load document '%sNoFile.pdf'.\n%s\n",  
     
    121121/// 
    122122void 
    123 DocumentTest::invalidFile (void) 
     123PDFDocumentTest::invalidFile (void) 
    124124{ 
    125125    GError *error = NULL; 
    126     CPPUNIT_ASSERT (!m_Document->loadFile (TEST_DATA_DIR "DocumentTest.cxx", 
     126    CPPUNIT_ASSERT (!m_Document->loadFile (TEST_DATA_DIR "PDFDocumentTest.cxx", 
    127127                                           NULL, &error)); 
    128128    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
    129129 
    130     gchar *documentError = Document::getErrorMessage(DocumentErrorDamaged); 
     130    gchar *documentError = IDocument::getErrorMessage(DocumentErrorDamaged); 
    131131    gchar *errorMessage = g_strdup_printf ( 
    132             "Failed to load document '%sDocumentTest.cxx'.\n%s\n",  
     132            "Failed to load document '%sPDFDocumentTest.cxx'.\n%s\n",  
    133133            TEST_DATA_DIR, documentError); 
    134134    g_free(documentError); 
     
    150150/// 
    151151void 
    152 DocumentTest::encryptedFile (void) 
     152PDFDocumentTest::encryptedFile (void) 
    153153{ 
    154154    GError *error = NULL; 
     
    157157    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
    158158 
    159     gchar *documentError = Document::getErrorMessage(DocumentErrorEncrypted); 
     159    gchar *documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); 
    160160    gchar *errorMessage = g_strdup_printf ( 
    161161            "Failed to load document '%stest_encrypted.pdf'.\n%s\n",  
     
    175175    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
    176176 
    177     documentError = Document::getErrorMessage(DocumentErrorEncrypted); 
     177    documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); 
    178178    errorMessage = g_strdup_printf ( 
    179179            "Failed to load document '%stest_encrypted.pdf'.\n%s\n",  
     
    207207/// 
    208208void 
    209 DocumentTest::validFile () 
     209PDFDocumentTest::validFile () 
    210210{ 
    211211    CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test2.pdf", 
     
    280280/// @brief Test changing pages. 
    281281/// 
    282 /// The Document class also has the information about the current page 
     282/// The IDocument class also has the information about the current page 
    283283/// that's shown, so we must change it through its methods. This test just 
    284284/// checks that the page is changed correctly. 
    285285/// 
    286286void 
    287 DocumentTest::pageChange () 
     287PDFDocumentTest::pageChange () 
    288288{ 
    289289    // First try with a 2 page document. 
     
    371371/// 
    372372void 
    373 DocumentTest::pageRotate () 
     373PDFDocumentTest::pageRotate () 
    374374{ 
    375375    CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test2.pdf", 
     
    403403/// @brief Test the document's zoom. 
    404404/// 
    405 /// The Document class is also responsible of the page's zoom level. It can 
     405/// The IDocument class is also responsible of the page's zoom level. It can 
    406406/// Zoom In, Zoom Out, Zoom to Width and Zoom to Fit. 
    407407/// 
     
    410410/// 
    411411void 
    412 DocumentTest::pageZoom () 
     412PDFDocumentTest::pageZoom () 
    413413{ 
    414414    // On this document only try Zoom In and Zoom Out.  
     
    416416                                           NULL, NULL)); 
    417417    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    418     CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), equalDelta); 
     418    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), DELTA); 
    419419    m_Document->zoomIn (); 
    420     CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2f, m_Document->getZoom (), equalDelta); 
     420    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2f, m_Document->getZoom (), DELTA); 
    421421    m_Document->zoomIn (); 
    422     CPPUNIT_ASSERT_DOUBLES_EQUAL (1.44f, m_Document->getZoom (), equalDelta); 
     422    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.44f, m_Document->getZoom (), DELTA); 
    423423    m_Document->zoomOut (); 
    424     CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2f, m_Document->getZoom (), equalDelta); 
     424    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2f, m_Document->getZoom (), DELTA); 
    425425    m_Document->zoomIn (); 
    426426    m_Document->zoomIn (); 
    427     CPPUNIT_ASSERT_DOUBLES_EQUAL (1.728f, m_Document->getZoom (), equalDelta); 
     427    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.728f, m_Document->getZoom (), DELTA); 
    428428 
    429429    // On this document we'll use the zoom to fit and zoom to width. 
     
    432432                                           NULL, NULL)); 
    433433    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    434     CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), equalDelta); 
     434    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), DELTA); 
    435435    m_Document->zoomToWidth (200);     
    436     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3361f, m_Document->getZoom (), equalDelta); 
     436    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3361f, m_Document->getZoom (), DELTA); 
    437437    m_Document->zoomToFit (100, 50);     
    438     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.0593f, m_Document->getZoom (), equalDelta); 
     438    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.0593f, m_Document->getZoom (), DELTA); 
    439439    m_Document->zoomToFit (50, 100);     
    440     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.0840f, m_Document->getZoom (), equalDelta); 
     440    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.0840f, m_Document->getZoom (), DELTA); 
    441441} 
    442442 
     
    455455/// 
    456456void 
    457 DocumentTest::pageRender () 
     457PDFDocumentTest::pageRender () 
    458458{ 
    459459    CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test2.pdf", 
     
    468468    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 
    469469    m_Document->zoomToWidth (300);  
    470     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3562f, m_Document->getZoom (), equalDelta); 
     470    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3562f, m_Document->getZoom (), DELTA); 
    471471    DocumentPage *page = m_Document->renderPage (); 
    472472    CPPUNIT_ASSERT_EQUAL (300, page->getWidth ());