Changeset 124
- Timestamp:
- 04/29/06 02:29:35 (2 years ago)
- Files:
-
- trunk/src/IDocument.cxx (modified) (3 diffs)
- trunk/src/IDocument.h (modified) (4 diffs)
- trunk/src/IDocumentObserver.h (added)
- trunk/src/IJob.cxx (added)
- trunk/src/IJob.h (added)
- trunk/src/JobLoad.cxx (modified) (8 diffs)
- trunk/src/JobLoad.h (modified) (3 diffs)
- trunk/src/MainPter.cxx (modified) (4 diffs)
- trunk/src/Makefile.am (modified) (1 diff)
- trunk/src/epdfview.h (modified) (2 diffs)
- trunk/tests/DumbDocumentObserver.cxx (added)
- trunk/tests/DumbDocumentObserver.h (added)
- trunk/tests/Makefile.am (modified) (1 diff)
- trunk/tests/PDFDocumentTest.cxx (modified) (25 diffs)
- trunk/tests/PDFDocumentTest.h (modified) (3 diffs)
- trunk/tests/main.cxx (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/IDocument.cxx
r122 r124 177 177 m_Creator = NULL; 178 178 m_CurrentPage = 0; 179 m_Observers = NULL; 179 180 m_Outline = NULL; 180 181 m_FileName = NULL; … … 218 219 g_async_queue_push (m_RenderQueue, (gpointer)request); 219 220 221 g_list_free (m_Observers); 220 222 delete m_Outline; 221 223 g_free (m_Author); … … 231 233 g_free (m_Subject); 232 234 g_free (m_Title); 235 } 236 237 void 238 IDocument::attach (const IDocumentObserver *observer) 239 { 240 g_assert (NULL != observer && "Tried to attach a NULL observer."); 241 242 m_Observers = g_list_prepend (m_Observers, (gpointer)observer); 243 } 244 245 void 246 IDocument::deattach (const IDocumentObserver *observer) 247 { 248 g_assert (NULL != observer && "Tried to deattach a NULL observer."); 249 250 m_Observers = g_list_remove_all (m_Observers, observer); 251 } 252 253 void 254 IDocument::notifyLoadError (GError *error) 255 { 256 for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 257 item = g_list_next (item) ) 258 { 259 IDocumentObserver *observer = (IDocumentObserver *)item->data; 260 observer->notifyLoadError (error); 261 } 262 g_error_free (error); 263 } 264 265 void 266 IDocument::load (const gchar *fileName, const gchar *password) 267 { 268 JobLoad *job = new JobLoad (); 269 job->setDocument (this); 270 job->setFileName (fileName); 271 job->setPassword (NULL); 272 273 IJob::queue (job); 233 274 } 234 275 trunk/src/IDocument.h
r121 r124 25 25 { 26 26 // Forward declarations. 27 class DocumentIndex; 28 class IDocumentObserver; 27 29 class DocumentPage; 28 class DocumentIndex;29 30 30 31 /// … … 173 174 virtual DocumentPage *renderPage (gint pageNum) = 0; 174 175 176 void attach (const IDocumentObserver *observer); 177 void deattach (const IDocumentObserver *observer); 178 179 void notifyLoadError (GError *error); 175 180 176 181 const gchar *getTitle (void); … … 211 216 void clearCache (void); 212 217 218 void load (const gchar *fileName, const gchar *password); 219 213 220 void goToFirstPage (void); 214 221 void goToLastPage (void); … … 251 258 gchar *m_Linearized; 252 259 gchar *m_ModifiedDate; 260 GList *m_Observers; 253 261 DocumentOutline *m_Outline; 254 262 GList *m_PageCache; trunk/src/JobLoad.cxx
r117 r124 25 25 static gboolean job_load_error (gpointer data); 26 26 static gboolean job_load_password (gpointer data); 27 static gpointer job_load_run (gpointer data);28 27 29 28 /// 30 29 /// @brief Constructs a new JobLoad object. 31 30 /// 32 JobLoad::JobLoad () 31 JobLoad::JobLoad (): 32 IJob () 33 33 { 34 34 m_FileName = NULL; 35 35 m_Error = NULL; 36 m_PageNum = 0;37 36 m_Password = NULL; 38 m_PasswordTries = 3; 39 m_Presenter = NULL; 40 m_Reload = FALSE; 41 m_Rotation = 0; 42 m_Zoom = 0.0; 37 m_Document = NULL; 43 38 } 44 39 … … 57 52 58 53 /// 59 /// @brief Checks if a new password can be tried.60 ///61 /// This function checks if we passed the number of time we can try a62 /// password.63 ///64 /// Be warned that this function alters the number of tries left.65 ///66 /// @return TRUE if we can try another password, FALSE otherwise.67 ///68 gboolean69 JobLoad::canTryPassword ()70 {71 if ( m_PasswordTries > 0 )72 {73 m_PasswordTries--;74 return TRUE;75 }76 77 return FALSE;78 }79 80 ///81 54 /// @brief Gets the file name to load or reload. 82 55 /// … … 101 74 102 75 /// 103 /// @brief Gets the previously used page num.104 ///105 /// This is for reloading, gives the page where we were before reloading106 /// the document.107 ///108 /// @return The numbe of the page where we were.109 ///110 gint111 JobLoad::getPageNum ()112 {113 return m_PageNum;114 }115 116 ///117 76 /// @brief Gets the password. 118 77 /// … … 126 85 127 86 /// 128 /// @brief The presenter that's opening the file. 129 /// 130 /// @return The presenter that is loading or reloading the document. 131 /// 132 MainPter & 133 JobLoad::getPresenter () 134 { 135 g_assert (NULL != m_Presenter && "The presenter is NULL."); 136 137 return *m_Presenter; 138 } 139 140 /// 141 /// @brief Gets the previously used rotation. 142 /// 143 /// This is for reloading. Gets the rotation of the document before reloading. 144 /// 145 /// @return The degrees the document was rotated before. 146 /// 147 gint 148 JobLoad::getRotation () 149 { 150 return m_Rotation; 151 } 152 153 /// 154 /// @brief Gets the previously used zoom. 155 /// 156 /// This is for reloading. Gets the zoom of the document before reloading. 157 /// 158 /// @return The degrees the document was zoomed before. 159 /// 160 gdouble 161 JobLoad::getZoom () 162 { 163 return m_Zoom; 164 } 165 166 /// 167 /// @brief Checks if we are reloading. 168 /// 169 /// @return TRUE if we are reloading, FALSE otherwise. 170 /// 171 gboolean 172 JobLoad::isReload () 173 { 174 return m_Reload; 175 } 87 /// @brief The document that's loading. 88 /// 89 /// @return The document that is loading. 90 /// 91 IDocument & 92 JobLoad::getDocument () 93 { 94 g_assert (NULL != m_Document && "The document is NULL."); 95 96 return *m_Document; 97 } 98 176 99 177 100 /// 178 101 /// @brief Open the document. 179 102 /// 180 /// This function will insensitive the Open and Reload actions, set 181 /// the view's status bar text, sets the wait cursor, and creates a new thread 182 /// that opens the document. 183 /// 184 void 103 /// 104 gboolean 185 105 JobLoad::run () 186 106 { 187 if ( !g_thread_supported () ) 188 { 189 g_thread_init (NULL); 190 } 191 192 // Unsensitive the open and reload actions. 193 IMainView &view = getPresenter ().getView (); 194 view.sensitiveOpen (FALSE); 195 view.sensitiveReload (FALSE); 196 // Show the statusbar text. 197 gchar *statusText = NULL; 198 if ( isReload () ) 199 { 200 statusText = g_strdup_printf (_("Reloading file %s..."), 201 getFileName ()); 107 GError *error = NULL; 108 if ( getDocument ().loadFile (getFileName (), getPassword (), &error) ) 109 { 110 JOB_NOTIFIER (job_load_done, this); 111 } 112 else if ( DocumentErrorEncrypted == error->code ) 113 { 114 g_error_free (error); 115 JOB_NOTIFIER (job_load_password, this); 202 116 } 203 117 else 204 118 { 205 statusText = g_strdup_printf (_("Loading file %s..."), getFileName ()); 206 } 207 view.setStatusBarText (statusText); 208 g_free (statusText); 209 // Set the cursor. 210 view.setCursor (MAIN_VIEW_CURSOR_WAIT); 211 212 GError *error = NULL; 213 if ( NULL == g_thread_create (job_load_run, this, FALSE, &error) ) 214 { 215 g_warning ("Couldn't create thread: %s\n", error->message); 216 g_error_free (error); 217 } 119 setError (error); 120 JOB_NOTIFIER (job_load_error, this); 121 } 122 return FALSE; 218 123 } 219 124 … … 246 151 247 152 /// 248 /// @brief Sets the page number.249 ///250 /// This is used for reloading, see getPageNum().251 ///252 /// @param pageNum The page to go when the document is reloaded.253 ///254 void255 JobLoad::setPage (gint pageNum)256 {257 m_PageNum = pageNum;258 }259 260 ///261 153 /// @brief Sets the password to open the document. 262 154 /// … … 271 163 272 164 /// 273 /// @brief Sets the presenter that loads the document. 274 /// 275 /// @param pter The MainPter that will load the document. 276 /// 277 void 278 JobLoad::setPresenter (MainPter *pter) 279 { 280 m_Presenter = pter; 281 } 282 283 /// 284 /// @brief Sets if we are reloading. 285 /// 286 /// @param reload TRUE if we are reloading, false otherwise. 287 /// 288 void 289 JobLoad::setReload (gboolean reload) 290 { 291 m_Reload = reload; 292 } 293 294 /// 295 /// @brief Sets the rotation to use after reloading. 296 /// 297 /// @param rotation The degrees of rotation. 298 /// 299 void 300 JobLoad::setRotation (gint rotation) 301 { 302 m_Rotation = rotation; 303 } 304 305 /// 306 /// @brief Sets the zoom to use after reloading. 307 /// 308 /// @param zoom The level of zoom. 309 /// 310 void 311 JobLoad::setZoom (gdouble zoom) 312 { 313 m_Zoom = zoom; 314 } 165 /// @brief Sets the document to load. 166 /// 167 /// @param document The document that will load. 168 /// 169 void 170 JobLoad::setDocument (IDocument *document) 171 { 172 g_assert ( NULL != document && "Tried to set a NULL document."); 173 174 m_Document = document; 175 } 176 315 177 316 178 //////////////////////////////////////////////////////////////// … … 319 181 320 182 /// 321 /// @brief The load is finished. 322 /// 323 /// This can be called either when the document was loaded correctly or 324 /// after an error. What it does is set the presenter in a known state 325 /// ready to be used again. 183 /// @brief The load is finished correctly. 184 /// 185 /// @param data This parameter holds the JobLoad that finished. 186 /// 187 gboolean 188 job_load_done (gpointer data) 189 { 190 g_assert (NULL != data && "The data parameter is NULL."); 191 192 JobLoad *job = (JobLoad *)data; 193 194 return FALSE; 195 } 196 197 /// 198 /// @brief The load had errors. 199 /// 200 /// This is called when the load of the document had any error except 201 /// when it's encrypted. 326 202 /// 327 203 /// @param data This parameter hold the JobLoad to open. 328 204 /// 329 205 gboolean 330 job_load_ done(gpointer data)206 job_load_error (gpointer data) 331 207 { 332 208 g_assert (NULL != data && "The data parameter is NULL."); 333 209 334 210 JobLoad *job = (JobLoad *)data; 335 job->getPresenter ().setInitialState (!job->isReload ()); 336 if ( job->isReload () ) 337 { 338 job->getPresenter ().setContext (job->getPageNum (), 339 job->getRotation (), job->getZoom ()); 340 } 341 delete job; 342 211 job->getDocument ().notifyLoadError (job->getError ()); 212 343 213 return FALSE; 344 }345 346 ///347 /// @brief The load had errors.348 ///349 /// This is called when the load of the document had any error except350 /// when it's encrypted.351 ///352 /// @param data This parameter hold the JobLoad to open.353 ///354 gboolean355 job_load_error (gpointer data)356 {357 g_assert (NULL != data && "The data parameter is NULL.");358 359 JobLoad *job = (JobLoad *)data;360 job->getPresenter ().getView ().showErrorMessage (_("Error Loading File"),361 job->getError ()->message);362 job->setReload (FALSE);363 return job_load_done (data);364 214 } 365 215 … … 381 231 382 232 JobLoad *job = (JobLoad *)data; 383 if ( job->canTryPassword () )384 {385 gchar *password =386 job->getPresenter ().getView ().promptPasswordDialog ();387 if ( password != NULL )388 {389 job->setPassword (password);390 g_free (password);391 GError *error = NULL;392 if ( NULL == g_thread_create (job_load_run, job, FALSE, &error) )393 {394 g_warning ("Couldn't create thread: %s\n", error->message);395 g_error_free (error);396 }397 return FALSE;398 }399 }400 else401 {402 job->getPresenter ().getView ().showErrorMessage (403 _("Error Loading File"),404 _("The password you have supplier is not a valid password "405 "for this file."));406 }407 233 408 234 return job_load_done (data); 409 235 } 410 411 ///412 /// @brief Opens the files.413 ///414 /// This is the threaded function that will try to call the presenter's415 /// loading function with the given file name and password. This function416 /// just tests if the load was successful or not and then tells glib to417 /// call the actual end function, that will show the result to the user.418 ///419 /// When this function is compiled with DEBUG defined, the calls to the420 /// "end" functions aren't scheduled by glib, since the test framework doesn't421 /// use it.422 ///423 /// @param data This parameter hold the JobLoad to open.424 ///425 gpointer426 job_load_run (gpointer data)427 {428 g_assert (NULL != data && "The data parameter is NULL.");429 430 JobLoad *job = (JobLoad *)data;431 GError *error = NULL;432 if ( job->getPresenter ().openDocument (job->getFileName (),433 job->getPassword (), &error) )434 {435 #if defined DEBUG436 job_load_done (job);437 #else438 g_idle_add (job_load_done, job);439 #endif440 }441 else if ( DocumentErrorEncrypted == error->code )442 {443 g_error_free (error);444 #if defined DEBUG445 job_load_password (job);446 #else447 g_idle_add (job_load_password, job);448 #endif449 }450 else451 {452 job->setError (error);453 #if defined DEBUG454 job_load_error (job);455 #else456 g_idle_add (job_load_error, job);457 #endif458 }459 460 return NULL;461 }trunk/src/JobLoad.h
r117 r124 22 22 { 23 23 // Forward declarations. 24 class MainPter;24 class IDocument; 25 25 26 26 /// … … 28 28 /// @brief A background job that loads a file. 29 29 /// 30 /// This class is used to load and reload the PDF files. It creates 31 /// a thread that loads a file name. 30 /// This class is used to load and reload the PDF files. 32 31 /// 33 class JobLoad 32 class JobLoad: public IJob 34 33 { 35 34 public: … … 37 36 ~JobLoad (void); 38 37 39 gboolean canTryPassword (void); 38 IDocument &getDocument (void); 39 GError *getError (void); 40 40 const gchar *getFileName (void); 41 GError *getError (void);42 gint getPageNum (void);43 41 const gchar *getPassword (void); 44 MainPter &getPresenter (void); 45 gint getRotation (void); 46 gdouble getZoom (void); 47 gboolean isReload (void); 48 void run (void); 42 gboolean run (void); 49 43 void setFileName (const gchar *fileName); 50 44 void setError (GError *error); 51 void setPage (gint pageNum);52 45 void setPassword (const gchar *password); 53 void setPresenter (MainPter *pter); 54 void setReload (gboolean reload); 55 void setRotation (gint rotation); 56 void setZoom (gdouble zoom); 46 void setDocument (IDocument *document); 57 47 58 48 protected: 59 49 gchar *m_FileName; 60 50 GError *m_Error; 61 gint m_PageNum;62 51 gchar *m_Password; 63 gint m_PasswordTries; 64 MainPter *m_Presenter; 65 gboolean m_Reload; 66 gint m_Rotation; 67 gdouble m_Zoom; 52 IDocument *m_Document; 68 53 }; 69 54 } trunk/src/MainPter.cxx
r123 r124 292 292 293 293 // Open the file. 294 JobLoad *job = new JobLoad ();294 /* JobLoad *job = new JobLoad (); 295 295 job->setPresenter (this); 296 296 job->setFileName (fileName); … … 298 298 job->setPassword (NULL); 299 299 job->setReload (FALSE); 300 job->run (); 300 job->run ();*/ 301 301 } 302 302 … … 363 363 { 364 364 // Reopen the document. 365 JobLoad *job = new JobLoad ();365 /* JobLoad *job = new JobLoad (); 366 366 job->setPresenter (this); 367 367 job->setFileName (m_Document->getFileName ()); … … 372 372 job->setRotation (m_Document->getRotation ()); 373 373 job->setZoom ( m_Document->getZoom ()); 374 job->run (); 374 job->run ();*/ 375 375 } 376 376 trunk/src/Makefile.am
r115 r124 13 13 epdfview.h \ 14 14 gettext.h \ 15 IJob.cxx \ 16 IJob.h \ 15 17 IDocument.cxx \ 16 18 IDocument.h \ 19 IDocumentObserver.h \ 17 20 JobLoad.cxx \ 18 21 JobLoad.h \ trunk/src/epdfview.h
r115 r124 26 26 #include <DocumentOutline.h> 27 27 #include <DocumentPage.h> 28 #include <IDocumentObserver.h> 28 29 #include <IDocument.h> 29 30 #include <PDFDocument.h> … … 32 33 #include <MainPter.h> 33 34 35 #include <IJob.h> 34 36 #include <JobLoad.h> 35 37 trunk/tests/Makefile.am
r101 r124 10 10 ConfigTest.cxx \ 11 11 ConfigTest.h \ 12 DocumentOutlineTest.cxx \13 DocumentOutlineTest.h \14 12 DumbDocument.cxx \ 15 13 DumbDocument.h \ 14 DumbDocumentObserver.cxx \ 15 DumbDocumentObserver.h \ 16 16 DumbMainView.cxx \ 17 17 DumbMainView.h \ 18 18 main.cxx \ 19 MainPterTest.cxx \20 MainPterTest.h \21 19 PDFDocumentTest.cxx \ 22 20 PDFDocumentTest.h \ 23 21 Utils.cxx \ 24 22 Utils.h 23 24 25 # DocumentOutlineTest.cxx 26 # DocumentOutlineTest.h 27 # MainPterTest.cxx 28 # MainPterTest.h 25 29 26 30 test_epdfview_CXXFLAGS = \ trunk/tests/PDFDocumentTest.cxx
r122 r124 18 18 #include <epdfview.h> 19 19 #include "Utils.h" 20 #include "DumbDocumentObserver.h" 20 21 #include "PDFDocumentTest.h" 21 22 … … 33 34 { 34 35 m_Document = new PDFDocument (); 36 m_Observer = new DumbDocumentObserver (); 37 m_Document->attach (m_Observer); 35 38 } 36 39 … … 41 44 PDFDocumentTest::tearDown () 42 45 { 46 m_Document->deattach (m_Observer); 47 delete m_Observer; 43 48 delete m_Document; 44 49 } … … 94 99 PDFDocumentTest::fileNotFound (void) 95 100 { 96 GError *error = NULL;97 101 gchar *testFile = getTestFile ("noFile.pdf"); 98 CPPUNIT_ASSERT (!m_Document->loadFile (testFile, NULL, &error)); 102 m_Document->load (testFile, NULL); 103 while ( !m_Observer->loadFinished () ) { } 99 104 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 100 105 CPPUNIT_ASSERT (m_Observer->notifiedError ()); 106 101 107 gchar *documentError = IDocument::getErrorMessage(DocumentErrorOpenFile); 102 108 gchar *errorMessage = g_strdup_printf ( 103 109 "Failed to load document '%s'.\n%s\n", testFile, documentError); 104 110 g_free(documentError); 111 const GError *error = m_Observer->getLoadError (); 105 112 DocumentError errorCode = (DocumentError)error->code; 106 113 CPPUNIT_ASSERT_EQUAL (DocumentErrorOpenFile, errorCode); … … 109 116 g_free (errorMessage); 110 117 g_free (testFile); 111 g_error_free (error); 112 } 113 118 } 119 /* 114 120 /// 115 121 /// @brief Test that loading an invalid file fails. … … 123 129 GError *error = NULL; 124 130 gchar *testFile = getTestFile ("PDFDocumentTest.cxx"); 125 CPPUNIT_ASSERT (!m_Document->loadFile (testFile, NULL, &error)); 131 CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, &error)); 132 while ( !m_Observer->loadFinished () ) { } 126 133 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 134 CPPUNIT_ASSERT (m_Observer->notifiedError ()); 127 135 128 136 gchar *documentError = IDocument::getErrorMessage(DocumentErrorDamaged); … … 130 138 "Failed to load document '%s'.\n%s\n", testFile, documentError); 131 139 g_free(documentError); 140 error = m_Observer->getLoadError (); 132 141 DocumentError errorCode = (DocumentError)error->code; 133 142 CPPUNIT_ASSERT_EQUAL (DocumentErrorDamaged, errorCode); … … 136 145 g_free (testFile); 137 146 g_free (errorMessage); 138 g_error_free (error);139 147 } 140 148 … … 152 160 GError *error = NULL; 153 161 gchar *testFile = getTestFile ("test_encrypted.pdf"); 154 CPPUNIT_ASSERT (!m_Document->loadFile (testFile, NULL, &error)); 162 CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, &error)); 163 while ( !m_Observer->loadFinished () ) { } 155 164 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 165 CPPUNIT_ASSERT (m_Observer->notifiedPassword ()); 156 166 157 167 gchar *documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); … … 159 169 "Failed to load document '%s'.\n%s\n", testFile, documentError); 160 170 g_free(documentError); 171 error = m_Observer->getLoadError (); 161 172 DocumentError errorCode = (DocumentError)error->code; 162 173 CPPUNIT_ASSERT_EQUAL (DocumentErrorEncrypted, errorCode); … … 164 175 error->message)); 165 176 g_free (errorMessage); 166 g_error_free (error);167 177 168 178 // Now try with an invalid password... 169 179 error = NULL; 170 CPPUNIT_ASSERT (!m_Document->loadFile (testFile, "invalidpasswd", &error)); 180 CPPUNIT_ASSERT (m_Document->loadFile (testFile, "invalidpasswd", &error)); 181 while ( !m_Observer->loadFinished () ) { } 171 182 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 183 CPPUNIT_ASSERT (m_Observer->notifiedPassword ()); 172 184 173 185 documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); … … 175 187 "Failed to load document '%s'.\n%s\n", testFile, documentError); 176 188 g_free(documentError); 189 error = m_Observer->getLoadError (); 177 190 errorCode = (DocumentError)error->code; 178 191 CPPUNIT_ASSERT_EQUAL (DocumentErrorEncrypted, errorCode); … … 180 193 error->message)); 181 194 g_free (errorMessage); 182 g_error_free (error);183 195 184 196 // And now, just to test that it can load the pdf using the … … 186 198 error = NULL; 187 199 CPPUNIT_ASSERT (m_Document->loadFile (testFile, "testpasswd", &error)); 188 CPPUNIT_ASSERT (m_Document->isLoaded ()); 189 CPPUNIT_ASSERT (NULL == error); 200 while ( !m_Observer->loadFinished () ) { } 201 CPPUNIT_ASSERT (m_Document->isLoaded ()); 202 CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); 190 203 CPPUNIT_ASSERT_EQUAL (0, 191 204 g_ascii_strcasecmp (testFile, m_Document->getFileName ())); … … 208 221 gchar *testFile = getTestFile ("test2.pdf"); 209 222 CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 223 while ( !m_Observer->loadFinished () ) { } 224 CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); 210 225 CPPUNIT_ASSERT (m_Document->isLoaded ()); 211 226 CPPUNIT_ASSERT_EQUAL (0, … … 246 261 testFile = getTestFile ("test1.pdf"); 247 262 CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 263 while ( !m_Observer->loadFinished () ) { } 264 CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); 248 265 CPPUNIT_ASSERT (m_Document->isLoaded ()); 249 266 CPPUNIT_ASSERT_EQUAL (0, … … 287 304 { 288 305 CPPUNIT_ASSERT (m_Document->loadFile (TEST_DIR "test1.pdf", NULL, NULL)); 306 while ( !m_Observer->loadFinished () ) { } 307 CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); 289 308 CPPUNIT_ASSERT (m_Document->isLoaded ()); 290 309 CPPUNIT_ASSERT_EQUAL (0, … … 307 326 gchar *testFile = getTestFile ("test2.pdf"); 308 327 CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 328 while ( !m_Observer->loadFinished () ) { } 329 CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); 309 330 CPPUNIT_ASSERT (m_Document->isLoaded ()); 310 331 CPPUNIT_ASSERT_EQUAL (2, m_Document->getNumPages ()); 311 332 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 333 CPPUNIT_ASSERT_EQUAL (1, m_Observer->getCurrentPage ()); 312 334 m_Document->goToNextPage (); 313 335 CPPUNIT_ASSERT_EQUAL (2, m_Document->getCurrentPageNum ()); 336 CPPUNIT_ASSERT_EQUAL (2, m_Observer->getCurrentPage ()); 314 337 // Don't let the page go after the last page. 315 338 m_Document->goToNextPage (); 316 339 CPPUNIT_ASSERT_EQUAL (2, m_Document->getCurrentPageNum ()); 340 CPPUNIT_ASSERT_EQUAL (2, m_Observer->getCurrentPage ()); 317 341 // Now go backwards. 318 342 m_Document->goToPreviousPage (); 319 343 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 344 CPPUNIT_ASSERT_EQUAL (1, m_Observer->getCurrentPage ()); 320 345 m_Document->goToPreviousPage (); 321 346 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 347 CPPUNIT_ASSERT_EQUAL (1, m_Observer->getCurrentPage ()); 322 348 // First and last pages. 323 349 m_Document->goToLastPage (); 324 350 CPPUNIT_ASSERT_EQUAL (2, m_Document->getCurrentPageNum ()); 351 CPPUNIT_ASSERT_EQUAL (2, m_Observer->getCurrentPage ()); 325 352 m_Document->goToFirstPage (); 326 353 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 354 CPPUNIT_ASSERT_EQUAL (1, m_Observer->getCurrentPage ()); 327 355 // Now, let's go to an specific page. If the page is beyond the 328 // last page, then the current page will be the last. On the other 329 // hand, if the page is less than the first (< 1) then the current 330 // page will be the first. 356 // last page or before the first page then the current page 357 // doesn't change. 331 358 m_Document->goToPage (2); 332 359 CPPUNIT_ASSERT_EQUAL (2, m_Document->getCurrentPageNum ()); 360 CPPUNIT_ASSERT_EQUAL (2, m_Observer->getCurrentPage ()); 333 361 m_Document->goToPage (1); 334 362 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 363 CPPUNIT_ASSERT_EQUAL (1, m_Observer->getCurrentPage ()); 335 364 m_Document->goToPage (13); 336 CPPUNIT_ASSERT_EQUAL (2, m_Document->getCurrentPageNum ()); 365 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 366 CPPUNIT_ASSERT_EQUAL (1, m_Observer->getCurrentPage ()); 337 367 m_Document->goToPage (0); 338 368 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 369 CPPUNIT_ASSERT_EQUAL (1, m_Observer->getCurrentPage ()); 339 370 340 371 // Let's try with a 5 page document. … … 342 373 testFile = getTestFile ("test1.pdf"); 343 374 CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 375 while ( !m_Observer->loadFinished () ) { } 376 CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); 344 377 CPPUNIT_ASSERT (m_Document->isLoaded ()); 345 378 CPPUNIT_ASSERT_EQUAL (5, m_Document->getNumPages ()); 346 379 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 380 CPPUNIT_ASSERT_EQUAL (1, m_Observer->getCurrentPage ()); 347 381 m_Document->goToNextPage (); 348 382 CPPUNIT_ASSERT_EQUAL (2, m_Document->getCurrentPageNum ()); 383 CPPUNIT_ASSERT_EQUAL (2, m_Observer->getCurrentPage ()); 349 384 m_Document->goToNextPage (); 350 385 CPPUNIT_ASSERT_EQUAL (3, m_Document->getCurrentPageNum ()); 386 CPPUNIT_ASSERT_EQUAL (3, m_Observer->getCurrentPage ()); 351 387 m_Document->goToPage (5); 352 388 CPPUNIT_ASSERT_EQUAL (5, m_Document->getCurrentPageNum ()); 389 CPPUNIT_ASSERT_EQUAL (5, m_Observer->getCurrentPage ()); 353 390 // Don't let the page go after the last page. 354 391 m_Document->goToNextPage (); 355 392 CPPUNIT_ASSERT_EQUAL (5, m_Document->getCurrentPageNum ()); 393 CPPUNIT_ASSERT_EQUAL (5, m_Observer->getCurrentPage ()); 356 394 // Now go backwards. 357 395 m_Document->goToPreviousPage (); 358 396 CPPUNIT_ASSERT_EQUAL (4, m_Document->getCurrentPageNum ()); 397 CPPUNIT_ASSERT_EQUAL (4, m_Observer->getCurrentPage ()); 359 398 m_Document->goToPreviousPage (); 360 399 CPPUNIT_ASSERT_EQUAL (3, m_Document->getCurrentPageNum ()); 400 CPPUNIT_ASSERT_EQUAL (3, m_Observer->getCurrentPage ()); 361 401 m_Document->goToPage (1); 362 402 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 403 CPPUNIT_ASSERT_EQUAL (1, m_Observer->getCurrentPage ()); 363 404 m_Document->goToPreviousPage (); 364 405 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 406 CPPUNIT_ASSERT_EQUAL (1, m_Observer->getCurrentPage ()); 365 407 // First and last pages. 366 408 m_Document->goToLastPage (); 367 409 CPPUNIT_ASSERT_EQUAL (5, m_Document->getCurrentPageNum ()); 410 CPPUNIT_ASSERT_EQUAL (5, m_Observer->getCurrentPage ()); 368 411 m_Document->goToFirstPage (); 369 412 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 413 CPPUNIT_ASSERT_EQUAL (1, m_Observer->getCurrentPage ()); 370 414 // Now, let's go to an specific page. If the page is beyond the 371 415 // last page, then the current page will be the last. On the other … … 374 418 m_Document->goToPage (3); 375 419 CPPUNIT_ASSERT_EQUAL (3, m_Document->getCurrentPageNum ()); 420 CPPUNIT_ASSERT_EQUAL (3, m_Observer->getCurrentPage ()); 376 421 m_Document->goToPage (2); 377 422 CPPUNIT_ASSERT_EQUAL (2, m_Document->getCurrentPageNum ()); 423 CPPUNIT_ASSERT_EQUAL (2, m_Observer->getCurrentPage ()); 378 424 m_Document->goToPage (13); 379 CPPUNIT_ASSERT_EQUAL (5, m_Document->getCurrentPageNum ()); 425 CPPUNIT_ASSERT_EQUAL (2, m_Document->getCurrentPageNum ()); 426 CPPUNIT_ASSERT_EQUAL (2, m_Observer->getCurrentPage ()); 380 427 m_Document->goToPage (0); 381 CPPUNIT_ASSERT_EQUAL (1, m_Document->getCurrentPageNum ()); 428 CPPUNIT_ASSERT_EQUAL (2, m_Document->getCurrentPageNum ()); 429 CPPUNIT_ASSERT_EQUAL (2, m_Observer->getCurrentPage ()); 382 430 383 431 g_free (testFile); … … 395 443 gchar *testFile = getTestFile ("test2.pdf"); 396 444 CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 445 while ( !m_Observer->loadFinished () ) { } 397 446 CPPUNIT_ASSERT (m_Document->isLoaded ()); 398 447 CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); 399 448 m_Document->rotateRight (); 400 449 CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 450 CPPUNIT_ASSERT (m_Observer->notifiedRotation ()); 401 451 m_Document->rotateLeft (); 402 452 CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); 403 m_Document->rotateRight (); 453 CPPUNIT_ASSERT (m_Observer->notifiedRotation ()); 454 m_Document->rotateRight (); 455 CPPUNIT_ASSERT (m_Observer->notifiedRotation ()); 404 456 m_Document->rotateRight (); 405 457 CPPUNIT_ASSERT_EQUAL (180, m_Document->getRotation ()); 406 m_Document->rotateRight (); 458 CPPUNIT_ASSERT (m_Observer->notifiedRotation ()); 459 m_Document->rotateRight (); 460 CPPUNIT_ASSERT (m_Observer->notifiedRotation ()); 407 461 m_Document->rotateRight (); 408 462 CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); 463 CPPUNIT_ASSERT (m_Observer->notifiedRotation ()); 409 464 m_Document->rotateLeft (); 410 465 CPPUNIT_ASSERT_EQUAL (270, m_Document->getRotation ()); 466 CPPUNIT_ASSERT (m_Observer->notifiedRotation ()); 411 467 412 468 g_free (testFile); 413 469 testFile = getTestFile ("test1.pdf"); 470 while ( !m_Observer->loadFinished () ) { } 414 471 CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 415 472 CPPUNIT_ASSERT (m_Document->isLoaded ()); 416 473 CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); 417 474 m_Document->rotateRight (); 418 m_Document->rotateRight (); 475 CPPUNIT_ASSERT (m_Observer->notifiedRotation ()); 476 m_Document->rotateRight (); 477 CPPUNIT_ASSERT (m_Observer->notifiedRotation ()); 419 478 m_Document->rotateLeft (); 420 479 CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 480 CPPUNIT_ASSERT (m_Observer->notifiedRotation ()); 421 481 422 482 g_free (testFile); … … 438 498 gchar *testFile = getTestFile ("test2.pdf"); 439 499 CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 500 while ( !m_Observer->loadFinished () ) { } 440 501 CPPUNIT_ASSERT (m_Document->isLoaded ()); 441 502 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), DELTA); 442 503 m_Document->zoomIn (); 443 504 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2f, m_Document->getZoom (), DELTA); 505 CPPUNIT_ASSERT (m_Observer->notifiedZoom ()); 506 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2f, m_Observer->getZoom (), DELTA); 444 507 m_Document->zoomIn (); 445 508 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.44f, m_Document->getZoom (), DELTA); 509 CPPUNIT_ASSERT (m_Observer->notifiedZoom ()); 510 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.44f, m_Observer->getZoom (), DELTA); 446 511 m_Document->zoomOut (); 447 512 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2f, m_Document->getZoom (), DELTA); 513 CPPUNIT_ASSERT (m_Observer->notifiedZoom ()); 514 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2f, m_Observer->getZoom (), DELTA); 448 515 m_Document->zoomIn (); 449 516 m_Document->zoomIn (); 450 517 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.728f, m_Document->getZoom (), DELTA); 518 CPPUNIT_ASSERT (m_Observer->notifiedZoom ()); 519 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.728f, m_Observer->getZoom (), DELTA); 451 520 452 521 // On this document we'll use the zoom to fit and zoom to width. … … 455 524 testFile = getTestFile ("test1.pdf"); 456 525 CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 526 while ( !m_Observer->loadFinished () ) { } 457 527 CPPUNIT_ASSERT (m_Document->isLoaded ()); 458 528 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0f, m_Document->getZoom (), DELTA); 459 529 m_Document->zoomToWidth (200); 460 530 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3361f, m_Document->getZoom (), DELTA); 531 CPPUNIT_ASSERT (m_Observer->notifiedZoom ()); 532 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3361f, m_Observer->getZoom (), DELTA); 461 533 m_Document->zoomToFit (100, 50); 462 534 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.0593f, m_Document->getZoom (), DELTA); 535 CPPUNIT_ASSERT (m_Observer->notifiedZoom ()); 536 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.0593f, m_Observer->getZoom (), DELTA); 463 537 m_Document->zoomToFit (50, 100); 464 538 C
