Changeset 98

Show
Ignore:
Timestamp:
04/20/06 11:13:01 (2 years ago)
Author:
jordi
Message:

Divided the pageZoom function from the MainPter? test to ZoomInAndOut?, ZoomWidth? and ZoomFit?, because I'm planning to make ZoomToWith? and ZoomToHeigh? toggle action that deserved separate test cases.

Also added the ZoomToFit? and ZoomToWidth? options to the configuration class. Also the test case was added.

Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/Config.cxx

    r96 r98  
    2828static gint DEFAULT_WINDOW_X = 0; 
    2929static gint DEFAULT_WINDOW_Y = 0; 
     30static gboolean DEFAULT_ZOOM_TO_FIT = FALSE; 
     31static gboolean DEFAULT_ZOOM_TO_WIDTH = FALSE; 
    3032 
    3133// Static member attributes. 
     
    105107 
    106108/// 
    107 /// @brief Gets an integer configuration option. 
     109/// @brief Gets a boolean configuration option. 
    108110/// 
    109111/// @param group Configuration group where the key belongs. 
     
    114116///         doesn't exists. 
    115117/// 
    116 gint 
    117 Config::getInteger (const gchar *group, const gchar *key, gint defaultValue) 
    118 { 
    119     gint value = defaultValue; 
     118gboolean 
     119Config::getBoolean (const gchar *group, const gchar *key, gboolean defaultValue) 
     120{ 
     121    gboolean value = defaultValue; 
    120122 
    121123    if ( g_key_file_has_key (m_Values, group, key, NULL) ) 
    122124    { 
    123125        GError *error = NULL; 
    124         gint savedValue = g_key_file_get_integer (m_Values, group, key, &error); 
     126        gboolean savedValue =  
     127            g_key_file_get_boolean (m_Values, group, key, &error); 
    125128        if ( NULL == error ) 
    126129        { 
     
    139142 
    140143/// 
     144/// @brief Gets an integer configuration option. 
     145/// 
     146/// @param group Configuration group where the key belongs. 
     147/// @param key The key name to retrieve its value. 
     148/// @param defaultValue The default value to return if @a key doesn't exists. 
     149/// 
     150/// @return The value of the @a key in @a group or @a defaultValue if @a key 
     151///         doesn't exists. 
     152/// 
     153gint 
     154Config::getInteger (const gchar *group, const gchar *key, gint defaultValue) 
     155{ 
     156    gint value = defaultValue; 
     157 
     158    if ( g_key_file_has_key (m_Values, group, key, NULL) ) 
     159    { 
     160        GError *error = NULL; 
     161        gint savedValue = g_key_file_get_integer (m_Values, group, key, &error); 
     162        if ( NULL == error ) 
     163        { 
     164            value = savedValue; 
     165        } 
     166        else 
     167        { 
     168            g_warning ("Error reading key '%s' from group '%s': %s\n",  
     169                       key, group, error->message); 
     170            g_error_free (error); 
     171        }         
     172    } 
     173 
     174    return value; 
     175} 
     176 
     177/// 
    141178/// @brief Gets an string configuration option. 
    142179/// 
     
    299336    g_key_file_set_integer (m_Values, "main window", "x", x); 
    300337    g_key_file_set_integer (m_Values, "main window", "y", y); 
     338} 
     339 
     340/// 
     341/// @brief Sets the zoom to fit option. 
     342/// 
     343/// @param activate Set to TRUE to activate the zoom to fit option. FALSE 
     344///        otherwise. 
     345/// 
     346void 
     347Config::setZoomToFit (gboolean activate) 
     348{ 
     349    g_key_file_set_boolean (m_Values, "main window", "zoomToFit", activate); 
     350    g_key_file_set_boolean (m_Values, "main window", "zoomToWidth",  
     351            !activate && zoomToWidth ()); 
     352} 
     353 
     354/// 
     355/// @brief Sets the zoom to with option. 
     356/// 
     357/// @param activate Set to TRUE to activate the zoom to width option. FALSE 
     358///        otherwise. 
     359/// 
     360void 
     361Config::setZoomToWidth (gboolean activate) 
     362{ 
     363    g_key_file_set_boolean (m_Values, "main window", "zoomToFit",  
     364            !activate && zoomToFit ()); 
     365    g_key_file_set_boolean (m_Values, "main window", "zoomToWidth", activate); 
     366} 
     367 
     368/// 
     369/// @brief Gets the zoom to fit option. 
     370/// 
     371/// @return TRUE if the zoom to fit option is activated. FALSE otherwise. 
     372/// 
     373gboolean 
     374Config::zoomToFit () 
     375{ 
     376    return getBoolean ("main window", "zoomToFit", DEFAULT_ZOOM_TO_FIT); 
     377} 
     378 
     379/// 
     380/// @brief Gets the zoom to width option. 
     381/// 
     382/// @return TRUE if the zoom to width option is activated. FALSE otherwise. 
     383/// 
     384gboolean 
     385Config::zoomToWidth () 
     386{ 
     387    return getBoolean ("main window", "zoomToWidth", DEFAULT_ZOOM_TO_WIDTH); 
    301388} 
    302389 
  • trunk/src/Config.h

    r96 r98  
    4444            gint getWindowX (void); 
    4545            gint getWindowY (void); 
     46            gboolean zoomToFit (void); 
     47            gboolean zoomToWidth (void); 
    4648            void save(void); 
    4749            void setOpenFileFolder (const gchar *folder); 
    4850            void setWindowSize (gint width, gint height); 
    4951            void setWindowPos (gint x, gint y); 
     52            void setZoomToFit (gboolean active); 
     53            void setZoomToWidth (gboolean active); 
    5054             
    5155        protected: 
     
    5862            static gboolean m_LoadFile; 
    5963 
     64            gboolean getBoolean (const gchar *group, const char *key, 
     65                                 gboolean defaultValue); 
    6066            gint getInteger (const gchar *group, const char *key,  
    6167                             gint defaultValue); 
  • trunk/tests/ConfigTest.cxx

    r96 r98  
    5858    CPPUNIT_ASSERT_EQUAL (650, config.getWindowHeight ()); 
    5959    CPPUNIT_ASSERT_EQUAL ((gchar *)NULL, config.getOpenFileFolder ()); 
     60    CPPUNIT_ASSERT ( !config.zoomToWidth () ); 
     61    CPPUNIT_ASSERT ( !config.zoomToFit () ); 
    6062} 
    6163 
     
    9092    g_free (openFolder); 
    9193} 
     94 
     95/// 
     96/// @brief Check setting the zoom values. 
     97/// 
     98/// Especially check that zoomToWidth() and zoomToFit() can't be 
     99/// set both to true. 
     100/// 
     101void 
     102ConfigTest::zoomValues () 
     103{ 
     104    Config &config = Config::getConfig (); 
     105     
     106    config.setZoomToFit (TRUE); 
     107    CPPUNIT_ASSERT ( !config.zoomToWidth () ); 
     108    CPPUNIT_ASSERT ( config.zoomToFit () ); 
     109    config.setZoomToFit (FALSE); 
     110    CPPUNIT_ASSERT ( !config.zoomToWidth () ); 
     111    CPPUNIT_ASSERT ( !config.zoomToFit () ); 
     112    config.setZoomToWidth (TRUE); 
     113    CPPUNIT_ASSERT ( config.zoomToWidth () ); 
     114    CPPUNIT_ASSERT ( !config.zoomToFit () ); 
     115    config.setZoomToWidth (FALSE); 
     116    CPPUNIT_ASSERT ( !config.zoomToWidth () ); 
     117    CPPUNIT_ASSERT ( !config.zoomToFit () ); 
     118    config.setZoomToFit (TRUE); 
     119    CPPUNIT_ASSERT ( !config.zoomToWidth () ); 
     120    CPPUNIT_ASSERT ( config.zoomToFit () ); 
     121    config.setZoomToWidth (TRUE); 
     122    CPPUNIT_ASSERT ( config.zoomToWidth () ); 
     123    CPPUNIT_ASSERT ( !config.zoomToFit () ); 
     124    config.setZoomToFit (TRUE); 
     125    CPPUNIT_ASSERT ( !config.zoomToWidth () ); 
     126    CPPUNIT_ASSERT ( config.zoomToFit () ); 
     127    config.setZoomToFit (FALSE); 
     128    CPPUNIT_ASSERT ( !config.zoomToWidth () ); 
     129    CPPUNIT_ASSERT ( !config.zoomToFit () ); 
     130} 
  • trunk/tests/ConfigTest.h

    r96 r98  
    2929        CPPUNIT_TEST (windowValues); 
    3030        CPPUNIT_TEST (currentFolder); 
     31        CPPUNIT_TEST (zoomValues); 
    3132        CPPUNIT_TEST_SUITE_END (); 
    3233 
     
    3839            void windowValues (void); 
    3940            void currentFolder (void); 
     41            void zoomValues (void); 
    4042    }; 
    4143} 
  • trunk/tests/MainPterTest.cxx

    r97 r98  
    513513/// ZoomIn insensitives the ZoomIn button. The same for the ZoomOut. 
    514514/// 
    515 /// Then will test Zoom Fit and Zoom Width with two different rotations. 
    516 /// 
    517 void 
    518 MainPterTest::pageZoom () 
     515/// 
     516void 
     517MainPterTest::pageZoomInAndOut () 
    519518{ 
    520519    m_View->setOpenFileName ("/tmp/test.pdf"); 
     
    549548    CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); 
    550549    CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); 
     550} 
     551 
     552/// 
     553/// @brief Tests page's zoom to width 
     554/// 
     555void 
     556MainPterTest::pageZoomWidth () 
     557{ 
     558    m_View->setOpenFileName ("/tmp/test.pdf"); 
     559    m_MainPter->openFileActivated (); 
     560    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     561    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     562    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
    551563 
    552564    // OK, now try to zoom width. Since rotation is 0 
     565    // the zoom level should be 75/100 = 0.75 
     566    m_MainPter->zoomWidthActivated (); 
     567    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     568    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     569    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); 
     570 
     571    // Now rotate and try again. 
     572    m_MainPter->rotateRightActivated ();  
     573    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     574    CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 
     575     
     576    // Since rotation is now 90 the zoom level should be 75/250 = 0.3 
     577    m_MainPter->zoomWidthActivated (); 
     578    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
     579    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     580} 
     581 
     582/// 
     583/// @brief Tests page's zoom to fit 
     584/// 
     585void 
     586MainPterTest::pageZoomFit () 
     587{ 
     588    m_View->setOpenFileName ("/tmp/test.pdf"); 
     589    m_MainPter->openFileActivated (); 
     590    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     591    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     592    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
     593 
     594    // OK, now try to zoom to fit. Since rotation is 0 
    553595    // the zoom level should be 50/250 = 0.2 
    554596    m_MainPter->zoomFitActivated (); 
     
    556598    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    557599    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 
    558     // For the width it should be 75/100 = 0.75 
    559     m_MainPter->zoomWidthActivated (); 
    560     CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    561     CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    562     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); 
    563600 
    564601    // Now rotate and try again. 
     
    571608    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
    572609    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    573     // For the width it should be 75/250 = 0.3 also. 
    574     m_MainPter->zoomWidthActivated (); 
    575     CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 
    576     CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    577 } 
     610} 
     611 
    578612 
    579613/// 
  • trunk/tests/MainPterTest.h

    r97 r98  
    3737        CPPUNIT_TEST (pageNavigationEntry); 
    3838        CPPUNIT_TEST (pageRotate); 
    39         CPPUNIT_TEST (pageZoom); 
     39        CPPUNIT_TEST (pageZoomInAndOut); 
     40        CPPUNIT_TEST (pageZoomWidth); 
     41        CPPUNIT_TEST (pageZoomFit); 
    4042        CPPUNIT_TEST (reloadNormal); 
    4143        CPPUNIT_TEST (reloadEncrypted); 
     
    5961            void pageNavigationEntry (void); 
    6062            void pageRotate (void); 
    61             void pageZoom (void); 
     63            void pageZoomInAndOut (void); 
     64            void pageZoomWidth (void); 
     65            void pageZoomFit (void); 
    6266            void reloadNormal (void); 
    6367            void reloadEncrypted (void);