remote_provisioning_tester.c 7.01 KB
Newer Older
1
/*
2 3
	liblinphone_tester - liblinphone test suite
	Copyright (C) 2013  Belledonne Communications SARL
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.
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.
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/>.
17 18
*/

19

20
#include "linphone/core.h"
21
#include "liblinphone_tester.h"
Benjamin REIS's avatar
Benjamin REIS committed
22
#include "tester_utils.h"
23 24

void linphone_configuration_status(LinphoneCore *lc, LinphoneConfiguringState status, const char *message) {
25
	stats* counters;
26 27
	ms_message("Configuring state = %i with message %s", status, message?message:"");

28
	counters = get_stats(lc);
29 30 31
	if (status == LinphoneConfiguringSkipped) {
		counters->number_of_LinphoneConfiguringSkipped++;
	} else if (status == LinphoneConfiguringFailed) {
32
		counters->number_of_LinphoneConfiguringFailed++;
33
	} else if (status == LinphoneConfiguringSuccessful) {
34
		counters->number_of_LinphoneConfiguringSuccessful++;
35 36 37 38 39
	}
}

static void remote_provisioning_skipped(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_rc", FALSE);
40
	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSkipped,1));
41 42 43 44
	linphone_core_manager_destroy(marie);
}

static void remote_provisioning_http(void) {
45
	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_rc", FALSE);
46 47
	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneRegistrationOk,1));
48 49
	/*make sure proxy config is not added in double, one time at core init, next time at configuring successfull*/
	BC_ASSERT_EQUAL(bctbx_list_size(linphone_core_get_proxy_config_list(marie->lc)), 1, int,"%i");
50 51 52
	linphone_core_manager_destroy(marie);
}

53 54
static void remote_provisioning_transient(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_transient_remote_rc", FALSE);
55 56
	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneRegistrationOk,1));
57 58
	BC_ASSERT_TRUE(linphone_core_is_provisioning_transient(marie->lc));
	BC_ASSERT_PTR_NULL(linphone_core_get_provisioning_uri(marie->lc));
59 60 61
	linphone_core_manager_destroy(marie);
}

62
static void remote_provisioning_https(void) {
63 64
	if (transport_supported(LinphoneTransportTls)) {
		LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_https_rc", FALSE);
65 66
		BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
		BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneRegistrationOk,1));
67
		linphone_core_manager_destroy(marie);
68
	}
69 70 71
}

static void remote_provisioning_not_found(void) {
72
	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_404_rc", FALSE);
73
	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringFailed,1));
74 75 76 77
	linphone_core_manager_destroy(marie);
}

static void remote_provisioning_invalid(void) {
78
	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_invalid_rc", FALSE);
79
	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringFailed,1));
80 81 82
	linphone_core_manager_destroy(marie);
}

83 84
static void remote_provisioning_invalid_uri(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_invalid_uri_rc", FALSE);
85
	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringFailed,1));
86 87 88
	linphone_core_manager_destroy(marie);
}

89
static void remote_provisioning_default_values(void) {
90
	LinphoneProxyConfig *lpc;
91
	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_default_values_rc", FALSE);
92
	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
93
	lpc = linphone_core_create_proxy_config(marie->lc);
94 95 96 97 98
	BC_ASSERT_TRUE(linphone_proxy_config_register_enabled(lpc));
	BC_ASSERT_EQUAL(linphone_proxy_config_get_expires(lpc), 604800, int, "%d");
	BC_ASSERT_STRING_EQUAL(linphone_proxy_config_get_server_addr(lpc), "<sip:sip.linphone.org:5223;transport=tls>");
	BC_ASSERT_STRING_EQUAL(linphone_proxy_config_get_route(lpc), "<sip:sip.linphone.org:5223;transport=tls>");
	BC_ASSERT_STRING_EQUAL(linphone_proxy_config_get_identity(lpc), "sip:?@sip.linphone.org");
jehan's avatar
jehan committed
99 100
	{
		LpConfig* lp = linphone_core_get_config(marie->lc);
101
		BC_ASSERT_STRING_EQUAL(lp_config_get_string(lp,"app","toto","empty"),"titi");
jehan's avatar
jehan committed
102
	}
103
	linphone_proxy_config_destroy(lpc);
104 105 106
	linphone_core_manager_destroy(marie);
}

107
static void remote_provisioning_file(void) {
108
	LinphoneCoreManager* marie;
109
	const LpConfig* conf;
110 111 112
#if TARGET_OS_IPHONE
	ms_message("Skipping remote provisioning from file on iOS");
	return;
113
#elif defined(__ANDROID__)
114
	marie = linphone_core_manager_new2("marie_remote_localfile_android_rc", FALSE);
115 116
#elif defined(LINPHONE_WINDOWS_UNIVERSAL)
	marie = linphone_core_manager_new2("marie_remote_localfile_win10_rc", FALSE);
117
#else
118
	marie = ms_new0(LinphoneCoreManager, 1);
119
	linphone_core_manager_init(marie, "marie_remote_localfile_rc",NULL);
120 121 122 123
	// fix relative path to absolute path
	{
		char* path = bc_tester_res("rcfiles/marie_remote_localfile2_rc");
		char* abspath = ms_strdup_printf("file://%s", path);
124
		lp_config_set_string(linphone_core_get_config(marie->lc), "misc", "config-uri", abspath);
125 126 127 128
		linphone_core_manager_start(marie, 1);
		ms_free(path);
		ms_free(abspath);
	}
129
#endif
130
	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
131 132

	conf = linphone_core_get_config( marie->lc );
133
	BC_ASSERT_EQUAL( lp_config_get_int(conf,"misc","tester_file_ok", 0), 1 , int, "%d");
134 135 136 137 138

	linphone_core_manager_destroy(marie);
}


139
test_t remote_provisioning_tests[] = {
140 141 142 143 144 145 146 147 148
	TEST_NO_TAG("Remote provisioning skipped", remote_provisioning_skipped),
	TEST_NO_TAG("Remote provisioning successful behind http", remote_provisioning_http),
	TEST_NO_TAG("Remote provisioning successful behind https", remote_provisioning_https),
	TEST_NO_TAG("Remote provisioning 404 not found", remote_provisioning_not_found),
	TEST_NO_TAG("Remote provisioning invalid", remote_provisioning_invalid),
	TEST_NO_TAG("Remote provisioning transient successful", remote_provisioning_transient),
	TEST_NO_TAG("Remote provisioning default values", remote_provisioning_default_values),
	TEST_NO_TAG("Remote provisioning from file", remote_provisioning_file),
	TEST_NO_TAG("Remote provisioning invalid URI", remote_provisioning_invalid_uri)
149 150
};

151
test_suite_t remote_provisioning_test_suite = {"RemoteProvisioning", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
152 153
											   sizeof(remote_provisioning_tests) / sizeof(remote_provisioning_tests[0]),
											   remote_provisioning_tests};