remote_provisioning_tester.c 6.81 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 50
	linphone_core_manager_destroy(marie);
}

51 52
static void remote_provisioning_transient(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_transient_remote_rc", FALSE);
53 54
	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));
55 56
	BC_ASSERT_TRUE(linphone_core_is_provisioning_transient(marie->lc));
	BC_ASSERT_PTR_NULL(linphone_core_get_provisioning_uri(marie->lc));
57 58 59
	linphone_core_manager_destroy(marie);
}

60
static void remote_provisioning_https(void) {
61 62
	if (transport_supported(LinphoneTransportTls)) {
		LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_https_rc", FALSE);
63 64
		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));
65
		linphone_core_manager_destroy(marie);
66
	}
67 68 69
}

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

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

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

87
static void remote_provisioning_default_values(void) {
88
	LinphoneProxyConfig *lpc;
89
	LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_default_values_rc", FALSE);
90
	BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
91
	lpc = linphone_core_create_proxy_config(marie->lc);
92 93 94 95 96
	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
97 98
	{
		LpConfig* lp = linphone_core_get_config(marie->lc);
99
		BC_ASSERT_STRING_EQUAL(lp_config_get_string(lp,"app","toto","empty"),"titi");
jehan's avatar
jehan committed
100
	}
101
	linphone_proxy_config_destroy(lpc);
102 103 104
	linphone_core_manager_destroy(marie);
}

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

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

	linphone_core_manager_destroy(marie);
}


137
test_t remote_provisioning_tests[] = {
138 139 140 141 142 143 144 145 146
	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)
147 148
};

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