Changeset 78 for trunk/tests/PDFDocumentTest.cxx
- Timestamp:
- 04/17/06 07:28:50 (3 years ago)
- Files:
-
- 1 modified
-
trunk/tests/PDFDocumentTest.cxx (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/PDFDocumentTest.cxx
r73 r78 26 26 27 27 /// 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 /// 34 static gchar * 35 getTestFile (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 /// 28 44 /// @brief Sets up the environment for each test. 29 45 /// … … 93 109 PDFDocumentTest::fileNotFound (void) 94 110 { 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)); 98 114 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 99 115 100 116 gchar *documentError = IDocument::getErrorMessage(DocumentErrorOpenFile); 101 117 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); 104 119 g_free(documentError); 105 120 DocumentError errorCode = (DocumentError)error->code; … … 108 123 error->message)); 109 124 g_free (errorMessage); 125 g_free (testFile); 110 126 g_error_free (error); 111 127 } … … 121 137 { 122 138 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)); 125 141 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 126 142 127 143 gchar *documentError = IDocument::getErrorMessage(DocumentErrorDamaged); 128 144 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); 131 146 g_free(documentError); 132 147 DocumentError errorCode = (DocumentError)error->code; … … 134 149 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp (errorMessage, 135 150 error->message)); 151 g_free (testFile); 136 152 g_free (errorMessage); 137 153 g_error_free (error); … … 150 166 { 151 167 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)); 154 170 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 155 171 156 172 gchar *documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); 157 173 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); 160 175 g_free(documentError); 161 176 DocumentError errorCode = (DocumentError)error->code; … … 168 183 // Now try with an invalid password... 169 184 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)); 172 186 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 173 187 174 188 documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); 175 189 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); 178 191 g_free(documentError); 179 192 errorCode = (DocumentError)error->code; … … 187 200 // correct password. 188 201 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)); 191 203 CPPUNIT_ASSERT (m_Document->isLoaded ()); 192 204 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); 198 211 } 199 212 … … 208 221 PDFDocumentTest::validFile () 209 222 { 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 ())); 216 228 CPPUNIT_ASSERT_EQUAL (0, 217 229 g_ascii_strcasecmp ("Lorem Ipsum Dolor Site Amet", … … 246 258 247 259 // 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 ())); 254 266 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", m_Document->getTitle ())); 255 267 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("", m_Document->getAuthor ())); … … 274 286 CPPUNIT_ASSERT_EQUAL (5, m_Document->getNumPages ()); 275 287 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 288 289 g_free (testFile); 276 290 } 277 291 … … 287 301 { 288 302 // 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)); 291 305 CPPUNIT_ASSERT (m_Document->isLoaded ()); 292 306 CPPUNIT_ASSERT_EQUAL (2, m_Document->getNumPages ()); … … 321 335 322 336 // 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)); 325 340 CPPUNIT_ASSERT (m_Document->isLoaded ()); 326 341 CPPUNIT_ASSERT_EQUAL (5, m_Document->getNumPages ()); … … 361 376 m_Document->goToPage (0); 362 377 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 378 379 g_free (testFile); 363 380 } 364 381 … … 372 389 PDFDocumentTest::pageRotate () 373 390 { 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)); 376 393 CPPUNIT_ASSERT (m_Document->isLoaded ()); 377 394 CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); … … 389 406 CPPUNIT_ASSERT_EQUAL (270, m_Document->getRotation ()); 390 407 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)); 393 411 CPPUNIT_ASSERT (m_Document->isLoaded ()); 394 412 CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); … … 397 415 m_Document->rotateLeft (); 398 416 CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 417 418 g_free (testFile); 399 419 } 400 420 … … 412 432 { 413 433 // 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)); 416 436 CPPUNIT_ASSERT (m_Document->isLoaded ()); 417 437 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), DELTA); … … 428 448 // On this document we'll use the zoom to fit and zoom to width. 429 449 // 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)); 432 453 CPPUNIT_ASSERT (m_Document->isLoaded ()); 433 454 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), DELTA); … … 438 459 m_Document->zoomToFit (50, 100); 439 460 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.0840f, m_Document->getZoom (), DELTA); 461 462 g_free (testFile); 440 463 } 441 464 … … 456 479 PDFDocumentTest::pageRender () 457 480 { 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)); 460 483 CPPUNIT_ASSERT (m_Document->isLoaded ()); 461 484 // Since the document is 595x842 but rotated 90 degrees, … … 481 504 delete[] testData; 482 505 delete page; 483 } 506 507 g_free (testFile); 508 }
