eventapi_tester.c 5.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
	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/>.
*/

#include <stdio.h>
#include "CUnit/Basic.h"
#include "linphonecore.h"
#include "private.h"
#include <event.h>
#include "liblinphone_tester.h"


static const char *subscribe_content="<somexml>blabla</somexml>";
static const char *notify_content="<somexml2>blabla</somexml2>";

void linphone_notify_received(LinphoneCore *lc, LinphoneEvent *lev, const char *eventname, const LinphoneContent *content){
}

void linphone_subscription_state_change(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state) {
34 35
	stats* counters = get_stats(lc);
	LinphoneCoreManager *mgr=get_manager(lc);
36 37 38 39 40 41 42 43 44 45 46 47
	LinphoneContent content;
	
	content.type="application";
	content.subtype="somexml2";
	content.data=(void*)notify_content;
	content.size=strlen(notify_content);
	
	switch(state){
		case LinphoneSubscriptionNone:
		break;
		case LinphoneSubscriptionIncomingReceived:
			counters->number_of_LinphoneSubscriptionIncomingReceived++;
48 49 50 51
			if (!mgr->decline_subscribe)
				linphone_event_accept_subscription(lev);
			else
				linphone_event_deny_subscription(lev, LinphoneReasonDeclined);
52 53 54 55 56 57 58 59 60
		break;
		case LinphoneSubscriptionOutoingInit:
			counters->number_of_LinphoneSubscriptionOutgoingInit++;
		break;
		case LinphoneSubscriptionPending:
			counters->number_of_LinphoneSubscriptionPending++;
		break;
		case LinphoneSubscriptionActive:
			counters->number_of_LinphoneSubscriptionActive++;
61 62
			if (linphone_event_get_dir(lev)==LinphoneSubscriptionIncoming){
				mgr->lev=lev;
63
				linphone_event_notify(lev,&content);
64
			}
65 66 67
		break;
		case LinphoneSubscriptionTerminated:
			counters->number_of_LinphoneSubscriptionTerminated++;
68
			mgr->lev=NULL;
69 70 71
		break;
		case LinphoneSubscriptionError:
			counters->number_of_LinphoneSubscriptionError++;
72
			mgr->lev=NULL;
73 74 75 76
		break;
	}
}

77 78 79 80 81 82
static void subscribe_test_declined(void) {
	LinphoneCoreManager* marie = linphone_core_manager_new(liblinphone_tester_file_prefix, "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new(liblinphone_tester_file_prefix, "pauline_rc");
	LinphoneContent content;
	MSList* lcs=ms_list_append(NULL,marie->lc);
	lcs=ms_list_append(lcs,pauline->lc);
83 84


85 86 87 88 89 90 91 92 93 94 95
	content.type="application";
	content.subtype="somexml";
	content.data=(char*)subscribe_content;
	content.size=strlen(subscribe_content);
	
	pauline->decline_subscribe=TRUE;
	
	linphone_core_subscribe(marie->lc,pauline->identity,"dodo",600,&content);
	
	CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionOutgoingInit,1,1000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneSubscriptionIncomingReceived,1,1000));
Simon Morlat's avatar
Simon Morlat committed
96
	CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionError,1,21000));/*yes flexisip will wait 20 secs in case of forking*/
97 98 99 100 101
	CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneSubscriptionTerminated,1,1000));
	
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}
102 103


104
static void subscribe_test_with_args(bool_t terminated_by_subscriber) {
105 106 107
	LinphoneCoreManager* marie = linphone_core_manager_new(liblinphone_tester_file_prefix, "marie_rc");
	LinphoneCoreManager* pauline = linphone_core_manager_new(liblinphone_tester_file_prefix, "pauline_rc");
	LinphoneContent content;
108
	LinphoneEvent *lev;
109 110 111
	MSList* lcs=ms_list_append(NULL,marie->lc);
	lcs=ms_list_append(lcs,pauline->lc);

112

113 114 115 116 117
	content.type="application";
	content.subtype="somexml";
	content.data=(char*)subscribe_content;
	content.size=strlen(subscribe_content);
	
118
	lev=linphone_core_subscribe(marie->lc,pauline->identity,"dodo",600,&content);
119 120 121 122 123 124
	
	CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionOutgoingInit,1,1000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneSubscriptionIncomingReceived,1,1000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionActive,1,1000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneSubscriptionActive,1,1000));

125 126 127 128 129 130 131 132
	if (terminated_by_subscriber){
		linphone_event_terminate(lev);
	}else{
		linphone_event_terminate(pauline->lev);
	}
	
	CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionTerminated,1,1000));
	CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneSubscriptionTerminated,1,1000));
133 134 135 136 137
	
	linphone_core_manager_destroy(marie);
	linphone_core_manager_destroy(pauline);
}

138 139 140 141 142 143 144 145
static void subscribe_test_terminated_by_subscriber(void){
	subscribe_test_with_args(TRUE);
}

static void subscribe_test_terminated_by_notifier(void){
	subscribe_test_with_args(FALSE);
}

146
test_t subscribe_tests[] = {
147 148 149
	{ "Subscribe declined"	,	subscribe_test_declined 	},
	{ "Subscribe terminated by subscriber", subscribe_test_terminated_by_subscriber },
	{ "Subscribe terminated by notifier", subscribe_test_terminated_by_notifier }
150 151 152 153 154 155 156 157 158 159
};

test_suite_t subscribe_test_suite = {
	"Subscribe",
	NULL,
	NULL,
	sizeof(subscribe_tests) / sizeof(subscribe_tests[0]),
	subscribe_tests
};