Changeset 27
- Timestamp:
- 04/11/06 12:15:53 (3 years ago)
- Location:
- trunk
- Files:
-
- 8 modified
-
src/IMainView.h (modified) (1 diff)
-
src/MainPter.cxx (modified) (2 diffs)
-
tests/DumbDocument.cxx (modified) (3 diffs)
-
tests/DumbDocument.h (modified) (1 diff)
-
tests/DumbMainView.cxx (modified) (6 diffs)
-
tests/DumbMainView.h (modified) (5 diffs)
-
tests/MainPterTest.cxx (modified) (1 diff)
-
tests/MainPterTest.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/IMainView.h
r26 r27 29 29 public: 30 30 virtual ~IMainView () {} 31 31 32 32 virtual gchar *openFileDialog () = 0; 33 virtual gchar *promptPasswordDialog () = 0; 33 34 virtual void sensitiveGoToFirstPage (gboolean sensitive) = 0; 34 35 virtual void sensitiveGoToLastPage (gboolean sensitive) = 0; -
trunk/src/MainPter.cxx
r26 r27 153 153 // state. 154 154 setInitialState (); 155 g_free (fileName);156 155 } 157 156 else 158 { 157 { 159 158 // We got an error, but also can be that the file is encrypted. 160 159 if ( DocumentErrorEncrypted == error->code ) 161 160 { 162 // TODO 161 // Now we got an encrypted file. 162 // Prompt for the password up to three time, until the password 163 // is correct or the user cancels the password dialog. 164 int passwordTries = 0; 165 gchar *password = NULL; 166 gboolean loaded = FALSE; 167 do 168 { 169 g_free (password); 170 password = getView ().promptPasswordDialog (); 171 loaded = m_Document->loadFile (fileName, password, NULL); 172 } while ( 3 > ++passwordTries && 173 NULL != password && 174 !loaded); 175 176 // We are go, just check if we could load it or show the 177 // error. 178 if ( loaded ) 179 { 180 // Phew, finally loaded. Set the initial state. 181 setInitialState (); 182 } 183 else if ( NULL != password ) 184 { 185 // We didn't get the correct password, but the user 186 // tried, because the password is not NULL. 187 getView ().showErrorMessage (_("Error Loading File"), 188 _("The password you have supplier is not a" 189 "valid password for this file.")); 190 g_free (password); 191 } 163 192 } 164 193 else … … 171 200 g_free (error); 172 201 } 202 g_free (fileName); 173 203 } 174 204 } -
trunk/tests/DumbDocument.cxx
r26 r27 30 30 m_Loaded = FALSE; 31 31 m_OpenError = DocumentErrorNone; 32 m_Password = NULL; 32 33 } 33 34 34 35 DumbDocument::~DumbDocument () 35 36 { 37 g_free (m_Password); 36 38 } 37 39 … … 47 49 { 48 50 if ( DocumentErrorNone == m_OpenError ) 51 { 52 setFileName (filename); 53 m_Loaded = TRUE; 54 } 55 else if ( DocumentErrorEncrypted == m_OpenError && 56 password != NULL && 57 0 == g_ascii_strcasecmp (password, m_Password)) 49 58 { 50 59 setFileName (filename); … … 80 89 m_OpenError = error; 81 90 } 91 92 void 93 DumbDocument::setPassword (const gchar *password) 94 { 95 g_free (m_Password); 96 m_Password = g_strdup (password); 97 } -
trunk/tests/DumbDocument.h
r26 r27 36 36 // Test functions. 37 37 void setOpenError (DocumentError error); 38 void setPassword (const gchar *password); 38 39 39 40 private: 40 41 gboolean m_Loaded; 41 42 DocumentError m_OpenError; 43 gchar *m_Password; 42 44 }; 43 45 } -
trunk/tests/DumbMainView.cxx
r26 r27 30 30 m_DocumentPage = NULL; 31 31 m_OpenFileName = g_strdup (""); 32 m_Password = NULL; 32 33 m_SensitiveGoToFirstPage = TRUE; 33 34 m_SensitiveGoToLastPage = TRUE; … … 42 43 m_ShownError = FALSE; 43 44 m_Title = g_strdup (""); 45 m_TimesShownPassword = 0; 44 46 } 45 47 … … 47 49 { 48 50 g_free (m_OpenFileName); 51 g_free (m_Password); 49 52 g_free (m_Title); 50 53 } … … 56 59 } 57 60 61 gchar * 62 DumbMainView::promptPasswordDialog (void) 63 { 64 m_TimesShownPassword++; 65 return g_strdup (m_Password); 66 } 67 58 68 void 59 69 DumbMainView::sensitiveGoToFirstPage (gboolean sensitive) … … 139 149 // Test Methods 140 150 //////////////////////////////////////////////////////////////// 151 152 gint 153 DumbMainView::countTimesShownPasswordPrompt () 154 { 155 return m_TimesShownPassword; 156 } 141 157 142 158 gboolean … … 220 236 { 221 237 g_free (m_OpenFileName); 222 m_OpenFileName = NULL; 223 if ( NULL != fileName ) 224 { 225 m_OpenFileName = g_strdup (fileName); 226 } 238 m_OpenFileName = g_strdup (fileName); 239 } 240 241 void 242 DumbMainView::setPassword (const gchar *password) 243 { 244 g_free (m_Password); 245 m_Password = g_strdup (password); 246 m_TimesShownPassword = 0; 227 247 } 228 248 -
trunk/tests/DumbMainView.h
r26 r27 29 29 30 30 gchar *openFileDialog (void); 31 gchar *promptPasswordDialog (void); 31 32 void sensitiveGoToFirstPage (gboolean sensitive); 32 33 void sensitiveGoToLastPage (gboolean sensitive); … … 44 45 45 46 // Methods for test purposes. 47 gint countTimesShownPasswordPrompt (); 46 48 const gchar *getTitle (void); 47 49 gboolean hasImagePageView (void); … … 57 59 gboolean isSensitiveZoomWidth (void); 58 60 void setOpenFileName (const gchar *fileName); 61 void setPassword (const gchar *password); 59 62 gboolean shownError (void); 60 63 … … 62 65 DocumentPage *m_DocumentPage; 63 66 gchar *m_OpenFileName; 67 gchar *m_Password; 64 68 gboolean m_SensitiveGoToFirstPage; 65 69 gboolean m_SensitiveGoToLastPage; … … 73 77 gboolean m_Shown; 74 78 gboolean m_ShownError; 79 gint m_TimesShownPassword; 75 80 gchar *m_Title; 76 81 }; -
trunk/tests/MainPterTest.cxx
r26 r27 170 170 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 171 171 CPPUNIT_ASSERT (m_View->shownError ()); 172 173 } 172 } 173 174 /// 175 /// @brief Test a cancelled password. 176 /// 177 /// A cancelled password is more or less the same as cancelling the loading 178 /// of a file. It's when the user tried to open an encrypted file, but when 179 /// the password is prompted, then it cancels :-) 180 /// It should happen the same as when cancelling the open file dialog. 181 /// 182 void 183 MainPterTest::cancelledPassword () 184 { 185 m_View->setOpenFileName ("/tmp/test.pdf"); 186 m_View->setPassword (NULL); 187 m_Document->setOpenError (DocumentErrorEncrypted); 188 m_MainPter->openFileActivated (); 189 CPPUNIT_ASSERT_EQUAL (0, 190 g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 191 CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 192 CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); 193 CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); 194 CPPUNIT_ASSERT (!m_View->isSensitiveGoToPage ()); 195 CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 196 CPPUNIT_ASSERT (!m_View->isSensitiveZoomIn ()); 197 CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); 198 CPPUNIT_ASSERT (!m_View->isSensitiveZoomFit ()); 199 CPPUNIT_ASSERT (!m_View->isSensitiveZoomWidth ()); 200 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 201 CPPUNIT_ASSERT (!m_View->shownError ()); 202 } 203 204 /// 205 /// @brief Test a bad password. 206 /// 207 /// This test is very similar to the previous, but this time the user 208 /// enters a bad password, trying to guess which is the correct password. 209 /// The presenter gives up after three times and shows an error message. 210 /// 211 void 212 MainPterTest::badPassword () 213 { 214 m_View->setOpenFileName ("/tmp/test.pdf"); 215 m_View->setPassword ("badpassword"); 216 m_Document->setPassword ("goodpassword"); 217 m_Document->setOpenError (DocumentErrorEncrypted); 218 m_MainPter->openFileActivated (); 219 CPPUNIT_ASSERT_EQUAL (0, 220 g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 221 CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 222 CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); 223 CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); 224 CPPUNIT_ASSERT (!m_View->isSensitiveGoToPage ()); 225 CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 226 CPPUNIT_ASSERT (!m_View->isSensitiveZoomIn ()); 227 CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); 228 CPPUNIT_ASSERT (!m_View->isSensitiveZoomFit ()); 229 CPPUNIT_ASSERT (!m_View->isSensitiveZoomWidth ()); 230 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 231 CPPUNIT_ASSERT (m_View->shownError ()); 232 CPPUNIT_ASSERT_EQUAL (3, m_View->countTimesShownPasswordPrompt ()); 233 } -
trunk/tests/MainPterTest.h
r26 r27 30 30 CPPUNIT_TEST (loadCancelled); 31 31 CPPUNIT_TEST (loadFailed); 32 CPPUNIT_TEST (cancelledPassword); 33 CPPUNIT_TEST (badPassword); 32 34 CPPUNIT_TEST_SUITE_END(); 33 35 … … 40 42 void loadCancelled (void); 41 43 void loadFailed (void); 42 44 void cancelledPassword (void); 45 void badPassword (void); 43 46 private: 44 47 DumbMainView *m_View;
