Show
Ignore:
Timestamp:
04/14/06 16:24:42 (3 years ago)
Author:
jordi
Message:

The Main presenter now can reload encrypted files without bothering the user about password, unless the document's password has been changed. In this case, it will behaviour like opening the file as new.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/tests/MainPterTest.cxx

    r64 r65  
    233233    m_View->setOpenFileName ("/tmp/test.pdf"); 
    234234    m_View->setPassword ("badpassword"); 
    235     m_Document->setPassword ("goodpassword"); 
     235    m_Document->setTestPassword ("goodpassword"); 
    236236    m_Document->setOpenError (DocumentErrorEncrypted); 
    237237    m_MainPter->openFileActivated (); 
     
    266266    m_View->setOpenFileName ("/tmp/test.pdf"); 
    267267    m_View->setPassword ("goodpassword"); 
    268     m_Document->setPassword ("goodpassword"); 
     268    m_Document->setTestPassword ("goodpassword"); 
    269269    m_Document->setOpenError (DocumentErrorEncrypted); 
    270270    m_MainPter->openFileActivated (); 
     
    566566    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
    567567    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    568     CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    569568 
    570569    // Reload the document. 
     
    576575    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
    577576    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    578     CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    579 } 
     577} 
     578 
     579/// 
     580/// @brief Tries to reload an encrypted file. 
     581/// 
     582/// Reloading an encrypted file won't ask for the password unless it changed,  
     583/// but here we assume that don't 
     584/// 
     585void 
     586MainPterTest::reloadEncrypted () 
     587{ 
     588    m_View->setOpenFileName ("/tmp/test.pdf"); 
     589    m_View->setPassword ("goodpassword"); 
     590    m_Document->setTestPassword ("goodpassword"); 
     591    m_Document->setOpenError (DocumentErrorEncrypted); 
     592    m_MainPter->openFileActivated (); 
     593    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     594    CPPUNIT_ASSERT_EQUAL (0,  
     595            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     596     
     597    m_MainPter->goToNextPageActivated (); 
     598    m_MainPter->rotateRightActivated ();  
     599    m_MainPter->zoomWidthActivated (); 
     600    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ());  
     601    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ());  
     602    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
     603    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     604 
     605    // Reload the document. 
     606    m_View->setPassword ("badpassword"); 
     607    m_Document->setTestPassword ("goodpassword"); 
     608    m_Document->setOpenError (DocumentErrorEncrypted); 
     609    m_MainPter->reloadActivated (); 
     610    CPPUNIT_ASSERT_EQUAL (0,  
     611            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     612    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ());  
     613    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ());  
     614    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
     615    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     616    CPPUNIT_ASSERT (!m_View->shownError ()); 
     617    CPPUNIT_ASSERT_EQUAL (0, m_View->countTimesShownPasswordPrompt ()); 
     618} 
     619 
     620/// 
     621/// @brief Tries to reload an encrypted file whose password changed. 
     622/// 
     623/// Reloading an encrypted file won't ask for the password unless it changed.  
     624/// 
     625void 
     626MainPterTest::reloadChangedPassword () 
     627{ 
     628    m_View->setOpenFileName ("/tmp/test.pdf"); 
     629    m_View->setPassword ("goodpassword"); 
     630    m_Document->setTestPassword ("goodpassword"); 
     631    m_Document->setOpenError (DocumentErrorEncrypted); 
     632    m_MainPter->openFileActivated (); 
     633    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     634    CPPUNIT_ASSERT_EQUAL (0,  
     635            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     636     
     637    m_MainPter->goToNextPageActivated (); 
     638    m_MainPter->rotateRightActivated ();  
     639    m_MainPter->zoomWidthActivated (); 
     640    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ());  
     641    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ());  
     642    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
     643    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     644 
     645    // Reload the document. 
     646    m_View->setPassword ("newpassword"); 
     647    m_Document->setTestPassword ("newpassword"); 
     648    CPPUNIT_ASSERT_EQUAL (0, 
     649            g_ascii_strcasecmp("goodpassword", m_Document->getPassword ())); 
     650    m_Document->setOpenError (DocumentErrorEncrypted); 
     651    m_MainPter->reloadActivated (); 
     652    CPPUNIT_ASSERT_EQUAL (0, 
     653            g_ascii_strcasecmp("newpassword", m_Document->getPassword ())); 
     654    CPPUNIT_ASSERT_EQUAL (0,  
     655            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     656    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ());  
     657    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ());  
     658    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
     659    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     660    CPPUNIT_ASSERT (!m_View->shownError ()); 
     661    CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); 
     662}