Commit 1c5111a3 authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI
Browse files

Add basic STUN tests

parent 6f6d0375
......@@ -14,7 +14,8 @@ liblinphone_tester_SOURCES= liblinphone_tester.c liblinphone_tester.h\
presence_tester.c \
upnp_tester.c \
eventapi_tester.c \
flexisip_tester.c
flexisip_tester.c \
stun_tester.c
#liblinphone_tester_CFLAGS=$(CUNIT_CFLAGS)
......
......@@ -7,13 +7,13 @@
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.
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/>.
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>
......@@ -53,7 +53,7 @@ const char *userhostsfile = "tester_hosts";
#ifdef ANDROID
extern void AndroidPrintf(FILE *stream, const char *fmt, ...);
#define fprintf(file, fmt, ...) AndroidPrintf(file, fmt, ##__VA_ARGS__)
#define fprintf(file, fmt, ...) AndroidPrintf(file, fmt, ##__VA_ARGS__)
#endif
......@@ -94,14 +94,14 @@ static LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char*
char rootcapath[256]={0};
char dnsuserhostspath[256]={0};
char nowebcampath[256]={0};
if (path==NULL) path=".";
if (file){
sprintf(filepath, "%s/%s", path, file);
CU_ASSERT_TRUE_FATAL(ortp_file_exist(filepath)==0);
}
lc = linphone_core_new(v_table,NULL,*filepath!='\0' ? filepath : NULL,NULL);
sal_enable_test_features(lc->sal,TRUE);
......@@ -182,7 +182,7 @@ LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_f
LinphoneProxyConfig* proxy;
int proxy_count;
int retry=0;
mgr->v_table.registration_state_changed=registration_state_changed;
mgr->v_table.auth_info_requested=auth_info_requested;
mgr->v_table.call_state_changed=call_state_changed;
......@@ -211,7 +211,7 @@ LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_f
}
CU_ASSERT_EQUAL(mgr->stat.number_of_LinphoneRegistrationOk,proxy_count);
enable_codec(mgr->lc,"PCMU",8000);
linphone_core_get_default_proxy(mgr->lc,&proxy);
if (proxy) {
mgr->identity = linphone_address_new(linphone_proxy_config_get_identity(proxy));
......@@ -277,7 +277,7 @@ static int test_suite_index(const char *suite_name) {
static int test_index(const char *suite_name, const char *test_name) {
int j,i;
j = test_suite_index(suite_name);
if(j != -1) {
for (i = 0; i < test_suite[j]->nb_tests; i++) {
......@@ -321,6 +321,7 @@ void liblinphone_tester_init(void) {
#ifdef UPNP
add_test_suite(&upnp_test_suite);
#endif
add_test_suite(&stun_test_suite);
add_test_suite(&event_test_suite);
add_test_suite(&flexisip_test_suite);
}
......@@ -444,7 +445,7 @@ int main (int argc, char *argv[]) {
int ret;
const char *suite_name=NULL;
const char *test_name=NULL;
liblinphone_tester_init();
for(i=1;i<argc;++i){
......@@ -482,14 +483,14 @@ int main (int argc, char *argv[]) {
suite_name = liblinphone_tester_test_suite_name(j);
fprintf(stdout, "%s\n", suite_name);
}
return 0;
return 0;
} else if (strcmp(argv[i],"--list-tests")==0){
CHECK_ARG("--list-tests", ++i, argc);
suite_name = argv[i];
for(j=0;j<liblinphone_tester_nb_tests(suite_name);j++) {
test_name = liblinphone_tester_test_name(suite_name, j);
fprintf(stdout, "%s\n", test_name);
}
}
return 0;
} else {
helper(argv[0]);
......@@ -502,15 +503,15 @@ int main (int argc, char *argv[]) {
if(test_suite_index(suite_name) == -1) {
fprintf(stderr, "Suite \"%s\" not found\n", suite_name);
return -1;
}
}
if(test_name != NULL) {
if(test_index(suite_name, test_name) == -1) {
fprintf(stderr, "Test \"%s\" not found\n", test_name);
return -1;
}
}
}
}
ret = liblinphone_tester_run_tests(suite_name, test_name);
liblinphone_tester_uninit();
return ret;
......@@ -537,7 +538,7 @@ void cunit_android_trace_handler(int level, const char *fmt, va_list args) {
(*env)->DeleteLocalRef(env,javaString);
}
JNIEXPORT
JNIEXPORT
JNIEXPORT jint JNICALL Java_org_linphone_tester_Tester_run(JNIEnv *env, jobject obj, jobjectArray stringArray) {
int i, ret;
......
......@@ -7,13 +7,13 @@
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.
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/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
......@@ -54,6 +54,7 @@ extern test_suite_t presence_test_suite;
extern test_suite_t upnp_test_suite;
extern test_suite_t event_test_suite;
extern test_suite_t flexisip_test_suite;
extern test_suite_t stun_test_suite;
extern int liblinphone_tester_nb_test_suites(void);
......@@ -155,7 +156,7 @@ typedef struct _stats {
int number_of_LinphonePresenceActivityWorking;
int number_of_LinphonePresenceActivityWorship;
const LinphonePresenceModel *last_received_presence;
int number_of_inforeceived;
LinphoneInfoMessage* last_received_info_message;
......
[net]
firewall_policy=2
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2014 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 "liblinphone_tester.h"
#include "ortp/stun.h"
#include "ortp/port.h"
static const char* stun_address = "stun.linphone.org";
static int test_stun_encode( char*buffer, size_t len, bool_t expect_fail )
{
StunAtrString username;
StunAtrString password;
StunMessage req;
memset(&req, 0, sizeof(StunMessage));
memset(&username,0,sizeof(username));
memset(&password,0,sizeof(password));
stunBuildReqSimple( &req, &username, TRUE , TRUE , 11);
len = stunEncodeMessage( &req, buffer, len, &password);
if (len<=0){
if( expect_fail )
ms_message("Fail to encode stun message (EXPECTED).\n");
else
ms_error("Fail to encode stun message.\n");
return -1;
}
return len;
}
static void linphone_stun_test_encode()
{
char smallBuff[12];
size_t smallLen = 12;
char bigBuff[STUN_MAX_MESSAGE_SIZE];
size_t bigLen = STUN_MAX_MESSAGE_SIZE;
size_t len = test_stun_encode(smallBuff, smallLen, TRUE);
CU_ASSERT(len == -1);
len = test_stun_encode(bigBuff, bigLen, TRUE);
CU_ASSERT(len > 0);
ms_message("STUN message encoded in %d bytes", len);
}
static void linphone_stun_test_grab_ip()
{
LinphoneCoreManager* lc_stun = linphone_core_manager_new2( "stun_rc", FALSE);
LinphoneCall dummy_call;
int ping_time;
int tmp=0;
memset(&dummy_call, 0, sizeof(LinphoneCall));
dummy_call.audio_port = 7078;
dummy_call.audio_port = 9078;
linphone_core_set_stun_server(lc_stun->lc, stun_address);
CU_ASSERT_STRING_EQUAL(stun_address, linphone_core_get_stun_server(lc_stun->lc));
wait_for(lc_stun->lc,lc_stun->lc,&tmp,1);
ping_time = linphone_core_run_stun_tests(lc_stun->lc, &dummy_call);
CU_ASSERT(ping_time != -1);
ms_message("Round trip to STUN: %d ms", ping_time);
CU_ASSERT( dummy_call.ac.addr[0] != '\0');
CU_ASSERT( dummy_call.ac.port != 0);
CU_ASSERT( dummy_call.vc.addr[0] != '\0');
CU_ASSERT( dummy_call.vc.port != 0);
ms_message("STUN test result: local audio port maps to %s:%i",
dummy_call.ac.addr,
dummy_call.ac.port);
ms_message("STUN test result: local video port maps to %s:%i",
dummy_call.vc.addr,
dummy_call.vc.port);
linphone_core_manager_destroy(lc_stun);
}
test_t stun_tests[] = {
{ "Basic Stun test (Ping/public IP)", linphone_stun_test_grab_ip },
{ "STUN encode buffer protection", linphone_stun_test_encode },
};
test_suite_t stun_test_suite = {
"Stun",
NULL,
NULL,
sizeof(stun_tests) / sizeof(stun_tests[0]),
stun_tests
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment