upnp_tester.c 2.19 KB
Newer Older
Yann Diorcet's avatar
Yann Diorcet committed
1
/*
Simon Morlat's avatar
Simon Morlat committed
2 3
    liblinphone_tester - liblinphone test suite
    Copyright (C) 2013  Belledonne Communications SARL
Yann Diorcet's avatar
Yann Diorcet committed
4 5 6

    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
Simon Morlat's avatar
Simon Morlat committed
7
    the Free Software Foundation, either version 2 of the License, or
Yann Diorcet's avatar
Yann Diorcet committed
8 9 10 11 12 13 14 15 16 17 18
    (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/>.
*/

19

20 21
#include "linphone/core.h"
#include "linphone/lpconfig.h"
Yann Diorcet's avatar
Yann Diorcet committed
22 23 24 25 26
#include "private.h"
#include "liblinphone_tester.h"

static void upnp_start_n_stop(void) {
	int tmp = 0;
Simon Morlat's avatar
Simon Morlat committed
27
	LinphoneCoreManager* lc_upnp = linphone_core_manager_new2( "upnp_rc", FALSE);
Yann Diorcet's avatar
Yann Diorcet committed
28
	wait_for(lc_upnp->lc,lc_upnp->lc,&tmp,1);
29
#ifdef BUILD_UPNP
30
	BC_ASSERT_PTR_NOT_NULL(lc_upnp->lc->upnp);
31
#endif
Yann Diorcet's avatar
Yann Diorcet committed
32 33 34 35 36
	linphone_core_manager_destroy(lc_upnp);
}

static void upnp_check_state(void) {
	int tmp = 0;
Simon Morlat's avatar
Simon Morlat committed
37
	LinphoneCoreManager* lc_upnp = linphone_core_manager_new2( "upnp_rc", FALSE);
Yann Diorcet's avatar
Yann Diorcet committed
38
	wait_for(lc_upnp->lc,lc_upnp->lc,&tmp,1);
39
	BC_ASSERT_EQUAL(linphone_core_get_upnp_state(lc_upnp->lc), LinphoneUpnpStateOk, int, "%d");
Yann Diorcet's avatar
Yann Diorcet committed
40 41 42 43 44
	linphone_core_manager_destroy(lc_upnp);
}

static void upnp_check_ipaddress(void) {
	int tmp = 0;
45
	const char *addr;
Simon Morlat's avatar
Simon Morlat committed
46
	LinphoneCoreManager* lc_upnp = linphone_core_manager_new2( "upnp_rc", FALSE);
Yann Diorcet's avatar
Yann Diorcet committed
47
	wait_for(lc_upnp->lc,lc_upnp->lc,&tmp,1);
48
	addr = linphone_core_get_upnp_external_ipaddress(lc_upnp->lc);
49 50
	BC_ASSERT_PTR_NOT_NULL(addr);
	if (addr!=NULL) {
51
		BC_ASSERT_GREATER((int)strlen(addr),7,int,"%d");
52
	}
Yann Diorcet's avatar
Yann Diorcet committed
53 54 55 56
	linphone_core_manager_destroy(lc_upnp);
}

test_t upnp_tests[] = {
57 58 59
	TEST_NO_TAG("Start and stop", upnp_start_n_stop),
	TEST_NO_TAG("Check state", upnp_check_state),
	TEST_NO_TAG("Check ip address", upnp_check_ipaddress)
Yann Diorcet's avatar
Yann Diorcet committed
60 61
};

62
test_suite_t upnp_test_suite = {"Upnp", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each,
63
								sizeof(upnp_tests) / sizeof(upnp_tests[0]), upnp_tests};