From 742a76938e037032723f373f1120c9b5efac2905 Mon Sep 17 00:00:00 2001 From: Julien Bonjean <julien@bonjean.info> Date: Mon, 15 Mar 2010 10:18:00 -0400 Subject: [PATCH] [#2535] Cleaned daemon unit tests --- sflphone-common/src/managerimpl.cpp | 2 +- sflphone-common/src/managerimpl.h | 2 +- sflphone-common/test/Makefile.am | 176 +- sflphone-common/test/README | 1 - sflphone-common/test/TestMain.cpp | 12 - sflphone-common/test/accounttest.cpp | 42 + sflphone-common/test/accounttest.h | 36 + sflphone-common/test/audiolayerTest.cpp | 221 --- sflphone-common/test/audiolayerTest.h | 92 - sflphone-common/test/audiorecorderTest.cpp | 61 - sflphone-common/test/audiorecorderTest.h | 73 - sflphone-common/test/configurationTest.cpp | 146 -- sflphone-common/test/configurationTest.h | 108 -- sflphone-common/test/history-sample | 21 - sflphone-common/test/history-sample.tpl | 20 - sflphone-common/test/historyTest.cpp | 211 --- sflphone-common/test/historyTest.h | 93 - sflphone-common/test/hookmanagerTest.cpp | 57 - sflphone-common/test/hookmanagerTest.h | 74 - sflphone-common/test/hooksTest.h | 68 - sflphone-common/test/main.cpp | 58 + sflphone-common/test/mainbufferTest.cpp | 1772 ------------------- sflphone-common/test/mainbufferTest.h | 136 -- sflphone-common/test/numbercleanerTest.cpp | 126 -- sflphone-common/test/numbercleanerTest.h | 102 -- sflphone-common/test/pluginmanagerTest.cpp | 111 -- sflphone-common/test/pluginmanagerTest.h | 94 - sflphone-common/test/rtpTest.cpp | 239 --- sflphone-common/test/rtpTest.h | 123 -- sflphone-common/test/run-tests | 24 - sflphone-common/test/sdesnegotiatorTest.cpp | 226 --- sflphone-common/test/sdesnegotiatorTest.h | 119 -- sflphone-common/test/sflphonedrc-sample | 74 - sflphone-common/test/validator.cpp | 22 + sflphone-common/test/validator.h | 21 + 35 files changed, 211 insertions(+), 4552 deletions(-) delete mode 100644 sflphone-common/test/README delete mode 100644 sflphone-common/test/TestMain.cpp create mode 100644 sflphone-common/test/accounttest.cpp create mode 100644 sflphone-common/test/accounttest.h delete mode 100644 sflphone-common/test/audiolayerTest.cpp delete mode 100644 sflphone-common/test/audiolayerTest.h delete mode 100644 sflphone-common/test/audiorecorderTest.cpp delete mode 100644 sflphone-common/test/audiorecorderTest.h delete mode 100644 sflphone-common/test/configurationTest.cpp delete mode 100644 sflphone-common/test/configurationTest.h delete mode 100644 sflphone-common/test/history-sample delete mode 100644 sflphone-common/test/history-sample.tpl delete mode 100644 sflphone-common/test/historyTest.cpp delete mode 100644 sflphone-common/test/historyTest.h delete mode 100644 sflphone-common/test/hookmanagerTest.cpp delete mode 100644 sflphone-common/test/hookmanagerTest.h delete mode 100644 sflphone-common/test/hooksTest.h create mode 100644 sflphone-common/test/main.cpp delete mode 100644 sflphone-common/test/mainbufferTest.cpp delete mode 100644 sflphone-common/test/mainbufferTest.h delete mode 100644 sflphone-common/test/numbercleanerTest.cpp delete mode 100644 sflphone-common/test/numbercleanerTest.h delete mode 100644 sflphone-common/test/pluginmanagerTest.cpp delete mode 100644 sflphone-common/test/pluginmanagerTest.h delete mode 100644 sflphone-common/test/rtpTest.cpp delete mode 100644 sflphone-common/test/rtpTest.h delete mode 100755 sflphone-common/test/run-tests delete mode 100644 sflphone-common/test/sdesnegotiatorTest.cpp delete mode 100644 sflphone-common/test/sdesnegotiatorTest.h delete mode 100644 sflphone-common/test/sflphonedrc-sample create mode 100644 sflphone-common/test/validator.cpp create mode 100644 sflphone-common/test/validator.h diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index af885c9964..e5efbdee68 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -3858,7 +3858,7 @@ std::string ManagerImpl::addAccount ( if (_dbus) _dbus->getConfigurationManager()->accountsChanged(); - return newAccountID; + return accountID.str(); } void ManagerImpl::deleteAllCredential (const AccountID& accountID) { diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h index c2938844f8..3e3b822c3d 100644 --- a/sflphone-common/src/managerimpl.h +++ b/sflphone-common/src/managerimpl.h @@ -1299,7 +1299,7 @@ class ManagerImpl { // ConferenceMap _conferencemap; - + private: diff --git a/sflphone-common/test/Makefile.am b/sflphone-common/test/Makefile.am index e3679eb678..46a90e6ccf 100644 --- a/sflphone-common/test/Makefile.am +++ b/sflphone-common/test/Makefile.am @@ -1,9 +1,34 @@ include ../globals.mak - -noinst_PROGRAMS = numbercleanerTester pluginmanagerTester hookmanagerTester audiolayerTester historyTester mainbufferTester sdesnegotiatorTester #rtpTester - -OBJECT_FILES= \ +TESTS = main +check_PROGRAMS = $(TESTS) +main_CXXFLAGS = $(CPPUNIT_CFLAGS) +main_LDADD = $(LLIBS) +main_LDFLAGS = -ldl +main_SOURCES = main.cpp \ + validator.cpp \ + validator.h \ + accounttest.h \ + accounttest.cpp + + + + + +LLIBS=$(CPPUNIT_LIBS) \ + ../src/libsflphone.la \ + $(ZEROCONFLIB) \ + $(LIB_DNSSD) \ + @ALSA_LIBS@ \ + @PULSEAUDIO_LIBS@ \ + @CPPUNIT_LIBS@ \ + @CCEXT2_LIBS@ \ + @CCGNU2_LIBS@ \ + @CCRTP_LIBS@ \ + @ZRTPCPP_LIBS@ \ + @libssl_LIBS@ \ + @SAMPLERATE_LIBS@ \ + $(PJSIP_LIBS) \ ../src/sflphoned-logger.o \ ../src/sflphoned-managerimpl.o \ ../src/sflphoned-account.o\ @@ -26,145 +51,4 @@ OBJECT_FILES= \ ../src/plug-in/pluginmanager.o \ ../src/plug-in/audiorecorder/audiorecord.o \ ../src/audio/samplerateconverter.o \ - ../src/history/historymanager.o - ../ - -numbercleanerTester_SOURCES = \ - numbercleanerTest.h \ - numbercleanerTest.cpp \ - TestMain.cpp - -numbercleanerTester_LDADD = \ - ../src/libsflphone.la \ - $(SFLPHONE_LIBS) $(ZEROCONFLIB) $(LIB_DNSSD) \ - @ALSA_LIBS@ \ - @PULSEAUDIO_LIBS@ \ - @CPPUNIT_LIBS@ \ - @CCEXT2_LIBS@ \ - @CCGNU2_LIBS@ \ - @CCRTP_LIBS@ \ - @SAMPLERATE_LIBS@ \ - @ZRTPCPP_LIBS@ \ - @libssl_LIBS@ \ - $(PJSIP_LIBS) \ - $(OBJECT_FILES) - -pluginmanagerTester_SOURCES = \ - pluginmanagerTest.h \ - pluginmanagerTest.cpp \ - TestMain.cpp - -pluginmanagerTester_LDADD = \ - ../src/libsflphone.la \ - $(SFLPHONE_LIBS) $(ZEROCONFLIB) $(LIB_DNSSD) \ - @ALSA_LIBS@ \ - @PULSEAUDIO_LIBS@ \ - @CPPUNIT_LIBS@ \ - @CCEXT2_LIBS@ \ - @CCGNU2_LIBS@ \ - @CCRTP_LIBS@ \ - @ZRTPCPP_LIBS@ \ - @libssl_LIBS@ \ - @SAMPLERATE_LIBS@ \ - $(PJSIP_LIBS) \ - $(OBJECT_FILES) - -hookmanagerTester_SOURCES = \ - hookmanagerTest.cpp \ - TestMain.cpp - -hookmanagerTester_LDADD = \ - ../src/libsflphone.la \ - $(SFLPHONE_LIBS) $(ZEROCONFLIB) $(LIB_DNSSD) \ - @ALSA_LIBS@ \ - @PULSEAUDIO_LIBS@ \ - @CPPUNIT_LIBS@ \ - @CCEXT2_LIBS@ \ - @CCGNU2_LIBS@ \ - @CCRTP_LIBS@ \ - @ZRTPCPP_LIBS@ \ - @libssl_LIBS@ \ - @SAMPLERATE_LIBS@ \ - $(PJSIP_LIBS) \ - $(OBJECT_FILES) - -audiolayerTester_SOURCES = \ - audiolayerTest.h \ - audiolayerTest.cpp \ - TestMain.cpp - -audiolayerTester_LDADD = \ - ../src/libsflphone.la \ - $(SFLPHONE_LIBS) $(ZEROCONFLIB) $(LIB_DNSSD) \ - @ALSA_LIBS@ \ - @PULSEAUDIO_LIBS@ \ - @CPPUNIT_LIBS@ \ - @CCEXT2_LIBS@ \ - @CCGNU2_LIBS@ \ - @CCRTP_LIBS@ \ - @ZRTPCPP_LIBS@ \ - @libssl_LIBS@ \ - @SAMPLERATE_LIBS@ \ - $(PJSIP_LIBS) \ - $(OBJECT_FILES) - -historyTester_SOURCES = \ - historyTest.h \ - historyTest.cpp \ - TestMain.cpp - -historyTester_LDADD = \ - ../src/libsflphone.la \ - $(SFLPHONE_LIBS) $(ZEROCONFLIB) $(LIB_DNSSD) \ - @ALSA_LIBS@ \ - @PULSEAUDIO_LIBS@ \ - @CPPUNIT_LIBS@ \ - @CCEXT2_LIBS@ \ - @CCGNU2_LIBS@ \ - @CCRTP_LIBS@ \ - @ZRTPCPP_LIBS@ \ - @libssl_LIBS@ \ - @SAMPLERATE_LIBS@ \ - $(PJSIP_LIBS) \ - $(OBJECT_FILES) - - -mainbufferTester_SOURCES = \ - mainbufferTest.h \ - mainbufferTest.cpp \ - TestMain.cpp - -mainbufferTester_LDADD = \ - ../src/libsflphone.la \ - $(SFLPHONE_LIBS) $(ZEROCONFLIB) $(LIB_DNSSD) \ - @ALSA_LIBS@ \ - @PULSEAUDIO_LIBS@ \ - @CPPUNIT_LIBS@ \ - @CCEXT2_LIBS@ \ - @CCGNU2_LIBS@ \ - @CCRTP_LIBS@ \ - @ZRTPCPP_LIBS@ \ - @libssl_LIBS@ \ - @SAMPLERATE_LIBS@ \ - $(PJSIP_LIBS) \ - $(OBJECT_FILES) - -sdesnegotiatorTester_SOURCES = \ - sdesnegotiatorTest.h \ - sdesnegotiatorTest.cpp \ - TestMain.cpp - -sdesnegotiatorTester_LDADD = \ - ../src/libsflphone.la \ - $(SFLPHONE_LIBS) $(ZEROCONFLIB) $(LIB_DNSSD) \ - @ALSA_LIBS@ \ - @PULSEAUDIO_LIBS@ \ - @CPPUNIT_LIBS@ \ - @CCEXT2_LIBS@ \ - @CCGNU2_LIBS@ \ - @CCRTP_LIBS@ \ - @ZRTPCPP_LIBS@ \ - @libssl_LIBS@ \ - @SAMPLERATE_LIBS@ \ - $(PJSIP_LIBS) \ - $(OBJECT_FILES) + ../src/history/historymanager.o \ No newline at end of file diff --git a/sflphone-common/test/README b/sflphone-common/test/README deleted file mode 100644 index d090ea2cea..0000000000 --- a/sflphone-common/test/README +++ /dev/null @@ -1 +0,0 @@ -The daemon has to be recompiled before compiling the unitary tests. diff --git a/sflphone-common/test/TestMain.cpp b/sflphone-common/test/TestMain.cpp deleted file mode 100644 index d6e9f932bf..0000000000 --- a/sflphone-common/test/TestMain.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include <cppunit/TextTestRunner.h> -#include <cppunit/extensions/TestFactoryRegistry.h> - -int main (int argc, const char* argv[]) -{ - CppUnit::TextTestRunner runner; - runner.addTest (CppUnit::TestFactoryRegistry::getRegistry().makeTest()); - - return runner.run(); - -} - diff --git a/sflphone-common/test/accounttest.cpp b/sflphone-common/test/accounttest.cpp new file mode 100644 index 0000000000..c4e645cb9f --- /dev/null +++ b/sflphone-common/test/accounttest.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2004-2007 Savoir-Faire Linux inc. + * Author: Julien Bonjean <julien.bonjean@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 <cppunit/extensions/HelperMacros.h> +#include <map> +#include "accounttest.h" +#include "manager.h" +#include "logger.h" +#include "validator.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( AccountTest ); + +void AccountTest::TestAddRemove(void) { + + std::map<std::string, std::string> details; + details[CONFIG_ACCOUNT_TYPE] = "SIP"; + details[CONFIG_ACCOUNT_ENABLE] = "false"; + + std::string accountId = Manager::instance().addAccount(details); + CPPUNIT_ASSERT(Validator::isNotNull(accountId)); + CPPUNIT_ASSERT(Manager::instance().accountExists(accountId)); + + Manager::instance().removeAccount(accountId); + + CPPUNIT_ASSERT(!Manager::instance().accountExists(accountId)); +} diff --git a/sflphone-common/test/accounttest.h b/sflphone-common/test/accounttest.h new file mode 100644 index 0000000000..6422684adb --- /dev/null +++ b/sflphone-common/test/accounttest.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2004-2007 Savoir-Faire Linux inc. + * Author: Julien Bonjean <julien.bonjean@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 ACCOUNTTEST_H_ +#define ACCOUNTTEST_H_ + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +class AccountTest : public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE( AccountTest ); + CPPUNIT_TEST( TestAddRemove ); + CPPUNIT_TEST_SUITE_END(); + + public: + void TestAddRemove(void); +}; + +#endif /* ACCOUNTTEST_H_ */ diff --git a/sflphone-common/test/audiolayerTest.cpp b/sflphone-common/test/audiolayerTest.cpp deleted file mode 100644 index 962bb8fc4b..0000000000 --- a/sflphone-common/test/audiolayerTest.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/* - * 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::setUp() -{ - - // Instanciate the manager - Manager::instance().init(); - Manager::instance().initConfigFile(); - - // _audiodriver = Manager::instance().getAudioDriver(); - - // std::string alsaPlugin; - // AlsaLayer *alsalayer; - - // int numCardIn, numCardOut, sampleRate, frameSize; - // layer = _audiodriver->getLayerType(); - - /* - alsaPlugin = Manager::instance().getConfigString( AUDIO , ALSA_PLUGIN ); - numCardIn = Manager::instance().getConfigInt( AUDIO , ALSA_CARD_ID_IN ); - numCardOut = Manager::instance().getConfigInt( AUDIO , ALSA_CARD_ID_OUT ); - sampleRate = Manager::instance().getConfigInt( AUDIO , ALSA_SAMPLE_RATE ); - if (sampleRate <=0 || sampleRate > 48000) { - sampleRate = 44100; - } - frameSize = Manager::instance().getConfigInt(AUDIO, ALSA_FRAME_SIZE ); - */ - - // get a pointer to the audio layer - // _audiodriver = Manager::instance().getAudioDriver(); - -} - -void AudioLayerTest::testAudioLayerConfig() -{ - int sampling_rate = Manager::instance().getConfigInt (AUDIO, AUDIO_SAMPLE_RATE); - int frame_size = Manager::instance().getConfigInt (AUDIO, ALSA_FRAME_SIZE); - frame_size = 0; // frame size in config not used anymore - - int layer = Manager::instance().getAudioDriver()->getLayerType(); - - if (layer != ALSA) - Manager::instance().switchAudioManager(); - - CPPUNIT_ASSERT ( (int) Manager::instance().getAudioDriver()->getSampleRate() == sampling_rate); - - CPPUNIT_ASSERT ( (int) Manager::instance().getAudioDriver()->getFrameSize() == frame_size); -} - -void AudioLayerTest::testAudioLayerSwitch() -{ - - _debug ("---------- AudioLayerTest::testAudioLayerSwitch ---------------------------"); - - - int previous_layer = Manager::instance().getAudioDriver()->getLayerType(); - - for (int i = 0; i < 2; i++) { - _debug ("---------- AudioLayerTest::testAudioLayerSwitch - %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 ---------------------------"); - - ManagerImpl* manager; - manager = &Manager::instance(); - - // _pulselayer = new PulseLayer (manager); - _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); - - // CPPUNIT_ASSERT (_pulselayer->getPlaybackStream()->pulseStream() != NULL); - // CPPUNIT_ASSERT (_pulselayer->getRecordStream()->pulseStream() != NULL); - - // Must return Access failure "PA_ERR_ACCESS" == 2 - // CPPUNIT_ASSERT (_pulselayer->getPlaybackStream()->getStreamState() == 2); - // CPPUNIT_ASSERT (_pulselayer->getRecordStream()->getStreamState() == 2); - _debug ("-------------------------- \n"); - _pulselayer->startStream (); - - // usleep(1000000); - - - 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); - - // usleep(1000000); - CPPUNIT_ASSERT (_pulselayer->disconnectAudioStream() == true); - -} - - -void AudioLayerTest::testAlsaConnect() -{ - - _debug ("---------- AudioLayerTest::testAlsaConnect ---------------------------"); - - int layer = Manager::instance().getAudioDriver()->getLayerType(); - - std::string alsaPlugin; - - if (layer != ALSA) { - Manager::instance().switchAudioManager(); - usleep (100000); - } - - // _audiolayer = Manager::instance().getAudioDriver(); - - // CPPUNIT_ASSERT(_audiolayer->closeLayer() == true); - // usleep(100000); - - // delete _audiolayer; _audiolayer == NULL; - - Manager::instance().setConfig (PREFERENCES, CONFIG_AUDIO, ALSA); - - - // _audiolayer->setErrorMessage(-1); - // CPPUNIT_ASSERT(Manager::instance().initAudioDriver() == true); - - // _audiolayer = Manager::instance().getAudioDriver(); - - // CPPUNIT_ASSERT(_audiolayer->getLayerType() == ALSA); - -} - -void AudioLayerTest::tearDown() -{ - // Delete the audio recorder module - // delete _ar; _ar = NULL; -} diff --git a/sflphone-common/test/audiolayerTest.h b/sflphone-common/test/audiolayerTest.h deleted file mode 100644 index 7bda91c508..0000000000 --- a/sflphone-common/test/audiolayerTest.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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 "manager.h" - -#include "config/config.h" -#include "user_cfg.h" - -#include "audio/audiolayer.h" -#include "audio/alsa/alsalayer.h" -#include "audio/pulseaudio/pulselayer.h" - -/* - * @file audiorecorderTest.cpp - * @brief Regroups unitary tests related to the plugin manager. - */ - -#ifndef _AUDIOLAYER_TEST_ -#define _AUDIOLAYER_TEST_ - - - -class AudioLayerTest : public CppUnit::TestCase { - - /* - * Use cppunit library macros to add unit test the factory - */ - CPPUNIT_TEST_SUITE( AudioLayerTest ); - CPPUNIT_TEST( testAudioLayerConfig ); - // CPPUNIT_TEST( testAudioLayerSwitch ); - CPPUNIT_TEST( testPulseConnect ); - // CPPUNIT_TEST( testAlsaConnect ); - CPPUNIT_TEST_SUITE_END(); - - public: - AudioLayerTest() : 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 testAudioLayerConfig(); - void testAudioLayerSwitch(); - void testPulseConnect(); - void testAlsaConnect(); - - private: - - ManagerImpl* manager; - - PulseLayer* _pulselayer; - - int layer; -}; - -/* Register our test module */ -CPPUNIT_TEST_SUITE_REGISTRATION( AudioLayerTest ); - -#endif diff --git a/sflphone-common/test/audiorecorderTest.cpp b/sflphone-common/test/audiorecorderTest.cpp deleted file mode 100644 index d4dda35db6..0000000000 --- a/sflphone-common/test/audiorecorderTest.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 "audiorecorderTest.h" - -using std::cout; -using std::endl; - -void AudioRecorderTest::setUp() -{ - // Instanciate the object - _ar = new AudioRecord(); -} - -void AudioRecorderTest::testRecordData() -{ - - /* - FILE_TYPE ft = FILE_WAV; - SOUND_FORMAT sf = INT16; - _ar->setSndSamplingRate(44100); - _ar->openFile("theWavFile.wav",ft,sf); - - cout << "file opened!"; - - SFLDataFormat buf [2]; - for (SFLDataFormat i = -32768; i < 32767; i++ ){ - buf[0] = i; - buf[1] = i; - _ar->recData(buf,2); - } - - _ar->closeFile(); - */ -} - -void AudioRecorderTest::tearDown() -{ - // Delete the audio recorder module - delete _ar; - _ar = NULL; -} diff --git a/sflphone-common/test/audiorecorderTest.h b/sflphone-common/test/audiorecorderTest.h deleted file mode 100644 index 216b657079..0000000000 --- a/sflphone-common/test/audiorecorderTest.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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/audiorecorder/audiorecord.h" - -/* - * @file audiorecorderTest.cpp - * @brief Regroups unitary tests related to the plugin manager. - */ - -#ifndef _AUDIORECORDER_TEST_ -#define _AUDIORECORDER_TEST_ - -class AudioRecorderTest : public CppUnit::TestCase { - - /* - * Use cppunit library macros to add unit test the factory - */ - CPPUNIT_TEST_SUITE( AudioRecorderTest ); - CPPUNIT_TEST( testRecordData ); - CPPUNIT_TEST_SUITE_END(); - - public: - AudioRecorderTest() : CppUnit::TestCase("Audio Recorder 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 testRecordData(); - - private: - AudioRecord *_ar; -}; - -/* Register our test module */ -CPPUNIT_TEST_SUITE_REGISTRATION( AudioRecorderTest ); - -#endif diff --git a/sflphone-common/test/configurationTest.cpp b/sflphone-common/test/configurationTest.cpp deleted file mode 100644 index 1819c92db1..0000000000 --- a/sflphone-common/test/configurationTest.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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" - -using std::cout; -using std::endl; - -void ConfigurationTest::setUp() -{ - // Load the default configuration - Manager::instance().initConfigFile(); -} - -void ConfigurationTest::testDefaultValueAudio() -{ - CPPUNIT_ASSERT (Manager::instance().getConfigString (AUDIO, ALSA_CARD_ID_IN) == ALSA_DFT_CARD) ; - CPPUNIT_ASSERT (Manager::instance().getConfigString (AUDIO, ALSA_CARD_ID_OUT) == ALSA_DFT_CARD); - CPPUNIT_ASSERT (Manager::instance().getConfigString (AUDIO, ALSA_SAMPLE_RATE) == DFT_SAMPLE_RATE); - CPPUNIT_ASSERT (Manager::instance().getConfigString (AUDIO, ALSA_FRAME_SIZE) == DFT_FRAME_SIZE) ; - CPPUNIT_ASSERT (Manager::instance().getConfigString (AUDIO, ALSA_PLUGIN) == PCM_DEFAULT); - CPPUNIT_ASSERT (Manager::instance().getConfigString (AUDIO, VOLUME_SPKR) == DFT_VOL_SPKR_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (AUDIO, VOLUME_MICRO) == DFT_VOL_MICRO_STR); -} - -void ConfigurationTest::testDefaultValuePreferences() -{ - CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, ZONE_TONE) == DFT_ZONE); - CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, CONFIG_DIALPAD) == YES_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, CONFIG_RINGTONE) == YES_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, CONFIG_SEARCHBAR) == YES_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, CONFIG_START) == NO_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, CONFIG_POPUP) == YES_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, CONFIG_NOTIFY) == YES_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, CONFIG_MAIL_NOTIFY) == NO_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, CONFIG_VOLUME) == YES_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, REGISTRATION_EXPIRE) == DFT_EXPIRE_VALUE); - CPPUNIT_ASSERT (Manager::instance().getConfigString (PREFERENCES, CONFIG_AUDIO) == DFT_AUDIO_MANAGER); - -} - -void ConfigurationTest::testDefaultValueSignalisation() -{ - CPPUNIT_ASSERT (Manager::instance().getConfigString (SIGNALISATION , SYMMETRIC) == YES_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (SIGNALISATION , PLAY_DTMF) == YES_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (SIGNALISATION , PLAY_TONES) == YES_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (SIGNALISATION , PULSE_LENGTH) == DFT_PULSE_LENGTH_STR); - CPPUNIT_ASSERT (Manager::instance().getConfigString (SIGNALISATION , SEND_DTMF_AS) == SIP_INFO_STR); -} - -void ConfigurationTest::testLoadSIPAccount() -{ - - 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() -{ - - 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() -{ - - 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() -{ - - // 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"); -} - -void ConfigurationTest::testSelectAudioDriver() -{ -} diff --git a/sflphone-common/test/configurationTest.h b/sflphone-common/test/configurationTest.h deleted file mode 100644 index 87828521ee..0000000000 --- a/sflphone-common/test/configurationTest.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2008 Savoir-Faire Linux inc. - * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -// Cppunit import -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCaller.h> -#include <cppunit/TestCase.h> -#include <cppunit/TestSuite.h> - -#include <assert.h> - -// Application import -#include "manager.h" -#include "audio/audiolayer.h" -#include "global.h" -#include "user_cfg.h" - -/* - * @file configurationTest.cpp - * @brief Regroups unitary tests related to the user configuration. - * Check if the default configuration has been successfully loaded - */ - -#ifndef _CONFIGURATION_TEST_ -#define _CONFIGURATION_TEST_ - -class ConfigurationTest : public CppUnit::TestCase { - - /* - * Use cppunit library macros to add unit test the factory - */ - CPPUNIT_TEST_SUITE( ConfigurationTest ); - CPPUNIT_TEST( testDefaultValueAudio ); - CPPUNIT_TEST( testDefaultValuePreferences ); - CPPUNIT_TEST( testDefaultValueSignalisation ); - CPPUNIT_TEST( testLoadSIPAccount ); - CPPUNIT_TEST( testUnloadSIPAccount ); - CPPUNIT_TEST( testInitVolume ); - CPPUNIT_TEST( testInitAudioDriver ); - CPPUNIT_TEST( testSelectAudioDriver ); - CPPUNIT_TEST_SUITE_END(); - - public: - ConfigurationTest() : CppUnit::TestCase("Configuration Tests") {} - - /* - * Code factoring - Common resources can be initialized here. - * This method is called by unitcpp before each test - */ - void setUp(); - - /* - * Code factoring - Common resources can be released here. - * This method is called by unitcpp after each test - */ - inline void tearDown(){ - // Not much to do - } - - /* - * Unit tests related to the audio preferences - */ - void testDefaultValueAudio(); - - /* - * Unit tests related to the global settings - */ - void testDefaultValuePreferences(); - - /* - * 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(); - void testSelectAudioDriver(); - -}; - -/* Register our test module */ -CPPUNIT_TEST_SUITE_REGISTRATION( ConfigurationTest ); - -#endif diff --git a/sflphone-common/test/history-sample b/sflphone-common/test/history-sample deleted file mode 100644 index a6f39f4ed3..0000000000 --- a/sflphone-common/test/history-sample +++ /dev/null @@ -1,21 +0,0 @@ -[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 deleted file mode 100644 index 221e449538..0000000000 --- a/sflphone-common/test/history-sample.tpl +++ /dev/null @@ -1,20 +0,0 @@ -[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 deleted file mode 100644 index b21179bb78..0000000000 --- a/sflphone-common/test/historyTest.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* - * 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" - -using std::cout; -using std::endl; - -#define HISTORY_SAMPLE "history-sample" -#define HISTORY_SAMPLE_SIZE 3 -#define CONFIG_SAMPLE "sflphonedrc-sample" -#define HUGE_HISTORY_LIMIT 20000 - -void HistoryTest::setUp() -{ - // Instanciate the cleaner singleton - history = new HistoryManager (); -} - -void HistoryTest::test_create_history_path () -{ - - 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 () -{ - 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 () -{ - 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 () -{ - 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 () -{ - 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 () -{ - std::map <std::string, std::string> res; - std::map <std::string, std::string>::iterator iter; - std::string tmp; - - // Load the sample user config - Manager::instance().initConfigFile (true, CONFIG_SAMPLE); - Manager::instance().loadAccountMap (); - - 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 (tmp == res ["144562436"]); - - tmp = "2|136|Emmanuel Milou|747638765|Account:1239059899"; - CPPUNIT_ASSERT (tmp == res ["747638685"]); - - // the account ID does not correspond to a loaded account - tmp = "1|5143848557|empty|775354987|empty"; - CPPUNIT_ASSERT (tmp == res ["775354456"]); -} - -void HistoryTest::test_set_serialized_history () -{ - // 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 (tmp == map_test ["144562436"]); - - tmp = "2|136|Emmanuel Milou|747638765|Account:1239059899"; - CPPUNIT_ASSERT (tmp == map_test ["747638685"]); - - // the account ID does not correspond to a loaded account - tmp = "1|5143848557|empty|775354987|empty"; - CPPUNIT_ASSERT (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 () -{ - // 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 deleted file mode 100644 index 38ac517c9f..0000000000 --- a/sflphone-common/test/historyTest.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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_load_history_from_file); - CPPUNIT_TEST (test_load_history_items_map); - CPPUNIT_TEST (test_save_history_items_map); - CPPUNIT_TEST (test_save_history_to_file); - 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_REGISTRATION( HistoryTest ); - -#endif diff --git a/sflphone-common/test/hookmanagerTest.cpp b/sflphone-common/test/hookmanagerTest.cpp deleted file mode 100644 index 817533a927..0000000000 --- a/sflphone-common/test/hookmanagerTest.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 "hookmanagerTest.h" - -using std::cout; -using std::endl; - - -void HookManagerTest::setUp() -{ - // Instanciate the hook manager singleton - urlhook = new UrlHook (); -} - -void HookManagerTest::testAddAction () -{ - - 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 () -{ - - 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 deleted file mode 100644 index 9c7464125d..0000000000 --- a/sflphone-common/test/hookmanagerTest.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 "hooks/urlhook.h" - -/* - * @file hookmanagerTest.cpp - * @brief Regroups unitary tests related to the hook manager. - */ - -#ifndef _HOOKMANAGER_TEST_ -#define _HOOKMANAGER_TEST_ - -class HookManagerTest : public CppUnit::TestCase { - - /** - * 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: - HookManagerTest() : 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 testAddAction (); - - void testLargeUrl (); - /* - * Code factoring - Common resources can be released here. - * This method is called by unitcpp after each test - */ - inline void tearDown (); - - private: - UrlHook *urlhook; -}; - -/* Register our test module */ -CPPUNIT_TEST_SUITE_REGISTRATION( HookManagerTest ); - -#endif diff --git a/sflphone-common/test/hooksTest.h b/sflphone-common/test/hooksTest.h deleted file mode 100644 index a08e7e3ecd..0000000000 --- a/sflphone-common/test/hooksTest.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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> - -/* - * @file hooksTest.cpp - * @brief Regroups unitary tests related to the hooks. - */ - -#ifndef _HOOKS_TEST_ -#define _HOOKS_TEST_ - -class HooksTest : public CppUnit::TestCase { - - /** - * Use cppunit library macros to add unit test the factory - */ - CPPUNIT_TEST_SUITE (HooksTest); - CPPUNIT_TEST (); - CPPUNIT_TEST_SUITE_END(); - - public: - HooksTest() : CppUnit::TestCase("Hooks implementation 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 testUnloadPlugins (); - - private: -}; - -/* Register our test module */ -CPPUNIT_TEST_SUITE_REGISTRATION (HooksTest); - -# diff --git a/sflphone-common/test/main.cpp b/sflphone-common/test/main.cpp new file mode 100644 index 0000000000..3dda5ada70 --- /dev/null +++ b/sflphone-common/test/main.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2004-2007 Savoir-Faire Linux inc. + * Author: Julien Bonjean <julien.bonjean@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 "accounttest.h" +#include "logger.h" +#include "global.h" +#include "manager.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(); + + Logger::setDebugMode(true); + Logger::setConsoleLog(true); + + // Get the top level suite from the registry + CppUnit::Test *suite = + CppUnit::TestFactoryRegistry::getRegistry().makeTest(); + + // Adds the test to the list of test to run + // CppUnit::TextUi::TestRunner runner; + CppUnit::TextTestRunner runner; + runner.addTest(suite); + + // Change the default outputter to a compiler error format outputter + runner.setOutputter(new CppUnit::CompilerOutputter(&runner.result(), + std::cerr)); + // Run the tests. + bool wasSucessful = runner.run(); + + // Return error code 1 if the one of test failed. + return wasSucessful ? 0 : 1; + + Manager::instance().terminate(); +} + +int main(void) { + return RunTests(); +} diff --git a/sflphone-common/test/mainbufferTest.cpp b/sflphone-common/test/mainbufferTest.cpp deleted file mode 100644 index 830ff2c769..0000000000 --- a/sflphone-common/test/mainbufferTest.cpp +++ /dev/null @@ -1,1772 +0,0 @@ -/* - * 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()"); - - 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()"); - - 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()"); - - 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()"); - - // 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()"); - - 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()"); - - 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()"); - - - 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()"); - - 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::testGetPutData()"); - - 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::testGetDataAndCallID()"); - - 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()"); - - 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()"); - - 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"); - - 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()"); - - 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 deleted file mode 100644 index 330228f9a9..0000000000 --- a/sflphone-common/test/mainbufferTest.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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_REGISTRATION( MainBufferTest ); - -#endif diff --git a/sflphone-common/test/numbercleanerTest.cpp b/sflphone-common/test/numbercleanerTest.cpp deleted file mode 100644 index 03dca41604..0000000000 --- a/sflphone-common/test/numbercleanerTest.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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 "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) -{ - - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_1) == VALID_NUMBER); -} - -void NumberCleanerTest::test_format_2 (void) -{ - - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_2) == VALID_NUMBER); -} - -void NumberCleanerTest::test_format_3 (void) -{ - - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_3) == VALID_NUMBER); -} - -void NumberCleanerTest::test_format_4 (void) -{ - - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_4) == VALID_NUMBER); -} - -void NumberCleanerTest::test_format_5 (void) -{ - - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_5) == VALID_NUMBER); -} - -void NumberCleanerTest::test_format_6 (void) -{ - - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_6) == VALID_NUMBER); -} - -void NumberCleanerTest::test_format_7 (void) -{ - - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_7) == VALID_NUMBER); -} - -void NumberCleanerTest::test_format_8 (void) -{ - - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_8) == VALID_NUMBER); -} - -void NumberCleanerTest::test_format_9 (void) -{ - - CPPUNIT_ASSERT (cleaner->clean (NUMBER_TEST_9) == VALID_NUMBER); -} - -void NumberCleanerTest::test_format_10 (void) -{ - - 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) -{ - - 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 deleted file mode 100644 index 3af6ab8c92..0000000000 --- a/sflphone-common/test/numbercleanerTest.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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_7); - CPPUNIT_TEST (test_format_8); - CPPUNIT_TEST (test_format_9); - CPPUNIT_TEST (test_format_10); - CPPUNIT_TEST (test_format_11); - 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_REGISTRATION( NumberCleanerTest ); - -#endif diff --git a/sflphone-common/test/pluginmanagerTest.cpp b/sflphone-common/test/pluginmanagerTest.cpp deleted file mode 100644 index 86b4890c6f..0000000000 --- a/sflphone-common/test/pluginmanagerTest.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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() -{ - CPPUNIT_ASSERT (_pm->loadDynamicLibrary (PLUGIN_TEST_NAME) != NULL); -} - -void PluginManagerTest::testUnloadDynamicLibrary() -{ - library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); - CPPUNIT_ASSERT (library != NULL); - CPPUNIT_ASSERT (_pm->unloadDynamicLibrary (library) == 0); -} - -void PluginManagerTest::testInstanciatePlugin() -{ - library = _pm->loadDynamicLibrary (PLUGIN_TEST_NAME); - CPPUNIT_ASSERT (library != NULL); - CPPUNIT_ASSERT (_pm->instanciatePlugin (library, &plugin) == 0); - CPPUNIT_ASSERT (plugin!=NULL); -} - -void PluginManagerTest::testInitPlugin() -{ - - 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() -{ - 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 () -{ - CPPUNIT_ASSERT (_pm->loadPlugins (PLUGIN_TEST_DIR) == 0); - CPPUNIT_ASSERT (_pm->isPluginLoaded (PLUGIN_TEST_DESC) == true); -} - -void PluginManagerTest::testUnloadPlugins () -{ - 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 deleted file mode 100644 index 293311b6d2..0000000000 --- a/sflphone-common/test/pluginmanagerTest.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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_REGISTRATION( PluginManagerTest ); - -#endif diff --git a/sflphone-common/test/rtpTest.cpp b/sflphone-common/test/rtpTest.cpp deleted file mode 100644 index 31dfcc8166..0000000000 --- a/sflphone-common/test/rtpTest.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* - * 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 "rtpTest.h" - -#include <unistd.h> - - -using std::cout; -using std::endl; - - -void RtpTest::setUp() -{ - - _debug ("------ Set up rtp test------"); - - Manager::instance().initConfigFile(); - Manager::instance().init(); - - 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() -{ - - audiortp = new AudioSymmetricRtpSession (Manager::instance(), sipcall); - - _debug ("------ void RtpTest::testRtpInit() ------"); - - try { - - _debug ("-------- Open Rtp Session ----------"); - audiortp->createNewSession (sipcall); - - } catch (...) { - - _debug ("!!! Exception occured while Oppenning Rtp !!!"); - - } - - CPPUNIT_ASSERT (audiortp != NULL); - - - audiortp->_RTXThread->computeCodecFrameSize (320,8000); - - // computeNbByteAudioLayer - - _debug ("------ Finilize Rtp Initialization ------ "); - - - _debug ("------ RtpTest::testRtpClose() ------"); - - try { - _debug ("------ Close Rtp Session -------"); - CPPUNIT_ASSERT (audiortp->closeRtpSession()); - - } catch (...) { - - _debug ("!!! Exception occured while closing Rtp !!!"); - - } - - delete audiortp; - - audiortp = NULL; - -} - -void RtpTest::testRtpThread() -{ - - audiortp = new AudioRtp(); - - _debug ("-------- Open Rtp Session ----------"); - - try { - - audiortp->createNewSession (sipcall); - - } catch (...) { - - _debug ("!!! Exception occured while Oppenning Rtp !!!"); - - } - - _debug ("------ void RtpTest::testRtpThread ------"); - - CPPUNIT_ASSERT (audiortp->_RTXThread->computeCodecFrameSize (160,8000) == 20.0f); - CPPUNIT_ASSERT (audiortp->_RTXThread->computeCodecFrameSize (320,16000) == 20.0f); - CPPUNIT_ASSERT (audiortp->_RTXThread->computeCodecFrameSize (882,44100) == 20.0f); - - // 20 ms at 44.1 khz corespond to 882 samples (1764 byte) - CPPUNIT_ASSERT (audiortp->_RTXThread->computeNbByteAudioLayer (20.f) == 1764); - - _debug ("------ Close Rtp Session -------"); - - try { - - CPPUNIT_ASSERT (audiortp->closeRtpSession()); - - } catch (...) { - - _debug ("!!! Exception occured while closing Rtp !!!"); - - } - - delete audiortp; - - audiortp = NULL; -} - - - -void RtpTest::testRtpResampling() -{ - - int nbSample = 50; - int rsmpl_nbSample = 0; - - SFLDataFormat *data = new SFLDataFormat[1024]; - SFLDataFormat *rsmpl_data = new SFLDataFormat[1024]; - - for (int i = 0; i < nbSample; i++) - data[i] = i; - - - audiortp = new AudioRtp(); - - _debug ("-------- Open Rtp Session ----------"); - - try { - - audiortp->createNewSession (sipcall); - - } catch (...) { - - _debug ("!!! Exception occured while Oppenning Rtp !!!"); - - } - - _debug ("------ void RtpTest::testRtpResampling ------"); - - CPPUNIT_ASSERT (0 == 0); - rsmpl_nbSample = audiortp->_RTXThread->reSampleData (data, rsmpl_data, 8000, nbSample, UP_SAMPLING); - _debug ("ORIGINAL DATA SET"); - - for (int i = 0; i < nbSample; i++) - printf (" %i=>%i ", i, data[i]); - - _debug ("RESAMPLED DATA SET"); - - for (int i = 0; i < rsmpl_nbSample; i++) - printf (" %i=>%i ", i, rsmpl_data[i]); - - printf (""); - - - _debug ("------ Close Rtp Session -------"); - - try { - - CPPUNIT_ASSERT (audiortp->closeRtpSession()); - - } catch (...) { - - _debug ("!!! Exception occured while closing Rtp !!!"); - - } - - 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 deleted file mode 100644 index 9e7c39ec6a..0000000000 --- a/sflphone-common/test/rtpTest.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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> - -#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/audiortp/AudioRtpSession.h" -#include "audio/audiortp/AudioSymmetricRtpSession.h" -#include "call.h" -#include "sip/sipcall.h" -#include "sip/sipvoiplink.h" - -#include "config/config.h" -#include "user_cfg.h" - -using namespace sfl; - -/* - * @file audiorecorderTest.cpp - * @brief Regroups unitary tests related to the plugin manager. - */ - -#ifndef _RTP_TEST_ -#define _RTP_TEST_ - -class AudioSymmetricRtpSession; -class AudioRtpSession; -class AudioRtpRTX; -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( testRtpThread ); - CPPUNIT_TEST( testRtpResampling ); - 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(); - - void testRtpThread(); - - void testRtpResampling(); - - - private: - - enum CallType {Incoming, Outgoing}; - - ManagerImpl* manager; - - AudioSymmetricRtpSession *audiortp; - - AudioRtpRTX *rtpthread; - - SIPCall *sipcall; - - pj_caching_pool _cp; - - pj_pool_t *_pool; - -}; - -/* Register our test module */ -CPPUNIT_TEST_SUITE_REGISTRATION( RtpTest ); - -#endif diff --git a/sflphone-common/test/run-tests b/sflphone-common/test/run-tests deleted file mode 100755 index 9b5d01405c..0000000000 --- a/sflphone-common/test/run-tests +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -myname="`basename $0`" -failures=0 - -for f in * -do - # Skip ourself - if [ "$f" = "$myname" ]; then - continue - fi - - if [ -x "$f" ]; then - echo - echo "=== Running [$f] test ===" - # Warning, libCppUnit returns 0 on failure. - ./"$f" && { - echo Warning: Failure in $f. - failures=$((failures+1)) - } - fi -done - -echo "Tests finshed, there were $failures failures." diff --git a/sflphone-common/test/sdesnegotiatorTest.cpp b/sflphone-common/test/sdesnegotiatorTest.cpp deleted file mode 100644 index 54f7f4b5ec..0000000000 --- a/sflphone-common/test/sdesnegotiatorTest.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* - * 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> - - -using std::cout; -using std::endl; - - -void SdesNegotiatorTest::setUp() -{ - -} - - -void SdesNegotiatorTest::tearDown() -{ - -} - -void SdesNegotiatorTest::testTagPattern() -{ - 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() -{ - 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() -{ - - 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() -{ - - 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() -{ - // 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() -{ - // 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() -{ - // 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 deleted file mode 100644 index f3e73f6c2f..0000000000 --- a/sflphone-common/test/sdesnegotiatorTest.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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" -// #include "config/config.h" -// #include "user_cfg.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: - - SdesNegotiatorTest() : CppUnit::TestCase("Sdes 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 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_REGISTRATION( SdesNegotiatorTest ); - -#endif diff --git a/sflphone-common/test/sflphonedrc-sample b/sflphone-common/test/sflphonedrc-sample deleted file mode 100644 index 6d0064a7c5..0000000000 --- a/sflphone-common/test/sflphonedrc-sample +++ /dev/null @@ -1,74 +0,0 @@ -[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 new file mode 100644 index 0000000000..6f34e3102f --- /dev/null +++ b/sflphone-common/test/validator.cpp @@ -0,0 +1,22 @@ +/* + * validator.cpp + * + * Created on: 2010-03-12 + * Author: jb + */ + +#include "validator.h" + +bool Validator::isNumber(std::string str) { + unsigned int i = 0; + if (!str.empty() && (str[i] == '-' || str[i] == '+')) + i++; + return string::npos == str.find_first_not_of(".eE0123456789", i); +} + +bool Validator::isNotNull(std::string str) { + if(!str.empty()) + return true; + else + return false; +} diff --git a/sflphone-common/test/validator.h b/sflphone-common/test/validator.h new file mode 100644 index 0000000000..363e3c9aef --- /dev/null +++ b/sflphone-common/test/validator.h @@ -0,0 +1,21 @@ +/* + * validator.h + * + * Created on: 2010-03-12 + * Author: jb + */ + +#ifndef VALIDATOR_H_ +#define VALIDATOR_H_ + +#include <string> +#include <iostream> + +using namespace std; + +class Validator { + public: + static bool isNumber(std::string str); + static bool isNotNull(std::string str); +}; +#endif /* VALIDATOR_H_ */ -- GitLab