presence_tester.c 3.75 KB
Newer Older
jehan's avatar
jehan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
	belle-sip - SIP (RFC3261) library.
    Copyright (C) 2010  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 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, see <http://www.gnu.org/licenses/>.
*/
Ghislain MARY's avatar
Ghislain MARY committed
18

jehan's avatar
jehan committed
19 20 21 22 23 24 25
#include <stdio.h>
#include "CUnit/Basic.h"
#include "linphonecore.h"
#include "private.h"
#include "liblinphone_tester.h"


jehan's avatar
jehan committed
26 27
void new_subscribtion_request(LinphoneCore *lc, LinphoneFriend *lf, const char *url){
	char* from=linphone_address_as_string(linphone_friend_get_address(lf));
28
	stats* counters;
jehan's avatar
jehan committed
29 30
	ms_message("New subscription request  from [%s]  url [%s]",from,url);
	ms_free(from);
31
	counters = (stats*)linphone_core_get_user_data(lc);
jehan's avatar
jehan committed
32 33 34
	counters->number_of_NewSubscriptionRequest++;
	linphone_core_add_friend(lc,lf); /*accept subscription*/
}
Ghislain MARY's avatar
Ghislain MARY committed
35

jehan's avatar
jehan committed
36
void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) {
37
	stats* counters;
jehan's avatar
jehan committed
38 39 40
	char* from=linphone_address_as_string(linphone_friend_get_address(lf));
	ms_message("New Notify request  from [%s] ",from);
	ms_free(from);
41
	counters = (stats*)linphone_core_get_user_data(lc);
jehan's avatar
jehan committed
42 43 44
	counters->number_of_NotifyReceived++;
}

Ghislain MARY's avatar
Ghislain MARY committed
45
static void simple_publish(void) {
46
	LinphoneCoreManager* marie = linphone_core_manager_new(liblinphone_tester_file_prefix, "marie_rc");
jehan's avatar
jehan committed
47 48 49 50 51 52 53 54 55
	LinphoneProxyConfig* proxy;
	linphone_core_get_default_proxy(marie->lc,&proxy);
	linphone_proxy_config_edit(proxy);
	linphone_proxy_config_enable_publish(proxy,TRUE);
	linphone_proxy_config_done(proxy);
	linphone_core_iterate(marie->lc);
	linphone_core_manager_destroy(marie);
}

Ghislain MARY's avatar
Ghislain MARY committed
56
static void simple_subscribe(void) {
57 58
	LinphoneCoreManager* marie = linphone_core_manager_new(liblinphone_tester_file_prefix, "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new(liblinphone_tester_file_prefix, "pauline_rc");
jehan's avatar
jehan committed
59
	const MSList* marie_friends = linphone_core_get_friend_list(marie->lc);
60
	LinphoneFriend* friend;
jehan's avatar
jehan committed
61
	CU_ASSERT_PTR_NOT_NULL_FATAL(marie_friends);
62
	friend = (LinphoneFriend*) marie_friends->data;
jehan's avatar
jehan committed
63 64 65 66 67 68 69 70 71 72 73 74
	linphone_friend_edit(friend);
	linphone_friend_enable_subscribes(friend,TRUE);
	linphone_friend_done(friend);

	CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&pauline->stat.number_of_NewSubscriptionRequest,1));
	CU_ASSERT_TRUE(wait_for(marie->lc,pauline->lc,&marie->stat.number_of_NotifyReceived,1));

	linphone_core_manager_destroy(marie);
	CU_ASSERT_FALSE(wait_for(NULL,pauline->lc,&pauline->stat.number_of_NewSubscriptionRequest,2)); /*just to wait for unsubscription even if not notified*/

	linphone_core_manager_destroy(pauline);
}
Ghislain MARY's avatar
Ghislain MARY committed
75 76

static void unsubscribe_while_subscribing(void) {
77
	LinphoneCoreManager* marie = linphone_core_manager_new(liblinphone_tester_file_prefix, "marie_rc");
jehan's avatar
jehan committed
78 79 80 81 82 83 84 85 86
	LinphoneFriend* friend = linphone_friend_new_with_addr("sip:toto@git.linphone.org"); /*any unexisting address*/
	linphone_friend_edit(friend);
	linphone_friend_enable_subscribes(friend,TRUE);
	linphone_friend_done(friend);
	linphone_core_add_friend(marie->lc,friend);
	linphone_core_iterate(marie->lc);
	linphone_core_manager_destroy(marie);
}

Ghislain MARY's avatar
Ghislain MARY committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

test_t presence_tests[] = {
	{ "Simple Subscribe", simple_subscribe },
	{ "Simple Publish", simple_publish },
	{ "Unsubscribe while subscribing", unsubscribe_while_subscribing },
};

test_suite_t presence_test_suite = {
	"Presence",
	NULL,
	NULL,
	sizeof(presence_tests) / sizeof(presence_tests[0]),
	presence_tests
};