~ubuntu-branches/ubuntu/precise/sflphone/precise

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
231
232
233
234
235
236
/*
 *  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 <stdio.h>
#include <sstream>

#include "configurationtest.h"
#include "constants.h"
#include "audio/alsa/alsalayer.h"
#include "audio/pulseaudio/pulselayer.h"

using std::cout;
using std::endl;

void ConfigurationTest::testDefaultValueAudio()
{
    DEBUG("-------------------- ConfigurationTest::testDefaultValueAudio() --------------------\n");

    CPPUNIT_ASSERT(Manager::instance().audioPreference.getCardin() == 0);  // ALSA_DFT_CARD);
    CPPUNIT_ASSERT(Manager::instance().audioPreference.getCardout() == 0);  // ALSA_DFT_CARD);
    CPPUNIT_ASSERT(Manager::instance().audioPreference.getSmplrate() == 44100);  // DFT_SAMPLE_RATE);
    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()
{
    DEBUG("-------------------- ConfigurationTest::testDefaultValuePreferences --------------------\n");

    CPPUNIT_ASSERT(Manager::instance().preferences.getZoneToneChoice() == Preferences::DFT_ZONE);
}

void ConfigurationTest::testDefaultValueSignalisation()
{
    DEBUG("-------------------- ConfigurationTest::testDefaultValueSignalisation --------------------\n");

    CPPUNIT_ASSERT(Manager::instance().voipPreferences.getSymmetricRtp() == true);
    CPPUNIT_ASSERT(Manager::instance().voipPreferences.getPlayDtmf() == true);
    CPPUNIT_ASSERT(Manager::instance().voipPreferences.getPlayTones() == true);
    CPPUNIT_ASSERT(Manager::instance().voipPreferences.getPulseLength() == 250);
}

void ConfigurationTest::testInitAudioDriver()
{
    DEBUG("-------------------- ConfigurationTest::testInitAudioDriver --------------------\n");

    // Load the audio driver
    Manager::instance().initAudioDriver();

    // Check the creation

    if (Manager::instance().getAudioDriver() == NULL)
        CPPUNIT_FAIL("Error while loading audio layer");

    // Check if it has been created with the right type
    if (Manager::instance().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 = new Conf::YamlParser("ymlParser.yml");
        parser->serializeEvents();
        parser->composeEvents();
        parser->constructNativeData();

        delete parser;
    } catch (Conf::YamlParserException &e) {
       ERROR("ConfigTree: %s", e.what());
    }
}

void ConfigurationTest::testYamlEmitter()
{
    Conf::MappingNode accountmap(NULL);
    Conf::MappingNode credentialmap(NULL);
    Conf::MappingNode srtpmap(NULL);
    Conf::MappingNode zrtpmap(NULL);
    Conf::MappingNode tlsmap(NULL);


    Conf::ScalarNode id("Account:1278432417");
    Conf::ScalarNode username("181");
    Conf::ScalarNode password("pass181");
    Conf::ScalarNode alias("sfl-181");
    Conf::ScalarNode hostname("192.168.50.3");
    Conf::ScalarNode enable(true);
    Conf::ScalarNode type("SIP");
    Conf::ScalarNode expire("3600");
    Conf::ScalarNode interface("default");
    Conf::ScalarNode port("5060");
    Conf::ScalarNode mailbox("97");
    Conf::ScalarNode publishAddr("192.168.50.182");
    Conf::ScalarNode publishPort("5060");
    Conf::ScalarNode sameasLocal(true);
    Conf::ScalarNode codecs("0/9/110/111/112/");
    Conf::ScalarNode stunServer("stun.sflphone.org");
    Conf::ScalarNode stunEnabled(false);
    Conf::ScalarNode displayName("Alexandre Savard");
    Conf::ScalarNode dtmfType("sipinfo");

    Conf::ScalarNode count("0");

    Conf::ScalarNode srtpenabled(false);
    Conf::ScalarNode keyExchange("sdes");
    Conf::ScalarNode rtpFallback(false);

    Conf::ScalarNode displaySas(false);
    Conf::ScalarNode displaySasOnce(false);
    Conf::ScalarNode helloHashEnabled(false);
    Conf::ScalarNode notSuppWarning(false);

    Conf::ScalarNode tlsport("");
    Conf::ScalarNode certificate("");
    Conf::ScalarNode calist("");
    Conf::ScalarNode ciphers("");
    Conf::ScalarNode tlsenabled(false);
    Conf::ScalarNode tlsmethod("TLSV1");
    Conf::ScalarNode timeout("0");
    Conf::ScalarNode tlspassword("");
    Conf::ScalarNode privatekey("");
    Conf::ScalarNode requirecertif(true);
    Conf::ScalarNode server("");
    Conf::ScalarNode verifyclient(true);
    Conf::ScalarNode verifyserver(true);

    accountmap.setKeyValue(aliasKey, &alias);
    accountmap.setKeyValue(typeKey, &type);
    accountmap.setKeyValue(idKey, &id);
    accountmap.setKeyValue(usernameKey, &username);
    accountmap.setKeyValue(passwordKey, &password);
    accountmap.setKeyValue(hostnameKey, &hostname);
    accountmap.setKeyValue(accountEnableKey, &enable);
    accountmap.setKeyValue(mailboxKey, &mailbox);
    accountmap.setKeyValue(expireKey, &expire);
    accountmap.setKeyValue(interfaceKey, &interface);
    accountmap.setKeyValue(portKey, &port);
    accountmap.setKeyValue(publishAddrKey, &publishAddr);
    accountmap.setKeyValue(publishPortKey, &publishPort);
    accountmap.setKeyValue(sameasLocalKey, &sameasLocal);
    accountmap.setKeyValue(dtmfTypeKey, &dtmfType);
    accountmap.setKeyValue(displayNameKey, &displayName);

    accountmap.setKeyValue(srtpKey, &srtpmap);
    srtpmap.setKeyValue(srtpEnableKey, &srtpenabled);
    srtpmap.setKeyValue(keyExchangeKey, &keyExchange);
    srtpmap.setKeyValue(rtpFallbackKey, &rtpFallback);

    accountmap.setKeyValue(zrtpKey, &zrtpmap);
    zrtpmap.setKeyValue(displaySasKey, &displaySas);
    zrtpmap.setKeyValue(displaySasOnceKey, &displaySasOnce);
    zrtpmap.setKeyValue(helloHashEnabledKey, &helloHashEnabled);
    zrtpmap.setKeyValue(notSuppWarningKey, &notSuppWarning);

    accountmap.setKeyValue(credKey, &credentialmap);
    Conf::SequenceNode credentialseq(NULL);
    accountmap.setKeyValue(credKey, &credentialseq);

    Conf::MappingNode credmap1(NULL);
    Conf::MappingNode credmap2(NULL);
    Conf::ScalarNode user1("user");
    Conf::ScalarNode pass1("pass");
    Conf::ScalarNode realm1("*");
    Conf::ScalarNode user2("john");
    Conf::ScalarNode pass2("doe");
    Conf::ScalarNode realm2("fbi");
    credmap1.setKeyValue(USERNAME, &user1);
    credmap1.setKeyValue(PASSWORD, &pass1);
    credmap1.setKeyValue(REALM, &realm1);
    credmap2.setKeyValue(USERNAME, &user2);
    credmap2.setKeyValue(PASSWORD, &pass2);
    credmap2.setKeyValue(REALM, &realm2);
    credentialseq.addNode(&credmap1);
    credentialseq.addNode(&credmap2);

    accountmap.setKeyValue(tlsKey, &tlsmap);
    tlsmap.setKeyValue(tlsPortKey, &tlsport);
    tlsmap.setKeyValue(certificateKey, &certificate);
    tlsmap.setKeyValue(calistKey, &calist);
    tlsmap.setKeyValue(ciphersKey, &ciphers);
    tlsmap.setKeyValue(tlsEnableKey, &tlsenabled);
    tlsmap.setKeyValue(methodKey, &tlsmethod);
    tlsmap.setKeyValue(timeoutKey, &timeout);
    tlsmap.setKeyValue(tlsPasswordKey, &tlspassword);
    tlsmap.setKeyValue(privateKeyKey, &privatekey);
    tlsmap.setKeyValue(requireCertifKey, &requirecertif);
    tlsmap.setKeyValue(serverKey, &server);
    tlsmap.setKeyValue(verifyClientKey, &verifyclient);
    tlsmap.setKeyValue(verifyServerKey, &verifyserver);

    try {
        Conf::YamlEmitter *emitter = new Conf::YamlEmitter("/tmp/ymlEmiter.txt");

        emitter->serializeAccount(&accountmap);
        emitter->serializeAccount(&accountmap);
        emitter->serializeData();

        delete emitter;
    } catch (Conf::YamlEmitterException &e) {
       ERROR("ConfigTree: %s", e.what());
    }
}