Show
Ignore:
Timestamp:
04/17/06 07:28:50 (3 years ago)
Author:
jordi
Message:

Since version 0.5.0 and up doesn't support the old Xpdf header files and because the CairoOutputDev?.h file is not installed on version 0.5.1, I now use Poppler's glib wrapper for PDF loading.

The glib wrapper needs an URI instead of a filename (why?), so the path to the file must be specified as an absolute path to be able to convert it to an URI (file:///dir1/dir2/file.pdf). This also means that the tests files had to be changed to use absolute paths. I added a function (that I'll change to a common utils source) that transform the filename to an absolute path.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/tests/PDFDocumentTest.cxx

    r73 r78  
    2626 
    2727/// 
     28/// @brief Returns the path to the test data file. 
     29/// 
     30/// It assumes that TEST_DIR is defined to the relative 
     31/// tests directory and that the checks are executed from the 
     32/// test build dir. 
     33/// 
     34static gchar * 
     35getTestFile (const gchar *fileName) 
     36{ 
     37    gchar *currentDir = g_get_current_dir (); 
     38    gchar *filePath = g_build_filename (currentDir, TEST_DIR, fileName, NULL); 
     39 
     40    return filePath; 
     41} 
     42 
     43/// 
    2844/// @brief Sets up the environment for each test. 
    2945/// 
     
    93109PDFDocumentTest::fileNotFound (void) 
    94110{ 
    95     GError *error = NULL;     
    96     CPPUNIT_ASSERT (!m_Document->loadFile (TEST_DATA_DIR "noFile.pdf",  
    97                                           NULL, &error)); 
     111    GError *error = NULL; 
     112    gchar *testFile = getTestFile ("noFile.pdf"); 
     113    CPPUNIT_ASSERT (!m_Document->loadFile (testFile, NULL, &error)); 
    98114    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
    99115     
    100116    gchar *documentError = IDocument::getErrorMessage(DocumentErrorOpenFile); 
    101117    gchar *errorMessage = g_strdup_printf ( 
    102             "Failed to load document '%sNoFile.pdf'.\n%s\n",  
    103             TEST_DATA_DIR, documentError); 
     118            "Failed to load document '%s'.\n%s\n", testFile, documentError); 
    104119    g_free(documentError); 
    105120    DocumentError errorCode = (DocumentError)error->code; 
     
    108123                                                 error->message)); 
    109124    g_free (errorMessage); 
     125    g_free (testFile); 
    110126    g_error_free (error); 
    111127} 
     
    121137{ 
    122138    GError *error = NULL; 
    123     CPPUNIT_ASSERT (!m_Document->loadFile (TEST_DATA_DIR "PDFDocumentTest.cxx", 
    124                                           NULL, &error)); 
     139    gchar *testFile = getTestFile ("PDFDocumentTest.cxx"); 
     140    CPPUNIT_ASSERT (!m_Document->loadFile (testFile, NULL, &error)); 
    125141    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
    126142 
    127143    gchar *documentError = IDocument::getErrorMessage(DocumentErrorDamaged); 
    128144    gchar *errorMessage = g_strdup_printf ( 
    129             "Failed to load document '%sPDFDocumentTest.cxx'.\n%s\n",  
    130             TEST_DATA_DIR, documentError); 
     145            "Failed to load document '%s'.\n%s\n", testFile, documentError); 
    131146    g_free(documentError); 
    132147    DocumentError errorCode = (DocumentError)error->code; 
     
    134149    CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp (errorMessage,  
    135150                                                 error->message)); 
     151    g_free (testFile); 
    136152    g_free (errorMessage); 
    137153    g_error_free (error); 
     
    150166{ 
    151167    GError *error = NULL; 
    152     CPPUNIT_ASSERT (!m_Document->loadFile (TEST_DATA_DIR "test_encrypted.pdf", 
    153                                           NULL, &error)); 
     168    gchar *testFile = getTestFile ("test_encrypted.pdf"); 
     169    CPPUNIT_ASSERT (!m_Document->loadFile (testFile, NULL, &error)); 
    154170    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
    155171 
    156172    gchar *documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); 
    157173    gchar *errorMessage = g_strdup_printf ( 
    158             "Failed to load document '%stest_encrypted.pdf'.\n%s\n",  
    159             TEST_DATA_DIR, documentError); 
     174            "Failed to load document '%s'.\n%s\n", testFile, documentError); 
    160175    g_free(documentError); 
    161176    DocumentError errorCode = (DocumentError)error->code; 
     
    168183    // Now try with an invalid password... 
    169184    error = NULL; 
    170     CPPUNIT_ASSERT (!m_Document->loadFile (TEST_DATA_DIR "test_encrypted.pdf", 
    171                                            "invalidpasswd", &error)); 
     185    CPPUNIT_ASSERT (!m_Document->loadFile (testFile, "invalidpasswd", &error)); 
    172186    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
    173187 
    174188    documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); 
    175189    errorMessage = g_strdup_printf ( 
    176             "Failed to load document '%stest_encrypted.pdf'.\n%s\n",  
    177             TEST_DATA_DIR, documentError); 
     190            "Failed to load document '%s'.\n%s\n", testFile, documentError); 
    178191    g_free(documentError); 
    179192    errorCode = (DocumentError)error->code; 
     
    187200    // correct password. 
    188201    error = NULL; 
    189     CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test_encrypted.pdf", 
    190                                           "testpasswd", &error)); 
     202    CPPUNIT_ASSERT (m_Document->loadFile (testFile, "testpasswd", &error)); 
    191203    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    192204    CPPUNIT_ASSERT (NULL == error); 
    193     CPPUNIT_ASSERT_EQUAL (0,  
    194             g_ascii_strcasecmp (TEST_DATA_DIR "test_encrypted.pdf",  
    195                                 m_Document->getFileName ())); 
    196     CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("testpasswd",  
    197                                                  m_Document->getPassword ())); 
     205    CPPUNIT_ASSERT_EQUAL (0, 
     206            g_ascii_strcasecmp (testFile, m_Document->getFileName ())); 
     207    CPPUNIT_ASSERT_EQUAL (0,  
     208            g_ascii_strcasecmp ("testpasswd", m_Document->getPassword ())); 
     209 
     210    g_free (testFile); 
    198211} 
    199212 
     
    208221PDFDocumentTest::validFile () 
    209222{ 
    210     CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test2.pdf", 
    211                                            NULL, NULL)); 
    212     CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    213     CPPUNIT_ASSERT_EQUAL (0,  
    214             g_ascii_strcasecmp (TEST_DATA_DIR "test2.pdf",  
    215                                 m_Document->getFileName ())); 
     223    gchar *testFile = getTestFile ("test2.pdf"); 
     224    CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 
     225    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
     226    CPPUNIT_ASSERT_EQUAL (0,  
     227            g_ascii_strcasecmp (testFile, m_Document->getFileName ())); 
    216228    CPPUNIT_ASSERT_EQUAL (0,  
    217229            g_ascii_strcasecmp ("Lorem Ipsum Dolor Site Amet",  
     
    246258 
    247259    // Another test file. 
    248     CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test1.pdf", 
    249                                            NULL, NULL)); 
    250     CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    251     CPPUNIT_ASSERT_EQUAL (0,  
    252             g_ascii_strcasecmp (TEST_DATA_DIR "test1.pdf",  
    253                                 m_Document->getFileName ())); 
     260    g_free (testFile); 
     261    testFile = getTestFile ("test1.pdf"); 
     262    CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 
     263    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
     264    CPPUNIT_ASSERT_EQUAL (0,  
     265            g_ascii_strcasecmp (testFile, m_Document->getFileName ())); 
    254266    CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", m_Document->getTitle ())); 
    255267    CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", m_Document->getAuthor ())); 
     
    274286    CPPUNIT_ASSERT_EQUAL (5, m_Document->getNumPages ()); 
    275287    CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 
     288 
     289    g_free (testFile); 
    276290} 
    277291 
     
    287301{ 
    288302    // First try with a 2 page document. 
    289     CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test2.pdf", 
    290                                           NULL, NULL)); 
     303    gchar *testFile = getTestFile ("test2.pdf"); 
     304    CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 
    291305    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    292306    CPPUNIT_ASSERT_EQUAL (2, m_Document->getNumPages ()); 
     
    321335 
    322336    // Let's try with a 5 page document. 
    323     CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test1.pdf", 
    324                                            NULL, NULL)); 
     337    g_free (testFile); 
     338    testFile = getTestFile ("test1.pdf"); 
     339    CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 
    325340    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    326341    CPPUNIT_ASSERT_EQUAL (5, m_Document->getNumPages ()); 
     
    361376    m_Document->goToPage (0); 
    362377    CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 
     378 
     379    g_free (testFile); 
    363380} 
    364381 
     
    372389PDFDocumentTest::pageRotate () 
    373390{ 
    374     CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test2.pdf", 
    375                                           NULL, NULL)); 
     391    gchar *testFile = getTestFile ("test2.pdf"); 
     392    CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 
    376393    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    377394    CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); 
     
    389406    CPPUNIT_ASSERT_EQUAL (270, m_Document->getRotation ()); 
    390407     
    391     CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test1.pdf", 
    392                                            NULL, NULL)); 
     408    g_free (testFile); 
     409    testFile = getTestFile ("test1.pdf"); 
     410    CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 
    393411    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    394412    CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); 
     
    397415    m_Document->rotateLeft (); 
    398416    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 
     417     
     418    g_free (testFile); 
    399419} 
    400420 
     
    412432{ 
    413433    // On this document only try Zoom In and Zoom Out.  
    414     CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test2.pdf", 
    415                                           NULL, NULL)); 
     434    gchar *testFile = getTestFile ("test2.pdf"); 
     435    CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 
    416436    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    417437    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), DELTA); 
     
    428448    // On this document we'll use the zoom to fit and zoom to width. 
    429449    // This document is A4 in size (595 x 842). 
    430     CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test1.pdf", 
    431                                            NULL, NULL)); 
     450    g_free (testFile); 
     451    testFile = getTestFile ("test1.pdf"); 
     452    CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 
    432453    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    433454    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), DELTA); 
     
    438459    m_Document->zoomToFit (50, 100);     
    439460    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.0840f, m_Document->getZoom (), DELTA); 
     461 
     462    g_free (testFile); 
    440463} 
    441464 
     
    456479PDFDocumentTest::pageRender () 
    457480{ 
    458     CPPUNIT_ASSERT (m_Document->loadFile (TEST_DATA_DIR "test2.pdf", 
    459                                           NULL, NULL)); 
     481    gchar *testFile = getTestFile ("test2.pdf"); 
     482    CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 
    460483    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    461484    // Since the document is 595x842 but rotated 90 degrees,  
     
    481504    delete[] testData; 
    482505    delete page; 
    483 } 
     506 
     507    g_free (testFile); 
     508}