Commit d4a36148 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Reorganize liblinphone tests.

parent bf0db8f9
......@@ -4,7 +4,7 @@ if BUILD_CUNIT_TESTS
noinst_PROGRAMS=liblinphone_tester
TESTS=$(noinst_PROGRAMS)
liblinphone_tester_SOURCES= liblinphone_tester.c register_tester.c message_tester.c call_tester.c presence_tester.c
liblinphone_tester_SOURCES= liblinphone_tester.c setup_tester.c register_tester.c message_tester.c call_tester.c presence_tester.c
#liblinphone_tester_CFLAGS=$(CUNIT_CFLAGS)
......
......@@ -15,6 +15,7 @@
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"
......@@ -22,13 +23,6 @@
#include "liblinphone_tester.h"
static int init(void) {
return 0;
}
static int uninit(void) {
return 0;
}
void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *msg){
char* to=linphone_address_as_string(linphone_call_get_call_log(call)->to);
char* from=linphone_address_as_string(linphone_call_get_call_log(call)->from);
......@@ -60,6 +54,7 @@ void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState
CU_FAIL("unexpected event");break;
}
}
void linphone_transfer_state_changed(LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state) {
char* to=linphone_address_as_string(linphone_call_get_call_log(transfered)->to);
char* from=linphone_address_as_string(linphone_call_get_call_log(transfered)->from);
......@@ -80,6 +75,7 @@ void linphone_transfer_state_changed(LinphoneCore *lc, LinphoneCall *transfered,
CU_FAIL("unexpected event");break;
}
}
static void linphone_call_cb(LinphoneCall *call,void * user_data) {
char* to=linphone_address_as_string(linphone_call_get_call_log(call)->to);
char* from=linphone_address_as_string(linphone_call_get_call_log(call)->from);
......@@ -90,6 +86,7 @@ static void linphone_call_cb(LinphoneCall *call,void * user_data) {
stats* counters = (stats*)linphone_core_get_user_data(lc);
counters->number_of_IframeDecoded++;
}
static bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr) {
LinphoneProxyConfig* proxy;
linphone_core_get_default_proxy(callee_mgr->lc,&proxy);
......@@ -140,7 +137,8 @@ static bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_m
wait_for(callee_mgr->lc,caller_mgr->lc,&callee_mgr->stat.number_of_LinphoneCallStreamsRunning,initial_callee.number_of_LinphoneCallStreamsRunning+1);
}
static void simple_call() {
static void simple_call(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
......@@ -180,7 +178,8 @@ static void simple_call() {
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
static void call_canceled() {
static void cancelled_call(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
......@@ -198,7 +197,7 @@ static void call_canceled() {
linphone_core_manager_destroy(pauline);
}
static void call_with_dns_time_out() {
static void call_with_dns_time_out(void) {
LinphoneCoreManager* marie = linphone_core_manager_new(NULL);
LCSipTransports transport = {9773,0,0,0};
linphone_core_set_sip_transports(marie->lc,&transport);
......@@ -213,7 +212,7 @@ static void call_with_dns_time_out() {
linphone_core_manager_destroy(marie);
}
static void call_ringing_canceled() {
static void cancelled_ringing_call(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
......@@ -231,7 +230,7 @@ static void call_ringing_canceled() {
linphone_core_manager_destroy(pauline);
}
static void call_early_declined() {
static void early_declined_call(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
......@@ -252,7 +251,7 @@ static void call_early_declined() {
linphone_core_manager_destroy(pauline);
}
static void call_terminated_by_caller() {
static void call_terminated_by_caller(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
......@@ -266,7 +265,7 @@ static void call_terminated_by_caller() {
linphone_core_manager_destroy(pauline);
}
static void call_paused_resumed() {
static void call_paused_resumed(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
LinphoneCall* call_obj;
......@@ -303,7 +302,8 @@ static bool_t pause_call_1(LinphoneCoreManager* mgr_1,LinphoneCall* call_1,Linph
CU_ASSERT_EQUAL(linphone_call_get_state(call_2),LinphoneCallPausedByRemote);
return linphone_call_get_state(call_1) == LinphoneCallPaused && linphone_call_get_state(call_2)==LinphoneCallPausedByRemote;
}
static void call_paused_resumed_from_callee() {
static void call_paused_resumed_from_callee(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
LinphoneCall* call_obj;
......@@ -329,7 +329,7 @@ static void call_paused_resumed_from_callee() {
linphone_core_manager_destroy(pauline);
}
static void call_with_video_added() {
static void call_with_video_added(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
LinphoneCall* call_obj;
......@@ -371,7 +371,8 @@ static void call_with_video_added() {
linphone_core_manager_destroy(marie);
linphone_core_manager_destroy(pauline);
}
static void simple_conference() {
static void simple_conference(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
stats initial_marie_stat;
stats initial_pauline_stat;
......@@ -428,8 +429,7 @@ static void simple_conference() {
ms_list_free(lcs);
}
static void call_srtp() {
static void srtp_call(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
......@@ -450,7 +450,7 @@ static void call_srtp() {
linphone_core_manager_destroy(pauline);
}
static void call_early_media() {
static void early_media_call(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_early_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
......@@ -468,22 +468,19 @@ static void call_early_media() {
linphone_core_manager_destroy(pauline);
}
static void simple_call_transfer() {
static void simple_call_transfer(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
LinphoneCoreManager* laure = linphone_core_manager_new("./tester/laure_rc");
LinphoneCall* pauline_called_by_marie;
char* laure_identity=linphone_address_as_string(laure->identity);
MSList* lcs=ms_list_append(NULL,marie->lc);
lcs=ms_list_append(lcs,pauline->lc);
lcs=ms_list_append(lcs,laure->lc);
LinphoneCall* marie_call_pauline;
LinphoneCall* pauline_called_by_marie;
CU_ASSERT_TRUE(call(marie,pauline));
marie_call_pauline=linphone_core_get_current_call(marie->lc);
pauline_called_by_marie=linphone_core_get_current_call(pauline->lc);
reset_counters(&marie->stat);
......@@ -520,7 +517,7 @@ static void simple_call_transfer() {
ms_list_free(lcs);
}
static void call_transfer_existing_call_outgoing_call() {
static void call_transfer_existing_call_outgoing_call(void) {
LinphoneCoreManager* marie = linphone_core_manager_new("./tester/marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new("./tester/pauline_rc");
LinphoneCoreManager* laure = linphone_core_manager_new("./tester/laure_rc");
......@@ -593,51 +590,29 @@ static void call_transfer_existing_call_outgoing_call() {
ms_list_free(lcs);
}
int call_test_suite () {
CU_pSuite pSuite = CU_add_suite("Call", init, uninit);
if (NULL == CU_add_test(pSuite, "call_early_declined", call_early_declined)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_canceled", call_canceled)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_with_dns_time_out", call_with_dns_time_out)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_ringing_canceled", call_ringing_canceled)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "simple_call", simple_call)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_early_media", call_early_media)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_terminated_by_caller", call_terminated_by_caller)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_paused_resumed", call_paused_resumed)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_paused_resumed_from_callee", call_paused_resumed_from_callee)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_srtp", call_srtp)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_with_video_added", call_with_video_added)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "simple_conference", simple_conference)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "simple_call_transfer", simple_call_transfer)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "call_transfer_existing_call_outgoing_call", call_transfer_existing_call_outgoing_call)) {
return CU_get_error();
}
test_t call_tests[] = {
{ "Early declined call", early_declined_call },
{ "Cancelled call", cancelled_call },
{ "Call with DNS timeout", call_with_dns_time_out },
{ "Cancelled ringing call", cancelled_ringing_call },
{ "Simple call", simple_call },
{ "Early-media call", early_media_call },
{ "Call terminated by caller", call_terminated_by_caller },
{ "Call paused resumed", call_paused_resumed },
{ "Call paused resumed from callee", call_paused_resumed_from_callee },
{ "SRTP call", srtp_call },
{ "Call with video added", call_with_video_added },
{ "Simple conference", simple_conference },
{ "Simple call transfer", simple_call_transfer },
{ "Call transfer existing call outgoing call", call_transfer_existing_call_outgoing_call }
};
test_suite_t call_test_suite = {
"Call",
NULL,
NULL,
sizeof(call_tests) / sizeof(call_tests[0]),
call_tests
};
return 0;
}
......@@ -22,24 +22,21 @@
#include "liblinphone_tester.h"
static test_suite_t **test_suite = NULL;
static int nb_test_suites = 0;
#if HAVE_CU_CURSES
static unsigned char curses = 0;
#endif
static stats global_stat;
const char* test_domain="sipopen.example.org";
const char* auth_domain="sip.example.org";
const char* test_username="liblinphone_tester";
const char* test_password="secret";
static int init(void) {
return 0;
}
static int uninit(void) {
return 0;
}
static void core_init_test(void) {
LinphoneCoreVTable v_table;
memset (&v_table,0,sizeof(v_table));
LinphoneCore* lc = linphone_core_new(&v_table,NULL,NULL,NULL);
CU_ASSERT_PTR_NOT_NULL_FATAL(lc);
linphone_core_destroy(lc);
}
LinphoneAddress * create_linphone_address(const char * domain) {
LinphoneAddress *addr = linphone_address_new(NULL);
......@@ -54,13 +51,6 @@ LinphoneAddress * create_linphone_address(const char * domain) {
CU_ASSERT_STRING_EQUAL("Mr Tester",linphone_address_get_display_name(addr));
return addr;
}
static void linphone_address_test(void) {
linphone_address_destroy(create_linphone_address(NULL));
}
static stats global_stat;
void auth_info_requested(LinphoneCore *lc, const char *realm, const char *username) {
ms_message("Auth info requested for user id [%s] at realm [%s]\n"
......@@ -110,8 +100,6 @@ LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* file,in
return lc;
}
bool_t wait_for(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value) {
MSList* lcs=NULL;
if (lc_1)
......@@ -123,6 +111,7 @@ bool_t wait_for(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value) {
ms_list_free(lcs);
return result;
}
bool_t wait_for_list(MSList* lcs,int* counter,int value,int timeout_ms) {
int retry=0;
MSList* iterator;
......@@ -135,6 +124,7 @@ bool_t wait_for_list(MSList* lcs,int* counter,int value,int timeout_ms) {
if(*counter<value) return FALSE;
else return TRUE;
}
static void enable_codec(LinphoneCore* lc,const char* type,int rate) {
MSList* codecs=ms_list_copy(linphone_core_get_audio_codecs(lc));
MSList* codecs_it;
......@@ -147,7 +137,6 @@ static void enable_codec(LinphoneCore* lc,const char* type,int rate) {
}
}
LinphoneCoreManager* linphone_core_manager_new(const char* rc_file) {
LinphoneCoreManager* mgr= malloc(sizeof(LinphoneCoreManager));
LinphoneProxyConfig* proxy;
......@@ -169,6 +158,7 @@ LinphoneCoreManager* linphone_core_manager_new(const char* rc_file) {
}
return mgr;
}
void linphone_core_manager_destroy(LinphoneCoreManager* mgr) {
linphone_core_destroy(mgr->lc);
if (mgr->identity) linphone_address_destroy(mgr->identity);
......@@ -176,44 +166,152 @@ void linphone_core_manager_destroy(LinphoneCoreManager* mgr) {
}
static void add_test_suite(test_suite_t *suite) {
if (test_suite == NULL) {
test_suite = (test_suite_t **)malloc(10 * sizeof(test_suite_t *));
}
test_suite[nb_test_suites] = suite;
nb_test_suites++;
if ((nb_test_suites % 10) == 0) {
test_suite = (test_suite_t **)realloc(test_suite, (nb_test_suites + 10) * sizeof(test_suite_t *));
}
}
int init_test_suite () {
static int run_test_suite(test_suite_t *suite) {
int i;
CU_pSuite pSuite = CU_add_suite("Setup", init, uninit);
CU_pSuite pSuite = CU_add_suite(suite->name, suite->init_func, suite->cleanup_func);
for (i = 0; i < suite->nb_tests; i++) {
if (NULL == CU_add_test(pSuite, suite->tests[i].name, suite->tests[i].func)) {
return CU_get_error();
}
}
if (NULL == CU_add_test(pSuite, "linphone address tester", linphone_address_test)) {
return CU_get_error();
return 0;
}
static int test_suite_index(const char *suite_name) {
int i;
for (i = 0; i < liblinphone_tester_nb_test_suites(); i++) {
if ((strcmp(suite_name, test_suite[i]->name) == 0) && (strlen(suite_name) == strlen(test_suite[i]->name))) {
return i;
}
}
if (NULL == CU_add_test(pSuite, "linphone core init/uninit tester", core_init_test)) {
return CU_get_error();
return -1;
}
int liblinphone_tester_nb_test_suites(void) {
return nb_test_suites;
}
int liblinphone_tester_nb_tests(const char *suite_name) {
int i = test_suite_index(suite_name);
if (i < 0) return 0;
return test_suite[i]->nb_tests;
}
const char * liblinphone_tester_test_suite_name(int suite_index) {
if (suite_index >= liblinphone_tester_nb_test_suites()) return NULL;
return test_suite[suite_index]->name;
}
const char * liblinphone_tester_test_name(const char *suite_name, int test_index) {
int suite_index = test_suite_index(suite_name);
if ((suite_index < 0) || (suite_index >= liblinphone_tester_nb_test_suites())) return NULL;
if (test_index >= test_suite[suite_index]->nb_tests) return NULL;
return test_suite[suite_index]->tests[test_index].name;
}
void liblinphone_tester_init(void) {
add_test_suite(&setup_test_suite);
add_test_suite(&register_test_suite);
add_test_suite(&call_test_suite);
add_test_suite(&message_test_suite);
add_test_suite(&presence_test_suite);
}
void liblinphone_tester_uninit(void) {
if (test_suite != NULL) {
free(test_suite);
test_suite = NULL;
nb_test_suites = 0;
}
}
register_test_suite();
int liblinphone_tester_run_tests(const char *suite_name, const char *test_name) {
int i;
call_test_suite();
/* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry())
return CU_get_error();
message_test_suite();
for (i = 0; i < liblinphone_tester_nb_test_suites(); i++) {
run_test_suite(test_suite[i]);
}
presence_test_suite();
#if HAVE_CU_GET_SUITE
if (suite_name){
CU_pSuite suite;
CU_basic_set_mode(CU_BRM_VERBOSE);
suite=CU_get_suite(suite_name);
if (test_name) {
CU_pTest test=CU_get_test_by_name(test_name, suite);
CU_basic_run_test(suite, test);
} else
CU_basic_run_suite(suite);
} else
#endif
{
#if HAVE_CU_CURSES
if (curses) {
/* Run tests using the CUnit curses interface */
CU_curses_run_tests();
}
else
#endif
{
/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
}
}
return 0;
CU_cleanup_registry();
return CU_get_error();
}
#ifndef WINAPI_FAMILY_PHONE_APP
int main (int argc, char *argv[]) {
int i;
char *test_name=NULL;
int ret;
char *suite_name=NULL;
char *test_name=NULL;
for(i=1;i<argc;++i){
if (strcmp(argv[i],"--help")==0){
fprintf(stderr,"%s \t--help\n\t\t\t--verbose",argv[0]);
return 0;
fprintf(stderr,"%s \t--help\n"
"\t\t\t--verbose\n"
"\t\t\t--domain <test sip domain>\n"
"\t\t\t---auth-domain <test auth domain>\n"
#if HAVE_CU_GET_SUITE
"\t\t\t--suite <suite name>\n"
"\t\t\t--test <test name>\n"
#endif
#if HAVE_CU_CURSES
"\t\t\t--curses\n"
#endif
, argv[0]);
return 0;
}else if (strcmp(argv[i],"--verbose")==0){
linphone_core_enable_logs(NULL);
linphone_core_enable_logs(NULL);
}else if (strcmp(argv[i],"--domain")==0){
i++;
test_domain=argv[i];
} else if (strcmp(argv[i],"--auth-domain")==0){
}else if (strcmp(argv[i],"--auth-domain")==0){
i++;
auth_domain=argv[i];
}else if (strcmp(argv[i],"--test")==0){
......@@ -225,29 +323,10 @@ int main (int argc, char *argv[]) {
}
}
/* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry())
return CU_get_error();
init_test_suite();
/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
if (suite_name){
#if 1 /*HAVE_CU_GET_SUITE*/
CU_pSuite suite;
suite=CU_get_suite(suite_name);
if (test_name) {
CU_pTest test=CU_get_test_by_name(test_name, suite);
CU_basic_run_test(suite, test);
} else
CU_basic_run_suite(suite);
#else
fprintf(stderr,"Your CUnit version does not support suite selection.\n");
liblinphone_tester_init();
ret = liblinphone_tester_run_tests(suite_name, test_name);
liblinphone_tester_uninit();
return ret;
}
#endif
} else
CU_basic_run_tests();
CU_cleanup_registry();
return CU_get_error();
}
......@@ -21,6 +21,51 @@
#include "CUnit/Basic.h"
typedef void (*test_function_t)(void);
typedef int (*test_suite_function_t)(const char *name);
typedef struct {
const char *name;
test_function_t func;
} test_t;
typedef struct {
const char *name;
CU_InitializeFunc init_func;
CU_CleanupFunc cleanup_func;
int nb_tests;
test_t *tests;
} test_suite_t;
#ifdef __cplusplus
extern "C" {
#endif
extern test_suite_t setup_test_suite;
extern test_suite_t register_test_suite;
extern test_suite_t call_test_suite;
extern test_suite_t message_test_suite;
extern test_suite_t presence_test_suite;
extern int liblinphone_tester_nb_test_suites(void);
extern int liblinphone_tester_nb_tests(const char *suite_name);
extern const char * liblinphone_tester_test_suite_name(int suite_index);
extern const char * liblinphone_tester_test_name(const char *suite_name, int test_index);
extern void liblinphone_tester_init(void);
extern void liblinphone_tester_uninit(void);
extern int liblinphone_tester_run_tests(const char *suite_name, const char *test_name);
#ifdef __cplusplus
};
#endif
const char* test_domain;
const char* auth_domain;
const char* test_username;
......@@ -77,6 +122,7 @@ typedef struct _stats {
int number_of_IframeDecoded;
}stats;
typedef struct _LinphoneCoreManager {
LinphoneCoreVTable v_table;
LinphoneCore* lc;
......@@ -104,9 +150,7 @@ LinphoneAddress * create_linphone_address(const char * domain);
LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* file,int proxy_count);
bool_t wait_for(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value);
bool_t wait_for_list(MSList* lcs,int* counter,int value,int timeout_ms);
int call_test_suite ();