diff --git a/sflphone-common/test/Makefile.am b/sflphone-common/test/Makefile.am index 46a90e6ccfe85c7a566e973a825122b52d3ade4b..c2371cd96a0f32b938b6be9b31d5cfb48021443d 100644 --- a/sflphone-common/test/Makefile.am +++ b/sflphone-common/test/Makefile.am @@ -1,16 +1,33 @@ 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 diff --git a/sflphone-common/test/accounttest.cpp b/sflphone-common/test/accounttest.cpp index c4e645cb9fd2f41cc10c5c8187eecbb7159e2afa..412a1b8b96f17dbd126ce7b3a25a33cac2e53f65 100644 --- a/sflphone-common/test/accounttest.cpp +++ b/sflphone-common/test/accounttest.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"; diff --git a/sflphone-common/test/accounttest.h b/sflphone-common/test/accounttest.h index 6422684adbac467dc835c67780f44f3488ad6e9e..61541c306881ee79bee6ed40a6307fb59017c213 100644 --- a/sflphone-common/test/accounttest.h +++ b/sflphone-common/test/accounttest.h @@ -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_ */ diff --git a/sflphone-common/test/audiolayertest.cpp b/sflphone-common/test/audiolayertest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7ea619ae2a84ccddbb11e17cc1d4e747e3f64ee2 --- /dev/null +++ b/sflphone-common/test/audiolayertest.cpp @@ -0,0 +1,133 @@ +/* + * 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); +} diff --git a/sflphone-common/test/audiolayertest.h b/sflphone-common/test/audiolayertest.h new file mode 100644 index 0000000000000000000000000000000000000000..b67edfe19c40e038042bc60e82ba3b6a1752017b --- /dev/null +++ b/sflphone-common/test/audiolayertest.h @@ -0,0 +1,72 @@ +/* + * 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 diff --git a/sflphone-common/test/configurationtest.cpp b/sflphone-common/test/configurationtest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3ccee26112b4983f28d566d48930988082bf4a48 --- /dev/null +++ b/sflphone-common/test/configurationtest.cpp @@ -0,0 +1,141 @@ +/* + * 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"); +} diff --git a/sflphone-common/test/configurationtest.h b/sflphone-common/test/configurationtest.h new file mode 100644 index 0000000000000000000000000000000000000000..7fe7c30ae0fcdcbea913cfbc39bf475e9888371d --- /dev/null +++ b/sflphone-common/test/configurationtest.h @@ -0,0 +1,88 @@ +/* + * 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 diff --git a/sflphone-common/test/constants.h b/sflphone-common/test/constants.h new file mode 100644 index 0000000000000000000000000000000000000000..28b27a69d6f3cf1464c565180c34ed1a93597ed3 --- /dev/null +++ b/sflphone-common/test/constants.h @@ -0,0 +1,18 @@ +/* + * 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_ */ diff --git a/sflphone-common/test/history-sample b/sflphone-common/test/history-sample new file mode 100644 index 0000000000000000000000000000000000000000..a6f39f4ed3316e02f1d5d3b750efc16ad43276d5 --- /dev/null +++ b/sflphone-common/test/history-sample @@ -0,0 +1,21 @@ +[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 + diff --git a/sflphone-common/test/history-sample.tpl b/sflphone-common/test/history-sample.tpl new file mode 100644 index 0000000000000000000000000000000000000000..221e449538f4d36e20f35bcb1c6d0dc1721e515e --- /dev/null +++ b/sflphone-common/test/history-sample.tpl @@ -0,0 +1,20 @@ +[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 diff --git a/sflphone-common/test/historytest.cpp b/sflphone-common/test/historytest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8634b60e48fa27000694cdf39735a0a0a8e54c8 --- /dev/null +++ b/sflphone-common/test/historytest.cpp @@ -0,0 +1,215 @@ +/* + * 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(); + CPPUNIT_ASSERT (map_test.size() ==3); + + // Check the first + tmp = "0|514-276-5468|Savoir-faire Linux|144562458|empty"; + CPPUNIT_ASSERT (Validator::isEqual(tmp, map_test ["144562436"])); + + tmp = "2|136|Emmanuel Milou|747638765|Account:1239059899"; + CPPUNIT_ASSERT (Validator::isEqual(tmp, map_test ["747638685"])); + + // the account ID does not correspond to a loaded account + tmp = "1|5143848557|empty|775354987|empty"; + CPPUNIT_ASSERT (Validator::isEqual(tmp, map_test ["775354456"])); + + history->save_history_items_map(&history_list); + CPPUNIT_ASSERT (history->save_history_to_file (&history_list)); +} + +void HistoryTest::test_set_serialized_history_with_limit() { + _debug ("-------------------- HistoryTest::test_set_serialized_history_with_limit --------------------\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; + time_t current, day = 86400; // One day in unix timestamp + std::stringstream current_1, current_2, current_3; + + (void) time(¤t); + current_1 << (current - 2 * day) << std::endl; + current_2 << (current - 5 * day) << std::endl; + current_3 << (current - 11 * day) << std::endl; + + map_test[current_1.str()] + = "0|514-276-5468|Savoir-faire Linux|144562458|empty"; + map_test[current_2.str()] + = "2|136|Emmanuel Milou|747638765|Account:1239059899"; + map_test[current_3.str()] + = "1|5143848557|empty|775354987|Account:43789459478"; + + CPPUNIT_ASSERT (history->load_history (HUGE_HISTORY_LIMIT, HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE); + // We use different value of history limit + // 10 days - the last entry should not be saved + CPPUNIT_ASSERT (history->set_serialized_history (map_test, 10) == 2); + CPPUNIT_ASSERT (history->get_history_size () == 2); + + // 4 days - the two last entries should not be saved + CPPUNIT_ASSERT (history->set_serialized_history (map_test, 4) == 1); + CPPUNIT_ASSERT (history->get_history_size () == 1); + + // 1 day - no entry should not be saved + CPPUNIT_ASSERT (history->set_serialized_history (map_test, 1) == 0); + CPPUNIT_ASSERT (history->get_history_size () == 0); +} + +void HistoryTest::tearDown() { + // Delete the history object + delete history; + history = 0; +} diff --git a/sflphone-common/test/historytest.h b/sflphone-common/test/historytest.h new file mode 100644 index 0000000000000000000000000000000000000000..334b9af7ffa2dbe9d588f6a0152212c51b5f9dfa --- /dev/null +++ b/sflphone-common/test/historytest.h @@ -0,0 +1,94 @@ +/* + * 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. + */ + +// 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 "history/historymanager.h" + +/* + * @file historyTest.h + * @brief Regroups unitary tests related to the phone number cleanup function. + */ + +#ifndef _HISTORY_TEST_ +#define _HISTORY_TEST_ + +class HistoryTest : public CppUnit::TestCase { + + /** + * Use cppunit library macros to add unit test the factory + */ + CPPUNIT_TEST_SUITE (HistoryTest); + CPPUNIT_TEST (test_create_history_path); + CPPUNIT_TEST (test_save_history_to_file); + CPPUNIT_TEST (test_save_history_items_map); + CPPUNIT_TEST (test_load_history_from_file); + CPPUNIT_TEST (test_load_history_items_map); + CPPUNIT_TEST (test_get_history_serialized); + CPPUNIT_TEST (test_set_serialized_history); + CPPUNIT_TEST (test_set_serialized_history_with_limit); + CPPUNIT_TEST_SUITE_END (); + + public: + HistoryTest() : CppUnit::TestCase("History Tests") {} + + /* + * Code factoring - Common resources can be initialized here. + * This method is called by unitcpp before each test + */ + void setUp(); + + void test_create_history_path (); + + void test_load_history_from_file (); + + void test_load_history_items_map (); + + void test_save_history_items_map (); + + void test_save_history_to_file (); + + void test_get_history_serialized (); + + void test_set_serialized_history (); + + void test_set_serialized_history_with_limit (); + + /* + * Code factoring - Common resources can be released here. + * This method is called by unitcpp after each test + */ + inline void tearDown (); + + private: + HistoryManager *history; +}; + +/* Register our test module */ +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(HistoryTest, "HistoryTest"); +CPPUNIT_TEST_SUITE_REGISTRATION( HistoryTest ); + +#endif diff --git a/sflphone-common/test/hookmanagertest.cpp b/sflphone-common/test/hookmanagertest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..57fc138a0a2cf230178eba3219a317940c9887cd --- /dev/null +++ b/sflphone-common/test/hookmanagertest.cpp @@ -0,0 +1,60 @@ +/* + * 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 <dlfcn.h> +#include "global.h" + +#include "hookmanagertest.h" + +using std::cout; +using std::endl; + + +void HookManagerTest::setUp() +{ + // Instanciate the hook manager singleton + urlhook = new UrlHook (); +} + +void HookManagerTest::testAddAction () +{ + _debug ("-------------------- HookManagerTest::testAddAction --------------------\n"); + + int status; + + status = urlhook->addAction ("http://www.google.ca/?arg1=arg1&arg2=nvls&x=2&y=45&z=1", "x-www-browser"); + CPPUNIT_ASSERT (status == 0); +} + +void HookManagerTest::testLargeUrl () +{ + _debug ("-------------------- HookManagerTest::testLargeUrl --------------------\n"); + + std::string url; + std::cout << url.max_size() << std::endl; +} + +void HookManagerTest::tearDown() +{ + // Delete the hook manager object + delete urlhook; + urlhook=0; +} diff --git a/sflphone-common/test/hookmanagertest.h b/sflphone-common/test/hookmanagertest.h new file mode 100644 index 0000000000000000000000000000000000000000..d9e130c0a5c781bd5f54bd40d7070a009f3df135 --- /dev/null +++ b/sflphone-common/test/hookmanagertest.h @@ -0,0 +1,71 @@ +/* + * 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 hookmanagerTest.cpp + * @brief Regroups unitary tests related to the hook manager. + */ + +#ifndef _HOOKMANAGER_TEST_ +#define _HOOKMANAGER_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 "hooks/urlhook.h" + +class HookManagerTest : public CppUnit::TestFixture { + + /** + * Use cppunit library macros to add unit test the factory + */ + CPPUNIT_TEST_SUITE (HookManagerTest); + CPPUNIT_TEST (testAddAction); + CPPUNIT_TEST (testLargeUrl); + CPPUNIT_TEST_SUITE_END (); + + public: + /* + * Code factoring - Common resources can be initialized here. + * This method is called by unitcpp before each test + */ + void setUp(); + + void testAddAction (); + + void testLargeUrl (); + /* + * Code factoring - Common resources can be released here. + * This method is called by unitcpp after each test + */ + void tearDown (); + + private: + UrlHook *urlhook; +}; +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(HookManagerTest, "HookManagerTest"); +CPPUNIT_TEST_SUITE_REGISTRATION( HookManagerTest ); + +#endif diff --git a/sflphone-common/test/main.cpp b/sflphone-common/test/main.cpp index 3dda5ada70ef4d27e7d97f15b8b515ddf798b46d..d0b7a6e09bfbd2b4ee483d44af932cc121fd0e95 100644 --- a/sflphone-common/test/main.cpp +++ b/sflphone-common/test/main.cpp @@ -17,27 +17,95 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "accounttest.h" #include "logger.h" #include "global.h" #include "manager.h" +#include "constants.h" + #include <cppunit/CompilerOutputter.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/ui/text/TextTestRunner.h> -int RunTests(void) { - Manager::instance().initConfigFile(); - Manager::instance().init(); +// TODO: Why some header cannot be included ? +#include "accounttest.h" +#include "audiolayertest.h" +#include "configurationtest.h" +//#include "historytest.h" +//#include "hookmanagertest.h" +#include "mainbuffertest.h" +#include "numbercleanertest.h" +//#include "pluginmanagertest.h" +//#include "rtptest.h" +#include "sdesnegotiatortest.h" + + +int main(int argc, char* argv[]) { + + printf("\nSFLphone Daemon Test Suite, by Savoir-Faire Linux 2004-2010\n\n"); - Logger::setDebugMode(true); Logger::setConsoleLog(true); + Logger::setDebugMode(true); + /* + Logger::setDebugMode(false); + + int argvIndex = 1; + + if (argc > 1) { + if (strcmp("--help", argv[1]) == 0) { + argvIndex++; + + CPPUNIT_NS::Test + *suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry( + "All Tests").makeTest(); + int testSuiteCount = suite->getChildTestCount(); + + printf("Usage: test [OPTIONS] [TEST_SUITE]\n"); + printf("\nOptions:\n"); + printf(" --debug - Debug mode\n"); + printf(" --help - Print help\n"); + printf("\nAvailable test suites:\n"); + for (int i = 0; i < testSuiteCount; i++) { + printf(" - %s\n", suite->getChildTestAt(i)->getName().c_str()); + } + exit(0); + } + else if (strcmp("--debug", argv[1]) == 0) { + argvIndex++; + + Logger::setDebugMode(true); + _info("Debug mode activated"); + } + } + + std::string testSuiteName = "All Tests"; + if(argvIndex < argc) + { + testSuiteName = argv[argvIndex]; + argvIndex++; + } + + printf("\n\n=== SFLphone initialization ===\n\n"); + Manager::instance().initConfigFile(true, CONFIG_SAMPLE); + Manager::instance().init(); + + printf("\n\n=== Test Suite: %s ===\n\n", testSuiteName.c_str()); // Get the top level suite from the registry - CppUnit::Test *suite = - CppUnit::TestFactoryRegistry::getRegistry().makeTest(); + CPPUNIT_NS::Test *suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry(testSuiteName).makeTest(); + */ + CPPUNIT_NS::Test *suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest(); + + /* + if(suite->getChildTestCount() == 0) + { + _error("Invalid test suite name: %s", testSuiteName.c_str()); + exit(-1); + } + */ + Manager::instance().initConfigFile(true, CONFIG_SAMPLE); + Manager::instance().init(); // Adds the test to the list of test to run - // CppUnit::TextUi::TestRunner runner; CppUnit::TextTestRunner runner; runner.addTest(suite); @@ -52,7 +120,3 @@ int RunTests(void) { Manager::instance().terminate(); } - -int main(void) { - return RunTests(); -} diff --git a/sflphone-common/test/mainbuffertest.cpp b/sflphone-common/test/mainbuffertest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2919828b475e28764fd7b9aafd202f10c16415c3 --- /dev/null +++ b/sflphone-common/test/mainbuffertest.cpp @@ -0,0 +1,1758 @@ +/* + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Alexandre Savard <alexandre.savard@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 <ccrtp/rtp.h> +#include <assert.h> +#include <string> +#include <cstring> +#include <math.h> +#include <dlfcn.h> +#include <iostream> +#include <sstream> + + +#include "mainbuffertest.h" + +#include <unistd.h> + + +using std::cout; +using std::endl; + + +void MainBufferTest::setUp() +{ + + +} + + +void MainBufferTest::tearDown() +{ + +} + + +void MainBufferTest::testRingBufferCreation() +{ + _debug ("-------------------- MainBufferTest::testRingBufferCreation --------------------\n"); + + CallID test_id = "1234"; + CallID null_id = "null id"; + + RingBuffer* test_ring_buffer; + RingBufferMap::iterator iter; + + // test mainbuffer ringbuffer map size + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 0); + test_ring_buffer = _mainbuffer.createRingBuffer (test_id); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 1); + + // test _mainbuffer.getRingBuffer method + CPPUNIT_ASSERT (test_ring_buffer != NULL); + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (null_id) == NULL); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 1); + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (test_id) == test_ring_buffer); + + // test _mainbuffer _ringBufferMap + iter = _mainbuffer._ringBufferMap.find (null_id); + CPPUNIT_ASSERT (iter == _mainbuffer._ringBufferMap.end()); + iter = _mainbuffer._ringBufferMap.find (test_id); + CPPUNIT_ASSERT (iter->first == test_id); + CPPUNIT_ASSERT (iter->second == test_ring_buffer); + CPPUNIT_ASSERT (iter->second == _mainbuffer.getRingBuffer (test_id)); + + // test creating twice a buffer (should not create it) + _mainbuffer.createRingBuffer (test_id); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 1); + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (test_id) == test_ring_buffer); + + // test remove ring buffer + CPPUNIT_ASSERT (_mainbuffer.removeRingBuffer (null_id) == true); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 1); + CPPUNIT_ASSERT (_mainbuffer.removeRingBuffer (test_id) == true); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 0); + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (test_id) == NULL); + + iter = _mainbuffer._ringBufferMap.find (test_id); + CPPUNIT_ASSERT (iter == _mainbuffer._ringBufferMap.end()); + +} + + +void MainBufferTest::testRingBufferReadPointer() +{ + _debug ("-------------------- MainBufferTest::testRingBufferReadPointer --------------------\n"); + + CallID call_id = "call id"; + CallID read_id = "read id"; + CallID null_id = "null id"; + CallID other_id = "other id"; + + RingBuffer* test_ring_buffer; + + // test ring buffer read pointers (one per participant) + test_ring_buffer = _mainbuffer.createRingBuffer (call_id); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 0); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (read_id) == (int) NULL); + + // create a read pointer + test_ring_buffer->createReadPointer (read_id); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 1); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (null_id) == (int) NULL); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (read_id) == 0); + + // store read pointer + test_ring_buffer->storeReadPointer (4, read_id); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 1); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (read_id) == 4); + + // recreate the same read pointer (should not add a pointer neither chage its value) + test_ring_buffer->createReadPointer (read_id); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 1); + test_ring_buffer->storeReadPointer (8, read_id); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (read_id) == 8); + + // test getSmallest read pointer (to get the length available to put data in the buffer) + test_ring_buffer->createReadPointer (other_id); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 2); + test_ring_buffer->storeReadPointer (4, other_id); + CPPUNIT_ASSERT (test_ring_buffer->getSmallestReadPointer() == 4); + + // remove read pointers + test_ring_buffer->removeReadPointer (other_id); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 1); + test_ring_buffer->removeReadPointer (read_id); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 0); +} + + +void MainBufferTest::testCallIDSet() +{ + _debug ("-------------------- MainBufferTest::testCallIDSet --------------------\n"); + + CallID test_id = "set id"; + CallID false_id = "false set id"; + // CallIDSet* callid_set = 0; + + CallIDMap::iterator iter_map; + CallIDSet::iterator iter_set; + + CallID call_id_1 = "call id 1"; + CallID call_id_2 = "call id 2"; + + // test initial settings + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 0); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 0); + iter_map = _mainbuffer._callIDMap.find (test_id); + CPPUNIT_ASSERT (iter_map ==_mainbuffer._callIDMap.end()); + + // test callidset creation + CPPUNIT_ASSERT (_mainbuffer.createCallIDSet (test_id) == true); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 1); + iter_map = _mainbuffer._callIDMap.find (test_id); + CPPUNIT_ASSERT (iter_map->first == test_id); + CPPUNIT_ASSERT (iter_map->second == _mainbuffer.getCallIDSet (test_id)); + + CPPUNIT_ASSERT (_mainbuffer.getCallIDSet (false_id) == NULL); + CPPUNIT_ASSERT (_mainbuffer.getCallIDSet (test_id) != NULL); + + + // Test callIDSet add call_ids + _mainbuffer.addCallIDtoSet (test_id, call_id_1); + iter_map = _mainbuffer._callIDMap.find (test_id); + CPPUNIT_ASSERT (iter_map->second->size() == 1); + iter_set = iter_map->second->find (call_id_1); + CPPUNIT_ASSERT (*iter_set == call_id_1); + + // test add second call id to set + _mainbuffer.addCallIDtoSet (test_id, call_id_2); + iter_map = _mainbuffer._callIDMap.find (test_id); + CPPUNIT_ASSERT (iter_map->second->size() == 2); + iter_set = iter_map->second->find (call_id_2); + CPPUNIT_ASSERT (*iter_set == call_id_2); + + // test add a call id twice + _mainbuffer.addCallIDtoSet (test_id, call_id_2); + iter_map = _mainbuffer._callIDMap.find (test_id); + CPPUNIT_ASSERT (iter_map->second->size() == 2); + iter_set = iter_map->second->find (call_id_2); + CPPUNIT_ASSERT (*iter_set == call_id_2); + + // test remove a call id + _mainbuffer.removeCallIDfromSet (test_id, call_id_2); + iter_map = _mainbuffer._callIDMap.find (test_id); + CPPUNIT_ASSERT (iter_map->second->size() == 1); + iter_set = iter_map->second->find (call_id_1); + CPPUNIT_ASSERT (*iter_set == call_id_1); + iter_set = iter_map->second->find (call_id_2); + CPPUNIT_ASSERT (iter_set == iter_map->second->end()); + + // test remove a call id twice + _mainbuffer.removeCallIDfromSet (test_id, call_id_2); + iter_map = _mainbuffer._callIDMap.find (test_id); + CPPUNIT_ASSERT (iter_map->second->size() == 1); + iter_set = iter_map->second->find (call_id_1); + CPPUNIT_ASSERT (*iter_set == call_id_1); + iter_set = iter_map->second->find (call_id_2); + CPPUNIT_ASSERT (iter_set == iter_map->second->end()); + + // Test removeCallIDSet + CPPUNIT_ASSERT (_mainbuffer.removeCallIDSet (false_id) == false); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 1); + CPPUNIT_ASSERT (_mainbuffer.removeCallIDSet (test_id) == true); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 0); + + iter_map = _mainbuffer._callIDMap.find (test_id); + CPPUNIT_ASSERT (iter_map ==_mainbuffer._callIDMap.end()); + + +} + + +void MainBufferTest::testRingBufferInt() +{ + _debug ("-------------------- MainBufferTest::testRingBufferInt --------------------\n"); + + // CallID test_id = "test_int"; + + int testint1 = 12; + int testint2 = 13; + int init_put_size; + + + // test with default ring buffer + RingBuffer* test_ring_buffer = _mainbuffer.createRingBuffer (default_id); + + // initial state + init_put_size = test_ring_buffer->AvailForPut(); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 0); + + // add some data + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint1, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 0); + + // add some other data + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint2, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - 2* (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 0); + + int testget = (int) NULL; + + // get some data (without any read pointers) + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen() == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->Get (&testget, sizeof (int)) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen() == 2*sizeof (int)); + CPPUNIT_ASSERT (testget == (int) NULL); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - 2* (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 0); + + // get some data (with a read pointer) + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 0); + test_ring_buffer->createReadPointer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 1); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == 0); + CPPUNIT_ASSERT (test_ring_buffer->getLen() == 0); + + // add some data + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint1, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 2*sizeof (int)); + + // add some other data + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint2, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - 2* (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 2*sizeof (int)); + + CPPUNIT_ASSERT (test_ring_buffer->Get (&testget, sizeof (int), 100, default_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen() == sizeof (int)); + CPPUNIT_ASSERT (testget == testint1); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 3*sizeof (int)); + + CPPUNIT_ASSERT (test_ring_buffer->Get (&testget, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (testget == testint2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == 0); + CPPUNIT_ASSERT (test_ring_buffer->getLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_size); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 4*sizeof (int)); + + + // test flush data + init_put_size = test_ring_buffer->AvailForPut(); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint1, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen() == sizeof (int)); + + + test_ring_buffer->flush(); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_size); + CPPUNIT_ASSERT (test_ring_buffer->getLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == 0); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 5*sizeof (int)); + + // test flush data + init_put_size = test_ring_buffer->AvailForPut(); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint1, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 5*sizeof (int)); + + test_ring_buffer->Discard (sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_size); + CPPUNIT_ASSERT (test_ring_buffer->getLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == 0); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 6*sizeof (int)); + + +} + + +void MainBufferTest::testRingBufferNonDefaultID() +{ + _debug ("-------------------- MainBufferTest::testRingBufferNonDefaultID --------------------\n"); + + CallID test_id = "test_int"; + + int testint1 = 12; + int testint2 = 13; + int init_put_size; + + + // test putData, getData with arbitrary read pointer id + RingBuffer* test_ring_buffer = _mainbuffer.createRingBuffer (default_id); + test_ring_buffer->createReadPointer (test_id); + + init_put_size = test_ring_buffer->AvailForPut(); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (default_id) == 0); + + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint1, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (default_id) == 0); + + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint2, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - 2* (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (default_id) == 0); + + int testget; + + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id) == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_id) == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->Get (&testget, sizeof (int), 100, test_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_id) == sizeof (int)); + CPPUNIT_ASSERT (testget == testint1); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (test_id) == sizeof (int)); + + CPPUNIT_ASSERT (test_ring_buffer->Get (&testget, sizeof (int), 100, test_id) == sizeof (int)); + CPPUNIT_ASSERT (testget == testint2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_size); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (test_id) == 2*sizeof (int)); + + + // test flush data + init_put_size = test_ring_buffer->AvailForPut(); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint1, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_id) == sizeof (int)); + + + test_ring_buffer->flush (test_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_size); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (test_id) == 3*sizeof (int)); + + // test flush data + init_put_size = test_ring_buffer->AvailForPut(); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint1, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (init_put_size - (int) sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (test_id) == 3*sizeof (int)); + + test_ring_buffer->Discard (sizeof (int), test_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_size); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (test_id) == 4*sizeof (int)); + + test_ring_buffer->removeReadPointer (test_id); + +} + + +void MainBufferTest::testRingBufferFloat() +{ + _debug ("-------------------- MainBufferTest::testRingBufferFloat --------------------\n"); + + float testfloat1 = 12.5; + float testfloat2 = 13.4; + + RingBuffer* test_ring_buffer = _mainbuffer.createRingBuffer (default_id); + test_ring_buffer->createReadPointer (default_id); + + + CPPUNIT_ASSERT (test_ring_buffer->Put (&testfloat1, sizeof (float)) == sizeof (float)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (float)); + + CPPUNIT_ASSERT (test_ring_buffer->Put (&testfloat2, sizeof (float)) == sizeof (float)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 2*sizeof (float)); + + float testget; + + CPPUNIT_ASSERT (test_ring_buffer->Get (&testget, sizeof (float)) == sizeof (float)); + CPPUNIT_ASSERT (test_ring_buffer->getLen() == sizeof (float)); + CPPUNIT_ASSERT (testget == testfloat1); + + CPPUNIT_ASSERT (test_ring_buffer->Get (&testget, sizeof (float)) == sizeof (float)); + CPPUNIT_ASSERT (testget == testfloat2); + CPPUNIT_ASSERT (test_ring_buffer->getLen() == 0); + + CPPUNIT_ASSERT (test_ring_buffer->Put (&testfloat1, sizeof (float)) == sizeof (float)); + test_ring_buffer->flush(); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + +} + + +void MainBufferTest::testTwoPointer() +{ + _debug ("-------------------- MainBufferTest::testTwoPointer --------------------\n"); + + RingBuffer* input_buffer = _mainbuffer.createRingBuffer (default_id); + input_buffer->createReadPointer (default_id); + RingBuffer* output_buffer = _mainbuffer.getRingBuffer (default_id); + + int test_input = 12; + int test_output; + + CPPUNIT_ASSERT (input_buffer->Put (&test_input, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (output_buffer->Get (&test_output, sizeof (float)) == sizeof (float)); + CPPUNIT_ASSERT (test_input == test_output); + +} + +void MainBufferTest::testBindUnbindBuffer() +{ + _debug ("-------------------- MainBufferTest::testBindUnbindBuffer --------------------\n"); + + CallID test_id1 = "bind unbind 1"; + CallID test_id2 = "bind unbind 2"; + + RingBufferMap::iterator iter_buffer; + CallIDMap::iterator iter_idset; + CallIDSet::iterator iter_id; + + ReadPointer::iterator iter_readpointer; + + RingBuffer* ringbuffer; + + // test initial state with no ring brffer created + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 0); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 0); + + iter_buffer = _mainbuffer._ringBufferMap.find (default_id); + CPPUNIT_ASSERT (iter_buffer == _mainbuffer._ringBufferMap.end()); + iter_idset = _mainbuffer._callIDMap.find (default_id); + CPPUNIT_ASSERT (iter_idset == _mainbuffer._callIDMap.end()); + + // bind test_id1 with default_id (both buffer not already created) + _mainbuffer.bindCallID (test_id1); + + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 2); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 2); + + iter_buffer = _mainbuffer._ringBufferMap.find (default_id); + CPPUNIT_ASSERT (iter_buffer->first == default_id); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (default_id)); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id1); + CPPUNIT_ASSERT (iter_buffer->first == test_id1); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (test_id1)); + + iter_idset = _mainbuffer._callIDMap.find (default_id); + CPPUNIT_ASSERT (iter_idset->second->size() == 1); + iter_id = iter_idset->second->find (test_id1); + CPPUNIT_ASSERT (*iter_id == test_id1); + + iter_idset = _mainbuffer._callIDMap.find (test_id1); + CPPUNIT_ASSERT (iter_idset->second->size() == 1); + iter_id = iter_idset->second->find (default_id); + CPPUNIT_ASSERT (*iter_id == default_id); + + ringbuffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 1); + iter_readpointer = ringbuffer->_readpointer.find (test_id1); + CPPUNIT_ASSERT (iter_readpointer->first == test_id1); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + + ringbuffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 1); + iter_readpointer = ringbuffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + + + // unbind test_id1 with default_id + _mainbuffer.unBindCallID (test_id1); + + _debug ("%i", (int) (_mainbuffer._ringBufferMap.size())); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 0); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 0); + + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (default_id) == NULL); + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (test_id1) == NULL); + + + // bind test_id2 with default_id (default_id already created) + // calling it twice not supposed to break anything + _mainbuffer.bindCallID (test_id1, default_id); + _mainbuffer.bindCallID (test_id1, default_id); + + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 2); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 2); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id2); + CPPUNIT_ASSERT (iter_buffer == _mainbuffer._ringBufferMap.end()); + iter_idset = _mainbuffer._callIDMap.find (test_id2); + CPPUNIT_ASSERT (iter_idset == _mainbuffer._callIDMap.end()); + + _mainbuffer.bindCallID (test_id2, default_id); + _mainbuffer.bindCallID (test_id2, default_id); + + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 3); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 3); + + iter_buffer = _mainbuffer._ringBufferMap.find (default_id); + CPPUNIT_ASSERT (iter_buffer->first == default_id); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (default_id)); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id1); + CPPUNIT_ASSERT (iter_buffer->first == test_id1); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (test_id1)); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id2); + CPPUNIT_ASSERT (iter_buffer->first == test_id2); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (test_id2)); + + iter_idset = _mainbuffer._callIDMap.find (default_id); + CPPUNIT_ASSERT (iter_idset->second->size() == 2); + iter_id = iter_idset->second->find (test_id1); + CPPUNIT_ASSERT (*iter_id == test_id1); + iter_id = iter_idset->second->find (test_id2); + CPPUNIT_ASSERT (*iter_id == test_id2); + + iter_idset = _mainbuffer._callIDMap.find (test_id1); + CPPUNIT_ASSERT (iter_idset->second->size() == 1); + iter_id = iter_idset->second->find (default_id); + CPPUNIT_ASSERT (*iter_id == default_id); + + iter_idset = _mainbuffer._callIDMap.find (test_id2); + CPPUNIT_ASSERT (iter_idset->second->size() == 1); + iter_id = iter_idset->second->find (default_id); + CPPUNIT_ASSERT (*iter_id == default_id); + + ringbuffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 2); + iter_readpointer = ringbuffer->_readpointer.find (test_id1); + CPPUNIT_ASSERT (iter_readpointer->first == test_id1); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = ringbuffer->_readpointer.find (test_id2); + CPPUNIT_ASSERT (iter_readpointer->first == test_id2); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + + ringbuffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 1); + iter_readpointer = ringbuffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + + ringbuffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 1); + iter_readpointer = ringbuffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + + // bind test_id1 with test_id2 (both testid1 and test_id2 already created) + // calling it twice not supposed to break anything + _mainbuffer.bindCallID (test_id1, test_id2); + _mainbuffer.bindCallID (test_id1, test_id2); + + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 3); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 3); + + iter_buffer = _mainbuffer._ringBufferMap.find (default_id); + CPPUNIT_ASSERT (iter_buffer->first == default_id); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (default_id)); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id1); + CPPUNIT_ASSERT (iter_buffer->first == test_id1); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (test_id1)); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id2); + CPPUNIT_ASSERT (iter_buffer->first == test_id2); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (test_id2)); + + iter_idset = _mainbuffer._callIDMap.find (default_id); + CPPUNIT_ASSERT (iter_idset->second->size() == 2); + iter_id = iter_idset->second->find (test_id1); + CPPUNIT_ASSERT (*iter_id == test_id1); + iter_id = iter_idset->second->find (test_id2); + CPPUNIT_ASSERT (*iter_id == test_id2); + + iter_idset = _mainbuffer._callIDMap.find (test_id1); + CPPUNIT_ASSERT (iter_idset->second->size() == 2); + iter_id = iter_idset->second->find (default_id); + CPPUNIT_ASSERT (*iter_id == default_id); + iter_id = iter_idset->second->find (test_id2); + CPPUNIT_ASSERT (*iter_id == test_id2); + + iter_idset = _mainbuffer._callIDMap.find (test_id2); + CPPUNIT_ASSERT (iter_idset->second->size() == 2); + iter_id = iter_idset->second->find (default_id); + CPPUNIT_ASSERT (*iter_id == default_id); + iter_id = iter_idset->second->find (test_id1); + CPPUNIT_ASSERT (*iter_id == test_id1); + + ringbuffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 2); + iter_readpointer = ringbuffer->_readpointer.find (test_id1); + CPPUNIT_ASSERT (iter_readpointer->first == test_id1); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = ringbuffer->_readpointer.find (test_id2); + CPPUNIT_ASSERT (iter_readpointer->first == test_id2); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + + ringbuffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 2); + iter_readpointer = ringbuffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = ringbuffer->_readpointer.find (test_id2); + CPPUNIT_ASSERT (iter_readpointer->first == test_id2); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + + ringbuffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 2); + iter_readpointer = ringbuffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = ringbuffer->_readpointer.find (test_id1); + CPPUNIT_ASSERT (iter_readpointer->first == test_id1); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + + // unbind test_id1 with test_id2 + // calling it twice not supposed to break anything + _mainbuffer.unBindCallID (test_id1, test_id2); + _mainbuffer.unBindCallID (test_id1, test_id2); + + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 3); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 3); + + iter_buffer = _mainbuffer._ringBufferMap.find (default_id); + CPPUNIT_ASSERT (iter_buffer->first == default_id); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (default_id)); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id1); + CPPUNIT_ASSERT (iter_buffer->first == test_id1); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (test_id1)); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id2); + CPPUNIT_ASSERT (iter_buffer->first == test_id2); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (test_id2)); + + iter_idset = _mainbuffer._callIDMap.find (default_id); + CPPUNIT_ASSERT (iter_idset->second->size() == 2); + iter_id = iter_idset->second->find (test_id1); + CPPUNIT_ASSERT (*iter_id == test_id1); + iter_id = iter_idset->second->find (test_id2); + CPPUNIT_ASSERT (*iter_id == test_id2); + + iter_idset = _mainbuffer._callIDMap.find (test_id1); + CPPUNIT_ASSERT (iter_idset->second->size() == 1); + iter_id = iter_idset->second->find (default_id); + CPPUNIT_ASSERT (*iter_id == default_id); + + iter_idset = _mainbuffer._callIDMap.find (test_id2); + CPPUNIT_ASSERT (iter_idset->second->size() == 1); + iter_id = iter_idset->second->find (default_id); + CPPUNIT_ASSERT (*iter_id == default_id); + + ringbuffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 2); + iter_readpointer = ringbuffer->_readpointer.find (test_id1); + CPPUNIT_ASSERT (iter_readpointer->first == test_id1); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = ringbuffer->_readpointer.find (test_id2); + CPPUNIT_ASSERT (iter_readpointer->first == test_id2); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + + ringbuffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 1); + iter_readpointer = ringbuffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + + ringbuffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 1); + iter_readpointer = ringbuffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + + + _debug ("ok1"); + + // unbind test_id1 with test_id2 + // calling it twice not supposed to break anything + _mainbuffer.unBindCallID (default_id, test_id2); + _mainbuffer.unBindCallID (default_id, test_id2); + + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 2); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 2); + + iter_buffer = _mainbuffer._ringBufferMap.find (default_id); + CPPUNIT_ASSERT (iter_buffer->first == default_id); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (default_id)); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id1); + CPPUNIT_ASSERT (iter_buffer->first == test_id1); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (test_id1)); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id2); + CPPUNIT_ASSERT (iter_buffer == _mainbuffer._ringBufferMap.end()); + + iter_idset = _mainbuffer._callIDMap.find (default_id); + CPPUNIT_ASSERT (iter_idset->second->size() == 1); + iter_id = iter_idset->second->find (test_id1); + CPPUNIT_ASSERT (*iter_id == test_id1); + iter_id = iter_idset->second->find (test_id2); + CPPUNIT_ASSERT (iter_id == iter_idset->second->end()); + + iter_idset = _mainbuffer._callIDMap.find (test_id1); + CPPUNIT_ASSERT (iter_idset->second->size() == 1); + iter_id = iter_idset->second->find (default_id); + CPPUNIT_ASSERT (*iter_id == default_id); + + iter_idset = _mainbuffer._callIDMap.find (test_id2); + CPPUNIT_ASSERT (iter_idset == _mainbuffer._callIDMap.end()); + + ringbuffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 1); + iter_readpointer = ringbuffer->_readpointer.find (test_id1); + CPPUNIT_ASSERT (iter_readpointer->first == test_id1); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = ringbuffer->_readpointer.find (test_id2); + CPPUNIT_ASSERT (iter_readpointer == ringbuffer->_readpointer.end()); + + ringbuffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 1); + iter_readpointer = ringbuffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = ringbuffer->_readpointer.find (test_id2); + CPPUNIT_ASSERT (iter_readpointer == ringbuffer->_readpointer.end()); + + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (test_id2) == NULL); + + + _mainbuffer.unBindCallID (default_id, test_id1); + + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 0); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 0); + + // test unbind all function + _mainbuffer.bindCallID (default_id, test_id1); + _mainbuffer.bindCallID (default_id, test_id2); + _mainbuffer.bindCallID (test_id1, test_id2); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 3); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 3); + + _mainbuffer.unBindAll (test_id2); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 2); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 2); + + iter_buffer = _mainbuffer._ringBufferMap.find (default_id); + CPPUNIT_ASSERT (iter_buffer->first == default_id); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (default_id)); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id1); + CPPUNIT_ASSERT (iter_buffer->first == test_id1); + CPPUNIT_ASSERT (iter_buffer->second == _mainbuffer.getRingBuffer (test_id1)); + + iter_buffer = _mainbuffer._ringBufferMap.find (test_id2); + CPPUNIT_ASSERT (iter_buffer == _mainbuffer._ringBufferMap.end()); + + iter_idset = _mainbuffer._callIDMap.find (default_id); + CPPUNIT_ASSERT (iter_idset->second->size() == 1); + iter_id = iter_idset->second->find (test_id1); + CPPUNIT_ASSERT (*iter_id == test_id1); + iter_id = iter_idset->second->find (test_id2); + CPPUNIT_ASSERT (iter_id == iter_idset->second->end()); + + iter_idset = _mainbuffer._callIDMap.find (test_id1); + CPPUNIT_ASSERT (iter_idset->second->size() == 1); + iter_id = iter_idset->second->find (default_id); + CPPUNIT_ASSERT (*iter_id == default_id); + + iter_idset = _mainbuffer._callIDMap.find (test_id2); + CPPUNIT_ASSERT (iter_idset == _mainbuffer._callIDMap.end()); + + ringbuffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 1); + iter_readpointer = ringbuffer->_readpointer.find (test_id1); + CPPUNIT_ASSERT (iter_readpointer->first == test_id1); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = ringbuffer->_readpointer.find (test_id2); + CPPUNIT_ASSERT (iter_readpointer == ringbuffer->_readpointer.end()); + + ringbuffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (ringbuffer != NULL); + CPPUNIT_ASSERT (ringbuffer->getNbReadPointer() == 1); + iter_readpointer = ringbuffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = ringbuffer->_readpointer.find (test_id2); + CPPUNIT_ASSERT (iter_readpointer == ringbuffer->_readpointer.end()); + + +} + +void MainBufferTest::testGetPutDataByID() +{ + _debug ("-------------------- MainBufferTest::testGetPutDataByID --------------------\n"); + + CallID test_id = "getData putData"; + CallID false_id = "false id"; + + _mainbuffer.bindCallID (test_id); + + int test_input1 = 12; + int test_input2 = 13; + int test_output; + + int avail_for_put_testid; + int avail_for_put_defaultid; + + // put by default_id get by test_id without preleminary put + avail_for_put_defaultid = _mainbuffer.availForPut(); + CPPUNIT_ASSERT (_mainbuffer.availForGetByID (default_id, test_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.getDataByID (&test_output, sizeof (int), 100, default_id, test_id) == 0); + + // put by default_id, get by test_id + CPPUNIT_ASSERT (_mainbuffer.availForPut() == avail_for_put_defaultid); + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input1, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForPut() == (avail_for_put_defaultid - (int) sizeof (int))); + CPPUNIT_ASSERT (_mainbuffer.availForGetByID (default_id, test_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.getDataByID (&test_output, sizeof (int), 100, default_id, test_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGetByID (default_id, test_id) == 0); + CPPUNIT_ASSERT (test_input1 == test_output); + + // get by default_id without preliminary input + avail_for_put_testid = _mainbuffer.availForPut (test_id); + CPPUNIT_ASSERT (_mainbuffer.availForGetByID (test_id, default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.getDataByID (&test_output, sizeof (int), 100, test_id, default_id) == 0); + + // pu by test_id get by test_id + CPPUNIT_ASSERT (_mainbuffer.availForPut (test_id) == avail_for_put_defaultid); + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input2, sizeof (int), 100, test_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGetByID (test_id, default_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.getDataByID (&test_output, sizeof (int), 100, test_id, default_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGetByID (test_id, default_id) == 0); + CPPUNIT_ASSERT (test_input2 == test_output); + + // put/get by false id + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input2, sizeof (int), 100, false_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.getDataByID (&test_input2, sizeof (int), 100, false_id, false_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.getDataByID (&test_input2, sizeof (int), 100, default_id, false_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.getDataByID (&test_input2, sizeof (int), 100, false_id, default_id) == 0); + + _mainbuffer.unBindCallID (test_id); + +} + + + +void MainBufferTest::testGetPutData() +{ + _debug ("-------------------- MainBufferTest::testGetPutData --------------------\n"); + + CallID test_id = "incoming rtp session"; + + _mainbuffer.bindCallID (test_id); + + int test_input1 = 12; + int test_input2 = 13; + int test_output; + + int avail_for_put_testid; + int avail_for_put_defaultid; + + // get by test_id without preleminary put + avail_for_put_defaultid = _mainbuffer.availForPut(); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.getData (&test_output, sizeof (int), 100, test_id) == 0); + + // put by default_id, get by test_id + CPPUNIT_ASSERT (_mainbuffer.availForPut() == avail_for_put_defaultid); + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input1, sizeof (int), 100) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForPut() == (avail_for_put_defaultid - (int) sizeof (int))); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.getData (&test_output, sizeof (int), 100, test_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id) == 0); + CPPUNIT_ASSERT (test_input1 == test_output); + + // get by default_id without preleminary put + avail_for_put_testid = _mainbuffer.availForPut (test_id); + CPPUNIT_ASSERT (_mainbuffer.availForGet() == 0); + CPPUNIT_ASSERT (_mainbuffer.getData (&test_output, sizeof (int)) == 0); + + // put by test_id, get by default_id + CPPUNIT_ASSERT (_mainbuffer.availForPut (test_id) == avail_for_put_testid); + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input2, sizeof (int), 100, test_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForPut (test_id) == (avail_for_put_testid - (int) sizeof (int))); + CPPUNIT_ASSERT (_mainbuffer.availForGet() == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.getData (&test_output, sizeof (int), 100) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet() == 0); + CPPUNIT_ASSERT (test_input2 == test_output); + + _mainbuffer.unBindCallID (test_id); + +} + + +void MainBufferTest::testDiscardFlush() +{ + _debug ("-------------------- MainBufferTest::testDiscardFlush --------------------\n"); + + CallID test_id = "flush discard"; + // _mainbuffer.createRingBuffer(test_id); + _mainbuffer.bindCallID (test_id); + + int test_input1 = 12; + // int test_output_size; + // int init_size; + + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input1, sizeof (int), 100, test_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet() == sizeof (int)); + _mainbuffer.discard (sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet() == 0); + + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id) == 0); + _mainbuffer.discard (sizeof (int), test_id); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id) == 0); + + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (test_id)->getReadPointer (default_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (test_id)->getReadPointer (test_id) == 0); + + + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (default_id)->getReadPointer (test_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.putData (&test_input1, sizeof (int), 100) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (default_id)->getReadPointer (test_id) == 0); + + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id) == sizeof (int)); + + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (default_id)->getReadPointer (test_id) == 0); + _mainbuffer.discard (sizeof (int), test_id); + CPPUNIT_ASSERT (_mainbuffer.getRingBuffer (default_id)->getReadPointer (test_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id) == 0); + + // _mainbuffer.removeRingBuffer(test_id); + _mainbuffer.unBindCallID (test_id); + +} + + +void MainBufferTest::testReadPointerInit() +{ + _debug ("-------------------- MainBufferTest::testReadPointerInit --------------------\n"); + + CallID test_id = "test read pointer init"; + // RingBuffer* test_ring_buffer = _mainbuffer.createRingBuffer(test_id); + + _mainbuffer.bindCallID (test_id); + + RingBuffer* test_ring_buffer = _mainbuffer.getRingBuffer (test_id); + + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 0); + test_ring_buffer->storeReadPointer (30); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer() == 30); + + test_ring_buffer->createReadPointer (test_id); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (test_id) == 0); + test_ring_buffer->storeReadPointer (10, test_id); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (test_id) == 10); + test_ring_buffer->removeReadPointer (test_id); + CPPUNIT_ASSERT (test_ring_buffer->getReadPointer (test_id) == (int) NULL); + test_ring_buffer->removeReadPointer ("false id"); + + // _mainbuffer.removeRingBuffer(test_id); + _mainbuffer.unBindCallID (test_id); +} + + +void MainBufferTest::testRingBufferSeveralPointers() +{ + _debug ("-------------------- MainBufferTest::testRingBufferSeveralPointers --------------------\n"); + + CallID test_id = "test multiple read pointer"; + RingBuffer* test_ring_buffer = _mainbuffer.createRingBuffer (test_id); + + CallID test_pointer1 = "test pointer 1"; + CallID test_pointer2 = "test pointer 2"; + + test_ring_buffer->createReadPointer (test_pointer1); + test_ring_buffer->createReadPointer (test_pointer2); + + int testint1 = 12; + int testint2 = 13; + int testint3 = 14; + int testint4 = 15; + + int testoutput; + + int initPutLen = test_ring_buffer->AvailForPut(); + + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint1, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == initPutLen - (int) sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_pointer1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_pointer2) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer2) == sizeof (int)); + + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint2, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == initPutLen - 2* (int) sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_pointer1) == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_pointer2) == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer1) == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer2) == 2*sizeof (int)); + + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint3, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 3*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == initPutLen - 3* (int) sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_pointer1) == 3*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_pointer2) == 3*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer1) == 3*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer2) == 3*sizeof (int)); + + CPPUNIT_ASSERT (test_ring_buffer->Put (&testint4, sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 4*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == initPutLen - 4* (int) sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_pointer1) == 4*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->getLen (test_pointer2) == 4*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer1) == 4*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer2) == 4*sizeof (int)); + + + CPPUNIT_ASSERT (test_ring_buffer->Get (&testoutput, sizeof (int), 100, test_pointer1) == sizeof (int)); + CPPUNIT_ASSERT (testoutput == testint1); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == initPutLen - 4* (int) sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer1) == 3*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer2) == 4*sizeof (int)); + + CPPUNIT_ASSERT (test_ring_buffer->Get (&testoutput, sizeof (int), 100, test_pointer2) == sizeof (int)); + CPPUNIT_ASSERT (testoutput == testint1); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == initPutLen - 3* (int) sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer1) == 3*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer2) == 3*sizeof (int)); + + // AvailForPut() is ok but AvailForGet(default_id) is not ok + // However, we should no be alowed to read in our own ring buffer + // if we are either an AudioLayer or and RTP session + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == 4*sizeof (int)); + + CPPUNIT_ASSERT (test_ring_buffer->Get (&testoutput, sizeof (int), 100, test_pointer1) == sizeof (int)); + CPPUNIT_ASSERT (testoutput == testint2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == initPutLen - 3* (int) sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer1) == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer2) == 3*sizeof (int)); + + // AvailForPut() is ok but AvailForGet(default_id) is not ok + // However, we should no be alowed to read in our own ring buffer + // if we are either an AudioLayer or and RTP session + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == 4*sizeof (int)); + + CPPUNIT_ASSERT (test_ring_buffer->Get (&testoutput, sizeof (int), 100, test_pointer2) == sizeof (int)); + CPPUNIT_ASSERT (testoutput == testint2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == initPutLen - 2* (int) sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer1) == 2*sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer2) == 2*sizeof (int)); + + // AvailForPut() is ok but AvailForGet(default_id) is not ok + // However, we should no be alowed to read in our own ring buffer + // if we are either an AudioLayer or and RTP session + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet() == 4*sizeof (int)); + + CPPUNIT_ASSERT (test_ring_buffer->Discard (sizeof (int), test_pointer1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == initPutLen - 2* (int) sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer2) == 2*sizeof (int)); + + CPPUNIT_ASSERT (test_ring_buffer->Discard (sizeof (int), test_pointer2) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == initPutLen - (int) sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_pointer2) == sizeof (int)); + + + test_ring_buffer->removeReadPointer (test_pointer1); + test_ring_buffer->removeReadPointer (test_pointer2); + + _mainbuffer.removeRingBuffer (test_id); +} + + + +void MainBufferTest::testConference() +{ + _debug ("-------------------- MainBufferTest::testConference --------------------\n"); + + CallID test_id1 = "participant A"; + CallID test_id2 = "participant B"; + RingBuffer* test_ring_buffer; + + RingBufferMap::iterator iter_ringbuffermap; + ReadPointer::iterator iter_readpointer; + CallIDMap::iterator iter_callidmap; + CallIDSet::iterator iter_callidset; + + + + // test initial setup + // ringbuffers + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer == NULL); + + // callidmap + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 0); + iter_callidmap = _mainbuffer._callIDMap.find (default_id); + CPPUNIT_ASSERT (iter_callidmap == _mainbuffer._callIDMap.end()); + + + // test bind Participant A with default + _mainbuffer.bindCallID (test_id1); + // ringbuffers + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 2); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 1); + iter_readpointer = test_ring_buffer->_readpointer.find (test_id1); + CPPUNIT_ASSERT (iter_readpointer->first == test_id1); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 1); + iter_readpointer = test_ring_buffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + // callidmap + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 2); + iter_callidmap = _mainbuffer._callIDMap.find (default_id); + CPPUNIT_ASSERT (iter_callidmap->first == default_id); + CPPUNIT_ASSERT (iter_callidmap->second->size() == 1); + iter_callidset = iter_callidmap->second->find (test_id1); + CPPUNIT_ASSERT (*iter_callidset == test_id1); + iter_callidmap = _mainbuffer._callIDMap.find (test_id1); + CPPUNIT_ASSERT (iter_callidmap->first == test_id1); + CPPUNIT_ASSERT (iter_callidmap->second->size() == 1); + iter_callidset = iter_callidmap->second->find (default_id); + CPPUNIT_ASSERT (*iter_callidset == default_id); + + // test bind Participant B with default + _mainbuffer.bindCallID (test_id2); + // ringbuffers + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 3); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 2); + iter_readpointer = test_ring_buffer->_readpointer.find (test_id1); + CPPUNIT_ASSERT (iter_readpointer->first == test_id1); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = test_ring_buffer->_readpointer.find (test_id2); + CPPUNIT_ASSERT (iter_readpointer->first == test_id2); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 1); + iter_readpointer = test_ring_buffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 1); + iter_readpointer = test_ring_buffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + // callidmap + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 3); + iter_callidmap = _mainbuffer._callIDMap.find (default_id); + CPPUNIT_ASSERT (iter_callidmap->first == default_id); + CPPUNIT_ASSERT (iter_callidmap->second->size() == 2); + iter_callidset = iter_callidmap->second->find (test_id1); + CPPUNIT_ASSERT (*iter_callidset == test_id1); + iter_callidset = iter_callidmap->second->find (test_id2); + CPPUNIT_ASSERT (*iter_callidset == test_id2); + iter_callidmap = _mainbuffer._callIDMap.find (test_id1); + CPPUNIT_ASSERT (iter_callidmap->first == test_id1); + CPPUNIT_ASSERT (iter_callidmap->second->size() == 1); + iter_callidset = iter_callidmap->second->find (default_id); + CPPUNIT_ASSERT (*iter_callidset == default_id); + iter_callidmap = _mainbuffer._callIDMap.find (test_id2); + CPPUNIT_ASSERT (iter_callidmap->first == test_id2); + CPPUNIT_ASSERT (iter_callidmap->second->size() == 1); + iter_callidset = iter_callidmap->second->find (default_id); + CPPUNIT_ASSERT (*iter_callidset == default_id); + + + // test bind Participant A with Participant B + _mainbuffer.bindCallID (test_id1, test_id2); + // ringbuffers + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 3); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 2); + iter_readpointer = test_ring_buffer->_readpointer.find (test_id1); + CPPUNIT_ASSERT (iter_readpointer->first == test_id1); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = test_ring_buffer->_readpointer.find (test_id2); + CPPUNIT_ASSERT (iter_readpointer->first == test_id2); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 2); + iter_readpointer = test_ring_buffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = test_ring_buffer->_readpointer.find (test_id2); + CPPUNIT_ASSERT (iter_readpointer->first == test_id2); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->getNbReadPointer() == 2); + iter_readpointer = test_ring_buffer->_readpointer.find (default_id); + CPPUNIT_ASSERT (iter_readpointer->first == default_id); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + iter_readpointer = test_ring_buffer->_readpointer.find (test_id1); + CPPUNIT_ASSERT (iter_readpointer->first == test_id1); + CPPUNIT_ASSERT (iter_readpointer->second == 0); + // callidmap + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 3); + iter_callidmap = _mainbuffer._callIDMap.find (default_id); + CPPUNIT_ASSERT (iter_callidmap->first == default_id); + CPPUNIT_ASSERT (iter_callidmap->second->size() == 2); + iter_callidset = iter_callidmap->second->find (test_id1); + CPPUNIT_ASSERT (*iter_callidset == test_id1); + iter_callidset = iter_callidmap->second->find (test_id2); + CPPUNIT_ASSERT (*iter_callidset == test_id2); + iter_callidmap = _mainbuffer._callIDMap.find (test_id1); + CPPUNIT_ASSERT (iter_callidmap->first == test_id1); + CPPUNIT_ASSERT (iter_callidmap->second->size() == 2); + iter_callidset = iter_callidmap->second->find (default_id); + CPPUNIT_ASSERT (*iter_callidset == default_id); + iter_callidset = iter_callidmap->second->find (test_id2); + CPPUNIT_ASSERT (*iter_callidset == test_id2); + iter_callidmap = _mainbuffer._callIDMap.find (test_id2); + CPPUNIT_ASSERT (iter_callidmap->first == test_id2); + CPPUNIT_ASSERT (iter_callidmap->second->size() == 2); + iter_callidset = iter_callidmap->second->find (default_id); + CPPUNIT_ASSERT (*iter_callidset == default_id); + iter_callidset = iter_callidmap->second->find (test_id1); + CPPUNIT_ASSERT (*iter_callidset == test_id1); + + + // test putData default + int testint = 12; + int init_put_defaultid; + int init_put_id1; + int init_put_id2; + + init_put_defaultid = _mainbuffer.getRingBuffer (default_id)->AvailForPut(); + init_put_id1 = _mainbuffer.getRingBuffer (test_id1)->AvailForPut(); + init_put_id2 = _mainbuffer.getRingBuffer (test_id2)->AvailForPut(); + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == 0); + // put data test ring buffers + CPPUNIT_ASSERT (_mainbuffer.putData (&testint, sizeof (int), 100) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id1); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget (get data even if some participant missing) + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + //putdata test ring buffers + CPPUNIT_ASSERT (_mainbuffer.putData (&testint, sizeof (int), 100, test_id1) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget (get data even if some participant missing) + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + //putdata test ring buffers + CPPUNIT_ASSERT (_mainbuffer.putData (&testint, sizeof (int), 100, test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id2 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + + + int test_output; + + // test getData default id (audio layer) + CPPUNIT_ASSERT (_mainbuffer.getData (&test_output, sizeof (int), 100) == sizeof (int)); + CPPUNIT_ASSERT (test_output == (testint + testint)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id2 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + // test getData test_id1 (audio layer) + CPPUNIT_ASSERT (_mainbuffer.getData (&test_output, sizeof (int), 100, test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_output == (testint + testint)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + // test getData test_id2 (audio layer) + CPPUNIT_ASSERT (_mainbuffer.getData (&test_output, sizeof (int), 100, test_id2) == sizeof (int)); + CPPUNIT_ASSERT (test_output == (testint + testint)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_defaultid); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id1); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == 0); + + + // test putData default (for discarting) + init_put_defaultid = _mainbuffer.getRingBuffer (default_id)->AvailForPut(); + init_put_id1 = _mainbuffer.getRingBuffer (test_id1)->AvailForPut(); + init_put_id2 = _mainbuffer.getRingBuffer (test_id2)->AvailForPut(); + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == 0); + // put data test ring buffers + CPPUNIT_ASSERT (_mainbuffer.putData (&testint, sizeof (int), 100) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id1); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + //putdata test ring buffers + CPPUNIT_ASSERT (_mainbuffer.putData (&testint, sizeof (int), 100, test_id1) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + //putdata test ring buffers + CPPUNIT_ASSERT (_mainbuffer.putData (&testint, sizeof (int), 100, test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id2 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + + // test discardData default id (audio layer) + CPPUNIT_ASSERT (_mainbuffer.discard (sizeof (int)) == sizeof (int)); + CPPUNIT_ASSERT (test_output == (testint + testint)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id2 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + // test discardData test_id1 (audio layer) + CPPUNIT_ASSERT (_mainbuffer.discard (sizeof (int), test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_output == (testint + testint)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + // test discardData test_id2 (audio layer) + CPPUNIT_ASSERT (_mainbuffer.discard (sizeof (int), test_id2) == sizeof (int)); + CPPUNIT_ASSERT (test_output == (testint + testint)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_defaultid); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id1); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == 0); + + + // test putData default (for flushing) + init_put_defaultid = _mainbuffer.getRingBuffer (default_id)->AvailForPut(); + init_put_id1 = _mainbuffer.getRingBuffer (test_id1)->AvailForPut(); + init_put_id2 = _mainbuffer.getRingBuffer (test_id2)->AvailForPut(); + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == 0); + // put data test ring buffers + CPPUNIT_ASSERT (_mainbuffer.putData (&testint, sizeof (int), 100) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id1); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + //putdata test ring buffers + CPPUNIT_ASSERT (_mainbuffer.putData (&testint, sizeof (int), 100, test_id1) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + //putdata test ring buffers + CPPUNIT_ASSERT (_mainbuffer.putData (&testint, sizeof (int), 100, test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id2 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + + // test flush default id (audio layer) + _mainbuffer.flush(); + CPPUNIT_ASSERT (test_output == (testint + testint)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + _debug ("%i", test_ring_buffer->putLen()); + test_ring_buffer->debug(); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id2 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == sizeof (int)); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == sizeof (int)); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + // test flush test_id1 (audio layer) + _mainbuffer.flush (test_id1); + CPPUNIT_ASSERT (test_output == (testint + testint)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_defaultid - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == sizeof (int)); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == (int) (init_put_id1 - sizeof (int))); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == sizeof (int)); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == sizeof (int)); + // test flush test_id2 (audio layer) + _mainbuffer.flush (test_id2); + CPPUNIT_ASSERT (test_output == (testint + testint)); + test_ring_buffer = _mainbuffer.getRingBuffer (default_id); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_defaultid); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id1); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id1); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id2) == 0); + test_ring_buffer = _mainbuffer.getRingBuffer (test_id2); + CPPUNIT_ASSERT (test_ring_buffer->putLen() == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForPut() == init_put_id2); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (default_id) == 0); + CPPUNIT_ASSERT (test_ring_buffer->AvailForGet (test_id1) == 0); + // test mainbuffer availforget + CPPUNIT_ASSERT (_mainbuffer.availForGet (default_id) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id1) == 0); + CPPUNIT_ASSERT (_mainbuffer.availForGet (test_id2) == 0); + + + _mainbuffer.unBindCallID (test_id1, test_id2); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 3); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 3); + + _mainbuffer.unBindCallID (test_id1); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 2); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 2); + + _mainbuffer.unBindCallID (test_id2); + CPPUNIT_ASSERT (_mainbuffer._ringBufferMap.size() == 0); + CPPUNIT_ASSERT (_mainbuffer._callIDMap.size() == 0); +} diff --git a/sflphone-common/test/mainbuffertest.h b/sflphone-common/test/mainbuffertest.h new file mode 100644 index 0000000000000000000000000000000000000000..4aefd398a884094a8946e6f0226bcd04392166a6 --- /dev/null +++ b/sflphone-common/test/mainbuffertest.h @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Alexandre Savard <alexandre.savard@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> + +#include <stdio.h> +#include <sstream> +#include <ccrtp/rtp.h> + + +// pjsip import +#include <pjsip.h> +#include <pjlib.h> +#include <pjsip_ua.h> +#include <pjlib-util.h> +#include <pjnath/stun_config.h> + +// Application import +#include "manager.h" +#include "audio/mainbuffer.h" +#include "audio/ringbuffer.h" +#include "call.h" +// #include "config/config.h" +// #include "user_cfg.h" + + + +/* + * @file audiorecorderTest.cpp + * @brief Regroups unitary tests related to the plugin manager. + */ + +#ifndef _MAINBUFFER_TEST_ +#define _MAINBUFFER_TEST_ + + + +class MainBufferTest : public CppUnit::TestCase { + + /* + * Use cppunit library macros to add unit test the factory + */ + CPPUNIT_TEST_SUITE( MainBufferTest ); + CPPUNIT_TEST( testRingBufferCreation ); + CPPUNIT_TEST( testRingBufferReadPointer ); + CPPUNIT_TEST( testCallIDSet ); + CPPUNIT_TEST( testRingBufferInt ); + CPPUNIT_TEST( testRingBufferNonDefaultID ); + CPPUNIT_TEST( testRingBufferFloat ); + CPPUNIT_TEST( testTwoPointer ); + CPPUNIT_TEST( testBindUnbindBuffer ); + CPPUNIT_TEST( testGetPutDataByID ); + CPPUNIT_TEST( testGetPutData ); + CPPUNIT_TEST( testDiscardFlush ); + CPPUNIT_TEST( testReadPointerInit ); + CPPUNIT_TEST( testRingBufferSeveralPointers ); + CPPUNIT_TEST( testConference ); + CPPUNIT_TEST_SUITE_END(); + + public: + + MainBufferTest() : CppUnit::TestCase("Audio Layer 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(); + + void testRingBufferCreation(); + + void testRingBufferReadPointer(); + + void testCallIDSet(); + + void testRingBufferInt(); + + void testRingBufferNonDefaultID(); + + void testRingBufferFloat(); + + void testTwoPointer(); + + void testBindUnbindBuffer(); + + void testGetPutDataByID(); + + void testGetPutData(); + + void testAvailForGetPut(); + + void testDiscardFlush(); + + void testReadPointerInit(); + + void testRingBufferSeveralPointers(); + + void testConference(); + + private: + + MainBuffer _mainbuffer; +}; + +/* Register our test module */ +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(MainBufferTest, "MainBufferTest"); +CPPUNIT_TEST_SUITE_REGISTRATION( MainBufferTest ); + +#endif diff --git a/sflphone-common/test/numbercleanertest.cpp b/sflphone-common/test/numbercleanertest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9529727f0f68d6ddb57e1083afbcb34a9e36154d --- /dev/null +++ b/sflphone-common/test/numbercleanertest.cpp @@ -0,0 +1,139 @@ +/* + * 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 <dlfcn.h> + +#include "global.h" + +#include "numbercleanertest.h" + +#define NUMBER_TEST_1 "514 333 4444" +#define NUMBER_TEST_2 "514-333-4444" +#define NUMBER_TEST_3 "(514) 333 4444" +#define NUMBER_TEST_4 "(514)-333-4444" +#define NUMBER_TEST_5 "(514) 333-4444" +#define NUMBER_TEST_6 "514 333 4444" +#define NUMBER_TEST_7 "ext 136" +#define NUMBER_TEST_8 "514 333 4444 ext. 136" +#define NUMBER_TEST_9 "514 333 4444 ext 136" +#define NUMBER_TEST_10 "136" + +#define VALID_NUMBER "5143334444" +#define VALID_PREPENDED_NUMBER "95143334444" +#define VALID_EXTENSION "136" + +using std::cout; +using std::endl; + + +void NumberCleanerTest::setUp() +{ + // Instanciate the cleaner singleton + cleaner = new NumberCleaner (); +} + +void NumberCleanerTest::test_format_1 (void) +{ + _debug ("-------------------- NumberCleanerTest::test_format_1 --------------------\n"); + + CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_1) == VALID_NUMBER); +} + +void NumberCleanerTest::test_format_2 (void) +{ + _debug ("-------------------- NumberCleanerTest::test_format_2 --------------------\n"); + + CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_2) == VALID_NUMBER); +} + +void NumberCleanerTest::test_format_3 (void) +{ + _debug ("-------------------- NumberCleanerTest::test_format_3 --------------------\n"); + + CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_3) == VALID_NUMBER); +} + +void NumberCleanerTest::test_format_4 (void) +{ + _debug ("-------------------- NumberCleanerTest::test_format_4 --------------------\n"); + + CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_4) == VALID_NUMBER); +} + +void NumberCleanerTest::test_format_5 (void) +{ + _debug ("-------------------- NumberCleanerTest::test_format_5 --------------------\n"); + + CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_5) == VALID_NUMBER); +} + +void NumberCleanerTest::test_format_6 (void) +{ + _debug ("-------------------- NumberCleanerTest::test_format_6 --------------------\n"); + + CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_6) == VALID_NUMBER); +} + +void NumberCleanerTest::test_format_7 (void) +{ + _debug ("-------------------- NumberCleanerTest::test_format_7 --------------------\n"); + + CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_7) == VALID_EXTENSION); +} + +void NumberCleanerTest::test_format_8 (void) +{ + _debug ("-------------------- NumberCleanerTest::test_format_8 --------------------\n"); + + CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_8) == VALID_NUMBER); +} + +void NumberCleanerTest::test_format_9 (void) +{ + _debug ("-------------------- NumberCleanerTest::test_format_9 --------------------\n"); + + CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_9) == VALID_NUMBER); +} + +void NumberCleanerTest::test_format_10 (void) +{ + _debug ("-------------------- NumberCleanerTest::test_format_10 --------------------\n"); + + cleaner->set_phone_number_prefix ("9"); + CPPUNIT_ASSERT (cleaner->get_phone_number_prefix () == "9"); + CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_1) == VALID_PREPENDED_NUMBER); +} + +void NumberCleanerTest::test_format_11 (void) +{ + _debug ("-------------------- NumberCleanerTest::test_format_11 --------------------\n"); + + cleaner->set_phone_number_prefix ("9"); + CPPUNIT_ASSERT (cleaner->get_phone_number_prefix () == "9"); + CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_10) == VALID_EXTENSION); +} + +void NumberCleanerTest::tearDown() +{ + // Delete the cleaner object + delete cleaner; + cleaner=0; +} diff --git a/sflphone-common/test/numbercleanertest.h b/sflphone-common/test/numbercleanertest.h new file mode 100644 index 0000000000000000000000000000000000000000..f303c72526287cd79ee786e1bfd1667b585e9fc8 --- /dev/null +++ b/sflphone-common/test/numbercleanertest.h @@ -0,0 +1,99 @@ +/* + * 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. + */ + +// 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 "numbercleaner.h" +// #include "../src/conference.h" +/* + * @file numbercleanerTest.cpp + * @brief Regroups unitary tests related to the phone number cleanup function. + */ + +#ifndef _NUMBERCLEANER_TEST_ +#define _NUMBERCLEANER_TEST_ + +class NumberCleanerTest : public CppUnit::TestCase { + + /** + * Use cppunit library macros to add unit test the factory + */ + CPPUNIT_TEST_SUITE (NumberCleanerTest); + CPPUNIT_TEST (test_format_1); + CPPUNIT_TEST (test_format_2); + CPPUNIT_TEST (test_format_3); + CPPUNIT_TEST (test_format_4); + CPPUNIT_TEST (test_format_5); + CPPUNIT_TEST (test_format_6); + CPPUNIT_TEST (test_format_10); + CPPUNIT_TEST_SUITE_END (); + + public: + NumberCleanerTest() : CppUnit::TestCase("Hook Manager Tests") {} + + /* + * Code factoring - Common resources can be initialized here. + * This method is called by unitcpp before each test + */ + void setUp(); + + void test_format_1 (); + + void test_format_2 (); + + void test_format_3 (); + + void test_format_4 (); + + void test_format_5 (); + + void test_format_6 (); + + void test_format_7 (); + + void test_format_8 (); + + void test_format_9 (); + + void test_format_10 (); + + void test_format_11 (); + + /* + * Code factoring - Common resources can be released here. + * This method is called by unitcpp after each test + */ + inline void tearDown (); + + private: + NumberCleaner *cleaner; +}; + +/* Register our test module */ +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(NumberCleanerTest, "NumberCleanerTest"); +CPPUNIT_TEST_SUITE_REGISTRATION( NumberCleanerTest ); + +#endif diff --git a/sflphone-common/test/pluginmanagertest.cpp b/sflphone-common/test/pluginmanagertest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93b18ba2ef7a271a39cda55e30fc9e22f2ce9200 --- /dev/null +++ b/sflphone-common/test/pluginmanagertest.cpp @@ -0,0 +1,124 @@ +/* + * 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 <dlfcn.h> + +#include "pluginmanagertest.h" + +using std::cout; +using std::endl; + +#define PLUGIN_TEST_DIR "/usr/lib/sflphone/plugins/" +#define PLUGIN_TEST_DESC "mytest" +#define PLUGIN_TEST_NAME "/usr/lib/sflphone/plugins/libplugintest.so" + + +void PluginManagerTest::setUp() +{ + // Instanciate the plugin manager singleton + _pm = PluginManager::instance(); + library = 0; + plugin = 0; +} + +void PluginManagerTest::testLoadDynamicLibrary() +{ + _debug ("-------------------- PluginManagerTest::testLoadDynamicLibrary --------------------\n"); + + CPPUNIT_ASSERT (_pm->loadDynamicLibrary (PLUGIN_TEST_NAME) != NULL); +} + +void PluginManagerTest::testUnloadDynamicLibrary() +{ + _debug ("-------------------- PluginManagerTest::testUnloadDynamicLibrary --------------------\n"); + + library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); + CPPUNIT_ASSERT (library != NULL); + CPPUNIT_ASSERT (_pm->unloadDynamicLibrary (library) == 0); +} + +void PluginManagerTest::testInstanciatePlugin() +{ + _debug ("-------------------- PluginManagerTest::testInstanciatePlugin --------------------\n"); + + library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); + CPPUNIT_ASSERT (library != NULL); + CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0); + CPPUNIT_ASSERT (plugin!=NULL); +} + +void PluginManagerTest::testInitPlugin() +{ + _debug ("-------------------- PluginManagerTest::testInitPlugin --------------------\n"); + + library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); + CPPUNIT_ASSERT (library != NULL); + CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0); + CPPUNIT_ASSERT (plugin!=NULL); + CPPUNIT_ASSERT (plugin->getPluginName() == PLUGIN_TEST_DESC); +} + +void PluginManagerTest::testRegisterPlugin() +{ + _debug ("-------------------- PluginManagerTest::testRegisterPlugin --------------------\n"); + + library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); + CPPUNIT_ASSERT (library != NULL); + CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0); + CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == false); + CPPUNIT_ASSERT (_pm->registerPlugin (plugin, library) == 0); + CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true); +} + +void PluginManagerTest::testLoadPlugins () +{ + _debug ("-------------------- PluginManagerTest::testLoadPlugins --------------------\n"); + + CPPUNIT_ASSERT (_pm->loadPlugins (PLUGIN_TEST_DIR) == 0); + CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true); +} + +void PluginManagerTest::testUnloadPlugins () +{ + _debug ("-------------------- PluginManagerTest::testUnloadPlugins --------------------\n"); + + CPPUNIT_ASSERT (_pm->loadPlugins (PLUGIN_TEST_DIR) == 0); + CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true); + CPPUNIT_ASSERT (_pm->unloadPlugins () == 0); + CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == false); +} + +void PluginManagerTest::tearDown() +{ + // Delete the plugin manager object + delete _pm; + _pm=0; + + if (plugin) + delete plugin; + + plugin = 0; + + if (library) + delete library; + + library = 0; +} diff --git a/sflphone-common/test/pluginmanagertest.h b/sflphone-common/test/pluginmanagertest.h new file mode 100644 index 0000000000000000000000000000000000000000..c52e9f66d58c136d4284b5b9b43fbfb0b622cac9 --- /dev/null +++ b/sflphone-common/test/pluginmanagertest.h @@ -0,0 +1,95 @@ +/* + * 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. + */ + +// 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 "plug-in/pluginmanager.h" +#include "plug-in/librarymanager.h" +#include "plug-in/plugin.h" + +/* + * @file pluginManagerTest.cpp + * @brief Regroups unitary tests related to the plugin manager. + */ + +#ifndef _PLUGINMANAGER_TEST_ +#define _PLUGINMANAGER_TEST_ + +class PluginManagerTest : public CppUnit::TestCase { + + /** + * Use cppunit library macros to add unit test the factory + */ + CPPUNIT_TEST_SUITE( PluginManagerTest ); + CPPUNIT_TEST( testLoadDynamicLibrary ); + CPPUNIT_TEST( testUnloadDynamicLibrary ); + CPPUNIT_TEST( testInstanciatePlugin ); + CPPUNIT_TEST( testInitPlugin ); + CPPUNIT_TEST( testRegisterPlugin ); + CPPUNIT_TEST( testLoadPlugins ); + CPPUNIT_TEST( testUnloadPlugins ); + CPPUNIT_TEST_SUITE_END(); + + public: + PluginManagerTest() : CppUnit::TestCase("Plugin Manager 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 (); + + void testLoadDynamicLibrary (); + + void testUnloadDynamicLibrary (); + + void testInstanciatePlugin (); + + void testInitPlugin (); + + void testRegisterPlugin (); + + void testLoadPlugins (); + + void testUnloadPlugins (); + + private: + PluginManager *_pm; + LibraryManager *library; + Plugin *plugin; +}; + +/* Register our test module */ +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(PluginManagerTest, "PluginManagerTest"); +CPPUNIT_TEST_SUITE_REGISTRATION( PluginManagerTest ); + +#endif diff --git a/sflphone-common/test/rtptest.cpp b/sflphone-common/test/rtptest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..924e9cf8df9f9afb7e8d06943f8260a8b5d6cdf9 --- /dev/null +++ b/sflphone-common/test/rtptest.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Alexandre Savarda <alexandre.savard@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 <ccrtp/rtp.h> +#include <assert.h> +#include <string> +#include <cstring> +#include <math.h> +#include <dlfcn.h> +#include <iostream> +#include <sstream> +#include <time.h> + +#include "rtptest.h" +#include "audio/audiortp/AudioRtpSession.h" +#include "audio/audiortp/AudioSymmetricRtpSession.h" + +#include <unistd.h> + +void RtpTest::setUp() { + + pjsipInit(); + + CallID cid = "123456"; + + sipcall = new SIPCall(cid, Call::Incoming, _pool); + + sipcall->setLocalIp("127.0.0.1"); + sipcall->setLocalAudioPort(RANDOM_LOCAL_PORT); + sipcall->setLocalExternAudioPort(RANDOM_LOCAL_PORT); +} + +bool RtpTest::pjsipInit() { + // Create memory cache for pool + pj_caching_pool_init(&_cp, &pj_pool_factory_default_policy, 0); + + // Create memory pool for application. + _pool = pj_pool_create(&_cp.factory, "rtpTest", 4000, 4000, NULL); + + if (!_pool) { + _debug ("----- RtpTest: Could not initialize pjsip memory pool ------"); + return PJ_ENOMEM; + } + + return true; +} + +void RtpTest::testRtpInitClose() { + _debug ("-------------------- RtpTest::testRtpInitClose --------------------\n"); + + audiortp = new AudioRtpFactory(); + + try { + _debug ("-------- Open Rtp Session ----------"); + audiortp->initAudioRtpConfig(sipcall); + audiortp->initAudioRtpSession(sipcall); + //AudioCodecType codecType = PAYLOAD_CODEC_ULAW; + //AudioCodec* audioCodec = Manager::instance().getCodecDescriptorMap().instantiateCodec(codecType); + //audiortp->start(audioCodec); + + } catch (...) { + _debug ("!!! Exception occured while Oppenning Rtp !!!"); + CPPUNIT_ASSERT(false); + + } + + CPPUNIT_ASSERT (audiortp != NULL); + + sleep(1); + + _debug ("------ RtpTest::testRtpClose() ------"); + + try { + _debug ("------ Close Rtp Session -------"); + audiortp->stop(); + + } catch (...) { + + _debug ("!!! Exception occured while closing Rtp !!!"); + CPPUNIT_ASSERT(false); + + } + + delete audiortp; + + audiortp = NULL; +} + +void RtpTest::tearDown() { + delete sipcall; + sipcall = NULL; +} diff --git a/sflphone-common/test/rtptest.h b/sflphone-common/test/rtptest.h new file mode 100644 index 0000000000000000000000000000000000000000..f6e89bce6da688cb403dbc870aeaaccd47e0bed6 --- /dev/null +++ b/sflphone-common/test/rtptest.h @@ -0,0 +1,110 @@ +/* + * 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. + */ + +#ifndef _RTP_TEST_ +#define _RTP_TEST_ + +// 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> +#include <sstream> +#include <ccrtp/rtp.h> + +// pjsip import +#include <pjsip.h> +#include <pjlib.h> +#include <pjsip_ua.h> +#include <pjlib-util.h> +#include <pjnath/stun_config.h> + +// Application import +#include "audio/audiortp/AudioRtpFactory.h" +#include "manager.h" +#include "call.h" +#include "sip/sipcall.h" +#include "sip/sipvoiplink.h" + +#include "config/config.h" +#include "user_cfg.h" + +using namespace sfl; + +class AudioSymmetricRtpSession; +class AudioRtpSession; +//class AudioRtpFactory; +class SIPVoIPLink; + +class RtpTest: public CppUnit::TestCase { + + /* + * Use cppunit library macros to add unit test the factory + */ +CPPUNIT_TEST_SUITE( RtpTest ); + CPPUNIT_TEST( testRtpInitClose ); + CPPUNIT_TEST_SUITE_END(); + +public: + + RtpTest() : + CppUnit::TestCase("Audio Layer 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(); + + bool pjsipInit(); + + void testRtpInitClose(); + +private: + + enum CallType { + Incoming, Outgoing + }; + + ManagerImpl* manager; + + AudioRtpFactory *audiortp; + + SIPCall *sipcall; + + pj_caching_pool _cp; + + pj_pool_t *_pool; +}; +/* Register our test module */ +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(RtpTest, "RtpTest"); +CPPUNIT_TEST_SUITE_REGISTRATION( RtpTest ); + +#endif diff --git a/sflphone-common/test/sdesnegotiatortest.cpp b/sflphone-common/test/sdesnegotiatortest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..26d545ffd061bda93c9daadb7b47dfc89dcfde6b --- /dev/null +++ b/sflphone-common/test/sdesnegotiatortest.cpp @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Alexandre Savard <alexandre.savard@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 <ccrtp/rtp.h> +#include <assert.h> +#include <string> +#include <cstring> +#include <math.h> +#include <dlfcn.h> +#include <iostream> +#include <sstream> + +#include "sdesnegotiatortest.h" + +#include <unistd.h> +#include "global.h" + + +using std::cout; +using std::endl; + + +void SdesNegotiatorTest::testTagPattern() +{ + _debug ("-------------------- SdesNegotiatorTest::testTagPattern --------------------\n"); + + std::string subject = "a=crypto:4"; + + pattern = new sfl::Pattern("^a=crypto:(?P<tag>[0-9]{1,9})"); + *pattern << subject; + + CPPUNIT_ASSERT(pattern->matches()); + CPPUNIT_ASSERT(pattern->group("tag").compare("4") == 0); + + delete pattern; + pattern = NULL; +} + + +void SdesNegotiatorTest::testCryptoSuitePattern() +{ + _debug ("-------------------- SdesNegotiatorTest::testCryptoSuitePattern --------------------\n"); + + std::string subject = "AES_CM_128_HMAC_SHA1_80"; + + pattern = new sfl::Pattern("(?P<cryptoSuite>AES_CM_128_HMAC_SHA1_80|" \ + "AES_CM_128_HMAC_SHA1_32|" \ + "F8_128_HMAC_SHA1_80|" \ + "[A-Za-z0-9_]+)"); + *pattern << subject; + + CPPUNIT_ASSERT(pattern->matches()); + CPPUNIT_ASSERT(pattern->group("cryptoSuite").compare("AES_CM_128_HMAC_SHA1_80") == 0); + + delete pattern; + pattern = NULL; +} + + +void SdesNegotiatorTest::testKeyParamsPattern() +{ + _debug ("-------------------- SdesNegotiatorTest::testKeyParamsPattern --------------------\n"); + + std::string subject = "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32"; + + pattern = new sfl::Pattern("(?P<srtpKeyMethod>inline|[A-Za-z0-9_]+)\\:" \ + "(?P<srtpKeyInfo>[A-Za-z0-9\x2B\x2F\x3D]+)\\|" \ + "(2\\^(?P<lifetime>[0-9]+)\\|" \ + "(?P<mkiValue>[0-9]+)\\:" \ + "(?P<mkiLength>[0-9]{1,3})\\;?)?", "g"); + + *pattern << subject; + + pattern->matches(); + CPPUNIT_ASSERT(pattern->group("srtpKeyMethod").compare("inline:")); + CPPUNIT_ASSERT(pattern->group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") +== 0); + CPPUNIT_ASSERT(pattern->group("lifetime").compare("20")== 0); + CPPUNIT_ASSERT(pattern->group("mkiValue").compare("1")== 0); + CPPUNIT_ASSERT(pattern->group("mkiLength").compare("32")== 0); + + delete pattern; + pattern = NULL; +} + + +void SdesNegotiatorTest::testKeyParamsPatternWithoutMKI() +{ + _debug ("-------------------- SdesNegotiatorTest::testKeyParamsPatternWithoutMKI --------------------\n"); + + std::string subject = "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj"; + + pattern = new sfl::Pattern("(?P<srtpKeyMethod>inline|[A-Za-z0-9_]+)\\:" \ + "(?P<srtpKeyInfo>[A-Za-z0-9\x2B\x2F\x3D]+)" \ + "(\\|2\\^(?P<lifetime>[0-9]+)\\|" \ + "(?P<mkiValue>[0-9]+)\\:" \ + "(?P<mkiLength>[0-9]{1,3})\\;?)?", "g"); + + *pattern << subject; + pattern->matches(); + CPPUNIT_ASSERT(pattern->group("srtpKeyMethod").compare("inline:")); + CPPUNIT_ASSERT(pattern->group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") +== 0); + + delete pattern; + pattern = NULL; +} + + +/** + * Make sure that all the fields can be extracted + * properly from the syntax. + */ +void SdesNegotiatorTest::testNegotiation() +{ + _debug ("-------------------- SdesNegotiatorTest::testNegotiation --------------------\n"); + + // Add a new SDES crypto line to be processed. + remoteOffer = new std::vector<std::string>(); + remoteOffer->push_back(std::string("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd|2^20|1:32")); + remoteOffer->push_back(std::string("a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32")); + + // Register the local capabilities. + localCapabilities = new std::vector<sfl::CryptoSuiteDefinition>(); + for(int i = 0; i < 3; i++) { + localCapabilities->push_back(sfl::CryptoSuites[i]); + } + + sdesnego = new sfl::SdesNegotiator(*localCapabilities, *remoteOffer); + + CPPUNIT_ASSERT(sdesnego->negotiate()); + // CPPUNIT_ASSERT(sdesnego->getKeyInfo().compare("AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd|2^20|1:32")==0); + + delete remoteOffer; + remoteOffer = NULL; + + delete localCapabilities; + localCapabilities = NULL; + + delete sdesnego; + sdesnego = NULL; +} + +/** + * Make sure that unproperly formatted crypto lines are rejected. + */ +void SdesNegotiatorTest::testComponent() +{ + _debug ("-------------------- SdesNegotiatorTest::testComponent --------------------\n"); + + // Register the local capabilities. + std::vector<sfl::CryptoSuiteDefinition> * capabilities = new std::vector<sfl::CryptoSuiteDefinition>(); + + //Support all the CryptoSuites + for(int i = 0; i < 3; i++) { + capabilities->push_back(sfl::CryptoSuites[i]); + } + + // Make sure that if a component is missing, negotiate will fail + std::string cryptoLine("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:|2^20|1:32"); + std::vector<std::string> * cryptoOffer = new std::vector<std::string>(); + cryptoOffer->push_back(cryptoLine); + + sfl::SdesNegotiator * negotiator = new sfl::SdesNegotiator(*capabilities, *cryptoOffer); + + CPPUNIT_ASSERT(negotiator->negotiate() == false); +} + + + +/** + * Make sure that most simple case does not fail. + */ +void SdesNegotiatorTest::testMostSimpleCase() +{ + _debug ("-------------------- SdesNegotiatorTest::testMostSimpleCase --------------------\n"); + + // Register the local capabilities. + std::vector<sfl::CryptoSuiteDefinition> * capabilities = new std::vector<sfl::CryptoSuiteDefinition>(); + + //Support all the CryptoSuites + for(int i = 0; i < 3; i++) { + capabilities->push_back(sfl::CryptoSuites[i]); + } + + // Make sure taht this case works (since it's default for most application) + std::string cryptoLine("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); + std::vector<std::string> * cryptoOffer = new std::vector<std::string>(); + cryptoOffer->push_back(cryptoLine); + + sfl::SdesNegotiator * negotiator = new sfl::SdesNegotiator(*capabilities, *cryptoOffer); + + CPPUNIT_ASSERT(negotiator->negotiate() == true); + + CPPUNIT_ASSERT(negotiator->getCryptoSuite().compare("AES_CM_128_HMAC_SHA1_80") == 0); + CPPUNIT_ASSERT(negotiator->getKeyMethod().compare("inline") == 0); + CPPUNIT_ASSERT(negotiator->getKeyInfo().compare("AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd") == 0); + CPPUNIT_ASSERT(negotiator->getLifeTime().compare("")== 0); + CPPUNIT_ASSERT(negotiator->getMkiValue().compare("")== 0); + CPPUNIT_ASSERT(negotiator->getMkiLength().compare("")== 0); + + delete capabilities; capabilities = NULL; + delete cryptoOffer; cryptoOffer = NULL; + delete negotiator; negotiator = NULL; +} diff --git a/sflphone-common/test/sdesnegotiatortest.h b/sflphone-common/test/sdesnegotiatortest.h new file mode 100644 index 0000000000000000000000000000000000000000..97172594a2b8a3b96b4ac52fd2b31a8d2403be97 --- /dev/null +++ b/sflphone-common/test/sdesnegotiatortest.h @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Alexandre Savard <alexandre.savard@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> + +#include <stdio.h> +#include <sstream> +#include <ccrtp/rtp.h> + +#include <vector> + +// pjsip import +#include <pjsip.h> +#include <pjlib.h> +#include <pjsip_ua.h> +#include <pjlib-util.h> +#include <pjnath/stun_config.h> + +// Application import +#include "sip/SdesNegotiator.h" +#include "sip/Pattern.h" + + +/* + * @file sdesnegotiationTest.cpp + * @brief Regroups unitary tests related to the plugin manager. + */ + +#ifndef _SDESNEGOTIATOR_TEST_ +#define _SDESNEGOTIATOR_TEST_ + + + +class SdesNegotiatorTest : public CppUnit::TestCase { + + /* + * Use cppunit library macros to add unit test the factory + */ + CPPUNIT_TEST_SUITE( SdesNegotiatorTest ); + CPPUNIT_TEST( testTagPattern ); + CPPUNIT_TEST( testCryptoSuitePattern ); + CPPUNIT_TEST( testKeyParamsPattern ); + CPPUNIT_TEST( testKeyParamsPatternWithoutMKI ); + CPPUNIT_TEST( testNegotiation ); + CPPUNIT_TEST( testMostSimpleCase ); + CPPUNIT_TEST_SUITE_END(); + + public: + + /* + * Code factoring - Common resources can be released here. + * This method is called by unitcpp after each test + */ + void testTagPattern(); + + void testCryptoSuitePattern(); + + void testKeyParamsPattern(); + + void testKeyParamsPatternCiscoStyle(); + + void testKeyParamsPatternWithoutMKI(); + + void testNegotiation(); + + void testComponent(); + + void testMostSimpleCase(); + + private: + + sfl::Pattern *pattern; + + sfl::SdesNegotiator *sdesnego; + + std::vector<std::string> *remoteOffer; + + std::vector<sfl::CryptoSuiteDefinition> *localCapabilities; +}; + +/* Register our test module */ +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SdesNegotiatorTest, "SdesNegotiatorTest"); +CPPUNIT_TEST_SUITE_REGISTRATION( SdesNegotiatorTest ); + +#endif diff --git a/sflphone-common/test/sflphonedrc-sample b/sflphone-common/test/sflphonedrc-sample new file mode 100644 index 0000000000000000000000000000000000000000..6d0064a7c50fc350fb1d55aa1faef4002c321427 --- /dev/null +++ b/sflphone-common/test/sflphonedrc-sample @@ -0,0 +1,74 @@ +[Account:1239059899] +Account.alias=1260@sip.sflphone.org +Account.enable=1 +Account.type=SIP +hostname=sflphone.org +password=NIPAgmLo +username=1260 + +[Account:1243544046] +Account.alias=Manu +Account.enable=1 +Account.mailbox=*97 +Account.type=SIP +hostname=192.168.50.3 +password=sfl-137pw +username=137 + +[Addressbook] +Addressbook.contact_photo=0 +Addressbook.enable=1 +Addressbook.list=1243608768.30329.0@emilou-desktop/1243456917.15690.23@emilou-desktop/ +Addressbook.max_results=25 +Addressbook.phone_business=1 +Addressbook.phone_home=0 +Addressbook.phone_mobile=0 + +[Audio] +Alsa.cardID_In=0 +Alsa.cardID_Out=0 +Alsa.framesize=20 +Alsa.plugin=default +Alsa.sampleRate=44100 +Record.path=/home/emilou +Rings.ringChoice=/usr/share/sflphone/ringtones/konga.ul +Volume.micro=100 +Volume.speakers=100 + +[Hooks] +Hooks.iax2_enabled=0 +Hooks.phone_number_add_prefix= +Hooks.phone_number_enabled=0 +Hooks.sip_enabled=0 +Hooks.url_command=x-www-browser +Hooks.url_sip_field=X-sflphone-url + +[Preferences] +Accounts.order=Account:1243544046/Account:1239138829/ +Audio.api=1 +Dialpad.display=0 +History.enabled=1 +History.limit=30 +History.maxCalls=20 +Notify.all=1 +Notify.mails=0 +Options.zoneToneChoice=North America +Pulseaudio.volumeCtrl=1 +Registration.expire=180 +Ringtones.enable=1 +SIP.portNum=5060 +Searchbar.display=1 +Start.hidden=0 +Volume.display=0 +Window.popup=0 +Zeroconf.enable=0 + +[VoIPLink] +DTMF.playDtmf=1 +DTMF.playTones=1 +DTMF.pulseLength=250 +DTMF.sendDTMFas=0 +STUN.enable=0 +STUN.server=stun.sflphone.org +VoIPLink.symmetric=1 + diff --git a/sflphone-common/test/validator.cpp b/sflphone-common/test/validator.cpp index 6f34e3102fc75bfb0d8974d82e25b80f887f9c2a..56bb01dc9e743fb3bafed1a6d19bf42c74272d64 100644 --- a/sflphone-common/test/validator.cpp +++ b/sflphone-common/test/validator.cpp @@ -20,3 +20,7 @@ bool Validator::isNotNull(std::string str) { else return false; } + +bool Validator::isEqual(std::string str1, std::string str2) { + return str1.compare(str2) == 0; +} diff --git a/sflphone-common/test/validator.h b/sflphone-common/test/validator.h index 363e3c9aef2ed7178568845ebcf6644ff2d0792f..9f2012e2a6277e1df4eb71ca0d8063c315a25503 100644 --- a/sflphone-common/test/validator.h +++ b/sflphone-common/test/validator.h @@ -17,5 +17,6 @@ class Validator { public: static bool isNumber(std::string str); static bool isNotNull(std::string str); + static bool isEqual(std::string str1, std::string str2); }; #endif /* VALIDATOR_H_ */