upnp_tester.c 2.07 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 19 20 21 22 23 24 25 26 27
    (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 "lpconfig.h"
#include "private.h"
#include "liblinphone_tester.h"

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

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

static void upnp_check_ipaddress(void) {
	int tmp = 0;
46
	const char *addr;
Simon Morlat's avatar
Simon Morlat committed
47
	LinphoneCoreManager* lc_upnp = linphone_core_manager_new2( "upnp_rc", FALSE);
Yann Diorcet's avatar
Yann Diorcet committed
48
	wait_for(lc_upnp->lc,lc_upnp->lc,&tmp,1);
49
	addr = linphone_core_get_upnp_external_ipaddress(lc_upnp->lc);
Yann Diorcet's avatar
Yann Diorcet committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
	CU_ASSERT_TRUE(addr != NULL && strlen(addr)>=7);
	linphone_core_manager_destroy(lc_upnp);
}

test_t upnp_tests[] = {
	{ "Start and stop", upnp_start_n_stop },
	{ "Check state", upnp_check_state },
	{ "Check ip address", upnp_check_ipaddress },
};

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