Commit 5be88657 authored by Julien Bonjean's avatar Julien Bonjean

[#2535] Cleaned unit test

parent 4cbf6758
include ../globals.mak
TESTS = main
TESTS = test
check_PROGRAMS = $(TESTS)
main_CXXFLAGS = $(CPPUNIT_CFLAGS)
main_LDADD = $(LLIBS)
main_LDFLAGS = -ldl
main_SOURCES = main.cpp \
test_CXXFLAGS = $(CPPUNIT_CFLAGS)
test_LDADD = $(LLIBS)
test_LDFLAGS = -ldl
test_SOURCES = main.cpp \
validator.cpp \
validator.h \
accounttest.h \
accounttest.cpp
accounttest.cpp \
audiolayertest.h \
audiolayertest.cpp \
configurationtest.h \
configurationtest.cpp \
historytest.h \
historytest.cpp \
hookmanagertest.h \
hookmanagertest.cpp \
mainbuffertest.h \
mainbuffertest.cpp \
numbercleanertest.h \
numbercleanertest.cpp \
pluginmanagertest.h \
pluginmanagertest.cpp \
rtptest.h \
rtptest.cpp \
sdesnegotiatortest.h \
sdesnegotiatortest.cpp
......
......@@ -24,9 +24,8 @@
#include "logger.h"
#include "validator.h"
CPPUNIT_TEST_SUITE_REGISTRATION( AccountTest );
void AccountTest::TestAddRemove(void) {
_debug ("-------------------- AccountTest::TestAddRemove --------------------\n");
std::map<std::string, std::string> details;
details[CONFIG_ACCOUNT_TYPE] = "SIP";
......
......@@ -32,5 +32,7 @@ class AccountTest : public CppUnit::TestFixture {
public:
void TestAddRemove(void);
};
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AccountTest, "AccountTest");
CPPUNIT_TEST_SUITE_REGISTRATION( AccountTest );
#endif /* ACCOUNTTEST_H_ */
/*
* Copyright (C) 2009 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.
*/
#include <stdio.h>
#include <sstream>
#include "audiolayertest.h"
#include <unistd.h>
using std::cout;
using std::endl;
void AudioLayerTest::testAudioLayerConfig() {
_debug ("-------------------- AudioLayerTest::testAudioLayerConfig --------------------\n");
int sampling_rate = Manager::instance().getConfigInt(AUDIO,
AUDIO_SAMPLE_RATE);
int frame_size = Manager::instance().getConfigInt(AUDIO, ALSA_FRAME_SIZE);
int layer = Manager::instance().getAudioDriver()->getLayerType();
if (layer != ALSA)
Manager::instance().switchAudioManager();
// TODO: Fix tests
//CPPUNIT_ASSERT ( (int) Manager::instance().getAudioDriver()->getSampleRate() == sampling_rate);
//CPPPUNIT_ASSERT ( (int) Manager::instance().getAudioDriver()->getFrameSize() == frame_size);
}
void AudioLayerTest::testAudioLayerSwitch() {
_debug ("-------------------- AudioLayerTest::testAudioLayerSwitch --------------------\n");
int previous_layer = Manager::instance().getAudioDriver()->getLayerType();
for (int i = 0; i < 2; i++) {
_debug ("iter - %i",i);
Manager::instance().switchAudioManager();
if (previous_layer == ALSA) {
CPPUNIT_ASSERT (Manager::instance().getAudioDriver()->getLayerType() == PULSEAUDIO);
} else {
CPPUNIT_ASSERT (Manager::instance().getAudioDriver()->getLayerType() == ALSA);
}
previous_layer = Manager::instance().getAudioDriver()->getLayerType();
usleep(100000);
}
}
void AudioLayerTest::testPulseConnect() {
_debug ("-------------------- AudioLayerTest::testPulseConnect --------------------\n");
if (Manager::instance().getAudioDriver()->getLayerType() == ALSA)
return;
ManagerImpl* manager;
manager = &Manager::instance();
_pulselayer = (PulseLayer*) Manager::instance().getAudioDriver();
CPPUNIT_ASSERT (_pulselayer->getLayerType() == PULSEAUDIO);
std::string alsaPlugin;
int numCardIn, numCardOut, sampleRate, frameSize;
alsaPlugin = manager->getConfigString(AUDIO, ALSA_PLUGIN);
numCardIn = manager->getConfigInt(AUDIO, ALSA_CARD_ID_IN);
numCardOut = manager->getConfigInt(AUDIO, ALSA_CARD_ID_OUT);
sampleRate = manager->getConfigInt(AUDIO, AUDIO_SAMPLE_RATE);
frameSize = manager->getConfigInt(AUDIO, ALSA_FRAME_SIZE);
CPPUNIT_ASSERT (_pulselayer->getPlaybackStream() == NULL);
CPPUNIT_ASSERT (_pulselayer->getRecordStream() == NULL);
_pulselayer->setErrorMessage(-1);
try {
CPPUNIT_ASSERT (_pulselayer->openDevice (numCardIn, numCardOut, sampleRate, frameSize, SFL_PCM_BOTH, alsaPlugin) == true);
} catch (...) {
_debug ("Exception occured wile opening device! ");
}
usleep(100000);
CPPUNIT_ASSERT (_pulselayer->getPlaybackStream() == NULL);
CPPUNIT_ASSERT (_pulselayer->getRecordStream() == NULL);
_debug ("-------------------------- \n");
_pulselayer->startStream();
CPPUNIT_ASSERT (_pulselayer->getPlaybackStream()->pulseStream() != NULL);
CPPUNIT_ASSERT (_pulselayer->getPlaybackStream()->pulseStream() != NULL);
// Must return No error "PA_OK" == 1
CPPUNIT_ASSERT (_pulselayer->getPlaybackStream()->getStreamState() == 1);
CPPUNIT_ASSERT (_pulselayer->getRecordStream()->getStreamState() == 1);
CPPUNIT_ASSERT (_pulselayer->getPlaybackStream()->disconnectStream() == true);
CPPUNIT_ASSERT (_pulselayer->getRecordStream()->disconnectStream() == true);
CPPUNIT_ASSERT (_pulselayer->getPlaybackStream()->connectStream() == true);
CPPUNIT_ASSERT (_pulselayer->getRecordStream()->connectStream() == true);
CPPUNIT_ASSERT (_pulselayer->getPlaybackStream()->getStreamState() == 1);
CPPUNIT_ASSERT (_pulselayer->getRecordStream()->getStreamState() == 1);
CPPUNIT_ASSERT (_pulselayer->getPlaybackStream()->connectStream() == true);
CPPUNIT_ASSERT (_pulselayer->getRecordStream()->connectStream() == true);
CPPUNIT_ASSERT (_pulselayer->getPlaybackStream()->getStreamState() == 1);
CPPUNIT_ASSERT (_pulselayer->getRecordStream()->getStreamState() == 1);
CPPUNIT_ASSERT (_pulselayer->disconnectAudioStream() == true);
}
/*
* Copyright (C) 2009 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.
*/
/*
* @file audiorecorderTest.cpp
* @brief Regroups unitary tests related to the plugin manager.
*/
#ifndef _AUDIOLAYER_TEST_
#define _AUDIOLAYER_TEST_
// 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 "config/config.h"
#include "user_cfg.h"
#include "audio/audiolayer.h"
#include "audio/alsa/alsalayer.h"
#include "audio/pulseaudio/pulselayer.h"
class AudioLayerTest: public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( AudioLayerTest );
CPPUNIT_TEST( testAudioLayerConfig );
CPPUNIT_TEST( testPulseConnect );
//TODO: this test ends the test sequence when using on a alsa only system
//CPPUNIT_TEST(testAudioLayerSwitch);
CPPUNIT_TEST_SUITE_END();
public:
void testAudioLayerConfig();
void testPulseConnect();
void testAudioLayerSwitch();
private:
ManagerImpl* manager;
PulseLayer* _pulselayer;
int layer;
};
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AudioLayerTest, "AudioLayerTest");
CPPUNIT_TEST_SUITE_REGISTRATION( AudioLayerTest );
#endif
/*
* 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.
*/
#include <stdio.h>
#include <sstream>
#include "configurationtest.h"
#include "constants.h"
using std::cout;
using std::endl;
void ConfigurationTest::testDefaultValueAudio() {
_debug ("-------------------- ConfigurationTest::testDefaultValueAudio() --------------------\n");
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, AUDIO_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::testDefaultValuePreferences() {
_debug ("-------------------- ConfigurationTest::testDefaultValuePreferences --------------------\n");
CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, ZONE_TONE) == DFT_ZONE);
CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, CONFIG_DIALPAD) == NO_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) == NO_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) == NO_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::testDefaultValueSignalisation() {
_debug ("-------------------- ConfigurationTest::testDefaultValueSignalisation --------------------\n");
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::testLoadSIPAccount() {
_debug ("-------------------- ConfigurationTest::testLoadSIPAccount --------------------\n");
AccountMap accounts;
Account *current;
std::ostringstream ss;
int nb_account; // Must be 1
// Load the account from the user file
nb_account = Manager::instance().loadAccountMap();
CPPUNIT_ASSERT_EQUAL (1, nb_account);
// Save the account information
accounts = Manager::instance()._accountMap;
AccountMap::iterator iter = accounts.begin();
CPPUNIT_ASSERT (Manager::instance().accountExists (iter->first) == true);
while (iter != accounts.end()) {
current = iter->second;
CPPUNIT_ASSERT (iter->first == current->getAccountID());
CPPUNIT_ASSERT (0 == current->getVoIPLink());
iter++;
}
}
void ConfigurationTest::testUnloadSIPAccount() {
_debug ("-------------------- ConfigurationTest::testUnloadSIPAccount --------------------\n");
AccountMap accounts;
// Load the accounts from the user file
Manager::instance().loadAccountMap();
// Unload the accounts
Manager::instance().unloadAccountMap();
// Save the account information
accounts = Manager::instance()._accountMap;
AccountMap::iterator iter = accounts.begin();
CPPUNIT_ASSERT (Manager::instance().accountExists (iter->first) == false);
if (iter != accounts.end()) {
CPPUNIT_FAIL ("Unload account map failed\n");
}
}
void ConfigurationTest::testInitVolume() {
_debug ("-------------------- ConfigurationTest::testInitVolume --------------------\n");
Manager::instance().initVolume();
CPPUNIT_ASSERT (Manager::instance().getConfigInt (AUDIO, VOLUME_SPKR) == Manager::instance().getSpkrVolume());
CPPUNIT_ASSERT (Manager::instance().getConfigInt (AUDIO, VOLUME_MICRO) == Manager::instance().getMicVolume());
}
void ConfigurationTest::testInitAudioDriver() {
_debug ("-------------------- ConfigurationTest::testInitAudioDriver --------------------\n");
// Load the audio driver
Manager::instance().initAudioDriver();
// Check the creation
if (Manager::instance().getAudioDriver() == NULL)
CPPUNIT_FAIL ("Error while loading audio layer");
// Check if it has been created with the right type
if (Manager::instance().getConfigInt(PREFERENCES, CONFIG_AUDIO) == ALSA)
CPPUNIT_ASSERT_EQUAL (Manager::instance().getAudioDriver()->getLayerType(), ALSA);
else if (Manager::instance().getConfigInt(PREFERENCES, CONFIG_AUDIO)
== PULSEAUDIO)
CPPUNIT_ASSERT_EQUAL (Manager::instance().getAudioDriver()->getLayerType(), PULSEAUDIO);
else
CPPUNIT_FAIL ("Wrong audio layer type");
}
/*
* 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.
*/
/*
* @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_
// 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 "audio/audiolayer.h"
#include "global.h"
#include "user_cfg.h"
class ConfigurationTest: public CppUnit::TestFixture {
/*
* Use cppunit library macros to add unit test the factory
*/
CPPUNIT_TEST_SUITE( ConfigurationTest );
CPPUNIT_TEST( testInitVolume );
CPPUNIT_TEST( testDefaultValueAudio );
CPPUNIT_TEST( testDefaultValuePreferences );
CPPUNIT_TEST( testDefaultValueSignalisation );
CPPUNIT_TEST( testInitAudioDriver );
CPPUNIT_TEST_SUITE_END();
public:
/*
* Unit tests related to the audio preferences
*/
void testDefaultValueAudio();
/*
* Unit tests related to the global settings
*/
void testDefaultValuePreferences();
/*
* Unit tests related to the global settings
*/
void testDefaultValueSignalisation();
/*
* Try to load one SIP account.
* So be sure to have only one SIP account so that the test could succeed
*/
void testLoadSIPAccount();
void testUnloadSIPAccount();
void testInitVolume();
void testInitAudioDriver();
};
/* Register our test module */
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ConfigurationTest, "ConfigurationTest");
CPPUNIT_TEST_SUITE_REGISTRATION( ConfigurationTest );
#endif
/*
* constants.h
*
* Created on: 2010-03-15
* Author: jb
*/
#ifndef CONSTANTS_H_
#define CONSTANTS_H_
#define YES_STR "1"
#define NO_STR "0"
#define HISTORY_SAMPLE "history-sample"
#define HISTORY_SAMPLE_SIZE 3
#define CONFIG_SAMPLE "sflphonedrc-sample"
#define HUGE_HISTORY_LIMIT 20000
#endif /* CONSTANTS_H_ */
[144562436]
accountid=
name=Savoir-faire Linux
number=514-276-5468
timestamp_stop=144562458
type=0
[747638685]
accountid=Account:1239059899
name=Emmanuel Milou
number=136
timestamp_stop=747638765
type=2
[775354456]
accountid=Account:43789459478
name=
number=5143848557
timestamp_stop=775354987
type=1
[144562436]
number=514-276-5468
name=Savoir-faire Linux
type=0
timestamp_stop=144562458
accountid=
[747638685]
name=Emmanuel Milou
timestamp_stop=747638765
number=136
type=2
accountid=Account:1239059899
[775354456]
number=5143848557
name=
timestamp_stop=775354987
type=1
accountid=Account:43789459478
/*
* Copyright (C) 2009 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.
*/
#include <stdio.h>
#include <sstream>
#include "historytest.h"
#include "manager.h"
#include "constants.h"
#include "validator.h"
using std::cout;
using std::endl;
void HistoryTest::setUp() {
// Instanciate the cleaner singleton
history = new HistoryManager();
}
void HistoryTest::test_create_history_path() {
_debug ("-------------------- HistoryTest::test_create_history_path --------------------\n");
int result;
char *cpath;
std::string path;
cpath = getenv("XDG_DATA_HOME");
(cpath != NULL) ? path = std::string(cpath) : path = std::string(HOMEDIR)
+ "/.local/share/sflphone/history";
result = history->create_history_path();
CPPUNIT_ASSERT (result == 0);
CPPUNIT_ASSERT (!history->is_loaded ());
CPPUNIT_ASSERT (history->_history_path == path);
}
void HistoryTest::test_load_history_from_file() {
_debug ("-------------------- HistoryTest::test_load_history_from_file --------------------\n");
bool res;
Conf::ConfigTree history_list;
history->create_history_path();
res = history->load_history_from_file(&history_list);
CPPUNIT_ASSERT (history->is_loaded ());
CPPUNIT_ASSERT (res == true);
}
void HistoryTest::test_load_history_items_map() {
_debug ("-------------------- HistoryTest::test_load_history_items_map --------------------\n");
std::string path;
int nb_items;
Conf::ConfigTree history_list;
history->set_history_path(HISTORY_SAMPLE);
history->load_history_from_file(&history_list);
nb_items = history->load_history_items_map(&history_list,
HUGE_HISTORY_LIMIT);
CPPUNIT_ASSERT (nb_items == HISTORY_SAMPLE_SIZE);
CPPUNIT_ASSERT (history->get_history_size () == HISTORY_SAMPLE_SIZE);
}
void HistoryTest::test_save_history_items_map() {
_debug ("-------------------- HistoryTest::test_save_history_items_map --------------------\n");
std::string path;
int nb_items_loaded, nb_items_saved;
Conf::ConfigTree history_list, history_list2;
history->set_history_path(HISTORY_SAMPLE);
history->load_history_from_file(&history_list);
nb_items_loaded = history->load_history_items_map(&history_list,
HUGE_HISTORY_LIMIT);
nb_items_saved = history->save_history_items_map(&history_list2);
CPPUNIT_ASSERT (nb_items_loaded == nb_items_saved);
}
void HistoryTest::test_save_history_to_file() {
_debug ("-------------------- HistoryTest::test_save_history_to_file --------------------\n");
std::string path;
Conf::ConfigTree history_list, history_list2;
std::map<std::string, std::string> res;
std::map<std::string, std::string>::iterator iter;
history->set_history_path(HISTORY_SAMPLE);
history->load_history_from_file(&history_list);
history->load_history_items_map(&history_list, HUGE_HISTORY_LIMIT);
history->save_history_items_map(&history_list2);
CPPUNIT_ASSERT (history->save_history_to_file (&history_list2));
}
void HistoryTest::test_get_history_serialized() {
_debug ("-------------------- HistoryTest::test_get_history_serialized --------------------\n");
std::map<std::string, std::string> res;
std::map<std::string, std::string>::iterator iter;
std::string tmp;
CPPUNIT_ASSERT (history->load_history (HUGE_HISTORY_LIMIT, HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE);
res = history->get_history_serialized();
CPPUNIT_ASSERT (res.size() ==HISTORY_SAMPLE_SIZE);
// Warning - If you change the history-sample file, you must change the following lines also so that the tests could work
// The reference here is the file history-sample in this test directory
// The serialized form is: calltype%to%from%callid
// Check the first
tmp = "0|514-276-5468|Savoir-faire Linux|144562458|empty";
CPPUNIT_ASSERT (Validator::isEqual(tmp, res ["144562436"]));
tmp = "2|136|Emmanuel Milou|747638765|Account:1239059899";
CPPUNIT_ASSERT (Validator::isEqual(tmp, res ["747638685"]));
// the account ID does not correspond to a loaded account
tmp = "1|5143848557|empty|775354987|empty";
CPPUNIT_ASSERT (Validator::isEqual(tmp, res ["775354456"]));
}
void HistoryTest::test_set_serialized_history() {
_debug ("-------------------- HistoryTest::test_set_serialized_history --------------------\n");
// We build a map to have an efficient test
std::map<std::string, std::string> map_test;
std::string tmp;
Conf::ConfigTree history_list;
map_test["144562436"] = "0|514-276-5468|Savoir-faire Linux|144562458|empty";
map_test["747638685"] = "2|136|Emmanuel Milou|747638765|Account:1239059899";
map_test["775354456"] = "1|5143848557|empty|775354987|Account:43789459478";
CPPUNIT_ASSERT (history->load_history (HUGE_HISTORY_LIMIT, HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE);
// We use a large history limit to be able to interpret results
CPPUNIT_ASSERT (history->set_serialized_history (map_test, HUGE_HISTORY_LIMIT) == 3);
CPPUNIT_ASSERT (history->get_history_size () == 3);
map_test.clear();
map_test = history->get_history_serialized();