setup_tester.c 9.98 KB
Newer Older
Ghislain MARY's avatar
Ghislain MARY committed
1
/*
2 3
	liblinphone_tester - liblinphone test suite
	Copyright (C) 2013  Belledonne Communications SARL
Ghislain MARY's avatar
Ghislain MARY committed
4

5 6 7 8
	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 2 of the License, or
	(at your option) any later version.
Ghislain MARY's avatar
Ghislain MARY committed
9

10 11 12 13
	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.
Ghislain MARY's avatar
Ghislain MARY committed
14

15 16
	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
Ghislain MARY's avatar
Ghislain MARY committed
17 18 19 20 21 22
*/

#include <stdio.h>
#include "CUnit/Basic.h"
#include "linphonecore.h"
#include "liblinphone_tester.h"
23
#include "lpconfig.h"
24
#include "private.h"
Ghislain MARY's avatar
Ghislain MARY committed
25

26 27 28 29 30 31
static void linphone_version_test(void){
	const char *version=linphone_core_get_version();
	/*make sure the git version is always included in the version number*/
	CU_ASSERT_TRUE(strstr(version,"unknown")==NULL);
}

Ghislain MARY's avatar
Ghislain MARY committed
32 33
static void core_init_test(void) {
	LinphoneCoreVTable v_table;
Sylvain Berfini's avatar
Sylvain Berfini committed
34
	LinphoneCore* lc;
Ghislain MARY's avatar
Ghislain MARY committed
35
	memset (&v_table,0,sizeof(v_table));
Sylvain Berfini's avatar
Sylvain Berfini committed
36
	lc = linphone_core_new(&v_table,NULL,NULL,NULL);
Simon Morlat's avatar
Simon Morlat committed
37 38
	/* until we have good certificates on our test server... */
	linphone_core_verify_server_certificates(lc,FALSE);
Ghislain MARY's avatar
Ghislain MARY committed
39 40 41 42 43 44 45 46
	CU_ASSERT_PTR_NOT_NULL_FATAL(lc);
	linphone_core_destroy(lc);
}

static void linphone_address_test(void) {
	linphone_address_destroy(create_linphone_address(NULL));
}

47 48 49 50 51 52 53 54 55
static void core_sip_transport_test(void) {
	LinphoneCoreVTable v_table;
	LinphoneCore* lc;
	LCSipTransports tr;
	memset (&v_table,0,sizeof(v_table));
	lc = linphone_core_new(&v_table,NULL,NULL,NULL);
	CU_ASSERT_PTR_NOT_NULL_FATAL(lc);
	linphone_core_get_sip_transports(lc,&tr);
	CU_ASSERT_EQUAL(tr.udp_port,5060); /*default config*/
Sylvain Berfini's avatar
Sylvain Berfini committed
56
	CU_ASSERT_EQUAL(tr.tcp_port,5060); /*default config*/
57 58 59 60 61 62 63 64 65

	tr.udp_port=LC_SIP_TRANSPORT_RANDOM;
	tr.tcp_port=LC_SIP_TRANSPORT_RANDOM;
	tr.tls_port=LC_SIP_TRANSPORT_RANDOM;

	linphone_core_set_sip_transports(lc,&tr);
	linphone_core_get_sip_transports(lc,&tr);

	CU_ASSERT_NOT_EQUAL(tr.udp_port,5060); /*default config*/
Sylvain Berfini's avatar
Sylvain Berfini committed
66
	CU_ASSERT_NOT_EQUAL(tr.tcp_port,5060); /*default config*/
67 68 69 70 71 72 73 74

	CU_ASSERT_EQUAL(lp_config_get_int(linphone_core_get_config(lc),"sip","sip_port",-2),LC_SIP_TRANSPORT_RANDOM);
	CU_ASSERT_EQUAL(lp_config_get_int(linphone_core_get_config(lc),"sip","sip_tcp_port",-2),LC_SIP_TRANSPORT_RANDOM);
	CU_ASSERT_EQUAL(lp_config_get_int(linphone_core_get_config(lc),"sip","sip_tls_port",-2),LC_SIP_TRANSPORT_RANDOM);

	linphone_core_destroy(lc);
}

75 76 77 78 79 80
static void linphone_interpret_url_test()
{
	LinphoneCoreVTable v_table;
	LinphoneCore* lc;
	const char* sips_address = "sips:margaux@sip.linphone.org";
	LinphoneAddress* address;
81

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
	memset ( &v_table,0,sizeof ( v_table ) );
	lc = linphone_core_new ( &v_table,NULL,NULL,NULL );
	CU_ASSERT_PTR_NOT_NULL_FATAL ( lc );

	address = linphone_core_interpret_url(lc, sips_address);

	CU_ASSERT_PTR_NOT_NULL_FATAL(address);
	CU_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_scheme(address), "sips");
	CU_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_username(address), "margaux");
	CU_ASSERT_STRING_EQUAL_FATAL(linphone_address_get_domain(address), "sip.linphone.org");

	linphone_address_destroy(address);

	linphone_core_destroy ( lc );
}

98 99 100 101 102 103 104 105 106 107 108 109 110
static void linphone_lpconfig_from_buffer(){

	static const char* buffer = "[buffer]\ntest=ok";
	static const char* buffer_linebreaks = "[buffer_linebreaks]\n\n\n\r\n\n\r\ntest=ok";
	LpConfig* conf;

	conf = lp_config_new_from_buffer(buffer);
	CU_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"buffer","test",""),"ok");
	lp_config_destroy(conf);

	conf = lp_config_new_from_buffer(buffer_linebreaks);
	CU_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"buffer_linebreaks","test",""),"ok");
	lp_config_destroy(conf);
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
}

static void linphone_lpconfig_from_buffer_zerolen_value(){
	/* parameters that have no value should return NULL, not "". */
	static const char* zerolen = "[test]\nzero_len=\nnon_zero_len=test";
	LpConfig* conf;

	conf = lp_config_new_from_buffer(zerolen);

	CU_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","zero_len","LOL"),"LOL");
	CU_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len",""),"test");

	lp_config_set_string(conf, "test", "non_zero_len", ""); /* should remove "non_zero_len" */
	CU_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len","LOL"), "LOL");

	lp_config_destroy(conf);
}

static void linphone_lpconfig_from_file_zerolen_value(){
	/* parameters that have no value should return NULL, not "". */
	static const char* zero_rc_file = "zero_length_params_rc";
	char* rc_path = ms_strdup_printf("%s/rcfiles/%s", liblinphone_tester_file_prefix, zero_rc_file);
	LpConfig* conf;

	conf = lp_config_new(rc_path);
136

137 138 139 140 141 142 143
	CU_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","zero_len","LOL"),"LOL");
	CU_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len",""),"test");

	lp_config_set_string(conf, "test", "non_zero_len", ""); /* should remove "non_zero_len" */
	CU_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len","LOL"), "LOL");

	lp_config_destroy(conf);
144
}
145

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
static void linphone_lpconfig_from_xml_zerolen_value(){
	static const char* zero_xml_file = "remote_zero_length_params_rc";
	char* xml_path = ms_strdup_printf("%s/rcfiles/%s", liblinphone_tester_file_prefix, zero_xml_file);
	LpConfig* conf;

	LinphoneCoreManager* mgr = linphone_core_manager_new2("empty_rc",FALSE);

	CU_ASSERT_EQUAL(linphone_remote_provisioning_load_file(mgr->lc, xml_path), 0);

	conf = mgr->lc->config;

	CU_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","zero_len","LOL"),"LOL");
	CU_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len",""),"test");

	lp_config_set_string(conf, "test", "non_zero_len", ""); /* should remove "non_zero_len" */
	CU_ASSERT_STRING_EQUAL(lp_config_get_string(conf,"test","non_zero_len","LOL"), "LOL");

	linphone_core_manager_destroy(mgr);

}

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
void linphone_proxy_config_address_equal_test() {
	LinphoneAddress *a = linphone_address_new("sip:toto@titi");
	LinphoneAddress *b = linphone_address_new("sips:toto@titi");
	LinphoneAddress *c = linphone_address_new("sip:toto@titi;transport=tcp");
	LinphoneAddress *d = linphone_address_new("sip:toto@titu");
	LinphoneAddress *e = linphone_address_new("sip:toto@titi;transport=udp");

	CU_ASSERT_FALSE(linphone_proxy_config_address_equal(a,NULL));
	CU_ASSERT_FALSE(linphone_proxy_config_address_equal(a,b));
	CU_ASSERT_FALSE(linphone_proxy_config_address_equal(a,c));
	CU_ASSERT_FALSE(linphone_proxy_config_address_equal(a,d));
	CU_ASSERT_TRUE(linphone_proxy_config_address_equal(a,e));
	CU_ASSERT_TRUE(linphone_proxy_config_address_equal(NULL,NULL));

	linphone_address_destroy(a);
	linphone_address_destroy(b);
	linphone_address_destroy(c);
	linphone_address_destroy(d);
}

void linphone_proxy_config_is_server_config_changed_test() {
	LinphoneProxyConfig* proxy_config = linphone_proxy_config_new();

190 191
	linphone_proxy_config_done(proxy_config); /*test done without edit*/

192 193 194 195 196 197 198 199 200 201
	linphone_proxy_config_set_identity(proxy_config,"sip:toto@titi");
	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_identity(proxy_config,"sips:toto@titi");
	CU_ASSERT_TRUE(linphone_proxy_config_is_server_config_changed(proxy_config));

	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_server_addr(proxy_config,"sip:toto.com");
	CU_ASSERT_TRUE(linphone_proxy_config_is_server_config_changed(proxy_config));

202
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
203
	linphone_proxy_config_edit(proxy_config);
204
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org:4444");
205
	CU_ASSERT_TRUE(linphone_proxy_config_is_server_config_changed(proxy_config));
206

207
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
208
	linphone_proxy_config_edit(proxy_config);
209
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org;transport=tcp");
210 211
	CU_ASSERT_TRUE(linphone_proxy_config_is_server_config_changed(proxy_config));

212
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org");
213
	linphone_proxy_config_edit(proxy_config);
214
	linphone_proxy_config_set_server_addr(proxy_config,"sip:sip.linphone.org;param=blue");
215 216 217 218 219 220 221 222 223 224 225 226 227
	CU_ASSERT_FALSE(linphone_proxy_config_is_server_config_changed(proxy_config));


	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_set_contact_parameters(proxy_config,"blabla=blue");
	CU_ASSERT_FALSE(linphone_proxy_config_is_server_config_changed(proxy_config));

	linphone_proxy_config_edit(proxy_config);
	linphone_proxy_config_enable_register(proxy_config,TRUE);
	CU_ASSERT_FALSE(linphone_proxy_config_is_server_config_changed(proxy_config));

	linphone_proxy_config_destroy(proxy_config);
}
Ghislain MARY's avatar
Ghislain MARY committed
228

jehan's avatar
jehan committed
229 230 231 232 233 234 235 236 237 238
static void chat_root_test(void) {
	LinphoneCoreVTable v_table;
	LinphoneCore* lc;
	memset (&v_table,0,sizeof(v_table));
	lc = linphone_core_new(&v_table,NULL,NULL,NULL);
	CU_ASSERT_PTR_NOT_NULL_FATAL(lc);
	linphone_core_create_chat_room(lc,"sip:toto@titi.com");
	linphone_core_destroy(lc);
}

Ghislain MARY's avatar
Ghislain MARY committed
239
test_t setup_tests[] = {
240
	{ "Version check", linphone_version_test },
Ghislain MARY's avatar
Ghislain MARY committed
241
	{ "Linphone Address", linphone_address_test },
242 243
	{ "Linphone proxy config address equal (internal api)", linphone_proxy_config_address_equal_test},
	{ "Linphone proxy config server address change (internal api)", linphone_proxy_config_is_server_config_changed_test},
Ghislain MARY's avatar
Ghislain MARY committed
244
	{ "Linphone core init/uninit", core_init_test },
245
	{ "Linphone random transport port",core_sip_transport_test},
246
	{ "Linphone interpret url", linphone_interpret_url_test },
jehan's avatar
jehan committed
247
	{ "LPConfig from buffer", linphone_lpconfig_from_buffer },
248 249
	{ "LPConfig zero_len value from buffer", linphone_lpconfig_from_buffer_zerolen_value },
	{ "LPConfig zero_len value from file", linphone_lpconfig_from_file_zerolen_value },
250
	{ "LPConfig zero_len value from XML", linphone_lpconfig_from_xml_zerolen_value },
jehan's avatar
jehan committed
251
	{ "Chat room", chat_root_test }
Ghislain MARY's avatar
Ghislain MARY committed
252 253 254 255 256 257 258 259 260 261
};

test_suite_t setup_test_suite = {
	"Setup",
	NULL,
	NULL,
	sizeof(setup_tests) / sizeof(setup_tests[0]),
	setup_tests
};