root/trunk/tests/ConfigTest.cxx

Revision 205, 5.6 kB (checked in by jordi, 2 years ago)

I've added the missing pure virtual function from last week and also added a new test function for the Config class to test the last saved folder option.

Line 
1// ePDFView - Configuration 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 "ConfigTest.h"
20
21using namespace ePDFView;
22
23// Register the test suite into the `registry'.
24CPPUNIT_TEST_SUITE_REGISTRATION (ConfigTest);
25
26///
27/// @brief Sets up the environment for each test.
28///
29/// Since the configuration is a singleton, we don't need to set up
30/// it.
31///
32void
33ConfigTest::setUp ()
34{
35    Config::loadFile (FALSE);
36}
37
38///
39/// @brief Cleans up after each test.
40///
41void
42ConfigTest::tearDown ()
43{
44    Config::destroy ();
45}
46
47///
48/// @brief Checks the defaults values (i.e., no values read from a file)
49///
50void
51ConfigTest::defaultValues ()
52{
53    Config &config = Config::getConfig ();
54
55    CPPUNIT_ASSERT_EQUAL (0, config.getWindowX ());
56    CPPUNIT_ASSERT_EQUAL (0, config.getWindowY ());
57    CPPUNIT_ASSERT_EQUAL (600, config.getWindowWidth ());
58    CPPUNIT_ASSERT_EQUAL (650, config.getWindowHeight ());
59    CPPUNIT_ASSERT (config.showToolbar ());
60    CPPUNIT_ASSERT (config.showStatusbar ());
61    CPPUNIT_ASSERT_EQUAL ((gchar *)NULL, config.getOpenFileFolder ());
62    CPPUNIT_ASSERT_EQUAL ((gchar *)NULL, config.getSaveFileFolder ());
63    CPPUNIT_ASSERT (!config.zoomToWidth ());
64    CPPUNIT_ASSERT (!config.zoomToFit ());
65
66    gchar *commandLine = config.getExternalBrowserCommandLine ();
67    CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("firefox %s", commandLine));
68    g_free (commandLine);
69}
70
71///
72/// @brief Check setting and retrieving values related to the main window.
73///
74void
75ConfigTest::windowValues ()
76{
77    Config &config = Config::getConfig ();
78
79    config.setWindowPos (30, 40);
80    config.setWindowSize (100, 90);
81
82    CPPUNIT_ASSERT_EQUAL (30, config.getWindowX ());
83    CPPUNIT_ASSERT_EQUAL (40, config.getWindowY ());
84    CPPUNIT_ASSERT_EQUAL (100, config.getWindowWidth ());
85    CPPUNIT_ASSERT_EQUAL (90, config.getWindowHeight ());   
86}
87
88///
89/// @brief Checks setting the value for showing the toolbar.
90///
91void
92ConfigTest::showToolbar ()
93{
94    Config &config = Config::getConfig ();
95
96    config.setShowToolbar (FALSE);
97    CPPUNIT_ASSERT ( !config.showToolbar () );
98    config.setShowToolbar (TRUE);
99    CPPUNIT_ASSERT ( config.showToolbar () );
100}
101
102///
103/// @brief Checks setting the value for showing the status bar.
104///
105void
106ConfigTest::showStatusbar ()
107{
108    Config &config = Config::getConfig ();
109
110    config.setShowStatusbar (FALSE);
111    CPPUNIT_ASSERT ( !config.showStatusbar () );
112    config.setShowStatusbar (TRUE);
113    CPPUNIT_ASSERT ( config.showStatusbar () );
114}
115
116///
117/// @brief Check setting the current folder for opening files.
118///
119void
120ConfigTest::openCurrentFolder ()
121{
122    Config &config = Config::getConfig ();
123
124    config.setOpenFileFolder ("/tmp");
125    gchar *openFolder = config.getOpenFileFolder ();
126    CPPUNIT_ASSERT ( 0 == g_ascii_strcasecmp ("/tmp", openFolder));
127    g_free (openFolder);
128}
129
130///
131/// @brief Check setting the current folder for saving files.
132///
133void
134ConfigTest::saveCurrentFolder ()
135{
136    Config &config = Config::getConfig ();
137
138    config.setSaveFileFolder ("/home");
139    gchar *saveFolder = config.getSaveFileFolder ();
140    CPPUNIT_ASSERT ( 0 == g_ascii_strcasecmp ("/home", saveFolder));
141    g_free (saveFolder);
142}
143
144///
145/// @brief Check setting the zoom values.
146///
147/// Especially check that zoomToWidth() and zoomToFit() can't be
148/// set both to true.
149///
150void
151ConfigTest::zoomValues ()
152{
153    Config &config = Config::getConfig ();
154   
155    config.setZoomToFit (TRUE);
156    CPPUNIT_ASSERT ( !config.zoomToWidth () );
157    CPPUNIT_ASSERT ( config.zoomToFit () );
158    config.setZoomToFit (FALSE);
159    CPPUNIT_ASSERT ( !config.zoomToWidth () );
160    CPPUNIT_ASSERT ( !config.zoomToFit () );
161    config.setZoomToWidth (TRUE);
162    CPPUNIT_ASSERT ( config.zoomToWidth () );
163    CPPUNIT_ASSERT ( !config.zoomToFit () );
164    config.setZoomToWidth (FALSE);
165    CPPUNIT_ASSERT ( !config.zoomToWidth () );
166    CPPUNIT_ASSERT ( !config.zoomToFit () );
167    config.setZoomToFit (TRUE);
168    CPPUNIT_ASSERT ( !config.zoomToWidth () );
169    CPPUNIT_ASSERT ( config.zoomToFit () );
170    config.setZoomToWidth (TRUE);
171    CPPUNIT_ASSERT ( config.zoomToWidth () );
172    CPPUNIT_ASSERT ( !config.zoomToFit () );
173    config.setZoomToFit (TRUE);
174    CPPUNIT_ASSERT ( !config.zoomToWidth () );
175    CPPUNIT_ASSERT ( config.zoomToFit () );
176    config.setZoomToFit (FALSE);
177    CPPUNIT_ASSERT ( !config.zoomToWidth () );
178    CPPUNIT_ASSERT ( !config.zoomToFit () );
179}
180
181///
182/// @brief Checks setting the external browser command line.
183///
184void
185ConfigTest::externalBrowser ()
186{
187    Config &config = Config::getConfig ();
188
189    config.setExternalBrowserCommandLine ("galeon %s");
190    gchar *commandLine = config.getExternalBrowserCommandLine ();
191    CPPUNIT_ASSERT ( 0 == g_ascii_strcasecmp ("galeon %s", commandLine));
192    g_free (commandLine);
193
194    config.setExternalBrowserCommandLine ("xterm -e lynx %s");
195    commandLine = config.getExternalBrowserCommandLine ();
196    CPPUNIT_ASSERT ( 0 == g_ascii_strcasecmp ("xterm -e lynx %s", commandLine));
197    g_free (commandLine);
198}
Note: See TracBrowser for help on using the browser.