1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/*
* Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 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.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#include "configurationtest.h"
#include "manager.h"
#include "config/yamlemitter.h"
#include "config/yamlparser.h"
#include "account.h"
#include "logger.h"
#include "audio/alsa/alsalayer.h"
#include "audio/pulseaudio/pulselayer.h"
#include "sip/sipaccount.h"
#include "test_utils.h"
void ConfigurationTest::testDefaultValueAudio()
{
TITLE();
CPPUNIT_ASSERT(Manager::instance().audioPreference.getCardin() == ALSA_DFT_CARD_ID);
CPPUNIT_ASSERT(Manager::instance().audioPreference.getCardout() == ALSA_DFT_CARD_ID);
CPPUNIT_ASSERT(Manager::instance().audioPreference.getSmplrate() == 44100);
CPPUNIT_ASSERT(Manager::instance().audioPreference.getPlugin() == PCM_DEFAULT);
CPPUNIT_ASSERT(Manager::instance().audioPreference.getVolumespkr() == 100);
CPPUNIT_ASSERT(Manager::instance().audioPreference.getVolumemic() == 100);
}
void ConfigurationTest::testDefaultValuePreferences()
{
TITLE();
CPPUNIT_ASSERT(Manager::instance().preferences.getZoneToneChoice() == Preferences::DFT_ZONE);
}
void ConfigurationTest::testDefaultValueSignalisation()
{
TITLE();
CPPUNIT_ASSERT(Manager::instance().voipPreferences.getSymmetricRtp());
CPPUNIT_ASSERT(Manager::instance().voipPreferences.getPlayDtmf());
CPPUNIT_ASSERT(Manager::instance().voipPreferences.getPlayTones());
CPPUNIT_ASSERT(Manager::instance().voipPreferences.getPulseLength() == 250);
}
void ConfigurationTest::testInitAudioDriver()
{
TITLE();
// 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().audioPreference.getAudioApi() == "alsa")
CPPUNIT_ASSERT(!dynamic_cast<PulseLayer*>(Manager::instance().getAudioDriver()));
else if (Manager::instance().audioPreference.getAudioApi() == "pulseaudio")
CPPUNIT_ASSERT(!dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver()));
else
CPPUNIT_FAIL("Wrong audio layer type");
}
void ConfigurationTest::testYamlParser()
{
try {
Conf::YamlParser parser("ymlParser.yml");
parser.serializeEvents();
parser.composeEvents();
parser.constructNativeData();
} catch (const Conf::YamlParserException &e) {
ERROR("ConfigTree: %s", e.what());
}
}
void ConfigurationTest::testYamlEmitter()
{
using namespace Conf;
MappingNode accountmap(NULL);
MappingNode credentialmap(NULL);
MappingNode srtpmap(NULL);
MappingNode zrtpmap(NULL);
MappingNode tlsmap(NULL);
ScalarNode id("Account:1278432417");
ScalarNode username("181");
ScalarNode password("pass181");
ScalarNode alias("sfl-181");
ScalarNode hostname("192.168.50.3");
ScalarNode enable(true);
ScalarNode type("SIP");
ScalarNode expire("3600");
ScalarNode interface("default");
ScalarNode port("5060");
ScalarNode mailbox("97");
ScalarNode publishAddr("192.168.50.182");
ScalarNode publishPort("5060");
ScalarNode sameasLocal(true);
ScalarNode codecs("0/9/110/111/112/");
ScalarNode stunServer("stun.sflphone.org");
ScalarNode stunEnabled(false);
ScalarNode displayName("Alexandre Savard");
ScalarNode dtmfType("sipinfo");
ScalarNode count("0");
ScalarNode srtpenabled(false);
ScalarNode keyExchange("sdes");
ScalarNode rtpFallback(false);
ScalarNode displaySas(false);
ScalarNode displaySasOnce(false);
ScalarNode helloHashEnabled(false);
ScalarNode notSuppWarning(false);
ScalarNode tlsport("");
ScalarNode certificate("");
ScalarNode calist("");
ScalarNode ciphers("");
ScalarNode tlsenabled(false);
ScalarNode tlsmethod("TLSV1");
ScalarNode timeout("0");
ScalarNode tlspassword("");
ScalarNode privatekey("");
ScalarNode requirecertif(true);
ScalarNode server("");
ScalarNode verifyclient(true);
ScalarNode verifyserver(true);
accountmap.setKeyValue(ALIAS_KEY, &alias);
accountmap.setKeyValue(TYPE_KEY, &type);
accountmap.setKeyValue(ID_KEY, &id);
accountmap.setKeyValue(USERNAME_KEY, &username);
accountmap.setKeyValue(PASSWORD_KEY, &password);
accountmap.setKeyValue(HOSTNAME_KEY, &hostname);
accountmap.setKeyValue(ACCOUNT_ENABLE_KEY, &enable);
accountmap.setKeyValue(MAILBOX_KEY, &mailbox);
accountmap.setKeyValue(Preferences::REGISTRATION_EXPIRE_KEY, &expire);
accountmap.setKeyValue(INTERFACE_KEY, &interface);
accountmap.setKeyValue(PORT_KEY, &port);
accountmap.setKeyValue(PUBLISH_ADDR_KEY, &publishAddr);
accountmap.setKeyValue(PUBLISH_PORT_KEY, &publishPort);
accountmap.setKeyValue(SAME_AS_LOCAL_KEY, &sameasLocal);
accountmap.setKeyValue(DTMF_TYPE_KEY, &dtmfType);
accountmap.setKeyValue(DISPLAY_NAME_KEY, &displayName);
accountmap.setKeyValue(SRTP_KEY, &srtpmap);
srtpmap.setKeyValue(SRTP_ENABLE_KEY, &srtpenabled);
srtpmap.setKeyValue(KEY_EXCHANGE_KEY, &keyExchange);
srtpmap.setKeyValue(RTP_FALLBACK_KEY, &rtpFallback);
accountmap.setKeyValue(ZRTP_KEY, &zrtpmap);
zrtpmap.setKeyValue(DISPLAY_SAS_KEY, &displaySas);
zrtpmap.setKeyValue(DISPLAY_SAS_ONCE_KEY, &displaySasOnce);
zrtpmap.setKeyValue(HELLO_HASH_ENABLED_KEY, &helloHashEnabled);
zrtpmap.setKeyValue(NOT_SUPP_WARNING_KEY, ¬SuppWarning);
accountmap.setKeyValue(CRED_KEY, &credentialmap);
SequenceNode credentialseq(NULL);
accountmap.setKeyValue(CRED_KEY, &credentialseq);
MappingNode credmap1(NULL);
MappingNode credmap2(NULL);
ScalarNode user1("user");
ScalarNode pass1("pass");
ScalarNode realm1("*");
ScalarNode user2("john");
ScalarNode pass2("doe");
ScalarNode realm2("fbi");
credmap1.setKeyValue(CONFIG_ACCOUNT_USERNAME, &user1);
credmap1.setKeyValue(CONFIG_ACCOUNT_PASSWORD, &pass1);
credmap1.setKeyValue(CONFIG_ACCOUNT_REALM, &realm1);
credmap2.setKeyValue(CONFIG_ACCOUNT_USERNAME, &user2);
credmap2.setKeyValue(CONFIG_ACCOUNT_PASSWORD, &pass2);
credmap2.setKeyValue(CONFIG_ACCOUNT_REALM, &realm2);
credentialseq.addNode(&credmap1);
credentialseq.addNode(&credmap2);
accountmap.setKeyValue(TLS_KEY, &tlsmap);
tlsmap.setKeyValue(TLS_PORT_KEY, &tlsport);
tlsmap.setKeyValue(CERTIFICATE_KEY, &certificate);
tlsmap.setKeyValue(CALIST_KEY, &calist);
tlsmap.setKeyValue(CIPHERS_KEY, &ciphers);
tlsmap.setKeyValue(TLS_ENABLE_KEY, &tlsenabled);
tlsmap.setKeyValue(METHOD_KEY, &tlsmethod);
tlsmap.setKeyValue(TIMEOUT_KEY, &timeout);
tlsmap.setKeyValue(TLS_PASSWORD_KEY, &tlspassword);
tlsmap.setKeyValue(PRIVATE_KEY_KEY, &privatekey);
tlsmap.setKeyValue(REQUIRE_CERTIF_KEY, &requirecertif);
tlsmap.setKeyValue(SERVER_KEY, &server);
tlsmap.setKeyValue(VERIFY_CLIENT_KEY, &verifyclient);
tlsmap.setKeyValue(VERIFY_SERVER_KEY, &verifyserver);
try {
YamlEmitter emitter("/tmp/ymlEmiter.txt");
emitter.serializeAccount(&accountmap);
emitter.serializeAccount(&accountmap);
emitter.serializeData();
} catch (const YamlEmitterException &e) {
ERROR("ConfigTree: %s", e.what());
}
}
|