From 81956b9600992bc500f504c2b36804ae7766bebf Mon Sep 17 00:00:00 2001 From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> Date: Thu, 9 Oct 2008 14:45:16 -0400 Subject: [PATCH] ConfigurationTest friend of managerimpl to be able call private method --- globals.mak | 1 + src/managerimpl.h | 1 + test/Makefile.am | 1 + test/configurationTest.cpp | 116 ++++++++++++------------------------- test/configurationTest.h | 90 ++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 78 deletions(-) create mode 100644 test/configurationTest.h diff --git a/globals.mak b/globals.mak index bb3d7b7db5..e6897c83ea 100644 --- a/globals.mak +++ b/globals.mak @@ -6,6 +6,7 @@ sflcodecdir=$(libdir)/sflphone/codecs AM_CPPFLAGS = \ -I$(src)/libs \ -I$(src)/src \ + -I$(src)/test \ -DPREFIX=\"$(prefix)\" \ -DPROGSHAREDIR=\"${datadir}/sflphone\" \ $(ZEROCONFFLAGS) \ diff --git a/src/managerimpl.h b/src/managerimpl.h index 3fbffe3110..55afeafa5e 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -1019,6 +1019,7 @@ class ManagerImpl { bool testAccountMap(); #endif + friend class ConfigurationTest; }; #endif // __MANAGER_H__ diff --git a/test/Makefile.am b/test/Makefile.am index 3ce425e19a..3107ed9e56 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -19,6 +19,7 @@ OBJECT_FILES= \ configurationTester_SOURCES = \ configurationTest.cpp \ + configurationTest.h \ TestMain.cpp configurationTester_LDADD = \ diff --git a/test/configurationTest.cpp b/test/configurationTest.cpp index ba7349ecd1..8f10ceac96 100644 --- a/test/configurationTest.cpp +++ b/test/configurationTest.cpp @@ -17,93 +17,53 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// Cppunit import -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCaller.h> -#include <cppunit/TestCase.h> -#include <cppunit/TestSuite.h> - -#include <assert.h> #include <stdio.h> -// Application import -#include "manager.h" -#include "global.h" -#include "user_cfg.h" - -/* - * @file configurationTest.cpp - * @brief Regroups unitary tests related to the user configuration. - * Check if the default configuration has been successfully loaded - */ +#include "configurationTest.h" using std::cout; using std::endl; +void ConfigurationTest::setUp(){ + // Load the default configuration + Manager::instance().initConfigFile(false); +} -class ConfigurationTest : public CppUnit::TestCase { - - /* - * Use cppunit library macros to add unit test the factory - */ - CPPUNIT_TEST_SUITE( ConfigurationTest ); - CPPUNIT_TEST( testDefaultValueAudio ); - CPPUNIT_TEST( testDefaultValuePreferences ); - CPPUNIT_TEST_SUITE_END(); - - public: - ConfigurationTest() : CppUnit::TestCase("Configuration Tests") {} - - /* - * Unit tests related to the audio preferences - */ - void testDefaultValueAudio(){ - CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, ALSA_CARD_ID_IN ) == ALSA_DFT_CARD) ; - CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, ALSA_CARD_ID_OUT ) == ALSA_DFT_CARD ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, ALSA_SAMPLE_RATE ) == DFT_SAMPLE_RATE); - CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, ALSA_FRAME_SIZE ) == DFT_FRAME_SIZE) ; - CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, ALSA_PLUGIN ) == PCM_DEFAULT ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, VOLUME_SPKR ) == DFT_VOL_SPKR_STR); - CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, VOLUME_MICRO ) == DFT_VOL_MICRO_STR); - } +void ConfigurationTest::testDefaultValueAudio(){ + CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, ALSA_CARD_ID_IN ) == ALSA_DFT_CARD) ; + CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, ALSA_CARD_ID_OUT ) == ALSA_DFT_CARD ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, ALSA_SAMPLE_RATE ) == DFT_SAMPLE_RATE); + CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, ALSA_FRAME_SIZE ) == DFT_FRAME_SIZE) ; + CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, ALSA_PLUGIN ) == PCM_DEFAULT ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, VOLUME_SPKR ) == DFT_VOL_SPKR_STR); + CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, VOLUME_MICRO ) == DFT_VOL_MICRO_STR); +} - /* - * Unit tests related to the global settings - */ - void testDefaultValuePreferences(){ - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, ZONE_TONE ) == DFT_ZONE ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_ZEROCONF ) == CONFIG_ZEROCONF_DEFAULT_STR ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_DIALPAD ) == YES_STR ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_RINGTONE ) == YES_STR ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_SEARCHBAR ) == YES_STR ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_START ) == NO_STR ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_POPUP ) == YES_STR ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_NOTIFY ) == YES_STR ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_MAIL_NOTIFY ) == NO_STR ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_VOLUME ) == YES_STR ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, REGISTRATION_EXPIRE ) == DFT_EXPIRE_VALUE ); - CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_AUDIO ) == DFT_AUDIO_MANAGER ); - - } +void ConfigurationTest::testDefaultValuePreferences(){ + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, ZONE_TONE ) == DFT_ZONE ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_ZEROCONF ) == CONFIG_ZEROCONF_DEFAULT_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_DIALPAD ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_RINGTONE ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_SEARCHBAR ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_START ) == NO_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_POPUP ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_NOTIFY ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_MAIL_NOTIFY ) == NO_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_VOLUME ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, REGISTRATION_EXPIRE ) == DFT_EXPIRE_VALUE ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_AUDIO ) == DFT_AUDIO_MANAGER ); - /* - * Code factoring - Common resources can be initialized here. - * This method is called by unitcpp before each test - */ - void setUp(){ - // Load the default configuration - Manager::instance().initConfigFile(false); - } +} - /* - * Code factoring - Common resources can be released here. - * This method is called by unitcpp after each test - */ - void tearDown(){ - // Not much to do - } +void ConfigurationTest::testDefaultValueSignalisation(){ + CPPUNIT_ASSERT( Manager::instance().getConfigString( SIGNALISATION , SYMMETRIC ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( SIGNALISATION , PLAY_DTMF ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( SIGNALISATION , PLAY_TONES ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( SIGNALISATION , PULSE_LENGTH ) == DFT_PULSE_LENGTH_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( SIGNALISATION , SEND_DTMF_AS ) == SIP_INFO_STR ); +} -}; +void ConfigurationTest::testLoadAccountMap(){ + Manager::instance().loadAccountMap(); +} -/* Register our test module */ -CPPUNIT_TEST_SUITE_REGISTRATION( ConfigurationTest ); diff --git a/test/configurationTest.h b/test/configurationTest.h new file mode 100644 index 0000000000..61109dc05a --- /dev/null +++ b/test/configurationTest.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2008 Savoir-Faire Linux inc. + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +// Cppunit import +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestCaller.h> +#include <cppunit/TestCase.h> +#include <cppunit/TestSuite.h> + +#include <assert.h> + +// Application import +#include "manager.h" +#include "global.h" +#include "user_cfg.h" + +/* + * @file configurationTest.cpp + * @brief Regroups unitary tests related to the user configuration. + * Check if the default configuration has been successfully loaded + */ + +#ifndef _CONFIGURATION_TEST_ +#define _CONFIGURATION_TEST_ + +class ConfigurationTest : public CppUnit::TestCase { + + /* + * Use cppunit library macros to add unit test the factory + */ + CPPUNIT_TEST_SUITE( ConfigurationTest ); + CPPUNIT_TEST( testDefaultValueAudio ); + CPPUNIT_TEST( testDefaultValuePreferences ); + CPPUNIT_TEST( testDefaultValueSignalisation ); + CPPUNIT_TEST( testLoadAccountMap ); + CPPUNIT_TEST_SUITE_END(); + + public: + ConfigurationTest() : CppUnit::TestCase("Configuration Tests") {} + + /* + * Code factoring - Common resources can be initialized here. + * This method is called by unitcpp before each test + */ + void setUp(); + + /* + * Code factoring - Common resources can be released here. + * This method is called by unitcpp after each test + */ + inline void tearDown(){ + // Not much to do + } + + /* + * Unit tests related to the audio preferences + */ + void testDefaultValueAudio(); + + /* + * Unit tests related to the global settings + */ + void testDefaultValuePreferences(); + + void testDefaultValueSignalisation(); + + void testLoadAccountMap(); + +}; + +/* Register our test module */ +CPPUNIT_TEST_SUITE_REGISTRATION( ConfigurationTest ); + +#endif -- GitLab