account_creator_tester.c 92.2 KB
Newer Older
Erwan Croze's avatar
Erwan Croze committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
	liblinphone_tester - liblinphone test suite
	Copyright (C) 2017  Belledonne Communications SARL

	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.

	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, see <http://www.gnu.org/licenses/>.
*/

#include "liblinphone_tester.h"
Benjamin REIS's avatar
Benjamin REIS committed
20
#include "tester_utils.h"
21
#include <ctype.h>
Erwan Croze's avatar
Erwan Croze committed
22 23 24

static const char XMLRPC_URL[] = "https://sip2.linphone.org:446/xmlrpc.php";

25
static const int TIMEOUT_REQUEST = 10000;
Erwan Croze's avatar
Erwan Croze committed
26

Erwan Croze's avatar
Erwan Croze committed
27 28
/////////// INIT //////////////

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
static void init_linphone_account_creator_service(LinphoneCore *lc) {
	LinphoneAccountCreatorService *service = linphone_account_creator_service_new();
	linphone_account_creator_service_set_constructor_cb(service, NULL);
	linphone_account_creator_service_set_destructor_cb(service, NULL);
	linphone_account_creator_service_set_create_account_cb(service, linphone_account_creator_create_account_linphone);
	linphone_account_creator_service_set_is_account_exist_cb(service, linphone_account_creator_is_account_exist_linphone);
	linphone_account_creator_service_set_activate_account_cb(service, linphone_account_creator_activate_account_linphone);
	linphone_account_creator_service_set_is_account_activated_cb(service, linphone_account_creator_is_account_activated_linphone);
	linphone_account_creator_service_set_link_account_cb(service, linphone_account_creator_link_phone_number_with_account_linphone);
	linphone_account_creator_service_set_activate_alias_cb(service, linphone_account_creator_activate_phone_number_link_linphone);
	linphone_account_creator_service_set_is_alias_used_cb(service, linphone_account_creator_is_phone_number_used_linphone);
	linphone_account_creator_service_set_is_account_linked_cb(service, linphone_account_creator_is_account_linked_linphone);
	linphone_account_creator_service_set_recover_account_cb(service, linphone_account_creator_recover_phone_account_linphone);
	linphone_account_creator_service_set_update_account_cb(service, linphone_account_creator_update_password_linphone);
	linphone_core_set_account_creator_service(lc, service);
Erwan Croze's avatar
Erwan Croze committed
44 45 46
}

static LinphoneAccountCreator * _linphone_account_creator_new(LinphoneCore *lc, const char * url) {
47
	init_linphone_account_creator_service(lc);
Erwan Croze's avatar
Erwan Croze committed
48 49 50 51
	LinphoneAccountCreator *creator = linphone_account_creator_new(lc, url);
	return creator;
}

Erwan Croze's avatar
Erwan Croze committed
52 53 54 55 56
/////////// LOCAL TESTS ///////////

////// USERNAME //////
static void local_username_too_short(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
57
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
58 59 60

	BC_ASSERT_EQUAL(
		linphone_account_creator_set_username(creator, ""),
61 62
		LinphoneAccountCreatorUsernameStatusTooShort,
		LinphoneAccountCreatorUsernameStatus,
Erwan Croze's avatar
Erwan Croze committed
63 64
		"%i");

65
	
Erwan Croze's avatar
Erwan Croze committed
66
	linphone_core_manager_destroy(marie);
67
	linphone_account_creator_unref(creator);
Erwan Croze's avatar
Erwan Croze committed
68 69 70 71
}

static void local_username_too_long(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
72
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
73 74

	BC_ASSERT_EQUAL(
75
		linphone_account_creator_set_username(creator, "usernametoolongforyou"),
76 77
		LinphoneAccountCreatorUsernameStatusTooLong,
		LinphoneAccountCreatorUsernameStatus,
Erwan Croze's avatar
Erwan Croze committed
78 79 80 81 82 83
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

84
static void local_username_invalid_character(void) {
Erwan Croze's avatar
Erwan Croze committed
85
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
86
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
87 88 89

	BC_ASSERT_EQUAL(
			linphone_account_creator_set_username(creator, "use!"),
90 91
			LinphoneAccountCreatorUsernameStatusInvalidCharacters,
			LinphoneAccountCreatorUsernameStatus,
Erwan Croze's avatar
Erwan Croze committed
92 93 94 95 96 97 98 99
			"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void local_username_ok(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
100
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
101 102

	BC_ASSERT_EQUAL(
Erwan Croze's avatar
Erwan Croze committed
103
			linphone_account_creator_set_username(creator, "XXXTESTuser_1"),
104 105
			LinphoneAccountCreatorUsernameStatusOk,
			LinphoneAccountCreatorUsernameStatus,
Erwan Croze's avatar
Erwan Croze committed
106 107 108 109 110 111 112 113 114 115
			"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

////// PASSWORD //////

static void local_password_too_short(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
116
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
117 118 119

	BC_ASSERT_EQUAL(
		linphone_account_creator_set_password(creator, ""),
120 121
		LinphoneAccountCreatorPasswordStatusTooShort,
		LinphoneAccountCreatorPasswordStatus,
Erwan Croze's avatar
Erwan Croze committed
122 123 124 125 126 127 128 129
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void local_password_too_long(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
130
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
131 132 133

	BC_ASSERT_EQUAL(
		linphone_account_creator_set_password(creator, "passwordtoolong"),
134 135
		LinphoneAccountCreatorPasswordStatusTooLong,
		LinphoneAccountCreatorPasswordStatus,
Erwan Croze's avatar
Erwan Croze committed
136 137 138 139 140 141 142 143
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void local_password_ok(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
144
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
145 146

	BC_ASSERT_EQUAL(
147
		linphone_account_creator_set_password(creator, "pass"),
148 149
		LinphoneAccountCreatorPasswordStatusOk,
		LinphoneAccountCreatorPasswordStatus,
Erwan Croze's avatar
Erwan Croze committed
150 151 152 153 154 155 156 157
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

////// EMAIL //////

158
static void local_email_malformed(void) {
Erwan Croze's avatar
Erwan Croze committed
159
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
160
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
161 162 163

	BC_ASSERT_EQUAL(
		linphone_account_creator_set_email(creator, "test.linphone.org"),
164 165
		LinphoneAccountCreatorEmailStatusMalformed,
		LinphoneAccountCreatorEmailStatus,
Erwan Croze's avatar
Erwan Croze committed
166 167
		"%i");

168 169
	BC_ASSERT_EQUAL(
		linphone_account_creator_set_email(creator, "test@linphone"),
170 171
		LinphoneAccountCreatorEmailStatusMalformed,
		LinphoneAccountCreatorEmailStatus,
172
		"%i");
Erwan Croze's avatar
Erwan Croze committed
173

174 175
	BC_ASSERT_EQUAL(
		linphone_account_creator_set_email(creator, "@linphone.org"),
176 177
		LinphoneAccountCreatorEmailStatusMalformed,
		LinphoneAccountCreatorEmailStatus,
178
		"%i");
Erwan Croze's avatar
Erwan Croze committed
179 180

	BC_ASSERT_EQUAL(
181
		linphone_account_creator_set_email(creator, "linphone@.org"),
182 183
		LinphoneAccountCreatorEmailStatusMalformed,
		LinphoneAccountCreatorEmailStatus,
184 185 186 187
		"%i");

	BC_ASSERT_EQUAL(
		linphone_account_creator_set_email(creator, ".linphone@.org"),
188 189
		LinphoneAccountCreatorEmailStatusMalformed,
		LinphoneAccountCreatorEmailStatus,
Erwan Croze's avatar
Erwan Croze committed
190 191 192 193 194 195
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

196
static void local_email_invalid_character(void) {
Erwan Croze's avatar
Erwan Croze committed
197
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
198
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
199 200

	BC_ASSERT_EQUAL(
201
		linphone_account_creator_set_email(creator, "test@linphone.org$"),
202 203
		LinphoneAccountCreatorEmailStatusInvalidCharacters,
		LinphoneAccountCreatorEmailStatus,
Erwan Croze's avatar
Erwan Croze committed
204 205 206 207 208 209
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

210
static void local_email_ok(void) {
Erwan Croze's avatar
Erwan Croze committed
211
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
212
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
213 214

	BC_ASSERT_EQUAL(
215
		linphone_account_creator_set_email(creator, "test@linphone.org"),
216 217
		LinphoneAccountCreatorEmailStatusOk,
		LinphoneAccountCreatorEmailStatus,
Erwan Croze's avatar
Erwan Croze committed
218 219
		"%i");

220 221
	BC_ASSERT_EQUAL(
		linphone_account_creator_set_email(creator, "test02@linphone5252.org"),
222 223
		LinphoneAccountCreatorEmailStatusOk,
		LinphoneAccountCreatorEmailStatus,
224
		"%i");
Erwan Croze's avatar
Erwan Croze committed
225 226

	BC_ASSERT_EQUAL(
227
		linphone_account_creator_set_email(creator, "9053test@50255linphone.org"),
228 229
		LinphoneAccountCreatorEmailStatusOk,
		LinphoneAccountCreatorEmailStatus,
Erwan Croze's avatar
Erwan Croze committed
230 231 232 233 234 235
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

236 237 238
////// PHONE NUMBER //////

static void local_phone_number_too_short(void) {
Erwan Croze's avatar
Erwan Croze committed
239
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
240
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
241 242

	BC_ASSERT_EQUAL(
243 244 245
		linphone_account_creator_set_phone_number(creator, "0123", "33")&LinphoneAccountCreatorPhoneNumberStatusTooShort,
		LinphoneAccountCreatorPhoneNumberStatusTooShort,
		LinphoneAccountCreatorPhoneNumberStatus,
Erwan Croze's avatar
Erwan Croze committed
246 247 248 249 250 251
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

252
static void local_phone_number_too_long(void) {
Erwan Croze's avatar
Erwan Croze committed
253
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
254
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
255 256

	BC_ASSERT_EQUAL(
257 258 259
		linphone_account_creator_set_phone_number(creator, "01234567891011", "33")&LinphoneAccountCreatorPhoneNumberStatusTooLong,
		LinphoneAccountCreatorPhoneNumberStatusTooLong,
		LinphoneAccountCreatorPhoneNumberStatus,
Erwan Croze's avatar
Erwan Croze committed
260 261 262 263 264 265
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

266
static void local_phone_number_invalid(void) {
Erwan Croze's avatar
Erwan Croze committed
267
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
268
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
269 270

	BC_ASSERT_EQUAL(
271 272 273
		linphone_account_creator_set_phone_number(creator, NULL, "33")&LinphoneAccountCreatorPhoneNumberStatusInvalid,
		LinphoneAccountCreatorPhoneNumberStatusInvalid,
		LinphoneAccountCreatorPhoneNumberStatus,
Erwan Croze's avatar
Erwan Croze committed
274 275 276 277 278 279
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

280
static void local_country_code_invalid(void) {
Erwan Croze's avatar
Erwan Croze committed
281
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
282
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
283

Erwan Croze's avatar
Erwan Croze committed
284
	BC_ASSERT_EQUAL(
285 286 287
		linphone_account_creator_set_phone_number(creator, "0123", "")&LinphoneAccountCreatorPhoneNumberStatusInvalidCountryCode,
		LinphoneAccountCreatorPhoneNumberStatusInvalidCountryCode,
		LinphoneAccountCreatorPhoneNumberStatus,
Erwan Croze's avatar
Erwan Croze committed
288
		"%i");
289

Erwan Croze's avatar
Erwan Croze committed
290 291
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
292
}
Erwan Croze's avatar
Erwan Croze committed
293

294
static void local_phone_number_ok(void) {
Erwan Croze's avatar
Erwan Croze committed
295
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
296
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, "");
Erwan Croze's avatar
Erwan Croze committed
297 298

	BC_ASSERT_EQUAL(
299 300 301
		linphone_account_creator_set_phone_number(creator, "000555455", "1")&LinphoneAccountCreatorPhoneNumberStatusOk,
		LinphoneAccountCreatorPhoneNumberStatusOk,
		LinphoneAccountCreatorPhoneNumberStatus,
Erwan Croze's avatar
Erwan Croze committed
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

/////////// SERVER TESTS ///////////

typedef struct _LinphoneAccountCreatorStats {
	int cb_done;
} LinphoneAccountCreatorStats;

static LinphoneAccountCreatorStats* new_linphone_account_creator_stats(void) {
	LinphoneAccountCreatorStats *stats = (LinphoneAccountCreatorStats*) ms_new0(LinphoneAccountCreatorStats, 1);
	return stats;
}

319 320
static void account_creator_set_cb_done(LinphoneAccountCreatorCbs *cbs) {
	LinphoneAccountCreatorStats *stats = (LinphoneAccountCreatorStats*) linphone_account_creator_cbs_get_user_data(cbs);
Erwan Croze's avatar
Erwan Croze committed
321 322 323 324
	stats->cb_done++;
	BC_ASSERT_TRUE(stats->cb_done);
}

325 326
static void account_creator_reset_cb_done(LinphoneAccountCreatorCbs *cbs) {
	LinphoneAccountCreatorStats *stats = (LinphoneAccountCreatorStats*) linphone_account_creator_cbs_get_user_data(cbs);
Erwan Croze's avatar
Erwan Croze committed
327 328
	stats->cb_done = 0;
	BC_ASSERT_FALSE(stats->cb_done);
Erwan Croze's avatar
Erwan Croze committed
329
}
Erwan Croze's avatar
Erwan Croze committed
330

331 332 333 334
static void account_creator_cb(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status, const char* resp) {
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
	LinphoneAccountCreatorStatus expected_status = (LinphoneAccountCreatorStatus)linphone_account_creator_service_get_user_data(
		linphone_account_creator_get_service(creator));
Erwan Croze's avatar
Erwan Croze committed
335 336 337
	BC_ASSERT_EQUAL(
		status,
		expected_status,
338
		LinphoneAccountCreatorStatus,
Erwan Croze's avatar
Erwan Croze committed
339 340 341 342
		"%i");
	account_creator_set_cb_done(cbs);
}

343 344 345 346 347 348 349 350 351 352 353 354 355 356
static void set_string(char **dest, const char *src, bool_t lowercase) {
	if (*dest) {
		ms_free(*dest);
		*dest = NULL;
	}
	if (src) {
		*dest = ms_strdup(src);
		if (lowercase) {
			char *cur = *dest;
			for (; *cur; cur++) *cur = tolower(*cur);
		}
	}
}

Erwan Croze's avatar
Erwan Croze committed
357 358
static void _get_activation_code_cb(LinphoneXmlRpcRequest *request) {
	LinphoneAccountCreator *creator = (LinphoneAccountCreator *)linphone_xml_rpc_request_get_user_data(request);
359
	LinphoneAccountCreatorStatus status = LinphoneAccountCreatorStatusRequestFailed;
Erwan Croze's avatar
Erwan Croze committed
360 361 362
	const char* resp = linphone_xml_rpc_request_get_string_response(request);
	if (linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk) {
		if (strstr(resp, "ERROR_") == resp) {
363
			status = LinphoneAccountCreatorStatusRequestFailed;
Erwan Croze's avatar
Erwan Croze committed
364
		} else {
365
			status = LinphoneAccountCreatorStatusRequestOk;
Erwan Croze's avatar
Erwan Croze committed
366 367 368 369 370 371
			set_string(&creator->activation_code, resp, FALSE);
		}
	}
	account_creator_cb(creator, status, resp);
}

372
LinphoneAccountCreatorStatus get_activation_code_account_cb(LinphoneAccountCreator *creator) {
Erwan Croze's avatar
Erwan Croze committed
373 374
	LinphoneXmlRpcRequest *request;
	if ((!creator->username && !creator->phone_number) || !creator->password) {
375
		return LinphoneAccountCreatorStatusMissingArguments;
Erwan Croze's avatar
Erwan Croze committed
376 377
	}

Ghislain MARY's avatar
Ghislain MARY committed
378 379 380 381
	request = linphone_xml_rpc_request_new(LinphoneXmlRpcArgString, "get_confirmation_key");
	linphone_xml_rpc_request_add_string_arg(request, creator->username ? creator->username : creator->phone_number);
	linphone_xml_rpc_request_add_string_arg(request, creator->password);
	linphone_xml_rpc_request_add_string_arg(request, linphone_proxy_config_get_domain(creator->proxy_cfg));
Erwan Croze's avatar
Erwan Croze committed
382 383 384 385 386
	linphone_xml_rpc_request_set_user_data(request, creator);
	linphone_xml_rpc_request_cbs_set_response(linphone_xml_rpc_request_get_callbacks(request), _get_activation_code_cb);
	linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
	linphone_xml_rpc_request_unref(request);

387
	return LinphoneAccountCreatorStatusRequestOk;
Erwan Croze's avatar
Erwan Croze committed
388 389 390 391
}

static void _delete_account_cb(LinphoneXmlRpcRequest *request) {
	LinphoneAccountCreator *creator = (LinphoneAccountCreator *)linphone_xml_rpc_request_get_user_data(request);
392
	LinphoneAccountCreatorStatus status = LinphoneAccountCreatorStatusRequestFailed;
Erwan Croze's avatar
Erwan Croze committed
393 394 395 396 397
	const char* resp = linphone_xml_rpc_request_get_string_response(request);
	if (linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk) {
		// We want to delete account from table but it's not an error if it doesn't exist or password doesn't match
		if (strstr(resp, "ERROR_ACCOUNT_DOESNT_EXIST") == resp
			|| strstr(resp, "ERROR_PASSWORD_DOESNT_MATCH") == resp) {
398
			status = LinphoneAccountCreatorStatusRequestOk;
Erwan Croze's avatar
Erwan Croze committed
399
		} else if (strstr(resp, "ERROR_") == resp) {
400
			status = LinphoneAccountCreatorStatusRequestFailed;
Erwan Croze's avatar
Erwan Croze committed
401
		} else {
402
			status = LinphoneAccountCreatorStatusRequestOk;
Erwan Croze's avatar
Erwan Croze committed
403 404 405 406 407
		}
	}
	account_creator_cb(creator, status, resp);
}

408
LinphoneAccountCreatorStatus delete_account_cb(LinphoneAccountCreator *creator) {
Erwan Croze's avatar
Erwan Croze committed
409 410
	LinphoneXmlRpcRequest *request;
	if ((!creator->username && !creator->phone_number) || !creator->password) {
411
		return LinphoneAccountCreatorStatusMissingArguments;
Erwan Croze's avatar
Erwan Croze committed
412 413
	}

Ghislain MARY's avatar
Ghislain MARY committed
414 415 416 417
	request = linphone_xml_rpc_request_new(LinphoneXmlRpcArgString, "delete_account");
	linphone_xml_rpc_request_add_string_arg(request, creator->username ? creator->username : creator->phone_number);
	linphone_xml_rpc_request_add_string_arg(request, creator->password);
	linphone_xml_rpc_request_add_string_arg(request, linphone_proxy_config_get_domain(creator->proxy_cfg));
Erwan Croze's avatar
Erwan Croze committed
418 419 420 421 422
	linphone_xml_rpc_request_set_user_data(request, creator);
	linphone_xml_rpc_request_cbs_set_response(linphone_xml_rpc_request_get_callbacks(request), _delete_account_cb);
	linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request);
	linphone_xml_rpc_request_unref(request);

423
	return LinphoneAccountCreatorStatusRequestOk;
Erwan Croze's avatar
Erwan Croze committed
424 425 426
}

static void get_activation_code(LinphoneAccountCreator *creator, int *cb_done) {
427 428 429
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusRequestOk);
Erwan Croze's avatar
Erwan Croze committed
430 431 432

	BC_ASSERT_EQUAL(
		get_activation_code_account_cb(creator),
433 434
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
Erwan Croze's avatar
Erwan Croze committed
435 436 437 438 439 440 441 442
		"%i");

	wait_for_until(creator->core, NULL, cb_done, 1, TIMEOUT_REQUEST);
}

static void server_delete_account_test(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
443
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
Erwan Croze's avatar
Erwan Croze committed
444 445
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

446 447 448 449
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusRequestOk);
Erwan Croze's avatar
Erwan Croze committed
450 451 452 453 454 455
	linphone_account_creator_set_email(creator, "user_2@linphone.org");
	linphone_account_creator_set_password(creator, "password");
	linphone_account_creator_set_phone_number(creator, "000555455","1");

	BC_ASSERT_EQUAL(
		delete_account_cb(creator),
456 457
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
Erwan Croze's avatar
Erwan Croze committed
458 459 460 461 462 463 464 465
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

	linphone_account_creator_unref(creator);

	// First attempt with the first password
	creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
466
	cbs = linphone_account_creator_get_callbacks(creator);
Erwan Croze's avatar
Erwan Croze committed
467

468
	linphone_account_creator_cbs_set_user_data(cbs, stats);
Erwan Croze's avatar
Erwan Croze committed
469
	account_creator_reset_cb_done(cbs);
470 471 472
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusRequestOk);
Erwan Croze's avatar
Erwan Croze committed
473 474 475 476 477 478
	linphone_account_creator_set_username(creator, "XXXTESTuser_1");
	linphone_account_creator_set_email(creator, "user_1@linphone.org");
	linphone_account_creator_set_password(creator, "password");

	BC_ASSERT_EQUAL(
		delete_account_cb(creator),
479 480
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
Erwan Croze's avatar
Erwan Croze committed
481 482 483 484 485 486 487 488
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

	linphone_account_creator_unref(creator);

	// Second attempt with the second password
	creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
489
	cbs = linphone_account_creator_get_callbacks(creator);
Erwan Croze's avatar
Erwan Croze committed
490

491
	linphone_account_creator_cbs_set_user_data(cbs, stats);
Erwan Croze's avatar
Erwan Croze committed
492
	account_creator_reset_cb_done(cbs);
493 494 495
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusRequestOk);
Erwan Croze's avatar
Erwan Croze committed
496 497 498 499 500 501
	linphone_account_creator_set_username(creator, "XXXTESTuser_1");
	linphone_account_creator_set_email(creator, "user_1@linphone.org");
	linphone_account_creator_set_password(creator, "newpassword");

	BC_ASSERT_EQUAL(
		delete_account_cb(creator),
502 503
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
Erwan Croze's avatar
Erwan Croze committed
504 505 506 507
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
	linphone_account_creator_unref(creator);

	creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
	cbs = linphone_account_creator_get_callbacks(creator);

	linphone_account_creator_cbs_set_user_data(cbs, stats);
	account_creator_reset_cb_done(cbs);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusRequestOk);
	linphone_account_creator_set_username(creator, "XXXTESTuser_3");
	linphone_account_creator_set_email(creator, "user_1@linphone.org");
	linphone_account_creator_set_password(creator, "password");

	BC_ASSERT_EQUAL(
		delete_account_cb(creator),
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

Erwan Croze's avatar
Erwan Croze committed
530 531 532 533 534
	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

535
/****************** Start Is Account Exist ************************/
Erwan Croze's avatar
Erwan Croze committed
536 537
static void server_account_doesnt_exist(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
538
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
539
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
Erwan Croze's avatar
Erwan Croze committed
540 541
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

542 543 544 545
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusAccountNotExist);
Erwan Croze's avatar
Erwan Croze committed
546
	linphone_account_creator_set_username(creator, "user_not_exist");
547
	linphone_account_creator_cbs_set_is_account_exist(cbs, account_creator_cb);
Erwan Croze's avatar
Erwan Croze committed
548 549

	BC_ASSERT_EQUAL(
550
		linphone_account_creator_is_account_exist(creator),
551 552
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
Erwan Croze's avatar
Erwan Croze committed
553 554 555 556 557 558 559 560 561 562 563
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_account_exist(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
564
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
565
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
566 567
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

568 569 570 571
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusAccountExist);
Erwan Croze's avatar
Erwan Croze committed
572
	linphone_account_creator_set_username(creator, "XXXTESTuser_1");
573
	linphone_account_creator_cbs_set_is_account_exist(cbs, account_creator_cb);
574 575 576

	BC_ASSERT_EQUAL(
		linphone_account_creator_is_account_exist(creator),
577 578
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
579 580 581 582 583 584 585 586 587 588 589
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_is_account_exist_cb_missing(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
590
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
591 592 593 594 595

	linphone_account_creator_set_username(creator, "user_exist");

	BC_ASSERT_EQUAL(
		linphone_account_creator_is_account_exist(creator),
596 597
		LinphoneAccountCreatorStatusMissingCallbacks,
		LinphoneAccountCreatorStatus,
598 599 600 601 602 603 604 605
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_is_account_exist_arg_missing(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
606
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
607
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
608 609
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

610 611 612 613 614
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusMissingArguments);
	linphone_account_creator_cbs_set_is_account_exist(cbs, account_creator_cb);
615 616 617

	BC_ASSERT_EQUAL(
		linphone_account_creator_is_account_exist(creator),
618 619
		LinphoneAccountCreatorStatusMissingArguments,
		LinphoneAccountCreatorStatus,
620 621 622 623 624 625 626 627 628
		"%i");

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}
/****************** End Is Account Exist ************************/

/****************** Start Create Account ************************/
Erwan Croze's avatar
Erwan Croze committed
629
static void server_account_created_with_email(void) {
630
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
631
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
632
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
633 634
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

635 636 637 638
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusAccountCreated);
Erwan Croze's avatar
Erwan Croze committed
639
	linphone_account_creator_set_username(creator, "XXXTESTuser_1");
640 641
	linphone_account_creator_set_email(creator, "user_1@linphone.org");
	linphone_account_creator_set_password(creator, "password");
642
	linphone_account_creator_cbs_set_create_account(cbs, account_creator_cb);
643 644 645

	BC_ASSERT_EQUAL(
		linphone_account_creator_create_account(creator),
646 647
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
648 649 650 651 652 653 654 655 656 657 658
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_create_account_already_create_with_email(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
659
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
660
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
661 662
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

663 664 665 666
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusAccountExist);
Erwan Croze's avatar
Erwan Croze committed
667 668
	linphone_account_creator_set_username(creator, "XXXTESTuser_1");
	linphone_account_creator_set_email(creator, "user_1@linphone.org");
669
	linphone_account_creator_set_password(creator, "password");
670
	linphone_account_creator_cbs_set_create_account(cbs, account_creator_cb);
671 672 673

	BC_ASSERT_EQUAL(
		linphone_account_creator_create_account(creator),
674 675
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
676 677 678 679 680 681 682 683 684
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

Erwan Croze's avatar
Erwan Croze committed
685
static void server_account_created_with_phone_number(void) {
686
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
687
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
688
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
689 690
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

691 692 693 694
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusAccountCreated);
Erwan Croze's avatar
Erwan Croze committed
695
	linphone_account_creator_set_email(creator, "user_2@linphone.org");
696
	linphone_account_creator_set_password(creator, "password");
Erwan Croze's avatar
Erwan Croze committed
697
	linphone_account_creator_set_phone_number(creator, "000555455","1");
698
	linphone_account_creator_cbs_set_create_account(cbs, account_creator_cb);
699 700 701

	BC_ASSERT_EQUAL(
		linphone_account_creator_create_account(creator),
702 703
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
704 705 706 707 708 709 710 711 712 713 714
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_create_account_already_create_as_account_with_phone_number(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
715
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
716
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
717 718
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

719 720 721 722
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusAccountExist);
Erwan Croze's avatar
Erwan Croze committed
723 724 725
	linphone_account_creator_set_email(creator, "user_2@linphone.org");
	linphone_account_creator_set_password(creator, "password");
	linphone_account_creator_set_phone_number(creator, "000555455","1");
726
	linphone_account_creator_cbs_set_create_account(cbs, account_creator_cb);
727 728 729

	BC_ASSERT_EQUAL(
		linphone_account_creator_create_account(creator),
730 731
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
732 733 734 735 736 737 738 739 740 741 742
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_create_account_already_create_as_alias_with_phone_number(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
743
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
744
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
Erwan Croze's avatar
Erwan Croze committed
745 746
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

747 748 749 750
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusAccountExistWithAlias);
Erwan Croze's avatar
Erwan Croze committed
751 752 753 754
	linphone_account_creator_set_username(creator, "XXXTESTuser_3");
	linphone_account_creator_set_email(creator, "user_2@linphone.org");
	linphone_account_creator_set_password(creator, "password");
	linphone_account_creator_set_phone_number(creator, "000555456","1");
755
	linphone_account_creator_cbs_set_create_account(cbs, account_creator_cb);
Erwan Croze's avatar
Erwan Croze committed
756 757

	BC_ASSERT_EQUAL(
758
		linphone_account_creator_create_account(creator),
759 760
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
Erwan Croze's avatar
Erwan Croze committed
761 762 763 764 765 766 767 768 769
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

770 771
static void server_create_account_cb_missing(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
772
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
773 774 775 776 777 778 779

	linphone_account_creator_set_username(creator, "user_exist");
	linphone_account_creator_set_email(creator, "user_1@linphone.org");
	linphone_account_creator_set_password(creator, "password");

	BC_ASSERT_EQUAL(
		linphone_account_creator_create_account(creator),
780 781
		LinphoneAccountCreatorStatusMissingCallbacks,
		LinphoneAccountCreatorStatus,
782 783 784 785 786 787 788 789
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_create_account_with_email_arg_username_missing(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
790
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
791
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
792 793 794 795 796
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

	linphone_account_creator_set_email(creator, "user_1@linphone.org");
	linphone_account_creator_set_password(creator, "password");

797 798 799 800 801
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusMissingArguments);
	linphone_account_creator_cbs_set_create_account(cbs, account_creator_cb);
802 803 804

	BC_ASSERT_EQUAL(
		linphone_account_creator_create_account(creator),
805 806
		LinphoneAccountCreatorStatusMissingArguments,
		LinphoneAccountCreatorStatus,
807 808 809 810 811 812 813 814 815
		"%i");

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_create_account_with_email_arg_email_missing(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
816
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
817
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
818 819 820 821 822
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

	linphone_account_creator_set_username(creator, "user_exist");
	linphone_account_creator_set_password(creator, "password");

823 824 825 826 827
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusMissingArguments);
	linphone_account_creator_cbs_set_create_account(cbs, account_creator_cb);
828 829 830

	BC_ASSERT_EQUAL(
		linphone_account_creator_create_account(creator),
831 832
		LinphoneAccountCreatorStatusMissingArguments,
		LinphoneAccountCreatorStatus,
833 834 835 836 837 838 839 840 841
		"%i");

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_create_account_with_email_arg_password_missing(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
842
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
843
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
844 845 846 847 848
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

	linphone_account_creator_set_username(creator, "user_exist");
	linphone_account_creator_set_email(creator, "user_1@linphone.org");

849 850 851 852 853
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusMissingArguments);
	linphone_account_creator_cbs_set_create_account(cbs, account_creator_cb);
854 855 856

	BC_ASSERT_EQUAL(
		linphone_account_creator_create_account(creator),
857 858
		LinphoneAccountCreatorStatusMissingArguments,
		LinphoneAccountCreatorStatus,
859 860 861 862 863 864 865 866 867
		"%i");

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_create_account_with_phone_number_arg_username_missing(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
868
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
869
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
870 871 872 873 874
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

	linphone_account_creator_set_phone_number(creator, "0123456", "33");
	linphone_account_creator_set_password(creator, "password");

875 876 877 878 879
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusMissingArguments);
	linphone_account_creator_cbs_set_create_account(cbs, account_creator_cb);
880 881 882

	BC_ASSERT_EQUAL(
		linphone_account_creator_create_account(creator),
883 884
		LinphoneAccountCreatorStatusMissingArguments,
		LinphoneAccountCreatorStatus,
885 886 887 888 889 890 891 892 893
		"%i");

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_create_account_with_phone_number_arg_phone_number_missing(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
894
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
895
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
896 897 898 899 900
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

	linphone_account_creator_set_username(creator, "user_exist");
	linphone_account_creator_set_password(creator, "password");

901 902 903 904 905
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusMissingArguments);
	linphone_account_creator_cbs_set_create_account(cbs, account_creator_cb);
906 907 908

	BC_ASSERT_EQUAL(
		linphone_account_creator_create_account(creator),
909 910
		LinphoneAccountCreatorStatusMissingArguments,
		LinphoneAccountCreatorStatus,
911 912 913 914 915 916 917 918 919
		"%i");

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}
/****************** End Create Account ************************/

/****************** Start Is Account Activated ************************/
920 921
static void server_account_not_activated(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
922
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
923
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
924 925
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

Erwan Croze's avatar
Erwan Croze committed
926
	linphone_account_creator_set_username(creator, "XXXTESTuser_1");
927

928 929 930 931 932
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusAccountNotActivated);
	linphone_account_creator_cbs_set_is_account_activated(cbs, account_creator_cb);
933 934 935

	BC_ASSERT_EQUAL(
		linphone_account_creator_is_account_activated(creator),
936 937
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
938 939 940 941 942 943 944 945 946 947 948
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_account_already_activated(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
949
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
950
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);
951 952
	LinphoneAccountCreatorStats *stats = new_linphone_account_creator_stats();

Erwan Croze's avatar
Erwan Croze committed
953
	linphone_account_creator_set_username(creator, "XXXTESTuser_1");
954

955 956 957 958 959
	linphone_account_creator_cbs_set_user_data(cbs, stats);
	linphone_account_creator_service_set_user_data(
		linphone_account_creator_get_service(creator),
		(void*)LinphoneAccountCreatorStatusAccountActivated);
	linphone_account_creator_cbs_set_is_account_activated(cbs, account_creator_cb);
960 961 962

	BC_ASSERT_EQUAL(
		linphone_account_creator_is_account_activated(creator),
963 964
		LinphoneAccountCreatorStatusRequestOk,
		LinphoneAccountCreatorStatus,
965 966 967 968 969 970 971 972 973
		"%i");

	wait_for_until(marie->lc, NULL, &stats->cb_done, 1, TIMEOUT_REQUEST);

	ms_free(stats);
	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

974 975
static void server_is_account_activated_cb_missing(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
976
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
977 978 979 980 981

	linphone_account_creator_set_username(creator, "user_exist");

	BC_ASSERT_EQUAL(
		linphone_account_creator_is_account_activated(creator),
982 983
		LinphoneAccountCreatorStatusMissingCallbacks,
		LinphoneAccountCreatorStatus,
984 985 986 987 988 989 990 991
		"%i");

	linphone_account_creator_unref(creator);
	linphone_core_manager_destroy(marie);
}

static void server_is_account_activated_arg_username_missing(void) {
	LinphoneCoreManager *marie = linphone_core_manager_new2("account_creator_rc", 0);
Erwan Croze's avatar
Erwan Croze committed
992
	LinphoneAccountCreator *creator = _linphone_account_creator_new(marie->lc, XMLRPC_URL);
993
	LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator);