diff --git a/autogen.sh b/autogen.sh index 47c9baa2215201ef4b04c53cd94067e69b7e784b..e63f71ddd78137734c54388664397300f863b2bd 100755 --- a/autogen.sh +++ b/autogen.sh @@ -6,4 +6,3 @@ libtoolize --force autoheader autoconf -f automake -a -./configure --prefix=/usr --with-debug diff --git a/configure.ac b/configure.ac index 30a2ac659b51a66e3f869079e3c196dd7f4bc81f..e58406ac18f0d74aa236e904d60132de1d0b24eb 100644 --- a/configure.ac +++ b/configure.ac @@ -135,8 +135,6 @@ AC_CHECK_FUNCS([bzero floor gethostbyname gethrtime gettimeofday \ dnl ***************************************** dnl Check for header files dnl ***************************************** -dnl Check for exosip2 -LP_CHECK_EXOSIP2 SFLPHONE_LIBS="$SFLPHONE_LIBS" dnl Check for GNU ccRTP diff --git a/globals.mak b/globals.mak index 41cc38fb63fc2017f0b12a6a8b67ce723fcaef3f..3ed71e1808ed32ba21f56c777fc33a92964c9e2a 100644 --- a/globals.mak +++ b/globals.mak @@ -8,6 +8,7 @@ PJSIP_LIBS = -lpjnath -lpjsua -lpjsip -lpjmedia -lpjsip-simple -lpjsip-ua -lpjme AM_CPPFLAGS = \ -I$(src)/libs \ -I$(src)/src \ + -I$(src)/test \ -DPREFIX=\"$(prefix)\" \ -DPROGSHAREDIR=\"${datadir}/sflphone\" \ $(ZEROCONFFLAGS) \ diff --git a/sflphone-gtk/autogen.sh b/sflphone-gtk/autogen.sh index 47c9baa2215201ef4b04c53cd94067e69b7e784b..e63f71ddd78137734c54388664397300f863b2bd 100755 --- a/sflphone-gtk/autogen.sh +++ b/sflphone-gtk/autogen.sh @@ -6,4 +6,3 @@ libtoolize --force autoheader autoconf -f automake -a -./configure --prefix=/usr --with-debug diff --git a/sflphone-gtk/src/accountlist.c b/sflphone-gtk/src/accountlist.c index 8e9654eb8661b2bfc612f9a30d0c205b89739094..893d057d24ed2776acbc99cc65c8e33617b0ed53 100644 --- a/sflphone-gtk/src/accountlist.c +++ b/sflphone-gtk/src/accountlist.c @@ -223,3 +223,44 @@ account_list_get_registered_accounts( void ) g_print(" %d registered accounts \n" , res ); return res; } + +gchar* account_list_get_current_id( void ){ + if( __CURRENT_ACCOUNT_ID == NULL ) + return ""; + else + return __CURRENT_ACCOUNT_ID; +} + +int account_list_get_sip_account_number( void ){ + + int n; + guint size, i; + account_t *current; + + size = account_list_get_size(); + n = 0; + for( i=0; i<size ;i++ ){ + current = account_list_get_nth( i ); + if( strcmp(g_hash_table_lookup(current->properties, ACCOUNT_TYPE), "SIP" ) == 0 ) + n++; + } + + return n; +} + +int account_list_get_iax_account_number( void ){ + + int n; + guint size, i; + account_t *current; + + size = account_list_get_size(); + n = 0; + for( i=0; i<size ;i++ ){ + current = account_list_get_nth( i ); + if( strcmp(g_hash_table_lookup(current->properties, ACCOUNT_TYPE), "IAX" ) == 0 ) + n++; + } + + return n; +} diff --git a/sflphone-gtk/src/accountlist.h b/sflphone-gtk/src/accountlist.h index 70756bfad130458da41f4cfdad4917f3b65daf52..18b5575d87504af68f280cdc15c35db0cbada95c 100644 --- a/sflphone-gtk/src/accountlist.h +++ b/sflphone-gtk/src/accountlist.h @@ -161,4 +161,22 @@ void account_list_move_up( guint index ); */ void account_list_move_down( guint index ); +/** + * Return the ID of the current default account + * @return gchar* The id + */ +gchar* account_list_get_current_id( void ); + +/** + * Returns the number of SIP accounts that have been configured + */ +int account_list_get_sip_account_number( void ); + +/** + * Returns the number of IAX accounts that have been configured + */ +int account_list_get_iax_account_number( void ); + + + #endif diff --git a/sflphone-gtk/src/actions.c b/sflphone-gtk/src/actions.c index 39cbbf2ca37676d0809c21c06bd09524fac43b9e..6b1aaf7c3fcad92b30537b8902025cd593704ba7 100644 --- a/sflphone-gtk/src/actions.c +++ b/sflphone-gtk/src/actions.c @@ -39,25 +39,35 @@ guint voice_mails; void sflphone_notify_voice_mail ( const gchar* accountID , guint count ) { - voice_mails = count ; - gchar* id = g_strdup( accountID ); - if(count > 0) - { - gchar * message = g_new0(gchar, 50); - if( count > 1) - g_sprintf(message, _("%d voice mails"), count); - else - g_sprintf(message, _("%d voice mail"), count); - statusbar_push_message(message, __MSG_VOICE_MAILS); - g_free(message); - } - // TODO: add ifdef - if( account_list_get_size() > 0 ) - { - account_t* acc = account_list_get_by_id( id ); - if( acc != NULL ) - notify_voice_mails( count , acc ); - } + gchar *id; + gchar *current; + + // We want to notify only for the default current account; ie the first in the list + id = g_strdup( accountID ); + current = account_list_get_current_id(); + if( strcmp( id, current ) != 0 ) + return; + + voice_mails = count ; + + if(count > 0) + { + gchar * message = g_new0(gchar, 50); + if( count > 1) + g_sprintf(message, _("%d voice mails"), count); + else + g_sprintf(message, _("%d voice mail"), count); + statusbar_push_message(message, __MSG_VOICE_MAILS); + g_free(message); + } + + // TODO: add ifdef + if( account_list_get_size() > 0 ) + { + account_t* acc = account_list_get_by_id( id ); + if( acc != NULL ) + notify_voice_mails( count , acc ); + } } void diff --git a/sflphone-gtk/src/configwindow.c b/sflphone-gtk/src/configwindow.c index 9081ef06e9a7434d5b4dfb899b5b8b80828aa89f..2c2c731bc37e8f1d3453b2cf7662b833e2cca495 100644 --- a/sflphone-gtk/src/configwindow.c +++ b/sflphone-gtk/src/configwindow.c @@ -314,7 +314,7 @@ set_pulse_app_volume_control( void ) dbus_set_pulse_app_volume_control(); } -static void update_port( GtkSpinButton *button, void *ptr ) +static void update_port( GtkSpinButton *button UNUSED, void *ptr ) { dbus_set_sip_port(gtk_spin_button_get_value_as_int((GtkSpinButton *)(ptr))); } @@ -439,6 +439,10 @@ create_accounts_tab() GtkWidget* create_general_settings () { + + int curPort; + int n; + GtkWidget *ret; GtkWidget *notifFrame; @@ -542,14 +546,18 @@ create_general_settings () gtk_box_pack_start( GTK_BOX(vbox) , widg , TRUE , TRUE , 1); g_signal_connect(G_OBJECT( widg ) , "clicked" , G_CALLBACK( set_pulse_app_volume_control ) , NULL); + n = account_list_get_sip_account_number(); + printf("sip account number = %i\n", n); + /** SIP port information */ - int curPort = dbus_get_sip_port(); + curPort = dbus_get_sip_port(); if(curPort <= 0 || curPort > 65535) curPort = 5060; - + frame = gtk_frame_new( _("SIP Port")); gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0); gtk_widget_show( frame ); + gtk_widget_set_sensitive( GTK_WIDGET(frame), (n==0)?FALSE:TRUE ); hbox = gtk_hbox_new(FALSE, 10); gtk_widget_show( hbox ); @@ -557,6 +565,7 @@ create_general_settings () GtkWidget *applyButton = gtk_button_new_with_label(_("Apply")); gtk_widget_set_size_request(applyButton, 60, 35); + //gtk_widget_set_sensitive( GTK_WIDGET(applyButton), (n==0)?FALSE:TRUE ); label = gtk_label_new(_("Port:")); diff --git a/src/audio/alsalayer.cpp b/src/audio/alsalayer.cpp index e1ba97a377118d7bcb8b8b0b6bb4a9a05c07b3e7..72673ec566442a3cd146b7d19423019e90a8cffa 100644 --- a/src/audio/alsalayer.cpp +++ b/src/audio/alsalayer.cpp @@ -296,8 +296,8 @@ AlsaLayer::open_device(std::string pcm_p, std::string pcm_c, int flag) snd_pcm_uframes_t period_size_out = getFrameSize() * getSampleRate() / 1000 * 2;//1024 ; snd_pcm_uframes_t buffer_size_out = period_size_out * 4 ; - unsigned int buffer_time = 80000; //80ms - unsigned int period_time = buffer_time / 4 ; //20ms + unsigned int buffer_time = 100000; //100ms + unsigned int period_time = buffer_time / 4 ; //25ms if(flag == SFL_PCM_BOTH || flag == SFL_PCM_CAPTURE) { diff --git a/src/audio/audiostream.cpp b/src/audio/audiostream.cpp index 520443d15741cb267021788087fc17d9f2e99305..1f7df13ba887c2c66f334f3cd1039567850680a1 100644 --- a/src/audio/audiostream.cpp +++ b/src/audio/audiostream.cpp @@ -21,14 +21,14 @@ static pa_channel_map channel_map ; -AudioStream::AudioStream( pa_context* context, int type, std::string desc, double vol ) +AudioStream::AudioStream( pa_context* context, int type, std::string desc, double vol UNUSED ) : _audiostream(NULL), _streamType(type), _streamDescription(desc), flag(PA_STREAM_AUTO_TIMING_UPDATE), sample_spec(), _volume() { sample_spec.format = PA_SAMPLE_S16LE; sample_spec.rate = 44100; sample_spec.channels = 1; channel_map.channels = 1; - pa_cvolume_set( &_volume , 1 , PA_VOLUME_MUTED ) ; // * vol / 100 ; + pa_cvolume_set( &_volume , 1 , PA_VOLUME_NORM ) ; // * vol / 100 ; _audiostream = createStream( context ); } @@ -49,7 +49,7 @@ AudioStream::disconnect( void ) } void -AudioStream::stream_state_callback( pa_stream* s, void* user_data ) +AudioStream::stream_state_callback( pa_stream* s, void* user_data UNUSED ) { _debug("The state of the stream changed\n"); assert(s); diff --git a/src/iaxcall.cpp b/src/iaxcall.cpp index 04c5928152a01f2fd7315283169502299bd98cf1..05327d77d6a15719bf26ce6b394a08ba33a992a1 100644 --- a/src/iaxcall.cpp +++ b/src/iaxcall.cpp @@ -55,9 +55,11 @@ IAXCall::setFormat(int format) int IAXCall::getSupportedFormat() { - CodecOrder map = getCodecMap().getActiveCodecs(); - int format = 0; - int iter; + CodecOrder map; + int format = 0; + unsigned int iter; + + map = getCodecMap().getActiveCodecs(); for(iter=0 ; iter < map.size() ; iter++){ switch(map[iter]) { @@ -85,7 +87,7 @@ IAXCall::getFirstMatchingFormat(int needles) { CodecOrder map = getCodecMap().getActiveCodecs(); int format = 0; - int iter; + unsigned int iter; for(iter=0 ; iter < map.size() ; iter++) { switch(map[iter]) { diff --git a/src/iaxvoiplink.cpp b/src/iaxvoiplink.cpp index 4da2f14b5c11c01ec4739b24576a95c94d0f9ef2..f8bf510607a42a1085f57e2c6addc8b2014a85a5 100644 --- a/src/iaxvoiplink.cpp +++ b/src/iaxvoiplink.cpp @@ -216,16 +216,18 @@ IAXVoIPLink::getEvent() void IAXVoIPLink::sendAudioFromMic(void) { - IAXCall* currentCall = getIAXCall(Manager::instance().getCurrentCallId()); - - if (!currentCall) { - // Let's mind our own business. - return; - } - - if( currentCall -> getAudioCodec() < 0 ) - return; + int maxBytesToGet, availBytesFromMic, bytesAvail, nbSample, compSize; + AudioCodec *ac; + + IAXCall* currentCall = getIAXCall(Manager::instance().getCurrentCallId()); + + if (!currentCall) { + // Let's mind our own business. + return; + } + if( currentCall -> getAudioCodec() < 0 ) + return; // Just make sure the currentCall is in state to receive audio right now. //_debug("Here we get: connectionState: %d state: %d \n", @@ -237,7 +239,7 @@ IAXVoIPLink::sendAudioFromMic(void) return; } - AudioCodec* ac = currentCall -> getCodecMap().getCodec( currentCall -> getAudioCodec() ); + ac = currentCall -> getCodecMap().getCodec( currentCall -> getAudioCodec() ); if (!ac) { // Audio codec still not determined. if (audiolayer) { @@ -252,10 +254,15 @@ IAXVoIPLink::sendAudioFromMic(void) // we have to get 20ms of data from the mic *20/1000 = /50 // rate/50 shall be lower than IAX__20S_48KHZ_MAX - int maxBytesToGet = audiolayer->getSampleRate()* audiolayer->getFrameSize() / 1000 * sizeof(SFLDataFormat); + maxBytesToGet = audiolayer->getSampleRate()* audiolayer->getFrameSize() / 1000 * sizeof(SFLDataFormat); + + // We have to update the audio layer type in case we switched + // TODO Find out a better way to do it + updateAudiolayer(); // available bytes inside ringbuffer - int availBytesFromMic = audiolayer->canGetMic(); + availBytesFromMic = audiolayer->canGetMic(); + if (availBytesFromMic < maxBytesToGet) { // We need packets full! @@ -263,17 +270,17 @@ IAXVoIPLink::sendAudioFromMic(void) } // take the lowest - int bytesAvail = (availBytesFromMic < maxBytesToGet) ? availBytesFromMic : maxBytesToGet; + bytesAvail = (availBytesFromMic < maxBytesToGet) ? availBytesFromMic : maxBytesToGet; //_debug("available = %d, maxBytesToGet = %d\n", availBytesFromMic, maxBytesToGet); // Get bytes from micRingBuffer to data_from_mic - int nbSample = audiolayer->getMic( micData, bytesAvail ) / sizeof(SFLDataFormat); + nbSample = audiolayer->getMic( micData, bytesAvail ) / sizeof(SFLDataFormat); // resample nbSample = converter->downsampleData( micData , micDataConverted , (int)ac ->getClockRate() , (int)audiolayer->getSampleRate() , nbSample ); // for the mono: range = 0 to IAX_FRAME2SEND * sizeof(int16) - int compSize = ac->codecEncode( micDataEncoded, micDataConverted , nbSample*sizeof(int16)); + compSize = ac->codecEncode( micDataEncoded, micDataConverted , nbSample*sizeof(int16)); // Send it out! _mutexIAX.enterMutex(); @@ -482,6 +489,8 @@ IAXVoIPLink::transfer(const CallID& id, const std::string& to) iax_transfer(call->getSession(), callto); _mutexIAX.leaveMutex(); + return true; + // should we remove it? // removeCall(id); } @@ -498,6 +507,8 @@ IAXVoIPLink::refuse(const CallID& id) iax_reject(call->getSession(), (char*) reason.c_str()); _mutexIAX.leaveMutex(); removeCall(id); + + return true; } bool @@ -510,6 +521,8 @@ IAXVoIPLink::carryingDTMFdigits(const CallID& id, char code) _mutexIAX.enterMutex(); iax_send_dtmf(call->getSession(), code); _mutexIAX.leaveMutex(); + + return true; } @@ -575,7 +588,6 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call) // note activity? // CallID id = call->getCallId(); - int16* output = 0; // for audio output switch(event->etype) { case IAX_EVENT_HANGUP: @@ -675,6 +687,13 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call) void IAXVoIPLink::iaxHandleVoiceEvent(iax_event* event, IAXCall* call) { + + + unsigned char *data; + unsigned int size, max, nbInt16; + int expandedSize, nbSample; + AudioCodec *ac; + // If we receive datalen == 0, some things of the jitter buffer in libiax2/iax.c // were triggered if (!event->datalen) { @@ -691,28 +710,28 @@ IAXVoIPLink::iaxHandleVoiceEvent(iax_event* event, IAXCall* call) call->setFormat(event->subclass); } //_debug("Receive: len=%d, format=%d, _receiveDataDecoded=%p\n", event->datalen, call->getFormat(), _receiveDataDecoded); - AudioCodec* ac = call->getCodecMap().getCodec( call -> getAudioCodec() ); + ac = call->getCodecMap().getCodec( call -> getAudioCodec() ); - unsigned char* data = (unsigned char*)event->data; - unsigned int size = event->datalen; + data = (unsigned char*)event->data; + size = event->datalen; // Decode data with relevant codec - int max = (int)( ac->getClockRate() * audiolayer->getFrameSize() / 1000 ); + max = (int)( ac->getClockRate() * audiolayer->getFrameSize() / 1000 ); if (size > max) { _debug("The size %d is bigger than expected %d. Packet cropped. Ouch!\n", size, max); size = max; } - int expandedSize = ac->codecDecode( spkrDataDecoded , data , size ); - int nbInt16 = expandedSize/sizeof(int16); + expandedSize = ac->codecDecode( spkrDataDecoded , data , size ); + nbInt16 = expandedSize/sizeof(int16); if (nbInt16 > max) { - _debug("We have decoded an IAX VOICE packet larger than expected: %s VS %s. Cropping.\n", nbInt16, max); + _debug("We have decoded an IAX VOICE packet larger than expected: %i VS %i. Cropping.\n", nbInt16, max); nbInt16 = max; } - int nbSample = nbInt16; + nbSample = nbInt16; // resample nbInt16 = converter->upsampleData( spkrDataDecoded , spkrDataConverted , ac->getClockRate() , audiolayer->getSampleRate() , nbSample); @@ -730,26 +749,40 @@ IAXVoIPLink::iaxHandleVoiceEvent(iax_event* event, IAXCall* call) void IAXVoIPLink::iaxHandleRegReply(iax_event* event) { - if (event->etype == IAX_EVENT_REGREJ) { - /* Authentication failed! */ - _mutexIAX.enterMutex(); - iax_destroy(_regSession); - _mutexIAX.leaveMutex(); - _regSession = NULL; - setRegistrationState(ErrorAuth); - } - else if (event->etype == IAX_EVENT_REGACK) { - /* Authentication succeeded */ - _mutexIAX.enterMutex(); - iax_destroy(_regSession); - _mutexIAX.leaveMutex(); - _regSession = NULL; - // I mean, save the timestamp, so that we re-register again in the REFRESH time. - // Defaults to 60, as per draft-guy-iax-03. - _nextRefreshStamp = time(NULL) + (event->ies.refresh ? event->ies.refresh : 60); - setRegistrationState(Registered); - } + int voicemail; + std::string account_id; + + if (event->etype == IAX_EVENT_REGREJ) { + /* Authentication failed! */ + _mutexIAX.enterMutex(); + iax_destroy(_regSession); + _mutexIAX.leaveMutex(); + _regSession = NULL; + setRegistrationState(ErrorAuth); + } + + else if (event->etype == IAX_EVENT_REGACK) { + /* Authentication succeeded */ + _mutexIAX.enterMutex(); + + // Looking for the voicemail information + //if( event->ies != 0 ) + voicemail = event->ies.msgcount; + _debug("iax voicemail number notification: %i\n", voicemail); + // Notify the client if new voicemail waiting for the current account + account_id = getAccountID(); + Manager::instance().startVoiceMessageNotification(account_id.c_str(), voicemail); + + iax_destroy(_regSession); + _mutexIAX.leaveMutex(); + _regSession = NULL; + + // I mean, save the timestamp, so that we re-register again in the REFRESH time. + // Defaults to 60, as per draft-guy-iax-03. + _nextRefreshStamp = time(NULL) + (event->ies.refresh ? event->ies.refresh : 60); + setRegistrationState(Registered); + } } void @@ -858,3 +891,8 @@ IAXVoIPLink::iaxCodecMapToFormat(IAXCall* call) } +void IAXVoIPLink::updateAudiolayer( void ) +{ + audiolayer = NULL; + audiolayer = Manager::instance().getAudioDriver(); +} diff --git a/src/iaxvoiplink.h b/src/iaxvoiplink.h index 9f1525afe28cffdb6c22a1947b7e81652d5e48f8..569ac88298964b0462cb4e4ef5945b3dd72cffdb 100644 --- a/src/iaxvoiplink.h +++ b/src/iaxvoiplink.h @@ -124,7 +124,7 @@ class IAXVoIPLink : public VoIPLink * @return bool true on success * false otherwise */ - bool cancel(const CallID& id) { return false; } + bool cancel(const CallID& id UNUSED ) { return false; } /** * Put a call on hold @@ -168,7 +168,7 @@ class IAXVoIPLink : public VoIPLink */ bool carryingDTMFdigits(const CallID& id, char code); - bool sendMessage(const std::string& to, const std::string& body) { return false; } + bool sendMessage(const std::string& to UNUSED, const std::string& body UNUSED) { return false; } bool isContactPresenceSupported() { return false; } @@ -188,6 +188,8 @@ class IAXVoIPLink : public VoIPLink */ void setPass(const std::string& pass) { _pass = pass; } + void updateAudiolayer( void ); + private: /** * Get IAX Call from an id diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index c6107423007acc01fb6d76646421f9e8ab80b9e2..82f6bae0a4698d1db62a9488c7f8030bfbc7a7ac 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -1032,7 +1032,7 @@ ManagerImpl::createSettingsPath (void) { * Initialization: Main Thread */ void -ManagerImpl::initConfigFile (void) +ManagerImpl::initConfigFile ( bool load_user_value ) { std::string mes = gettext("Init config file\n"); _debug("%s",mes.c_str()); @@ -1079,7 +1079,7 @@ ManagerImpl::initConfigFile (void) fill_config_int(CONFIG_SIP_PORT, DFT_SIP_PORT); // Loads config from ~/.sflphone/sflphonedrc or so.. - if (createSettingsPath() == 1) { + if (createSettingsPath() == 1 && load_user_value) { _exist = _config.populateFromFile(_path); } @@ -1161,6 +1161,7 @@ ManagerImpl::getActiveCodecList( void ) std::stringstream ss; ss << active[i]; v.push_back((ss.str()).data()); + _debug("%s\n", ss.str().data()); i++; } return v; @@ -1576,8 +1577,11 @@ ManagerImpl::getCurrentAudioOutputPlugin( void ) void ManagerImpl::initAudioDriver(void) { - _debugInit("AudioLayer Creation"); + int error; + + _debugInit("AudioLayer Creation"); + if( getConfigInt( PREFERENCES , CONFIG_AUDIO ) == ALSA ) _audiodriver = new AlsaLayer( this ); else if( getConfigInt( PREFERENCES , CONFIG_AUDIO ) == PULSEAUDIO ) @@ -1588,7 +1592,7 @@ ManagerImpl::initAudioDriver(void) if (_audiodriver == 0) { _debug("Init audio driver error\n"); } else { - int error = getAudioDriver()->getErrorMessage(); + error = getAudioDriver()->getErrorMessage(); if (error == -1) { _debug("Init audio driver: %i\n", error); } @@ -2401,7 +2405,13 @@ UserAgent *ManagerImpl::getUserAgent() int ManagerImpl::getSipPort() { - return _userAgent->getSipPort(); + if( _userAgent ) + return _userAgent->getSipPort(); + else + { + // It means that no SIP accounts are configured, so return a default value + return 0; + } } void diff --git a/src/managerimpl.h b/src/managerimpl.h index bb16b7134ba0f72d5436f7efad8b375614a64e95..b97edb59d6de79e94137ccbc14f1658584427a95 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -784,7 +784,7 @@ class ManagerImpl { * Fills the local _config (Conf::ConfigTree) with the default contents. * Called in main.cpp, just before Manager::init(). */ - void initConfigFile (void); + void initConfigFile ( bool load_user_value = true ); /** * Tell if the setup was already loaded @@ -1058,6 +1058,8 @@ private: bool testAccountMap(); #endif + friend class ConfigurationTest; + public: /** * Retuun the instance of sip manager diff --git a/test/Makefile.am b/test/Makefile.am index aab435ef9c922e4e59e616d90cdf30b3d953b404..14411aa140bbc3264308b27f0cd418287544821c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -20,6 +20,7 @@ OBJECT_FILES= \ configurationTester_SOURCES = \ configurationTest.cpp \ + configurationTest.h \ TestMain.cpp configurationTester_LDADD = \ diff --git a/test/configurationTest.cpp b/test/configurationTest.cpp index 02225a54aaf540b9673c7e72f82205af493433b4..8208c9944fa6699baa92d5aabf63ff621af995c5 100644 --- a/test/configurationTest.cpp +++ b/test/configurationTest.cpp @@ -1,38 +1,137 @@ -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCaller.h> -#include <cppunit/TestCase.h> -#include <cppunit/TestSuite.h> -#include <assert.h> +/* + * 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 "manager.h" -#include "global.h" +#include <stdio.h> +#include <sstream> -// Cppunit import +#include "configurationTest.h" -class ConfigurationTest : public CppUnit::TestCase { +using std::cout; +using std::endl; - CPPUNIT_TEST_SUITE( ConfigurationTest ); - CPPUNIT_TEST( testDefaultValueAudio ); - CPPUNIT_TEST( testTheTest ); - CPPUNIT_TEST_SUITE_END(); +void ConfigurationTest::setUp(){ + // Load the default configuration + Manager::instance().initConfigFile(); +} - public: - ConfigurationTest() : CppUnit::TestCase("Configuration Tests") {} - - void testDefaultValueAudio(){ - CPPUNIT_ASSERT( Manager::instance().getConfigString( AUDIO, ALSA_PLUGIN ) == "default" ); - } +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 testTheTest(){ - CPPUNIT_ASSERT( 3 == 2 ); - } +void ConfigurationTest::testDefaultValuePreferences(){ + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, ZONE_TONE ) == DFT_ZONE ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_ZEROCONF ) == CONFIG_ZEROCONF_DEFAULT_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_DIALPAD ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_RINGTONE ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_SEARCHBAR ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_START ) == NO_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_POPUP ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_NOTIFY ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_MAIL_NOTIFY ) == NO_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_VOLUME ) == YES_STR ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, REGISTRATION_EXPIRE ) == DFT_EXPIRE_VALUE ); + CPPUNIT_ASSERT( Manager::instance().getConfigString( PREFERENCES, CONFIG_AUDIO ) == DFT_AUDIO_MANAGER ); - void setUp(){ - } +} - void tearDown(){ - } +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(){ -CPPUNIT_TEST_SUITE_REGISTRATION( ConfigurationTest ); + 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/test/configurationTest.h b/test/configurationTest.h new file mode 100644 index 0000000000000000000000000000000000000000..87828521eed303cbe2b195684f0ffbe45048db74 --- /dev/null +++ b/test/configurationTest.h @@ -0,0 +1,108 @@ +/* + * 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