| 1 | // ePDFView - Main Presenter Test Fixture. |
|---|
| 2 | // Copyright (C) 2006 Emma's Software. |
|---|
| 3 | // |
|---|
| 4 | // This program is free software; you can redistribute it and/or modify |
|---|
| 5 | // it under the terms of the GNU General Public License as published by |
|---|
| 6 | // the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | // (at your option) any later version. |
|---|
| 8 | // |
|---|
| 9 | // This program is distributed in the hope that it will be useful, |
|---|
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | // GNU General Public License for more details. |
|---|
| 13 | // |
|---|
| 14 | // You should have received a copy of the GNU General Public License |
|---|
| 15 | // along with this program; if not, write to the Free Software |
|---|
| 16 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 | |
|---|
| 18 | #include <epdfview.h> |
|---|
| 19 | #include "DumbDocument.h" |
|---|
| 20 | #include "DumbMainView.h" |
|---|
| 21 | #include "MainPterTest.h" |
|---|
| 22 | |
|---|
| 23 | using namespace ePDFView; |
|---|
| 24 | |
|---|
| 25 | G_LOCK_EXTERN (JobRender); |
|---|
| 26 | |
|---|
| 27 | // Register the test suite into the `registry'. |
|---|
| 28 | CPPUNIT_TEST_SUITE_REGISTRATION (MainPterTest); |
|---|
| 29 | |
|---|
| 30 | /// |
|---|
| 31 | /// @brief Sets up the environment for each test. |
|---|
| 32 | /// |
|---|
| 33 | void |
|---|
| 34 | MainPterTest::setUp () |
|---|
| 35 | { |
|---|
| 36 | m_Document = new DumbDocument (); |
|---|
| 37 | m_MainPter = new MainPter (m_Document); |
|---|
| 38 | m_View = new DumbMainView (m_MainPter); |
|---|
| 39 | m_MainPter->setView (m_View); |
|---|
| 40 | Config::loadFile (FALSE); |
|---|
| 41 | G_LOCK (JobRender); |
|---|
| 42 | JobRender::m_CanProcessJobs = TRUE; |
|---|
| 43 | G_UNLOCK (JobRender); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | /// |
|---|
| 47 | /// @brief Cleans up after each test. |
|---|
| 48 | /// |
|---|
| 49 | void |
|---|
| 50 | MainPterTest::tearDown () |
|---|
| 51 | { |
|---|
| 52 | G_LOCK (JobRender); |
|---|
| 53 | JobRender::m_CanProcessJobs = FALSE; |
|---|
| 54 | IJob::clearQueue (); |
|---|
| 55 | G_UNLOCK (JobRender); |
|---|
| 56 | // We only need to delete the presenter, as all other |
|---|
| 57 | // classes are deleted by it. |
|---|
| 58 | delete m_MainPter; |
|---|
| 59 | // Drop the current configuration. |
|---|
| 60 | Config::destroy (); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | /// |
|---|
| 65 | /// @brief Tests the initial status of the main presenter. |
|---|
| 66 | /// |
|---|
| 67 | /// Initially the presenter hasn't loaded a document, yet, so |
|---|
| 68 | /// the main window's title is 'PDF Viewer', the page selection |
|---|
| 69 | /// and zoom actions are insensitive and the documentView has |
|---|
| 70 | /// no image yet. Also the side bar won't be displayed, yet. |
|---|
| 71 | /// |
|---|
| 72 | void |
|---|
| 73 | MainPterTest::initialStatus () |
|---|
| 74 | { |
|---|
| 75 | CPPUNIT_ASSERT ( m_View->isShown () ); |
|---|
| 76 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 77 | g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); |
|---|
| 78 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 79 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); |
|---|
| 80 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); |
|---|
| 81 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPage ()); |
|---|
| 82 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 83 | CPPUNIT_ASSERT (!m_View->isSensitiveReload ()); |
|---|
| 84 | CPPUNIT_ASSERT (!m_View->isSensitiveRotateLeft ()); |
|---|
| 85 | CPPUNIT_ASSERT (!m_View->isSensitiveRotateRight ()); |
|---|
| 86 | CPPUNIT_ASSERT (!m_View->isSensitiveSave ()); |
|---|
| 87 | CPPUNIT_ASSERT (!m_View->isSensitiveZoom ()); |
|---|
| 88 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomIn ()); |
|---|
| 89 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); |
|---|
| 90 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomFit ()); |
|---|
| 91 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomWidth ()); |
|---|
| 92 | CPPUNIT_ASSERT (!m_View->isShownIndex ()); |
|---|
| 93 | CPPUNIT_ASSERT (m_View->isShownToolbar ()); |
|---|
| 94 | CPPUNIT_ASSERT (m_View->isShownStatusbar ()); |
|---|
| 95 | #if defined (HAVE_CUPS) |
|---|
| 96 | CPPUNIT_ASSERT (!m_View->isSensitivePrint ()); |
|---|
| 97 | #endif // HAVE_CUPS |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | /// |
|---|
| 101 | /// @brief Test loading a document. |
|---|
| 102 | /// |
|---|
| 103 | /// Loading a document will set the title to the document's title or the |
|---|
| 104 | /// document's file name, if it has no title. Also will sensitive the |
|---|
| 105 | /// go to next page, go to last page and all zoom actions. Also will |
|---|
| 106 | /// show the document's first page. Since this document don't have |
|---|
| 107 | /// outline, the sidebar won't be displayed. |
|---|
| 108 | /// |
|---|
| 109 | void |
|---|
| 110 | MainPterTest::loadDocument () |
|---|
| 111 | { |
|---|
| 112 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 113 | m_MainPter->openFileActivated (); |
|---|
| 114 | m_MainPter->waitForFileLoaded (); |
|---|
| 115 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 116 | g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); |
|---|
| 117 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 118 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 119 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 120 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 121 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 122 | CPPUNIT_ASSERT (m_View->isSensitiveReload ()); |
|---|
| 123 | CPPUNIT_ASSERT (m_View->isSensitiveRotateLeft ()); |
|---|
| 124 | CPPUNIT_ASSERT (m_View->isSensitiveRotateRight ()); |
|---|
| 125 | CPPUNIT_ASSERT (m_View->isSensitiveSave ()); |
|---|
| 126 | CPPUNIT_ASSERT (m_View->isSensitiveZoom ()); |
|---|
| 127 | CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); |
|---|
| 128 | CPPUNIT_ASSERT (m_View->isSensitiveZoomOut ()); |
|---|
| 129 | CPPUNIT_ASSERT (m_View->isSensitiveZoomFit ()); |
|---|
| 130 | CPPUNIT_ASSERT (m_View->isSensitiveZoomWidth ()); |
|---|
| 131 | CPPUNIT_ASSERT (!m_View->isShownIndex ()); |
|---|
| 132 | #if defined (HAVE_CUPS) |
|---|
| 133 | CPPUNIT_ASSERT (m_View->isSensitivePrint ()); |
|---|
| 134 | #endif // HAVE_CUPS |
|---|
| 135 | |
|---|
| 136 | // Now try a document with a title. |
|---|
| 137 | m_Document->setTitle (g_strdup ("Test PDF")); |
|---|
| 138 | m_MainPter->openFileActivated (); |
|---|
| 139 | m_MainPter->waitForFileLoaded (); |
|---|
| 140 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 141 | g_ascii_strcasecmp ("Test PDF", m_View->getTitle ())); |
|---|
| 142 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 143 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 144 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 145 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 146 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 147 | CPPUNIT_ASSERT (m_View->isSensitiveReload ()); |
|---|
| 148 | CPPUNIT_ASSERT (m_View->isSensitiveRotateLeft ()); |
|---|
| 149 | CPPUNIT_ASSERT (m_View->isSensitiveRotateRight ()); |
|---|
| 150 | CPPUNIT_ASSERT (m_View->isSensitiveSave ()); |
|---|
| 151 | CPPUNIT_ASSERT (m_View->isSensitiveZoom ()); |
|---|
| 152 | CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); |
|---|
| 153 | CPPUNIT_ASSERT (m_View->isSensitiveZoomOut ()); |
|---|
| 154 | CPPUNIT_ASSERT (m_View->isSensitiveZoomFit ()); |
|---|
| 155 | CPPUNIT_ASSERT (m_View->isSensitiveZoomWidth ()); |
|---|
| 156 | CPPUNIT_ASSERT (!m_View->isShownIndex ()); |
|---|
| 157 | #if defined (HAVE_CUPS) |
|---|
| 158 | CPPUNIT_ASSERT (m_View->isSensitivePrint ()); |
|---|
| 159 | #endif // HAVE_CUPS |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | /// |
|---|
| 163 | /// @brief Tests a canceled open file. |
|---|
| 164 | /// |
|---|
| 165 | /// When the user cancels the open dialog, then nothing should change. |
|---|
| 166 | /// |
|---|
| 167 | void |
|---|
| 168 | MainPterTest::loadCanceled () |
|---|
| 169 | { |
|---|
| 170 | // returning a NULL file name is what will happen when cancel. |
|---|
| 171 | m_View->setOpenFileName (NULL); |
|---|
| 172 | m_MainPter->openFileActivated (); |
|---|
| 173 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 174 | g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); |
|---|
| 175 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 176 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); |
|---|
| 177 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); |
|---|
| 178 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPage ()); |
|---|
| 179 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 180 | CPPUNIT_ASSERT (!m_View->isSensitiveReload ()); |
|---|
| 181 | CPPUNIT_ASSERT (!m_View->isSensitiveRotateLeft ()); |
|---|
| 182 | CPPUNIT_ASSERT (!m_View->isSensitiveRotateRight ()); |
|---|
| 183 | CPPUNIT_ASSERT (!m_View->isSensitiveSave ()); |
|---|
| 184 | CPPUNIT_ASSERT (!m_View->isSensitiveZoom ()); |
|---|
| 185 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomIn ()); |
|---|
| 186 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); |
|---|
| 187 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomFit ()); |
|---|
| 188 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomWidth ()); |
|---|
| 189 | CPPUNIT_ASSERT (!m_View->shownError ()); |
|---|
| 190 | #if defined (HAVE_CUPS) |
|---|
| 191 | CPPUNIT_ASSERT (!m_View->isSensitivePrint ()); |
|---|
| 192 | #endif // HAVE_CUPS |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | /// |
|---|
| 197 | /// @brief Test a failed load. |
|---|
| 198 | /// |
|---|
| 199 | /// A failed load (anything but a DocumentErrorNone and DocumentErrorEncrypted) |
|---|
| 200 | /// is very similar to the load canceled, but an error message is shown |
|---|
| 201 | /// to the user. |
|---|
| 202 | /// |
|---|
| 203 | void |
|---|
| 204 | MainPterTest::loadFailed () |
|---|
| 205 | { |
|---|
| 206 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 207 | m_Document->setOpenError (DocumentErrorDamaged); |
|---|
| 208 | m_MainPter->openFileActivated (); |
|---|
| 209 | m_MainPter->waitForFileLoaded (); |
|---|
| 210 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 211 | g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); |
|---|
| 212 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 213 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); |
|---|
| 214 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); |
|---|
| 215 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPage ()); |
|---|
| 216 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 217 | CPPUNIT_ASSERT (!m_View->isSensitiveReload ()); |
|---|
| 218 | CPPUNIT_ASSERT (!m_View->isSensitiveRotateLeft ()); |
|---|
| 219 | CPPUNIT_ASSERT (!m_View->isSensitiveRotateRight ()); |
|---|
| 220 | CPPUNIT_ASSERT (!m_View->isSensitiveSave ()); |
|---|
| 221 | CPPUNIT_ASSERT (!m_View->isSensitiveZoom ()); |
|---|
| 222 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomIn ()); |
|---|
| 223 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); |
|---|
| 224 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomFit ()); |
|---|
| 225 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomWidth ()); |
|---|
| 226 | CPPUNIT_ASSERT (m_View->shownError ()); |
|---|
| 227 | #if defined (HAVE_CUPS) |
|---|
| 228 | CPPUNIT_ASSERT (!m_View->isSensitivePrint ()); |
|---|
| 229 | #endif // HAVE_CUPS |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | /// |
|---|
| 233 | /// @brief Test a canceled password. |
|---|
| 234 | /// |
|---|
| 235 | /// A canceled password is more or less the same as canceling the loading |
|---|
| 236 | /// of a file. It's when the user tried to open an encrypted file, but when |
|---|
| 237 | /// the password is prompted, then it cancels :-) |
|---|
| 238 | /// It should happen the same as when canceling the open file dialog. |
|---|
| 239 | /// |
|---|
| 240 | void |
|---|
| 241 | MainPterTest::canceledPassword () |
|---|
| 242 | { |
|---|
| 243 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 244 | m_View->setPassword (NULL); |
|---|
| 245 | m_Document->setOpenError (DocumentErrorEncrypted); |
|---|
| 246 | m_MainPter->openFileActivated (); |
|---|
| 247 | m_MainPter->waitForFileLoaded (); |
|---|
| 248 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 249 | g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); |
|---|
| 250 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 251 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); |
|---|
| 252 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); |
|---|
| 253 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPage ()); |
|---|
| 254 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 255 | CPPUNIT_ASSERT (!m_View->isSensitiveReload ()); |
|---|
| 256 | CPPUNIT_ASSERT (!m_View->isSensitiveRotateLeft ()); |
|---|
| 257 | CPPUNIT_ASSERT (!m_View->isSensitiveRotateRight ()); |
|---|
| 258 | CPPUNIT_ASSERT (!m_View->isSensitiveSave ()); |
|---|
| 259 | CPPUNIT_ASSERT (!m_View->isSensitiveZoom ()); |
|---|
| 260 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomIn ()); |
|---|
| 261 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); |
|---|
| 262 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomFit ()); |
|---|
| 263 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomWidth ()); |
|---|
| 264 | CPPUNIT_ASSERT (!m_View->shownError ()); |
|---|
| 265 | #if defined (HAVE_CUPS) |
|---|
| 266 | CPPUNIT_ASSERT (!m_View->isSensitivePrint ()); |
|---|
| 267 | #endif // HAVE_CUPS |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | /// |
|---|
| 271 | /// @brief Test a bad password. |
|---|
| 272 | /// |
|---|
| 273 | /// This test is very similar to the previous, but this time the user |
|---|
| 274 | /// enters a bad password, trying to guess which is the correct password. |
|---|
| 275 | /// The presenter gives up after three times and shows an error message. |
|---|
| 276 | /// |
|---|
| 277 | void |
|---|
| 278 | MainPterTest::badPassword () |
|---|
| 279 | { |
|---|
| 280 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 281 | m_View->setPassword ("badpassword"); |
|---|
| 282 | m_Document->setTestPassword ("goodpassword"); |
|---|
| 283 | m_Document->setOpenError (DocumentErrorEncrypted); |
|---|
| 284 | m_MainPter->openFileActivated (); |
|---|
| 285 | m_MainPter->waitForFileLoaded (); |
|---|
| 286 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 287 | g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); |
|---|
| 288 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 289 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); |
|---|
| 290 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); |
|---|
| 291 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPage ()); |
|---|
| 292 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 293 | CPPUNIT_ASSERT (!m_View->isSensitiveReload ()); |
|---|
| 294 | CPPUNIT_ASSERT (!m_View->isSensitiveRotateLeft ()); |
|---|
| 295 | CPPUNIT_ASSERT (!m_View->isSensitiveRotateRight ()); |
|---|
| 296 | CPPUNIT_ASSERT (!m_View->isSensitiveSave ()); |
|---|
| 297 | CPPUNIT_ASSERT (!m_View->isSensitiveZoom ()); |
|---|
| 298 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomIn ()); |
|---|
| 299 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); |
|---|
| 300 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomFit ()); |
|---|
| 301 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomWidth ()); |
|---|
| 302 | CPPUNIT_ASSERT (m_View->shownError ()); |
|---|
| 303 | CPPUNIT_ASSERT_EQUAL (3, m_View->countTimesShownPasswordPrompt ()); |
|---|
| 304 | #if defined (HAVE_CUPS) |
|---|
| 305 | CPPUNIT_ASSERT (!m_View->isSensitivePrint ()); |
|---|
| 306 | #endif // HAVE_CUPS |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | /// |
|---|
| 310 | /// @brief Test a good password. |
|---|
| 311 | /// |
|---|
| 312 | /// This test just check that giving the correct password opens the |
|---|
| 313 | /// file correctly. |
|---|
| 314 | /// |
|---|
| 315 | void |
|---|
| 316 | MainPterTest::goodPassword () |
|---|
| 317 | { |
|---|
| 318 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 319 | m_View->setPassword ("goodpassword"); |
|---|
| 320 | m_Document->setTestPassword ("goodpassword"); |
|---|
| 321 | m_Document->setOpenError (DocumentErrorEncrypted); |
|---|
| 322 | m_MainPter->openFileActivated (); |
|---|
| 323 | m_MainPter->waitForFileLoaded (); |
|---|
| 324 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 325 | g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); |
|---|
| 326 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 327 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 328 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 329 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 330 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 331 | CPPUNIT_ASSERT (m_View->isSensitiveReload ()); |
|---|
| 332 | CPPUNIT_ASSERT (m_View->isSensitiveRotateLeft ()); |
|---|
| 333 | CPPUNIT_ASSERT (m_View->isSensitiveRotateRight ()); |
|---|
| 334 | CPPUNIT_ASSERT (m_View->isSensitiveSave ()); |
|---|
| 335 | CPPUNIT_ASSERT (m_View->isSensitiveZoom ()); |
|---|
| 336 | CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); |
|---|
| 337 | CPPUNIT_ASSERT (m_View->isSensitiveZoomOut ()); |
|---|
| 338 | CPPUNIT_ASSERT (m_View->isSensitiveZoomFit ()); |
|---|
| 339 | CPPUNIT_ASSERT (m_View->isSensitiveZoomWidth ()); |
|---|
| 340 | CPPUNIT_ASSERT (!m_View->shownError ()); |
|---|
| 341 | CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); |
|---|
| 342 | #if defined (HAVE_CUPS) |
|---|
| 343 | CPPUNIT_ASSERT (m_View->isSensitivePrint ()); |
|---|
| 344 | #endif // HAVE_CUPS |
|---|
| 345 | } |
|---|
| 346 | |
|---|
| 347 | /// |
|---|
| 348 | /// @brief Test the last folder used to open a file. |
|---|
| 349 | /// |
|---|
| 350 | /// When the presenter wants to open a file, it should pass to the |
|---|
| 351 | /// view the last folder that was used to open a file, so the |
|---|
| 352 | /// view can show it up when opening the dialog. |
|---|
| 353 | /// |
|---|
| 354 | void |
|---|
| 355 | MainPterTest::openLastFolder () |
|---|
| 356 | { |
|---|
| 357 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 358 | m_MainPter->openFileActivated (); |
|---|
| 359 | m_MainPter->waitForFileLoaded (); |
|---|
| 360 | CPPUNIT_ASSERT (NULL == m_View->getLastOpenFileFolder ()); |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | m_View->setOpenFileName ("/usr/test.pdf"); |
|---|
| 364 | m_MainPter->openFileActivated (); |
|---|
| 365 | m_MainPter->waitForFileLoaded (); |
|---|
| 366 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/tmp", |
|---|
| 367 | m_View->getLastOpenFileFolder ())); |
|---|
| 368 | |
|---|
| 369 | m_MainPter->openFileActivated (); |
|---|
| 370 | m_MainPter->waitForFileLoaded (); |
|---|
| 371 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/usr", |
|---|
| 372 | m_View->getLastOpenFileFolder ())); |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | /// |
|---|
| 376 | /// @brief Test saving a document. |
|---|
| 377 | /// |
|---|
| 378 | /// Saving a document will call the saveFile() function of the document's class. |
|---|
| 379 | /// |
|---|
| 380 | void |
|---|
| 381 | MainPterTest::saveDocument () |
|---|
| 382 | { |
|---|
| 383 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 384 | m_MainPter->openFileActivated (); |
|---|
| 385 | m_MainPter->waitForFileLoaded (); |
|---|
| 386 | m_View->setSaveFileName ("/tmp/copy.pdf"); |
|---|
| 387 | m_MainPter->saveFileActivated (); |
|---|
| 388 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/tmp/copy.pdf", |
|---|
| 389 | m_Document->getSavedFileName ())); |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | /// |
|---|
| 393 | /// @brief Tests a canceled save file. |
|---|
| 394 | /// |
|---|
| 395 | /// When the user cancels the save dialog, then nothing should be saved. |
|---|
| 396 | /// |
|---|
| 397 | void |
|---|
| 398 | MainPterTest::saveCanceled () |
|---|
| 399 | { |
|---|
| 400 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 401 | m_MainPter->openFileActivated (); |
|---|
| 402 | m_MainPter->waitForFileLoaded (); |
|---|
| 403 | // returning a NULL file name is what will happen when cancel. |
|---|
| 404 | m_View->setSaveFileName (NULL); |
|---|
| 405 | m_MainPter->saveFileActivated (); |
|---|
| 406 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("", |
|---|
| 407 | m_Document->getSavedFileName ())); |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | /// |
|---|
| 411 | /// @brief Test the last folder used to save a file. |
|---|
| 412 | /// |
|---|
| 413 | /// When the presenter wants to save a file, it should pass to the |
|---|
| 414 | /// view the last folder that was used to save a file, so the |
|---|
| 415 | /// view can show it up when saving the dialog. |
|---|
| 416 | /// |
|---|
| 417 | void |
|---|
| 418 | MainPterTest::saveLastFolder () |
|---|
| 419 | { |
|---|
| 420 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 421 | m_MainPter->openFileActivated (); |
|---|
| 422 | m_MainPter->waitForFileLoaded (); |
|---|
| 423 | m_View->setSaveFileName ("/tmp/copy.pdf"); |
|---|
| 424 | m_MainPter->saveFileActivated (); |
|---|
| 425 | m_MainPter->waitForFileSaved (); |
|---|
| 426 | CPPUNIT_ASSERT (NULL == m_View->getLastSaveFileFolder ()); |
|---|
| 427 | |
|---|
| 428 | |
|---|
| 429 | m_View->setSaveFileName ("/usr/copy.pdf"); |
|---|
| 430 | m_MainPter->saveFileActivated (); |
|---|
| 431 | m_MainPter->waitForFileSaved (); |
|---|
| 432 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/tmp", |
|---|
| 433 | m_View->getLastSaveFileFolder ())); |
|---|
| 434 | |
|---|
| 435 | m_MainPter->saveFileActivated (); |
|---|
| 436 | m_MainPter->waitForFileSaved (); |
|---|
| 437 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/usr", |
|---|
| 438 | m_View->getLastSaveFileFolder ())); |
|---|
| 439 | |
|---|
| 440 | } |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | /// |
|---|
| 444 | /// @brief Test page navigation. |
|---|
| 445 | /// |
|---|
| 446 | /// I'll load a 4-pages document and will try to go to the first, last, next, |
|---|
| 447 | /// previous and also on a page using the entry on the toolbar. |
|---|
| 448 | /// |
|---|
| 449 | void |
|---|
| 450 | MainPterTest::pageNavigation () |
|---|
| 451 | { |
|---|
| 452 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 453 | m_Document->setNumPages (4); |
|---|
| 454 | m_MainPter->openFileActivated (); |
|---|
| 455 | m_MainPter->waitForFileLoaded (); |
|---|
| 456 | // Check that sets the correct current page. |
|---|
| 457 | CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ()); |
|---|
| 458 | // Going to the next page should make all actions sensitive. |
|---|
| 459 | m_MainPter->goToNextPageActivated (); |
|---|
| 460 | CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); |
|---|
| 461 | CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); |
|---|
| 462 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 463 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 464 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 465 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 466 | // Going to the last will make some insensitive. |
|---|
| 467 | m_MainPter->goToLastPageActivated (); |
|---|
| 468 | CPPUNIT_ASSERT_EQUAL (4, m_View->getCurrentPage ()); |
|---|
| 469 | CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); |
|---|
| 470 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); |
|---|
| 471 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); |
|---|
| 472 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 473 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 474 | // Again to the last won't harm (just in case...) nor going next. |
|---|
| 475 | m_MainPter->goToLastPageActivated (); |
|---|
| 476 | m_MainPter->goToNextPageActivated (); |
|---|
| 477 | CPPUNIT_ASSERT_EQUAL (4, m_View->getCurrentPage ()); |
|---|
| 478 | CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); |
|---|
| 479 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); |
|---|
| 480 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); |
|---|
| 481 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 482 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 483 | // But going to the previous will change something. |
|---|
| 484 | m_MainPter->goToPreviousPageActivated (); |
|---|
| 485 | CPPUNIT_ASSERT_EQUAL (3, m_View->getCurrentPage ()); |
|---|
| 486 | CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); |
|---|
| 487 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 488 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 489 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 490 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 491 | // Now, to the first again. |
|---|
| 492 | m_MainPter->goToFirstPageActivated (); |
|---|
| 493 | CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ()); |
|---|
| 494 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 495 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 496 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 497 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 498 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 499 | // Check sane behaviour. |
|---|
| 500 | m_MainPter->goToFirstPageActivated (); |
|---|
| 501 | m_MainPter->goToPreviousPageActivated (); |
|---|
| 502 | CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ()); |
|---|
| 503 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 504 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 505 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 506 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 507 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | /// |
|---|
| 511 | /// @brief Test the page navigation using the entry on the toolbar. |
|---|
| 512 | /// |
|---|
| 513 | /// The application has a text entry that the user can use to to a |
|---|
| 514 | /// page just by writing the number. Any non number after the first number |
|---|
| 515 | /// character will be discarded. |
|---|
| 516 | /// |
|---|
| 517 | void |
|---|
| 518 | MainPterTest::pageNavigationEntry () |
|---|
| 519 | { |
|---|
| 520 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 521 | m_Document->setNumPages (4); |
|---|
| 522 | m_MainPter->openFileActivated (); |
|---|
| 523 | m_MainPter->waitForFileLoaded (); |
|---|
| 524 | // Check that sets the correct current page. |
|---|
| 525 | CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ()); |
|---|
| 526 | |
|---|
| 527 | // Now try again using the page entry on toolbar. |
|---|
| 528 | m_View->setGoToPageText ("2 of 4"); |
|---|
| 529 | m_MainPter->goToPageActivated (); |
|---|
| 530 | CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); |
|---|
| 531 | CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); |
|---|
| 532 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 533 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 534 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 535 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 536 | |
|---|
| 537 | m_View->setGoToPageText ("4 of 4"); |
|---|
| 538 | m_MainPter->goToPageActivated (); |
|---|
| 539 | CPPUNIT_ASSERT_EQUAL (4, m_View->getCurrentPage ()); |
|---|
| 540 | CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); |
|---|
| 541 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); |
|---|
| 542 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); |
|---|
| 543 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 544 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 545 | |
|---|
| 546 | m_View->setGoToPageText ("1 of 4"); |
|---|
| 547 | m_MainPter->goToPageActivated (); |
|---|
| 548 | CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ()); |
|---|
| 549 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 550 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 551 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 552 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 553 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 554 | |
|---|
| 555 | // Invalid values. Remains to the same page. |
|---|
| 556 | m_View->setGoToPageText ("123123 of 1"); |
|---|
| 557 | m_MainPter->goToPageActivated (); |
|---|
| 558 | CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ()); |
|---|
| 559 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 560 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 561 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 562 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 563 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 564 | |
|---|
| 565 | m_View->setGoToPageText ("0 of 12"); |
|---|
| 566 | m_MainPter->goToPageActivated (); |
|---|
| 567 | CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ()); |
|---|
| 568 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); |
|---|
| 569 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 570 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 571 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 572 | CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 573 | |
|---|
| 574 | m_MainPter->goToNextPageActivated (); |
|---|
| 575 | m_View->setGoToPageText ("Jejej :-)"); |
|---|
| 576 | m_MainPter->goToPageActivated (); |
|---|
| 577 | CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); |
|---|
| 578 | CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); |
|---|
| 579 | CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); |
|---|
| 580 | CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); |
|---|
| 581 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); |
|---|
| 582 | CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); |
|---|
| 583 | } |
|---|
| 584 | |
|---|
| 585 | /// |
|---|
| 586 | /// @brief Test the rotation of the page. |
|---|
| 587 | /// |
|---|
| 588 | /// This is a very simple test about page rotation. |
|---|
| 589 | /// |
|---|
| 590 | void |
|---|
| 591 | MainPterTest::pageRotate () |
|---|
| 592 | { |
|---|
| 593 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 594 | m_MainPter->openFileActivated (); |
|---|
| 595 | m_MainPter->waitForFileLoaded (); |
|---|
| 596 | CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); |
|---|
| 597 | |
|---|
| 598 | m_MainPter->rotateRightActivated (); |
|---|
| 599 | CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); |
|---|
| 600 | |
|---|
| 601 | m_MainPter->rotateLeftActivated (); |
|---|
| 602 | CPPUNIT_ASSERT_EQUAL (0, m_Document->getRotation ()); |
|---|
| 603 | } |
|---|
| 604 | |
|---|
| 605 | /// |
|---|
| 606 | /// @brief Tests page's zoom. |
|---|
| 607 | /// |
|---|
| 608 | /// The DumbDocument has a fixed size of 100x250 pixels and the DumbMainView |
|---|
| 609 | /// has a fixed pageView of 75x50. We will make sure that getting to the max |
|---|
| 610 | /// ZoomIn insensitives the ZoomIn button. The same for the ZoomOut. |
|---|
| 611 | /// |
|---|
| 612 | /// |
|---|
| 613 | void |
|---|
| 614 | MainPterTest::pageZoomInAndOut () |
|---|
| 615 | { |
|---|
| 616 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 617 | m_MainPter->openFileActivated (); |
|---|
| 618 | m_MainPter->waitForFileLoaded (); |
|---|
| 619 | CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); |
|---|
| 620 | |
|---|
| 621 | m_MainPter->zoomInActivated (); |
|---|
| 622 | CPPUNIT_ASSERT_DOUBLES_EQUAL (1.2, m_Document->getZoom (), 0.0001); |
|---|
| 623 | |
|---|
| 624 | m_MainPter->zoomOutActivated (); |
|---|
| 625 | CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); |
|---|
| 626 | |
|---|
| 627 | CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); |
|---|
| 628 | CPPUNIT_ASSERT (m_View->isSensitiveZoomOut ()); |
|---|
| 629 | // Make sure we go to the last zoom level. |
|---|
| 630 | for (int count = 0 ; count < 20 ; count++) |
|---|
| 631 | { |
|---|
| 632 | m_MainPter->zoomInActivated (); |
|---|
| 633 | } |
|---|
| 634 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomIn ()); |
|---|
| 635 | CPPUNIT_ASSERT (m_View->isSensitiveZoomOut ()); |
|---|
| 636 | for (int count = 0 ; count < 40 ; count ++) |
|---|
| 637 | { |
|---|
| 638 | m_MainPter->zoomOutActivated (); |
|---|
| 639 | } |
|---|
| 640 | CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); |
|---|
| 641 | CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); |
|---|
| 642 | } |
|---|
| 643 | |
|---|
| 644 | /// |
|---|
| 645 | /// @brief Tests page's zoom to width |
|---|
| 646 | /// |
|---|
| 647 | void |
|---|
| 648 | MainPterTest::pageZoomWidth () |
|---|
| 649 | { |
|---|
| 650 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 651 | m_MainPter->openFileActivated (); |
|---|
| 652 | m_MainPter->waitForFileLoaded (); |
|---|
| 653 | |
|---|
| 654 | m_MainPter->zoomWidthActivated (TRUE); |
|---|
| 655 | CPPUNIT_ASSERT (m_View->isZoomToWidthActive ()); |
|---|
| 656 | m_MainPter->zoomWidthActivated (FALSE); |
|---|
| 657 | CPPUNIT_ASSERT (!m_View->isZoomToWidthActive ()); |
|---|
| 658 | m_MainPter->zoomWidthActivated (TRUE); |
|---|
| 659 | CPPUNIT_ASSERT (m_View->isZoomToWidthActive ()); |
|---|
| 660 | // Changing any of the zoom in or zoom out features should make the |
|---|
| 661 | // zoom to width not being active. |
|---|
| 662 | m_MainPter->zoomInActivated (); |
|---|
| 663 | CPPUNIT_ASSERT (!m_View->isZoomToWidthActive ()); |
|---|
| 664 | m_MainPter->zoomWidthActivated (TRUE); |
|---|
| 665 | m_MainPter->zoomOutActivated (); |
|---|
| 666 | CPPUNIT_ASSERT (!m_View->isZoomToWidthActive ()); |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | /// |
|---|
| 670 | /// @brief Tests page's zoom to fit |
|---|
| 671 | /// |
|---|
| 672 | void |
|---|
| 673 | MainPterTest::pageZoomFit () |
|---|
| 674 | { |
|---|
| 675 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 676 | m_MainPter->openFileActivated (); |
|---|
| 677 | m_MainPter->waitForFileLoaded (); |
|---|
| 678 | |
|---|
| 679 | m_MainPter->zoomFitActivated (TRUE); |
|---|
| 680 | CPPUNIT_ASSERT (m_View->isZoomToFitActive ()); |
|---|
| 681 | m_MainPter->zoomFitActivated (FALSE); |
|---|
| 682 | CPPUNIT_ASSERT (!m_View->isZoomToFitActive ()); |
|---|
| 683 | m_MainPter->zoomFitActivated (TRUE); |
|---|
| 684 | CPPUNIT_ASSERT (m_View->isZoomToFitActive ()); |
|---|
| 685 | // Changing any of the zoom in or zoom out features should make the |
|---|
| 686 | // zoom to fit not being active. |
|---|
| 687 | m_MainPter->zoomInActivated (); |
|---|
| 688 | CPPUNIT_ASSERT (!m_View->isZoomToFitActive ()); |
|---|
| 689 | m_MainPter->zoomFitActivated (TRUE); |
|---|
| 690 | m_MainPter->zoomOutActivated (); |
|---|
| 691 | CPPUNIT_ASSERT (!m_View->isZoomToFitActive ()); |
|---|
| 692 | } |
|---|
| 693 | |
|---|
| 694 | /// |
|---|
| 695 | /// @brief Checks rotation and zoom. |
|---|
| 696 | /// |
|---|
| 697 | /// This tests that rotation while the zoom to width or zoom to |
|---|
| 698 | /// fit are activated also changed the zoom level. |
|---|
| 699 | /// |
|---|
| 700 | void |
|---|
| 701 | MainPterTest::pageZoomAndRotate () |
|---|
| 702 | { |
|---|
| 703 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 704 | m_MainPter->openFileActivated (); |
|---|
| 705 | m_MainPter->waitForFileLoaded (); |
|---|
| 706 | CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); |
|---|
| 707 | |
|---|
| 708 | // The document is 100x250 and the page view 75x50. |
|---|
| 709 | // ZoomToWidth 75/100 = 0.75 |
|---|
| 710 | m_MainPter->zoomWidthActivated (TRUE); |
|---|
| 711 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); |
|---|
| 712 | // Rotate left. 75/250 = 0.3 |
|---|
| 713 | m_MainPter->rotateLeftActivated (); |
|---|
| 714 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); |
|---|
| 715 | m_MainPter->rotateRightActivated (); |
|---|
| 716 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); |
|---|
| 717 | m_MainPter->rotateRightActivated (); |
|---|
| 718 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); |
|---|
| 719 | m_MainPter->rotateLeftActivated (); |
|---|
| 720 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); |
|---|
| 721 | |
|---|
| 722 | // Now try the same with zoom to fit. |
|---|
| 723 | // 50/250 = 0.2 |
|---|
| 724 | m_MainPter->zoomFitActivated (TRUE); |
|---|
| 725 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); |
|---|
| 726 | // Rotate left, 75/250 = 0.3 |
|---|
| 727 | m_MainPter->rotateLeftActivated (); |
|---|
| 728 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); |
|---|
| 729 | m_MainPter->rotateRightActivated (); |
|---|
| 730 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); |
|---|
| 731 | m_MainPter->rotateRightActivated (); |
|---|
| 732 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); |
|---|
| 733 | m_MainPter->rotateLeftActivated (); |
|---|
| 734 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); |
|---|
| 735 | } |
|---|
| 736 | |
|---|
| 737 | /// |
|---|
| 738 | /// @brief Test the current zoom level indicator. |
|---|
| 739 | /// |
|---|
| 740 | /// The main view has an entry in the tool bar that tells the user |
|---|
| 741 | /// which is the current document's zoom level. Also, when the user |
|---|
| 742 | /// enter a new zoom level and presses ENTER, the new zoom level is |
|---|
| 743 | /// used. |
|---|
| 744 | /// |
|---|
| 745 | void |
|---|
| 746 | MainPterTest::pageZoomIndicator () |
|---|
| 747 | { |
|---|
| 748 | // When the open is first opened, the zoom is 100%. |
|---|
| 749 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 750 | m_MainPter->openFileActivated (); |
|---|
| 751 | m_MainPter->waitForFileLoaded (); |
|---|
| 752 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("100%", m_View->getZoomText ())); |
|---|
| 753 | |
|---|
| 754 | // Try changing a little the zoom level. |
|---|
| 755 | m_MainPter->zoomInActivated (); |
|---|
| 756 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("120%", m_View->getZoomText ())); |
|---|
| 757 | m_MainPter->zoomInActivated (); |
|---|
| 758 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("144%", m_View->getZoomText ())); |
|---|
| 759 | m_MainPter->zoomOutActivated (); |
|---|
| 760 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("120%", m_View->getZoomText ())); |
|---|
| 761 | m_MainPter->zoomOutActivated (); |
|---|
| 762 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("100%", m_View->getZoomText ())); |
|---|
| 763 | m_MainPter->zoomOutActivated (); |
|---|
| 764 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("83.3%", m_View->getZoomText ())); |
|---|
| 765 | |
|---|
| 766 | // Now try to set the zoom level by hand. If the zoom level is |
|---|
| 767 | // clamped 400% and 5.41%. |
|---|
| 768 | m_View->setZoomText ("50%"); |
|---|
| 769 | m_MainPter->zoomActivated (); |
|---|
| 770 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.5, m_Document->getZoom (), 0.0001); |
|---|
| 771 | m_View->setZoomText ("1000%"); |
|---|
| 772 | m_MainPter->zoomActivated (); |
|---|
| 773 | CPPUNIT_ASSERT_DOUBLES_EQUAL (4.0, m_Document->getZoom (), 0.0001); |
|---|
| 774 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("400%", m_View->getZoomText ())); |
|---|
| 775 | m_View->setZoomText ("1"); |
|---|
| 776 | m_MainPter->zoomActivated (); |
|---|
| 777 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.0541, m_Document->getZoom (), 0.0001); |
|---|
| 778 | CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("5.41%", m_View->getZoomText ())); |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | /// |
|---|
| 782 | /// @brief Test to reload a normal document. |
|---|
| 783 | /// |
|---|
| 784 | /// A "normal" document is a non encrypted document. The document |
|---|
| 785 | /// should then be viewed at the same page, scale an rotation. |
|---|
| 786 | /// |
|---|
| 787 | void |
|---|
| 788 | MainPterTest::reloadNormal () |
|---|
| 789 | { |
|---|
| 790 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 791 | m_MainPter->openFileActivated (); |
|---|
| 792 | m_MainPter->waitForFileLoaded (); |
|---|
| 793 | |
|---|
| 794 | m_MainPter->goToNextPageActivated (); |
|---|
| 795 | m_MainPter->rotateRightActivated (); |
|---|
| 796 | m_MainPter->zoomWidthActivated (TRUE); |
|---|
| 797 | CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); |
|---|
| 798 | CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); |
|---|
| 799 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); |
|---|
| 800 | |
|---|
| 801 | // Reload the document. |
|---|
| 802 | m_MainPter->reloadActivated (); |
|---|
| 803 | m_MainPter->waitForFileLoaded (); |
|---|
| 804 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 805 | g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); |
|---|
| 806 | CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); |
|---|
| 807 | CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); |
|---|
| 808 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); |
|---|
| 809 | } |
|---|
| 810 | |
|---|
| 811 | /// |
|---|
| 812 | /// @brief Tries to reload an encrypted file. |
|---|
| 813 | /// |
|---|
| 814 | /// Reloading an encrypted file won't ask for the password unless it changed, |
|---|
| 815 | /// but here we assume that don't |
|---|
| 816 | /// |
|---|
| 817 | void |
|---|
| 818 | MainPterTest::reloadEncrypted () |
|---|
| 819 | { |
|---|
| 820 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 821 | m_View->setPassword ("goodpassword"); |
|---|
| 822 | m_Document->setTestPassword ("goodpassword"); |
|---|
| 823 | m_Document->setOpenError (DocumentErrorEncrypted); |
|---|
| 824 | m_MainPter->openFileActivated (); |
|---|
| 825 | m_MainPter->waitForFileLoaded (); |
|---|
| 826 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 827 | g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); |
|---|
| 828 | |
|---|
| 829 | m_MainPter->goToNextPageActivated (); |
|---|
| 830 | m_MainPter->rotateRightActivated (); |
|---|
| 831 | m_MainPter->zoomWidthActivated (TRUE); |
|---|
| 832 | CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); |
|---|
| 833 | CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); |
|---|
| 834 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); |
|---|
| 835 | |
|---|
| 836 | // Reload the document. |
|---|
| 837 | m_View->setPassword ("badpassword"); |
|---|
| 838 | m_Document->setTestPassword ("goodpassword"); |
|---|
| 839 | m_Document->setOpenError (DocumentErrorEncrypted); |
|---|
| 840 | m_MainPter->reloadActivated (); |
|---|
| 841 | m_MainPter->waitForFileLoaded (); |
|---|
| 842 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 843 | g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); |
|---|
| 844 | CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); |
|---|
| 845 | CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); |
|---|
| 846 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); |
|---|
| 847 | CPPUNIT_ASSERT (!m_View->shownError ()); |
|---|
| 848 | CPPUNIT_ASSERT_EQUAL (0, m_View->countTimesShownPasswordPrompt ()); |
|---|
| 849 | } |
|---|
| 850 | |
|---|
| 851 | /// |
|---|
| 852 | /// @brief Tries to reload an encrypted file whose password changed. |
|---|
| 853 | /// |
|---|
| 854 | /// Reloading an encrypted file won't ask for the password unless it changed. |
|---|
| 855 | /// If the password changed, then the document starts on the first page. |
|---|
| 856 | /// |
|---|
| 857 | void |
|---|
| 858 | MainPterTest::reloadChangedPassword () |
|---|
| 859 | { |
|---|
| 860 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 861 | m_View->setPassword ("goodpassword"); |
|---|
| 862 | m_Document->setTestPassword ("goodpassword"); |
|---|
| 863 | m_Document->setOpenError (DocumentErrorEncrypted); |
|---|
| 864 | m_MainPter->openFileActivated (); |
|---|
| 865 | m_MainPter->waitForFileLoaded (); |
|---|
| 866 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 867 | g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); |
|---|
| 868 | |
|---|
| 869 | m_MainPter->goToNextPageActivated (); |
|---|
| 870 | m_MainPter->rotateRightActivated (); |
|---|
| 871 | m_MainPter->zoomWidthActivated (TRUE); |
|---|
| 872 | CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); |
|---|
| 873 | CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); |
|---|
| 874 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); |
|---|
| 875 | |
|---|
| 876 | // Reload the document. |
|---|
| 877 | m_View->setPassword ("newpassword"); |
|---|
| 878 | m_Document->setTestPassword ("newpassword"); |
|---|
| 879 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 880 | g_ascii_strcasecmp("goodpassword", m_Document->getPassword ())); |
|---|
| 881 | m_Document->setOpenError (DocumentErrorEncrypted); |
|---|
| 882 | m_MainPter->reloadActivated (); |
|---|
| 883 | m_MainPter->waitForFileLoaded (); |
|---|
| 884 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 885 | g_ascii_strcasecmp("newpassword", m_Document->getPassword ())); |
|---|
| 886 | CPPUNIT_ASSERT_EQUAL (0, |
|---|
| 887 | g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); |
|---|
| 888 | CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); |
|---|
| 889 | CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); |
|---|
| 890 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); |
|---|
| 891 | CPPUNIT_ASSERT (!m_View->shownError ()); |
|---|
| 892 | CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); |
|---|
| 893 | } |
|---|
| 894 | |
|---|
| 895 | /// |
|---|
| 896 | /// @brief Checks that the index is shown when a document has outline. |
|---|
| 897 | /// |
|---|
| 898 | /// When the presenter needs to show the outline, it just passes the root |
|---|
| 899 | /// outline item to the view, and the view must then render it whatever it |
|---|
| 900 | /// can (a GtkTreeView in GTK, etc...) |
|---|
| 901 | /// |
|---|
| 902 | void |
|---|
| 903 | MainPterTest::showIndex () |
|---|
| 904 | { |
|---|
| 905 | DocumentOutline *outline = new DocumentOutline (); |
|---|
| 906 | DocumentOutline *child = new DocumentOutline (); |
|---|
| 907 | child->setParent (outline); |
|---|
| 908 | child->setTitle ("Outline 1"); |
|---|
| 909 | child->setDestination (2); |
|---|
| 910 | outline->addChild (child); |
|---|
| 911 | m_Document->setPageMode (PageModeOutlines); |
|---|
| 912 | m_Document->setOutline (outline); |
|---|
| 913 | m_Document->setNumPages (4); |
|---|
| 914 | |
|---|
| 915 | m_View->setOpenFileName ("/tmp/test.pdf"); |
|---|
| 916 | m_MainPter->openFileActivated (); |
|---|
| 917 | m_MainPter->waitForFileLoaded (); |
|---|
| 918 | CPPUNIT_ASSERT (m_View->isShownIndex ()); |
|---|
| 919 | CPPUNIT_ASSERT (outline == m_View->getOutline ()); |
|---|
| 920 | |
|---|
| 921 | // When the user does click on a outline item, the view |
|---|
| 922 | // sends to the presenter the outline that has been activated. |
|---|
| 923 | // Then the presenter goes to that page. |
|---|
| 924 | m_MainPter->outlineActivated (child); |
|---|
| 925 | CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); |
|---|
| 926 | |
|---|
| 927 | // When the user clicks on the "Show Index" option, the |
|---|
| 928 | // index should hide. Another click and the index should |
|---|
| 929 | // appear. |
|---|
| 930 | m_MainPter->showIndexActivated (FALSE); |
|---|
| 931 | CPPUNIT_ASSERT (!m_View->isShownIndex ()); |
|---|
| 932 | m_MainPter->showIndexActivated (TRUE); |
|---|
| 933 | CPPUNIT_ASSERT (m_View->isShownIndex ()); |
|---|
| 934 | } |
|---|
| 935 | |
|---|
| 936 | /// |
|---|
| 937 | /// @brief Checks showing and hidding the tool bar and status bar. |
|---|
| 938 | /// |
|---|
| 939 | void |
|---|
| 940 | MainPterTest::showToolAndStatusBars () |
|---|
| 941 | { |
|---|
| 942 | m_MainPter->showToolbarActivated (FALSE); |
|---|
| 943 | m_MainPter->showStatusbarActivated (FALSE); |
|---|
| 944 | CPPUNIT_ASSERT (!m_View->isShownToolbar ()); |
|---|
| 945 | CPPUNIT_ASSERT (!m_View->isShownStatusbar ()); |
|---|
| 946 | m_MainPter->showToolbarActivated (FALSE); |
|---|
| 947 | m_MainPter->showStatusbarActivated (TRUE); |
|---|
| 948 | CPPUNIT_ASSERT (!m_View->isShownToolbar ()); |
|---|
| 949 | CPPUNIT_ASSERT (m_View->isShownStatusbar ()); |
|---|
| 950 | m_MainPter->showToolbarActivated (TRUE); |
|---|
| 951 | m_MainPter->showStatusbarActivated (FALSE); |
|---|
| 952 | CPPUNIT_ASSERT (m_View->isShownToolbar ()); |
|---|
| 953 | CPPUNIT_ASSERT (!m_View->isShownStatusbar ()); |
|---|
| 954 | m_MainPter->showToolbarActivated (TRUE); |
|---|
| 955 | m_MainPter->showStatusbarActivated (TRUE); |
|---|
| 956 | CPPUNIT_ASSERT (m_View->isShownToolbar ()); |
|---|
| 957 | CPPUNIT_ASSERT (m_View->isShownStatusbar ()); |
|---|
| 958 | } |
|---|
| 959 | |
|---|