From d3d0573d133ee4c94ded736c4ec805eae9622898 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Tue, 3 Mar 2015 15:11:24 +0100 Subject: [PATCH 1/4] Tester: create tester_utils which contain factorized code for all testers (in progress) --- tester/Makefile.am | 31 +-- tester/accountmanager.c | 26 +-- tester/call_tester.c | 26 +-- tester/liblinphone_tester.c | 104 +-------- tester/liblinphone_tester.h | 22 +- tester/log_collection_tester.c | 6 +- tester/message_tester.c | 26 +-- tester/player_tester.c | 2 +- tester/register_tester.c | 51 ++--- tester/setup_tester.c | 5 +- tester/tester_utils.c | 392 +++++++++++++++++++++++++++++++++ tester/tester_utils.h | 77 +++++++ tester/video_tester.c | 2 +- 13 files changed, 566 insertions(+), 204 deletions(-) create mode 100644 tester/tester_utils.c create mode 100644 tester/tester_utils.h diff --git a/tester/Makefile.am b/tester/Makefile.am index 9e5731950..bc05e61e7 100644 --- a/tester/Makefile.am +++ b/tester/Makefile.am @@ -11,26 +11,27 @@ liblinphone_HEADERS = liblinphone_tester.h lib_LTLIBRARIES = liblinphonetester.la liblinphonetester_la_SOURCES = tester.c \ - setup_tester.c \ - register_tester.c \ - message_tester.c \ + accountmanager.c \ call_tester.c \ - multicast_call_tester.c \ - presence_tester.c \ - upnp_tester.c \ + dtmf_tester.c \ eventapi_tester.c \ flexisip_tester.c \ - stun_tester.c \ - remote_provisioning_tester.c \ - quality_reporting_tester.c \ log_collection_tester.c \ - transport_tester.c \ - player_tester.c \ - dtmf_tester.c \ - accountmanager.c \ + message_tester.c \ + multi_call.c \ + multicast_call_tester.c \ offeranswer_tester.c \ - video_tester.c \ - multi_call.c + player_tester.c \ + presence_tester.c \ + quality_reporting_tester.c \ + register_tester.c \ + remote_provisioning_tester.c \ + setup_tester.c \ + stun_tester.c \ + tester_utils.c \ + transport_tester.c \ + upnp_tester.c \ + video_tester.c liblinphonetester_la_LDFLAGS= -no-undefined liblinphonetester_la_LIBADD= ../coreapi/liblinphone.la $(CUNIT_LIBS) diff --git a/tester/accountmanager.c b/tester/accountmanager.c index 80bc7942e..f987b3895 100644 --- a/tester/accountmanager.c +++ b/tester/accountmanager.c @@ -33,7 +33,7 @@ typedef struct _Account Account; Account *account_new(LinphoneAddress *identity, const char *unique_id){ char *modified_username; Account *obj=ms_new0(Account,1); - + /* we need to inhibit leak detector because the two LinphoneAddress will remain behond the scope of the test being run */ belle_sip_object_inhibit_leak_detector(TRUE); obj->identity=linphone_address_clone(identity); @@ -82,7 +82,7 @@ void account_manager_destroy(void){ Account *account_manager_get_account(AccountManager *m, const LinphoneAddress *identity){ MSList *it; - + for(it=m->accounts;it!=NULL;it=it->next){ Account *a=(Account*)it->data; if (linphone_address_weak_equal(a->identity,identity)){ @@ -120,15 +120,15 @@ void account_create_on_server(Account *account, const LinphoneProxyConfig *refcf char *tmp; LinphoneAddress *server_addr; LCSipTransports tr; - + vtable.registration_state_changed=account_created_on_server_cb; vtable.auth_info_requested=account_created_auth_requested_cb; - lc=configure_lc_from(&vtable,liblinphone_tester_file_prefix,NULL,account); + lc=configure_lc_from(&vtable,tester_file_prefix,NULL,account); tr.udp_port=LC_SIP_TRANSPORT_RANDOM; tr.tcp_port=LC_SIP_TRANSPORT_RANDOM; tr.tls_port=LC_SIP_TRANSPORT_RANDOM; linphone_core_set_sip_transports(lc,&tr); - + cfg=linphone_core_create_proxy_config(lc); linphone_address_set_secure(tmp_identity, FALSE); linphone_address_set_password(tmp_identity,account->password); @@ -137,7 +137,7 @@ void account_create_on_server(Account *account, const LinphoneProxyConfig *refcf linphone_proxy_config_set_identity(cfg,tmp); ms_free(tmp); linphone_address_unref(tmp_identity); - + server_addr=linphone_address_new(linphone_proxy_config_get_server_addr(refcfg)); linphone_address_set_secure(server_addr, FALSE); linphone_address_set_transport(server_addr,LinphoneTransportTcp); /*use tcp for account creation, we may not have certificates configured at this stage*/ @@ -147,9 +147,9 @@ void account_create_on_server(Account *account, const LinphoneProxyConfig *refcf ms_free(tmp); linphone_address_unref(server_addr); linphone_proxy_config_set_expires(cfg,3600); - + linphone_core_add_proxy_config(lc,cfg); - + if (wait_for_until(lc,NULL,&account->auth_requested,1,10000)==FALSE){ ms_fatal("Account for %s could not be created on server.", linphone_proxy_config_get_identity(refcfg)); } @@ -161,13 +161,13 @@ void account_create_on_server(Account *account, const LinphoneProxyConfig *refcf linphone_address_unref(tmp_identity); ms_free(tmp); linphone_proxy_config_done(cfg); - + ai=linphone_auth_info_new(linphone_address_get_username(account->modified_identity), NULL, account->password,NULL,NULL,linphone_address_get_domain(account->modified_identity)); linphone_core_add_auth_info(lc,ai); linphone_auth_info_destroy(ai); - + if (wait_for_until(lc,NULL,&account->created,1,3000)==FALSE){ ms_fatal("Account for %s is not working on server.", linphone_proxy_config_get_identity(refcfg)); } @@ -187,7 +187,7 @@ LinphoneAddress *account_manager_check_account(AccountManager *m, LinphoneProxyC LinphoneAuthInfo *ai; char *tmp; bool_t create_account=FALSE; - + if (!account){ account=account_new(id_addr,m->unique_id); ms_message("No account for %s exists, going to create one.",identity); @@ -199,7 +199,7 @@ LinphoneAddress *account_manager_check_account(AccountManager *m, LinphoneProxyC tmp=linphone_address_as_string(id_addr); linphone_proxy_config_set_identity(cfg,tmp); ms_free(tmp); - + if (create_account){ account_create_on_server(account,cfg); } @@ -208,7 +208,7 @@ LinphoneAddress *account_manager_check_account(AccountManager *m, LinphoneProxyC account->password,NULL,NULL,linphone_address_get_domain(account->modified_identity)); linphone_core_add_auth_info(lc,ai); linphone_auth_info_destroy(ai); - + linphone_address_unref(id_addr); return account->modified_identity; } diff --git a/tester/call_tester.c b/tester/call_tester.c index f431ff8cb..4e8c657e5 100644 --- a/tester/call_tester.c +++ b/tester/call_tester.c @@ -1616,8 +1616,8 @@ static void video_call_base(LinphoneCoreManager* pauline,LinphoneCoreManager* ma } if (mode==LinphoneMediaEncryptionDTLS) { /* for DTLS we must access certificates or at least have a directory to store them */ - marie->lc->user_certificates_path = ms_strdup_printf("%s/certificates/marie", liblinphone_tester_file_prefix); - pauline->lc->user_certificates_path = ms_strdup_printf("%s/certificates/pauline", liblinphone_tester_file_prefix); + marie->lc->user_certificates_path = ms_strdup_printf("%s/certificates/marie", tester_file_prefix); + pauline->lc->user_certificates_path = ms_strdup_printf("%s/certificates/pauline", tester_file_prefix); } linphone_core_set_media_encryption(marie->lc,mode); @@ -2055,12 +2055,12 @@ static void call_with_file_player(void) { LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); LinphonePlayer *player; char hellopath[256]; - char *recordpath = create_filepath(liblinphone_tester_writable_dir_prefix, "record", "wav"); + char *recordpath = create_filepath(tester_writable_dir_prefix, "record", "wav"); /*make sure the record file doesn't already exists, otherwise this test will append new samples to it*/ unlink(recordpath); - snprintf(hellopath,sizeof(hellopath), "%s/sounds/hello8000.wav", liblinphone_tester_file_prefix); + snprintf(hellopath,sizeof(hellopath), "%s/sounds/hello8000.wav", tester_file_prefix); /*caller uses files instead of soundcard in order to avoid mixing soundcard input with file played using call's player*/ linphone_core_use_files(marie->lc,TRUE); @@ -2133,12 +2133,12 @@ static void call_with_mkv_file_player(void) { ms_warning("Test skipped, no mkv support."); goto end; } - recordpath = create_filepath(liblinphone_tester_writable_dir_prefix, "record", "wav"); + recordpath = create_filepath(tester_writable_dir_prefix, "record", "wav"); /*make sure the record file doesn't already exists, otherwise this test will append new samples to it*/ unlink(recordpath); - snprintf(hellowav,sizeof(hellowav), "%s/sounds/hello8000_mkv_ref.wav", liblinphone_tester_file_prefix); - snprintf(hellomkv,sizeof(hellomkv), "%s/sounds/hello8000.mkv", liblinphone_tester_file_prefix); + snprintf(hellowav,sizeof(hellowav), "%s/sounds/hello8000_mkv_ref.wav", tester_file_prefix); + snprintf(hellomkv,sizeof(hellomkv), "%s/sounds/hello8000.mkv", tester_file_prefix); /*caller uses files instead of soundcard in order to avoid mixing soundcard input with file played using call's player*/ linphone_core_use_files(marie->lc,TRUE); @@ -2216,8 +2216,8 @@ void call_base(LinphoneMediaEncryption mode, bool_t enable_video,bool_t enable_r linphone_core_set_media_encryption(marie->lc,mode); linphone_core_set_media_encryption(pauline->lc,mode); if (mode==LinphoneMediaEncryptionDTLS) { /* for DTLS we must access certificates or at least have a directory to store them */ - marie->lc->user_certificates_path = ms_strdup_printf("%s/certificates/marie", liblinphone_tester_file_prefix); - pauline->lc->user_certificates_path = ms_strdup_printf("%s/certificates/pauline", liblinphone_tester_file_prefix); + marie->lc->user_certificates_path = ms_strdup_printf("%s/certificates/marie", tester_file_prefix); + pauline->lc->user_certificates_path = ms_strdup_printf("%s/certificates/pauline", tester_file_prefix); } linphone_core_set_firewall_policy(marie->lc,policy); @@ -2849,7 +2849,7 @@ static void record_call(const char *filename, bool_t enableVideo) { formats = linphone_core_get_supported_file_formats(marie->lc); for(i=0, format = formats[0]; format != NULL; i++, format = formats[i]) { - filepath = create_filepath(liblinphone_tester_writable_dir_prefix, filename, format); + filepath = create_filepath(tester_writable_dir_prefix, filename, format); remove(filepath); linphone_call_params_set_record_file(marieParams, filepath); CU_ASSERT_TRUE(call_succeeded = call_with_params(marie, pauline, marieParams, paulineParams)); @@ -2887,7 +2887,7 @@ static void video_call_snapshot(void) { LinphoneCallParams *marieParams = linphone_core_create_default_call_parameters(marie->lc); LinphoneCallParams *paulineParams = linphone_core_create_default_call_parameters(pauline->lc); LinphoneCall *callInst = NULL; - char *filename = create_filepath(liblinphone_tester_writable_dir_prefix, "snapshot", "jpeg"); + char *filename = create_filepath(tester_writable_dir_prefix, "snapshot", "jpeg"); int dummy = 0; bool_t call_succeeded = FALSE; @@ -3331,8 +3331,8 @@ static void call_with_generic_cn(void) { LinphoneCoreManager* marie; LinphoneCoreManager* pauline; LinphoneCall *pauline_call; - char *audio_file_with_silence=ms_strdup_printf("%s/%s",liblinphone_tester_file_prefix,"sounds/ahbahouaismaisbon.wav"); - char *recorded_file=ms_strdup_printf("%s/%s",liblinphone_tester_writable_dir_prefix,"result.wav"); + char *audio_file_with_silence=ms_strdup_printf("%s/%s",tester_file_prefix,"sounds/ahbahouaismaisbon.wav"); + char *recorded_file=ms_strdup_printf("%s/%s",tester_writable_dir_prefix,"result.wav"); belle_sip_object_enable_leak_detector(TRUE); begin=belle_sip_object_get_object_count(); diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index 0411af166..b97a5632c 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -28,8 +28,6 @@ #include #endif -extern int liblinphone_tester_use_log_file; - #ifdef ANDROID #include @@ -132,45 +130,15 @@ static void liblinphone_tester_qnx_log_handler(OrtpLogLevel lev, const char *fmt -void helper(const char *name) { - liblinphone_tester_fprintf(stderr,"%s --help\n" - "\t\t\t--verbose\n" - "\t\t\t--silent\n" - "\t\t\t--list-suites\n" - "\t\t\t--list-tests \n" +static const char* liblinphone_helper = "\t\t\t--config \n" "\t\t\t--domain \n" "\t\t\t--auth-domain \n" - "\t\t\t--suite \n" - "\t\t\t--test \n" - "\t\t\t--dns-hosts \n" - "\t\t\t--log-file \n" -#if HAVE_CU_CURSES - "\t\t\t--curses\n" -#endif - "\t\t\t--xml\n" - "\t\t\t--xml-file \n" - , name); -} - -#define CHECK_ARG(argument, index, argc) \ -if(index >= argc) { \ -fprintf(stderr, "Missing argument for \"%s\"\n", argument); \ -return -1; \ -} \ + "\t\t\t--dns-hosts \n"; #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int main (int argc, char *argv[]) { - int i; - int ret; - const char *suite_name=NULL; - const char *test_name=NULL; - const char *xml_file="CUnitAutomated-Results.xml"; - char *xml_tmp_file=NULL; - int xml = 0; - FILE* log_file=NULL; - #ifdef HAVE_GTK gtk_init(&argc, &argv); #if !GLIB_CHECK_VERSION(2,32,0) // backward compatibility with Debian 6 and CentOS 6 @@ -190,83 +158,23 @@ int main (int argc, char *argv[]) liblinphone_tester_init(); for(i=1;i0) i += ret; + else return ret; } } - - if( xml && (suite_name || test_name) ){ - printf("Cannot use both xml and specific test suite\n"); - return -1; - } - - if( xml ){ - xml_tmp_file = ms_strdup_printf("%s.tmp", xml_file); - liblinphone_tester_set_xml_output(xml_tmp_file); - } - liblinphone_tester_enable_xml(xml); - - ret = liblinphone_tester_run_tests(suite_name, test_name); - liblinphone_tester_uninit(); - - if ( xml ) { - /*create real xml file only if tester did not crash*/ - ms_strcat_printf(xml_tmp_file, "-Results.xml"); - rename(xml_tmp_file, xml_file); - ms_free(xml_tmp_file); - } - return ret; } #endif diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index 8df680545..7afc0dc90 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -22,34 +22,16 @@ -#include "CUnit/Basic.h" +#include "tester_utils.h" #include "linphonecore.h" #ifdef HAVE_CONFIG_H #include "config.h" #endif -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 const char *liblinphone_tester_file_prefix; -extern const char *liblinphone_tester_writable_dir_prefix; extern test_suite_t setup_test_suite; extern test_suite_t register_test_suite; extern test_suite_t call_test_suite; @@ -241,7 +223,7 @@ typedef struct _stats { int number_of_rtcp_received; int number_of_video_windows_created; - + int number_of_LinphoneFileTransferDownloadSuccessful; int number_of_LinphoneCoreLogCollectionUploadStateDelivered; int number_of_LinphoneCoreLogCollectionUploadStateNotDelivered; diff --git a/tester/log_collection_tester.c b/tester/log_collection_tester.c index ba6311497..35436bbcd 100644 --- a/tester/log_collection_tester.c +++ b/tester/log_collection_tester.c @@ -67,7 +67,7 @@ static size_t getline(char **lineptr, size_t *n, FILE *stream) { p = bufptr; while(c != EOF) { size_t curpos = p-bufptr; - + if (curpos > (size - 1)) { size = size + 128; bufptr = realloc(bufptr, size); @@ -94,7 +94,7 @@ static size_t getline(char **lineptr, size_t *n, FILE *stream) { static LinphoneLogCollectionState old_collection_state; static void collect_init() { old_collection_state = linphone_core_log_collection_enabled(); - linphone_core_set_log_collection_path(liblinphone_tester_writable_dir_prefix); + linphone_core_set_log_collection_path(tester_writable_dir_prefix); } static void collect_cleanup(LinphoneCoreManager *marie) { @@ -171,7 +171,7 @@ static time_t check_file(LinphoneCoreManager* mgr) { CU_ASSERT_PTR_NOT_NULL(file); if (!file) return 0; // 1) expect to find folder name in filename path - CU_ASSERT_PTR_NOT_NULL(strstr(filepath, liblinphone_tester_writable_dir_prefix)); + CU_ASSERT_PTR_NOT_NULL(strstr(filepath, tester_writable_dir_prefix)); // 2) check file contents while (getline(&line, &line_size, file) != -1) { diff --git a/tester/message_tester.c b/tester/message_tester.c index 0a9fd26bd..1ed21c964 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -68,7 +68,7 @@ void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* char receive_file[256]; LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(message); LinphoneCore *lc = linphone_chat_room_get_core(cr); - snprintf(receive_file,sizeof(receive_file), "%s/receive_file.dump", liblinphone_tester_writable_dir_prefix); + snprintf(receive_file,sizeof(receive_file), "%s/receive_file.dump", tester_writable_dir_prefix); if (!linphone_chat_message_get_user_data(message)) { /*first chunk, creating file*/ file = fopen(receive_file,"wb"); @@ -462,8 +462,8 @@ static void file_transfer_message(void) { LinphoneContent* content; FILE *file_to_send = NULL; size_t file_size; - char *send_filepath = ms_strdup_printf("%s/images/nowebcamCIF.jpg", liblinphone_tester_file_prefix); - char *receive_filepath = ms_strdup_printf("%s/receive_file.dump", liblinphone_tester_writable_dir_prefix); + char *send_filepath = ms_strdup_printf("%s/images/nowebcamCIF.jpg", tester_file_prefix); + char *receive_filepath = ms_strdup_printf("%s/receive_file.dump", tester_writable_dir_prefix); LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); @@ -944,15 +944,15 @@ static void file_transfer_using_external_body_url(void) { /* create a chatroom on pauline's side */ to = linphone_address_as_string(marie->identity); chat_room = linphone_core_create_chat_room(pauline->lc,to); - + message = linphone_chat_room_create_message(chat_room, NULL); - + cbs = linphone_chat_message_get_callbacks(message); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); - + linphone_chat_message_set_external_body_url(message, "https://www.linphone.org:444//tmp/54ec58280ace9_c30709218df8eaba61d1.jpg"); linphone_chat_room_send_chat_message(chat_room, message); - + CU_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1)); if (marie->stat.last_received_chat_message) { linphone_chat_message_download_file(marie->stat.last_received_chat_message); @@ -1391,8 +1391,8 @@ static void message_storage_migration() { char src_db[256]; char tmp_db[256]; MSList* chatrooms; - snprintf(src_db,sizeof(src_db), "%s/messages.db", liblinphone_tester_file_prefix); - snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", liblinphone_tester_writable_dir_prefix); + snprintf(src_db,sizeof(src_db), "%s/messages.db", tester_file_prefix); + snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", tester_writable_dir_prefix); CU_ASSERT_EQUAL_FATAL(message_tester_copy_file(src_db, tmp_db), 0); @@ -1431,8 +1431,8 @@ static void history_range_full_test(){ LinphoneChatRoom *chatroom; char src_db[256]; char tmp_db[256]; - snprintf(src_db,sizeof(src_db), "%s/messages.db", liblinphone_tester_file_prefix); - snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", liblinphone_tester_writable_dir_prefix); + snprintf(src_db,sizeof(src_db), "%s/messages.db", tester_file_prefix); + snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", tester_writable_dir_prefix); CU_ASSERT_EQUAL_FATAL(message_tester_copy_file(src_db, tmp_db), 0); @@ -1473,8 +1473,8 @@ static void history_messages_count() { MSList *messages; char src_db[256]; char tmp_db[256]; - snprintf(src_db,sizeof(src_db), "%s/messages.db", liblinphone_tester_file_prefix); - snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", liblinphone_tester_writable_dir_prefix); + snprintf(src_db,sizeof(src_db), "%s/messages.db", tester_file_prefix); + snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", tester_writable_dir_prefix); CU_ASSERT_EQUAL_FATAL(message_tester_copy_file(src_db, tmp_db), 0); diff --git a/tester/player_tester.c b/tester/player_tester.c index beb6e9d19..2264ba7dd 100644 --- a/tester/player_tester.c +++ b/tester/player_tester.c @@ -71,7 +71,7 @@ static void play_file(const char *filename, bool_t unsupported_format, const cha } static void playing_test(void) { - char *filename = ms_strdup_printf("%s/sounds/hello_opus_h264.mkv", liblinphone_tester_file_prefix); + char *filename = ms_strdup_printf("%s/sounds/hello_opus_h264.mkv", tester_file_prefix); const char *audio_mime = "opus"; const char *video_mime = "h264"; play_file(filename, !linphone_local_player_matroska_supported(), audio_mime, video_mime); diff --git a/tester/register_tester.c b/tester/register_tester.c index b0687352d..00c98e5fa 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -18,6 +18,7 @@ #include #include "CUnit/Basic.h" +#include "tester_utils.h" #include "linphonecore.h" #include "private.h" #include "liblinphone_tester.h" @@ -34,13 +35,13 @@ static void auth_info_requested(LinphoneCore *lc, const char *realm, const char static LinphoneCoreManager* create_lcm_with_auth(unsigned int with_auth) { LinphoneCoreManager* mgr=linphone_core_manager_new(NULL); - + if (with_auth) { LinphoneCoreVTable* vtable = linphone_core_v_table_new(); vtable->auth_info_requested=auth_info_requested; linphone_core_add_listener(mgr->lc,vtable); } - + /*to allow testing with 127.0.0.1*/ linphone_core_set_network_reachable(mgr->lc,TRUE); return mgr; @@ -195,12 +196,12 @@ static void register_with_custom_headers(void){ LinphoneProxyConfig *cfg=linphone_core_get_default_proxy_config(marie->lc); int initial_register_ok=marie->stat.number_of_LinphoneRegistrationOk; const char *value; - + linphone_core_set_network_reachable(marie->lc, FALSE); linphone_proxy_config_set_custom_header(cfg, "ah-bah-ouais", "...mais bon."); /*unfortunately it is difficult to programmatically check that sent custom headers are actually sent. * A server development would be required here.*/ - + linphone_core_set_network_reachable(marie->lc, TRUE); wait_for(marie->lc, NULL, &marie->stat.number_of_LinphoneRegistrationOk,initial_register_ok+1); value=linphone_proxy_config_get_custom_header(cfg, "Server"); @@ -336,11 +337,11 @@ static void authenticated_register_with_no_initial_credentials(){ LinphoneCoreVTable* vtable = linphone_core_v_table_new(); stats* counters; char route[256]; - + sprintf(route,"sip:%s",test_route); - + mgr = linphone_core_manager_new(NULL); - + vtable->auth_info_requested=auth_info_requested; linphone_core_add_listener(mgr->lc,vtable); @@ -357,9 +358,9 @@ static void authenticated_register_with_late_credentials(){ stats* counters; LCSipTransports transport = {5070,5070,0,5071}; char route[256]; - + sprintf(route,"sip:%s",test_route); - + mgr = linphone_core_manager_new(NULL); counters = get_stats(mgr->lc); @@ -397,9 +398,9 @@ static void authenticated_register_with_wrong_credentials_with_params_base(const LCSipTransports transport = {5070,5070,0,5071}; LinphoneAuthInfo *info=linphone_auth_info_new(test_username,NULL,"wrong passwd",NULL,auth_domain,NULL); /*create authentication structure from identity*/ char route[256]; - + sprintf(route,"sip:%s",test_route); - + sal_set_refresher_retry_after(mgr->lc->sal,500); if (user_agent) { linphone_core_set_user_agent(mgr->lc,user_agent,NULL); @@ -411,7 +412,7 @@ static void authenticated_register_with_wrong_credentials_with_params_base(const /*wait for retry*/ CU_ASSERT_TRUE(wait_for(mgr->lc,mgr->lc,&counters->number_of_auth_info_requested,4)); CU_ASSERT_EQUAL(counters->number_of_LinphoneRegistrationFailed,1); - + /*check the detailed error info */ if (!user_agent || strcmp(user_agent,"tester-no-403")!=0){ LinphoneProxyConfig *cfg=NULL; @@ -425,7 +426,7 @@ static void authenticated_register_with_wrong_credentials_with_params_base(const CU_ASSERT_EQUAL(linphone_error_info_get_protocol_code(ei),403); CU_ASSERT_PTR_NULL(linphone_error_info_get_details(ei)); } - + } } static void authenticated_register_with_wrong_credentials_with_params(const char* user_agent) { @@ -474,7 +475,7 @@ static void network_state_change(){ stats *counters; LinphoneCoreManager *mgr=configure_lcm(); LinphoneCore *lc=mgr->lc; - + counters = get_stats(lc); register_ok=counters->number_of_LinphoneRegistrationOk; linphone_core_set_network_reachable(lc,FALSE); @@ -507,7 +508,7 @@ static void transport_change(){ int number_of_udp_proxy=0; int total_number_of_proxies; memset(&sip_tr,0,sizeof(sip_tr)); - + mgr=configure_lcm(); lc=mgr->lc; counters = get_stats(lc); @@ -630,7 +631,7 @@ static void io_recv_error(){ stats* counters ; int number_of_udp_proxy=0; - + mgr=configure_lcm(); lc=mgr->lc; counters = get_stats(lc); @@ -716,7 +717,7 @@ static void io_recv_error_without_active_register(){ mgr=configure_lcm(); lc=mgr->lc; counters = get_stats(lc); - + register_ok=counters->number_of_LinphoneRegistrationOk; number_of_udp_proxy=get_number_of_udp_proxy(lc); @@ -747,17 +748,17 @@ static void tls_certificate_failure(){ LinphoneCoreManager* mgr; LinphoneCore *lc; char rootcapath[256]; - + mgr=linphone_core_manager_new2("pauline_rc",FALSE); lc=mgr->lc; - snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/agent.pem", liblinphone_tester_file_prefix); /*bad root ca*/ + snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/agent.pem", tester_file_prefix); /*bad root ca*/ linphone_core_set_root_ca(mgr->lc,rootcapath); linphone_core_set_network_reachable(lc,TRUE); CU_ASSERT_TRUE(wait_for(mgr->lc,mgr->lc,&mgr->stat.number_of_LinphoneRegistrationFailed,1)); linphone_core_set_root_ca(mgr->lc,NULL); /*no root ca*/ linphone_core_refresh_registers(mgr->lc); CU_ASSERT_TRUE(wait_for(lc,lc,&mgr->stat.number_of_LinphoneRegistrationFailed,2)); - snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", liblinphone_tester_file_prefix); /*goot root ca*/ + snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", tester_file_prefix); /*goot root ca*/ linphone_core_set_root_ca(mgr->lc,rootcapath); linphone_core_refresh_registers(mgr->lc); CU_ASSERT_TRUE(wait_for(lc,lc,&mgr->stat.number_of_LinphoneRegistrationOk,1)); @@ -772,7 +773,7 @@ static void tls_with_non_tls_server(){ LinphoneAddress* addr; char tmp[256]; LinphoneCore *lc; - + mgr=linphone_core_manager_new2( "marie_rc", 0); lc=mgr->lc; sal_set_transport_timeout(lc->sal,3000); @@ -792,10 +793,10 @@ static void tls_alt_name_register(){ LinphoneCoreManager* mgr; LinphoneCore *lc; char rootcapath[256]; - + mgr=linphone_core_manager_new2("pauline_alt_rc",FALSE); lc=mgr->lc; - snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", liblinphone_tester_file_prefix); + snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", tester_file_prefix); linphone_core_set_root_ca(mgr->lc,rootcapath); linphone_core_refresh_registers(mgr->lc); CU_ASSERT_TRUE(wait_for(lc,lc,&mgr->stat.number_of_LinphoneRegistrationOk,1)); @@ -807,10 +808,10 @@ static void tls_wildcard_register(){ LinphoneCoreManager* mgr; LinphoneCore *lc; char rootcapath[256]; - + mgr=linphone_core_manager_new2("pauline_wild_rc",FALSE); lc=mgr->lc; - snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", liblinphone_tester_file_prefix); + snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", tester_file_prefix); linphone_core_set_root_ca(mgr->lc,rootcapath); linphone_core_refresh_registers(mgr->lc); CU_ASSERT_TRUE(wait_for(lc,lc,&mgr->stat.number_of_LinphoneRegistrationOk,2)); diff --git a/tester/setup_tester.c b/tester/setup_tester.c index 06d734d6a..89ebe6438 100644 --- a/tester/setup_tester.c +++ b/tester/setup_tester.c @@ -18,6 +18,7 @@ #include #include "CUnit/Basic.h" +#include "tester_utils.h" #include "linphonecore.h" #include "liblinphone_tester.h" #include "lpconfig.h" @@ -128,7 +129,7 @@ static void linphone_lpconfig_from_buffer_zerolen_value(){ static void linphone_lpconfig_from_file_zerolen_value(){ /* parameters that have no value should return NULL, not "". */ const char* zero_rc_file = "zero_length_params_rc"; - char* rc_path = ms_strdup_printf("%s/rcfiles/%s", liblinphone_tester_file_prefix, zero_rc_file); + char* rc_path = ms_strdup_printf("%s/rcfiles/%s", tester_file_prefix, zero_rc_file); LpConfig* conf; /* not using lp_config_new() because it expects a readable file, and iOS (for instance) @@ -149,7 +150,7 @@ static void linphone_lpconfig_from_file_zerolen_value(){ static void linphone_lpconfig_from_xml_zerolen_value(){ const char* zero_xml_file = "remote_zero_length_params_rc"; - char* xml_path = ms_strdup_printf("%s/rcfiles/%s", liblinphone_tester_file_prefix, zero_xml_file); + char* xml_path = ms_strdup_printf("%s/rcfiles/%s", tester_file_prefix, zero_xml_file); LpConfig* conf; LinphoneCoreManager* mgr = linphone_core_manager_new2("empty_rc",FALSE); diff --git a/tester/tester_utils.c b/tester/tester_utils.c new file mode 100644 index 000000000..341aecd38 --- /dev/null +++ b/tester/tester_utils.c @@ -0,0 +1,392 @@ +/* +tester - liblinphone test suite +Copyright (C) 2013 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 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. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#define tester_fprintf fprintf +#define ms_warning printf +#define ms_fatal abort + +#include "tester_utils.h" + +#include + +#if WINAPI_FAMILY_PHONE_APP +const char *tester_file_prefix="Assets"; +#elif defined(__QNX__) +const char *tester_file_prefix="./app/native/assets/"; +#else +const char *tester_file_prefix="."; +#endif + +/* TODO: have the same "static" for QNX and windows as above? */ +#ifdef ANDROID +const char *tester_writable_dir_prefix = "/data/data/org.linphone.tester/cache"; +#else +const char *tester_writable_dir_prefix = "."; +#endif + +static test_suite_t **test_suite = NULL; +static int nb_test_suites = 0; + +#if HAVE_CU_CURSES +static unsigned char curses = 0; +#endif + +int tester_use_log_file = 0; +char* tester_xml_file = NULL; +int tester_xml_enabled = FALSE; +char * suite_name; +char * test_name; + +void helper(const char *name, const char* additionnal_helper) { + fprintf(stderr,"%s --help\n" + "\t\t\t--verbose\n" + "\t\t\t--silent\n" + "\t\t\t--list-suites\n" + "\t\t\t--list-tests \n" + "\t\t\t--suite \n" + "\t\t\t--test \n" + "\t\t\t--log-file \n" +#if HAVE_CU_CURSES + "\t\t\t--curses\n" +#endif + "\t\t\t--xml\n" + "\t\t\t--xml-file \n" + "And additionnaly:\n" + "%s" + , name + , additionnal_helper); +} + +int parge_args(int argc, char **argv, int argid, const char * additionnal_helper) +{ + int i = argid; + + if (strcmp(argv[i],"--help")==0){ + helper(argv[0], additionnal_helper); + return -1; +// } else if (strcmp(argv[i],"--verbose")==0){ +// linphone_core_set_log_level(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL); +// } else if (strcmp(argv[i],"--silent")==0){ +// linphone_core_set_log_level(ORTP_FATAL); + } else if (strcmp(argv[i],"--test")==0){ + CHECK_ARG("--test", ++i, argc); + test_name=argv[i]; + }else if (strcmp(argv[i],"--suite")==0){ + CHECK_ARG("--suite", ++i, argc); + suite_name=argv[i]; + } else if (strcmp(argv[i],"--list-suites")==0){ + tester_list_suites(); + return -1; + } else if (strcmp(argv[i],"--list-tests")==0){ + CHECK_ARG("--list-tests", ++i, argc); + suite_name = argv[i]; + tester_list_suite_tests(suite_name); + return -1; + } else if (strcmp(argv[i], "--xml-file") == 0){ + CHECK_ARG("--xml-file", ++i, argc); + tester_xml_file = argv[i]; + tester_xml_enabled = 1; + } else if (strcmp(argv[i], "--xml") == 0){ + tester_xml_enabled = 1; + } else if (strcmp(argv[i],"--log-file")==0){ + CHECK_ARG("--log-file", ++i, argc); + FILE *log_file=fopen(argv[i],"w"); + if (!log_file) { + ms_fatal("Cannot open file [%s] for writting logs because [%s]",argv[i],strerror(errno)); + } else { + tester_use_log_file=1; + tester_fprintf(stdout,"Redirecting traces to file [%s]",argv[i]); + // linphone_core_set_log_file(log_file); + } + }else { + tester_fprintf(stderr, "Unknown option \"%s\"\n", argv[i]); + helper(argv[0], additionnal_helper); + return -2; + } + + if( tester_xml_enabled && (suite_name || test_name) ){ + printf("Cannot use both xml and specific test suite\n"); + return -1; + } + + /* returns number of arguments read */ + return i - argid; +} + +int tester_start() { + int ret; + char * xml_tmp_file; + if( tester_xml_enabled ){ + xml_tmp_file = ms_strdup_printf("%s.tmp", tester_xml_file); + } + + ret = tester_run_tests(suite_name, test_name); + tester_uninit(); + + if ( tester_xml_enabled ) { + /*create real xml file only if tester did not crash*/ + ms_strcat_printf(xml_tmp_file, "-Results.xml"); + rename(xml_tmp_file, tester_xml_file); + ms_free(xml_tmp_file); + } + return ret; +} + + +int tester_test_suite_index(const char *suite_name) { + int i; + + for (i = 0; i < tester_nb_test_suites(); i++) { + if ((strcmp(suite_name, test_suite[i]->name) == 0) && (strlen(suite_name) == strlen(test_suite[i]->name))) { + return i; + } + } + + return -1; +} + +void tester_list_suites() { + int j; + for(j=0;jnb_tests; i++) { + if ((strcmp(test_name, test_suite[j]->tests[i].name) == 0) && (strlen(test_name) == strlen(test_suite[j]->tests[i].name))) { + return i; + } + } + } + + return -1; +} + +int tester_nb_test_suites(void) { + return nb_test_suites; +} + +int tester_nb_tests(const char *suite_name) { + int i = tester_test_suite_index(suite_name); + if (i < 0) return 0; + return test_suite[i]->nb_tests; +} + +const char * tester_test_suite_name(int suite_index) { + if (suite_index >= tester_nb_test_suites()) return NULL; + return test_suite[suite_index]->name; +} + +const char * tester_test_name(const char *suite_name, int test_index) { + int suite_index = tester_test_suite_index(suite_name); + if ((suite_index < 0) || (suite_index >= 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; +} + +static void test_all_tests_complete_message_handler(const CU_pFailureRecord pFailure) { +#ifdef HAVE_CU_GET_SUITE + char * results = CU_get_run_results_string(); + if (liblinphone_tester_use_log_file) { + ms_warning("\n\n %s", results); + } + tester_fprintf(stdout,"\n\n %s",results); + ms_free(results); +#endif +} + +static void test_suite_init_failure_message_handler(const CU_pSuite pSuite) { + if (liblinphone_tester_use_log_file) ms_warning("Suite initialization failed for [%s].", pSuite->pName); + tester_fprintf(stdout,"Suite initialization failed for [%s].", pSuite->pName); +} + +static void test_suite_cleanup_failure_message_handler(const CU_pSuite pSuite) { + if (liblinphone_tester_use_log_file) ms_warning("Suite cleanup failed for '%s'.", pSuite->pName); + tester_fprintf(stdout,"Suite cleanup failed for [%s].", pSuite->pName); +} + +#ifdef HAVE_CU_GET_SUITE +static void test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite) { + if (liblinphone_tester_use_log_file) ms_warning("Suite [%s] Test [%s]", pSuite->pName,pTest->pName); + tester_fprintf(stdout,"\nSuite [%s] Test [%s]\n", pSuite->pName,pTest->pName); +} + +static void test_suite_start_message_handler(const CU_pSuite pSuite) { + if (liblinphone_tester_use_log_file) ms_warning("Suite [%s]", pSuite->pName); + tester_fprintf(stdout,"\nSuite [%s]", pSuite->pName); +} +#endif + +/*derivated from cunit*/ +static void test_complete_message_handler(const CU_pTest pTest, + const CU_pSuite pSuite, + const CU_pFailureRecord pFailureList) { + int i; + CU_pFailureRecord pFailure = pFailureList; + if (pFailure) { + if (liblinphone_tester_use_log_file) ms_warning("Suite [%s], Test [%s] had failures:", pSuite->pName, pTest->pName); + tester_fprintf(stdout,"\nSuite [%s], Test [%s] had failures:", pSuite->pName, pTest->pName); + } else { + if (liblinphone_tester_use_log_file) ms_warning(" passed"); + tester_fprintf(stdout," passed"); + } + for (i = 1 ; (NULL != pFailure) ; pFailure = pFailure->pNext, i++) { + if (liblinphone_tester_use_log_file) ms_warning("\n %d. %s:%u - %s", i, + (NULL != pFailure->strFileName) ? pFailure->strFileName : "", + pFailure->uiLineNumber, + (NULL != pFailure->strCondition) ? pFailure->strCondition : ""); + tester_fprintf(stdout,"\n %d. %s:%u - %s", i, + (NULL != pFailure->strFileName) ? pFailure->strFileName : "", + pFailure->uiLineNumber, + (NULL != pFailure->strCondition) ? pFailure->strCondition : ""); + } +} + +int tester_run_tests(const char *suite_name, const char *test_name) { + int i; + int ret; +/* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + for (i = 0; i < tester_nb_test_suites(); i++) { + tester_run_suite(test_suite[i]); + } +#ifdef HAVE_CU_GET_SUITE + CU_set_test_start_handler(test_start_message_handler); +#endif + CU_set_test_complete_handler(test_complete_message_handler); + CU_set_all_test_complete_handler(test_all_tests_complete_message_handler); + CU_set_suite_init_failure_handler(test_suite_init_failure_message_handler); + CU_set_suite_cleanup_failure_handler(test_suite_cleanup_failure_message_handler); +#ifdef HAVE_CU_GET_SUITE + CU_set_suite_start_handler(test_suite_start_message_handler); +#endif + if( tester_xml_file != NULL ){ + CU_set_output_filename(tester_xml_file); + } + if( tester_xml_enabled != 0 ){ + CU_automated_run_tests(); + } else { + +#if !HAVE_CU_GET_SUITE + if( suite_name ){ + ms_warning("Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'\n", suite_name); + } +#else + if (!test_name && suite_name && strcmp("Call",suite_name) == 0) { + /*special case for suite Call which is now splitted into simple and multi*/ + CU_run_suite(CU_get_suite("Single call")); + CU_run_suite(CU_get_suite("Multi call")); + } else if (suite_name){ + CU_pSuite suite; + suite=CU_get_suite(suite_name); + if (!suite) { + ms_error("Could not find suite '%s'. Available suites are:", suite_name); + liblinphone_tester_list_suites(); + return -1; + } else if (test_name) { + CU_pTest test=CU_get_test_by_name(test_name, suite); + if (!test) { + ms_error("Could not find test '%s' in suite '%s'. Available tests are:", test_name, suite_name); + // do not use suite_name here, since this method is case sensitive + liblinphone_tester_list_suite_tests(suite->pName); + return -2; + } else { + CU_ErrorCode err= CU_run_test(suite, test); + if (err != CUE_SUCCESS) ms_error("CU_basic_run_test error %d", err); + } + } else { + CU_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_run_all_tests(); + } + } + + } + ret=CU_get_number_of_tests_failed()!=0; + +/* Redisplay list of failed tests on end */ + if (CU_get_number_of_failure_records()){ + CU_basic_show_failures(CU_get_failure_list()); + tester_fprintf(stdout,"\n"); + } + + CU_cleanup_registry(); + + return ret; +} + +void tester_add_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 tester_run_suite(test_suite_t *suite) { + int i; + + 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(); + } + } + + return 0; +} + +void tester_uninit() { + if (test_suite != NULL) { + free(test_suite); + test_suite = NULL; + nb_test_suites = 0; + } +} diff --git a/tester/tester_utils.h b/tester/tester_utils.h new file mode 100644 index 000000000..890f5b249 --- /dev/null +++ b/tester/tester_utils.h @@ -0,0 +1,77 @@ +/* + tester - liblinphone test suite + Copyright (C) 2013 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 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. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +#ifndef TESTER_UTILS_H +#define TESTER_UTILS_H + +#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 const char *tester_file_prefix; +extern const char *tester_writable_dir_prefix; + +#define CHECK_ARG(argument, index, argc) \ +if(index >= argc) { \ +fprintf(stderr, "Missing argument for \"%s\"\n", argument); \ +return -1; \ +} \ + +int tester_parse_args(int argc, char** argv, int argid, const char * additionnal_helper); +int tester_start(); + + +int tester_test_suite_index(const char *suite_name); +void tester_list_suites(); +void tester_list_suite_tests(const char *suite_name); +int tester_test_index(const char *suite_name, const char *test_name); +int tester_nb_test_suites(void); +int tester_nb_tests(const char *suite_name); +const char * tester_test_suite_name(int suite_index); +const char * tester_test_name(const char *suite_name, int test_index); +int tester_run_tests(const char *suite_name, const char *test_name); + +void tester_add_suite(test_suite_t *suite); +int tester_run_suite(test_suite_t *suite); + +void tester_uninit(); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/tester/video_tester.c b/tester/video_tester.c index 8d912e26a..1e0032211 100644 --- a/tester/video_tester.c +++ b/tester/video_tester.c @@ -306,7 +306,7 @@ static void two_incoming_early_media_video_calls_test(void) { /* Configure early media audio to play ring during early-media and send remote ring back tone. */ linphone_core_set_ring_during_incoming_early_media(marie->lc, TRUE); - ringback_path = ms_strdup_printf("%s/sounds/ringback.wav", liblinphone_tester_file_prefix); + ringback_path = ms_strdup_printf("%s/sounds/ringback.wav", tester_file_prefix); linphone_core_set_remote_ringback_tone(marie->lc, ringback_path); ms_free(ringback_path); From 0887089bc67c615c130445f9675e7c8bc8e0e5de Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 13 Mar 2015 12:06:56 +0100 Subject: [PATCH 2/4] Tester: continuing --- configure.ac | 2 +- mediastreamer2 | 2 +- oRTP | 2 +- tester/Makefile.am | 9 +- tester/accountmanager.c | 2 +- tester/call_tester.c | 26 +- .../bc_tester_completion} | 0 tester/common/bc_tester_utils.c | 356 ++++++++++++++++ .../bc_tester_utils.h} | 30 +- tester/flexisip_tester.c | 232 +++++------ tester/liblinphone_tester.c | 128 ++++-- tester/liblinphone_tester.h | 24 +- tester/log_collection_tester.c | 4 +- tester/message_tester.c | 22 +- tester/player_tester.c | 2 +- tester/register_tester.c | 9 +- tester/setup_tester.c | 5 +- tester/tester.c | 361 +--------------- tester/tester_utils.c | 392 ------------------ tester/video_tester.c | 2 +- 20 files changed, 634 insertions(+), 976 deletions(-) rename tester/{liblinphone_completion => common/bc_tester_completion} (100%) create mode 100644 tester/common/bc_tester_utils.c rename tester/{tester_utils.h => common/bc_tester_utils.h} (65%) delete mode 100644 tester/tester_utils.c diff --git a/configure.ac b/configure.ac index 8cb6c0155..99276802c 100644 --- a/configure.ac +++ b/configure.ac @@ -30,7 +30,7 @@ AC_SUBST(LINPHONE_VERSION) AC_MSG_NOTICE([$PACKAGE_NAME-$PACKAGE_VERSION A full featured audio/video sip phone.]) AC_MSG_NOTICE([licensed under the terms of the General Public License (GPL)]) -AM_INIT_AUTOMAKE([1.9 tar-pax]) +AM_INIT_AUTOMAKE([1.9 tar-pax subdir-objects]) AC_SUBST([LIBTOOL_DEPS]) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])],) AC_SUBST([docdir], [${datadir}/doc]) diff --git a/mediastreamer2 b/mediastreamer2 index 2be165a12..429161741 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit 2be165a129a174a6b9a51574aee85f90d4f38084 +Subproject commit 42916174111a5db519f60d6b37ec115fef8d0436 diff --git a/oRTP b/oRTP index 3b0892f87..72522333e 160000 --- a/oRTP +++ b/oRTP @@ -1 +1 @@ -Subproject commit 3b0892f87fecbd7d3e2b34b381527ab1d7e59a59 +Subproject commit 72522333e7298cb2432dfa6316097a5d19698de8 diff --git a/tester/Makefile.am b/tester/Makefile.am index bc05e61e7..ece11eda7 100644 --- a/tester/Makefile.am +++ b/tester/Makefile.am @@ -10,7 +10,7 @@ liblinphone_HEADERS = liblinphone_tester.h lib_LTLIBRARIES = liblinphonetester.la -liblinphonetester_la_SOURCES = tester.c \ +liblinphonetester_la_SOURCES = \ accountmanager.c \ call_tester.c \ dtmf_tester.c \ @@ -28,16 +28,17 @@ liblinphonetester_la_SOURCES = tester.c \ remote_provisioning_tester.c \ setup_tester.c \ stun_tester.c \ - tester_utils.c \ transport_tester.c \ + tester.c \ upnp_tester.c \ - video_tester.c + video_tester.c \ + common/bc_tester_utils.c common/bc_tester_utils.h liblinphonetester_la_LDFLAGS= -no-undefined liblinphonetester_la_LIBADD= ../coreapi/liblinphone.la $(CUNIT_LIBS) AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/coreapi -AM_CFLAGS = $(STRICT_OPTIONS) $(STRICT_OPTIONS_CC) -DIN_LINPHONE $(ORTP_CFLAGS) $(MEDIASTREAMER_CFLAGS) $(CUNIT_CFLAGS) $(BELLESIP_CFLAGS) $(LIBXML2_CFLAGS) $(SQLITE3_CFLAGS) +AM_CFLAGS = -DBC_CONFIG_FILE=\"config.h\" $(STRICT_OPTIONS) $(STRICT_OPTIONS_CC) -DIN_LINPHONE $(ORTP_CFLAGS) $(MEDIASTREAMER_CFLAGS) $(CUNIT_CFLAGS) $(BELLESIP_CFLAGS) $(LIBXML2_CFLAGS) $(SQLITE3_CFLAGS) if BUILD_GTK_UI diff --git a/tester/accountmanager.c b/tester/accountmanager.c index f987b3895..d46c2064d 100644 --- a/tester/accountmanager.c +++ b/tester/accountmanager.c @@ -123,7 +123,7 @@ void account_create_on_server(Account *account, const LinphoneProxyConfig *refcf vtable.registration_state_changed=account_created_on_server_cb; vtable.auth_info_requested=account_created_auth_requested_cb; - lc=configure_lc_from(&vtable,tester_file_prefix,NULL,account); + lc=configure_lc_from(&vtable,bc_tester_read_dir_prefix,NULL,account); tr.udp_port=LC_SIP_TRANSPORT_RANDOM; tr.tcp_port=LC_SIP_TRANSPORT_RANDOM; tr.tls_port=LC_SIP_TRANSPORT_RANDOM; diff --git a/tester/call_tester.c b/tester/call_tester.c index 4e8c657e5..1f27e4653 100644 --- a/tester/call_tester.c +++ b/tester/call_tester.c @@ -1616,8 +1616,8 @@ static void video_call_base(LinphoneCoreManager* pauline,LinphoneCoreManager* ma } if (mode==LinphoneMediaEncryptionDTLS) { /* for DTLS we must access certificates or at least have a directory to store them */ - marie->lc->user_certificates_path = ms_strdup_printf("%s/certificates/marie", tester_file_prefix); - pauline->lc->user_certificates_path = ms_strdup_printf("%s/certificates/pauline", tester_file_prefix); + marie->lc->user_certificates_path = ms_strdup_printf("%s/certificates/marie", bc_tester_read_dir_prefix); + pauline->lc->user_certificates_path = ms_strdup_printf("%s/certificates/pauline", bc_tester_read_dir_prefix); } linphone_core_set_media_encryption(marie->lc,mode); @@ -2055,12 +2055,12 @@ static void call_with_file_player(void) { LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); LinphonePlayer *player; char hellopath[256]; - char *recordpath = create_filepath(tester_writable_dir_prefix, "record", "wav"); + char *recordpath = create_filepath(bc_tester_writable_dir_prefix, "record", "wav"); /*make sure the record file doesn't already exists, otherwise this test will append new samples to it*/ unlink(recordpath); - snprintf(hellopath,sizeof(hellopath), "%s/sounds/hello8000.wav", tester_file_prefix); + snprintf(hellopath,sizeof(hellopath), "%s/sounds/hello8000.wav", bc_tester_read_dir_prefix); /*caller uses files instead of soundcard in order to avoid mixing soundcard input with file played using call's player*/ linphone_core_use_files(marie->lc,TRUE); @@ -2133,12 +2133,12 @@ static void call_with_mkv_file_player(void) { ms_warning("Test skipped, no mkv support."); goto end; } - recordpath = create_filepath(tester_writable_dir_prefix, "record", "wav"); + recordpath = create_filepath(bc_tester_writable_dir_prefix, "record", "wav"); /*make sure the record file doesn't already exists, otherwise this test will append new samples to it*/ unlink(recordpath); - snprintf(hellowav,sizeof(hellowav), "%s/sounds/hello8000_mkv_ref.wav", tester_file_prefix); - snprintf(hellomkv,sizeof(hellomkv), "%s/sounds/hello8000.mkv", tester_file_prefix); + snprintf(hellowav,sizeof(hellowav), "%s/sounds/hello8000_mkv_ref.wav", bc_tester_read_dir_prefix); + snprintf(hellomkv,sizeof(hellomkv), "%s/sounds/hello8000.mkv", bc_tester_read_dir_prefix); /*caller uses files instead of soundcard in order to avoid mixing soundcard input with file played using call's player*/ linphone_core_use_files(marie->lc,TRUE); @@ -2216,8 +2216,8 @@ void call_base(LinphoneMediaEncryption mode, bool_t enable_video,bool_t enable_r linphone_core_set_media_encryption(marie->lc,mode); linphone_core_set_media_encryption(pauline->lc,mode); if (mode==LinphoneMediaEncryptionDTLS) { /* for DTLS we must access certificates or at least have a directory to store them */ - marie->lc->user_certificates_path = ms_strdup_printf("%s/certificates/marie", tester_file_prefix); - pauline->lc->user_certificates_path = ms_strdup_printf("%s/certificates/pauline", tester_file_prefix); + marie->lc->user_certificates_path = ms_strdup_printf("%s/certificates/marie", bc_tester_read_dir_prefix); + pauline->lc->user_certificates_path = ms_strdup_printf("%s/certificates/pauline", bc_tester_read_dir_prefix); } linphone_core_set_firewall_policy(marie->lc,policy); @@ -2849,7 +2849,7 @@ static void record_call(const char *filename, bool_t enableVideo) { formats = linphone_core_get_supported_file_formats(marie->lc); for(i=0, format = formats[0]; format != NULL; i++, format = formats[i]) { - filepath = create_filepath(tester_writable_dir_prefix, filename, format); + filepath = create_filepath(bc_tester_writable_dir_prefix, filename, format); remove(filepath); linphone_call_params_set_record_file(marieParams, filepath); CU_ASSERT_TRUE(call_succeeded = call_with_params(marie, pauline, marieParams, paulineParams)); @@ -2887,7 +2887,7 @@ static void video_call_snapshot(void) { LinphoneCallParams *marieParams = linphone_core_create_default_call_parameters(marie->lc); LinphoneCallParams *paulineParams = linphone_core_create_default_call_parameters(pauline->lc); LinphoneCall *callInst = NULL; - char *filename = create_filepath(tester_writable_dir_prefix, "snapshot", "jpeg"); + char *filename = create_filepath(bc_tester_writable_dir_prefix, "snapshot", "jpeg"); int dummy = 0; bool_t call_succeeded = FALSE; @@ -3331,8 +3331,8 @@ static void call_with_generic_cn(void) { LinphoneCoreManager* marie; LinphoneCoreManager* pauline; LinphoneCall *pauline_call; - char *audio_file_with_silence=ms_strdup_printf("%s/%s",tester_file_prefix,"sounds/ahbahouaismaisbon.wav"); - char *recorded_file=ms_strdup_printf("%s/%s",tester_writable_dir_prefix,"result.wav"); + char *audio_file_with_silence=ms_strdup_printf("%s/%s",bc_tester_read_dir_prefix,"sounds/ahbahouaismaisbon.wav"); + char *recorded_file=ms_strdup_printf("%s/%s",bc_tester_writable_dir_prefix,"result.wav"); belle_sip_object_enable_leak_detector(TRUE); begin=belle_sip_object_get_object_count(); diff --git a/tester/liblinphone_completion b/tester/common/bc_tester_completion similarity index 100% rename from tester/liblinphone_completion rename to tester/common/bc_tester_completion diff --git a/tester/common/bc_tester_utils.c b/tester/common/bc_tester_utils.c new file mode 100644 index 000000000..0c7bb7038 --- /dev/null +++ b/tester/common/bc_tester_utils.c @@ -0,0 +1,356 @@ +/* +tester - liblinphone test suite +Copyright (C) 2013 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 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. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + + +/* this must be provided at compile time*/ +#include BC_CONFIG_FILE + +#include "bc_tester_utils.h" + +#include +#include +#include "CUnit/Automated.h" + +#if WINAPI_FAMILY_PHONE_APP +const char *bc_tester_read_dir_prefix="Assets"; +#elif defined(__QNX__) +const char *bc_tester_read_dir_prefix="./app/native/assets/"; +#else +const char *bc_tester_read_dir_prefix="."; +#endif + +/* TODO: have the same "static" for QNX and windows as above? */ +#ifdef ANDROID +const char *bc_tester_writable_dir_prefix = "/data/data/org.linphone.tester/cache"; +#else +const char *bc_tester_writable_dir_prefix = "."; +#endif + +static test_suite_t **test_suite = NULL; +static int nb_test_suites = 0; + +#if HAVE_CU_CURSES +static unsigned char curses = 0; +#endif + +char* xml_file = NULL; +int xml_enabled = 0; +char * suite_name; +char * test_name; +void (*tester_printf_va)(int level, const char *fmt, va_list args); +int verbosity_info; +int verbosity_error; + +static void tester_printf(int level, const char *fmt, ...) { + va_list args; + va_start (args, fmt); + tester_printf_va(level, fmt, args); + va_end (args); +} + +static int tester_run_suite(test_suite_t *suite) { + int i; + + 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(); + } + } + + return 0; +} + +const char * tester_test_suite_name(int suite_index) { + if (suite_index >= nb_test_suites) return NULL; + return test_suite[suite_index]->name; +} + +static int tester_test_suite_index(const char *suite_name) { + int i; + + for (i = 0; i < nb_test_suites; i++) { + if ((strcmp(suite_name, test_suite[i]->name) == 0) && (strlen(suite_name) == strlen(test_suite[i]->name))) { + return i; + } + } + + return -1; +} +const char * tester_test_name(const char *suite_name, int test_index) { + int suite_index = tester_test_suite_index(suite_name); + if ((suite_index < 0) || (suite_index >= 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; +} + +static int tester_nb_tests(const char *suite_name) { + int i = tester_test_suite_index(suite_name); + if (i < 0) return 0; + return test_suite[i]->nb_tests; +} + +static void tester_list_suites() { + int j; + for(j=0;jpName); +} + +static void suite_cleanup_failure_message_handler(const CU_pSuite pSuite) { + tester_printf(verbosity_error,"Suite cleanup failed for [%s].", pSuite->pName); +} + +#ifdef HAVE_CU_GET_SUITE +static void suite_start_message_handler(const CU_pSuite pSuite) { + tester_printf(verbosity_info,"Suite [%s] started\n", pSuite->pName); +} +static void suite_complete_message_handler(const CU_pSuite pSuite, const CU_pFailureRecord pFailure) { + tester_printf(verbosity_info,"Suite [%s] ended\n", pSuite->pName); +} + +static void test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite) { + tester_printf(verbosity_info,"Suite [%s] Test [%s] started", pSuite->pName,pTest->pName); +} + +/*derivated from cunit*/ +static void test_complete_message_handler(const CU_pTest pTest, + const CU_pSuite pSuite, + const CU_pFailureRecord pFailureList) { + int i; + char * result = malloc(sizeof(char)*2048);//not very pretty but... + sprintf(result, "Suite [%s] Test [%s]", pSuite->pName, pTest->pName); + CU_pFailureRecord pFailure = pFailureList; + if (pFailure) { + strncat(result, " failed:", strlen(" failed:")); + for (i = 1 ; (NULL != pFailure) ; pFailure = pFailure->pNext, i++) { + sprintf(result, "%s\n %d. %s:%u - %s", result, i, + (NULL != pFailure->strFileName) ? pFailure->strFileName : "", + pFailure->uiLineNumber, + (NULL != pFailure->strCondition) ? pFailure->strCondition : ""); + } + } else { + strncat(result, " passed", strlen(" passed")); + } + tester_printf(verbosity_info,"%s\n", result); + free(result); +} +#endif + +static int tester_run_tests(const char *suite_name, const char *test_name) { + int i; + + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + for (i = 0; i < nb_test_suites; i++) { + tester_run_suite(test_suite[i]); + } +#ifdef HAVE_CU_GET_SUITE + CU_set_suite_start_handler(suite_start_message_handler); + CU_set_suite_complete_handler(suite_complete_message_handler); + CU_set_test_start_handler(test_start_message_handler); + CU_set_test_complete_handler(test_complete_message_handler); +#endif + CU_set_all_test_complete_handler(all_complete_message_handler); + CU_set_suite_init_failure_handler(suite_init_failure_message_handler); + CU_set_suite_cleanup_failure_handler(suite_cleanup_failure_message_handler); + + if( xml_enabled != 0 ){ + CU_automated_run_tests(); + } else { + +#if !HAVE_CU_GET_SUITE + if( suite_name ){ + tester_printf(verbosity_info, "Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'", suite_name); + } +#else + if (suite_name){ + CU_pSuite suite; + suite=CU_get_suite(suite_name); + if (!suite) { + tester_printf(verbosity_error, "Could not find suite '%s'. Available suites are:", suite_name); + tester_list_suites(); + return -1; + } else if (test_name) { + CU_pTest test=CU_get_test_by_name(test_name, suite); + if (!test) { + tester_printf(verbosity_error, "Could not find test '%s' in suite '%s'. Available tests are:", test_name, suite_name); + // do not use suite_name here, since this method is case sensitive + tester_list_suite_tests(suite->pName); + return -2; + } else { + CU_ErrorCode err= CU_run_test(suite, test); + if (err != CUE_SUCCESS) tester_printf(verbosity_error, "CU_basic_run_test error %d", err); + } + } else { + CU_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_run_all_tests(); + } + } + } + return CU_get_number_of_tests_failed()!=0; + +} + + +void bc_tester_helper(const char *name, const char* additionnal_helper) { + fprintf(stdout,"%s --help\n" + "\t\t\t--list-suites\n" + "\t\t\t--list-tests \n" + "\t\t\t--suite \n" + "\t\t\t--test \n" +#if HAVE_CU_CURSES + "\t\t\t--curses\n" +#endif + "\t\t\t--xml\n" + "\t\t\t--xml-file \n" + "And additionally:\n" + "%s" + , name + , additionnal_helper); +} + +void bc_tester_init(void (*ftester_printf)(int level, const char *fmt, va_list args), int iverbosity_info, int iverbosity_error) { + tester_printf_va = ftester_printf; + verbosity_error = iverbosity_error; + verbosity_info = iverbosity_info; +} + +int bc_tester_parse_args(int argc, char **argv, int argid) +{ + int i = argid; + + if (strcmp(argv[i],"--help")==0){ + return -1; + } else if (strcmp(argv[i],"--test")==0){ + CHECK_ARG("--test", ++i, argc); + test_name=argv[i]; + }else if (strcmp(argv[i],"--suite")==0){ + CHECK_ARG("--suite", ++i, argc); + suite_name=argv[i]; + } else if (strcmp(argv[i],"--list-suites")==0){ + tester_list_suites(); + return 0; + } else if (strcmp(argv[i],"--list-tests")==0){ + CHECK_ARG("--list-tests", ++i, argc); + suite_name = argv[i]; + tester_list_suite_tests(suite_name); + return 0; + } else if (strcmp(argv[i], "--xml-file") == 0){ + CHECK_ARG("--xml-file", ++i, argc); + xml_file = argv[i]; + xml_enabled = 1; + } else if (strcmp(argv[i], "--xml") == 0){ + xml_enabled = 1; + }else { + fprintf(stderr, "Unknown option \"%s\"\n", argv[i]); + return -1; + } + + if( xml_enabled && (suite_name || test_name) ){ + fprintf(stderr, "Cannot use both XML and specific test suite\n"); + return -1; + } + + /* returns number of arguments read + 1 */ + return i - argid + 1; +} + +int bc_tester_start() { + int ret; + if( xml_enabled ){ + char * xml_tmp_file = malloc(sizeof(char) * (strlen(xml_file) + strlen(".tmp") + 1)); + snprintf(xml_tmp_file, sizeof(xml_tmp_file), "%s.tmp", xml_file); + CU_set_output_filename(xml_tmp_file); + free(xml_tmp_file); + } + + ret = tester_run_tests(suite_name, test_name); + + return ret; +} +void bc_tester_add_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 *)); + } +} + +void bc_tester_uninit() { + /* Redisplay list of failed tests on end */ + if (CU_get_number_of_failure_records()){ + CU_basic_show_failures(CU_get_failure_list()); + tester_printf(verbosity_info,""); /*add missing final newline*/ + } + CU_cleanup_registry(); + + if( xml_enabled ){ + /*create real xml file only if tester did not crash*/ + char * xml_tmp_file = malloc(sizeof(char) * (strlen(xml_file) + strlen(".tmp") + 1)); + snprintf(xml_tmp_file, sizeof(xml_tmp_file), "%s.tmp", xml_file); + rename(xml_tmp_file, xml_file); + free(xml_tmp_file); + } + + if (test_suite != NULL) { + free(test_suite); + test_suite = NULL; + nb_test_suites = 0; + } +} diff --git a/tester/tester_utils.h b/tester/common/bc_tester_utils.h similarity index 65% rename from tester/tester_utils.h rename to tester/common/bc_tester_utils.h index 890f5b249..f12916c7f 100644 --- a/tester/tester_utils.h +++ b/tester/common/bc_tester_utils.h @@ -22,6 +22,9 @@ #include "CUnit/Basic.h" +extern const char *bc_tester_read_dir_prefix; +extern const char *bc_tester_writable_dir_prefix; + typedef void (*test_function_t)(void); typedef int (*test_suite_function_t)(const char *name); @@ -42,8 +45,6 @@ typedef struct { extern "C" { #endif -extern const char *tester_file_prefix; -extern const char *tester_writable_dir_prefix; #define CHECK_ARG(argument, index, argc) \ if(index >= argc) { \ @@ -51,24 +52,13 @@ fprintf(stderr, "Missing argument for \"%s\"\n", argument); \ return -1; \ } \ -int tester_parse_args(int argc, char** argv, int argid, const char * additionnal_helper); -int tester_start(); - - -int tester_test_suite_index(const char *suite_name); -void tester_list_suites(); -void tester_list_suite_tests(const char *suite_name); -int tester_test_index(const char *suite_name, const char *test_name); -int tester_nb_test_suites(void); -int tester_nb_tests(const char *suite_name); -const char * tester_test_suite_name(int suite_index); -const char * tester_test_name(const char *suite_name, int test_index); -int tester_run_tests(const char *suite_name, const char *test_name); - -void tester_add_suite(test_suite_t *suite); -int tester_run_suite(test_suite_t *suite); - -void tester_uninit(); +void bc_tester_init(void (*ftester_printf)(int level, const char *fmt, va_list args) + , int verbosity_info, int verbosity_error); +void bc_tester_helper(const char *name, const char* additionnal_helper); +int bc_tester_parse_args(int argc, char** argv, int argid); +int bc_tester_start(); +void bc_tester_add_suite(test_suite_t *suite); +void bc_tester_uninit(); #ifdef __cplusplus diff --git a/tester/flexisip_tester.c b/tester/flexisip_tester.c index a4f19aee6..5c7b9b11d 100644 --- a/tester/flexisip_tester.c +++ b/tester/flexisip_tester.c @@ -31,7 +31,7 @@ static void subscribe_forking(void) { LinphoneEvent *lev; int expires= 600; MSList* lcs=ms_list_append(NULL,marie->lc); - + lcs=ms_list_append(lcs,pauline->lc); lcs=ms_list_append(lcs,pauline2->lc); @@ -39,9 +39,9 @@ static void subscribe_forking(void) { linphone_content_set_type(content,"application"); linphone_content_set_subtype(content,"somexml"); linphone_content_set_buffer(content, liblinphone_tester_get_subscribe_content(), strlen(liblinphone_tester_get_subscribe_content())); - + lev=linphone_core_subscribe(marie->lc,pauline->identity,"dodo",expires,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,3000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline2->stat.number_of_LinphoneSubscriptionIncomingReceived,1,1000)); @@ -67,10 +67,10 @@ static void message_forking(void) { char* to = linphone_address_as_string(marie->identity); LinphoneChatRoom* chat_room = linphone_core_create_chat_room(pauline->lc,to); LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); - + lcs=ms_list_append(lcs,pauline->lc); lcs=ms_list_append(lcs,marie2->lc); - + linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneMessageReceived,1,3000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneMessageReceived,1,1000)); @@ -92,15 +92,15 @@ static void message_forking_with_unreachable_recipients(void) { char* to = linphone_address_as_string(marie->identity); LinphoneChatRoom* chat_room = linphone_core_create_chat_room(pauline->lc,to); LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); - + lcs=ms_list_append(lcs,pauline->lc); lcs=ms_list_append(lcs,marie2->lc); lcs=ms_list_append(lcs,marie3->lc); - + /*marie2 and marie3 go offline*/ linphone_core_set_network_reachable(marie2->lc,FALSE); linphone_core_set_network_reachable(marie3->lc,FALSE); - + linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneMessageReceived,1,3000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneMessageDelivered,1,1000)); @@ -110,14 +110,14 @@ static void message_forking_with_unreachable_recipients(void) { /*marie 2 goes online */ linphone_core_set_network_reachable(marie2->lc,TRUE); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneMessageReceived,1,3000)); - + /*wait a long time so that all transactions are expired*/ wait_for_list(lcs,NULL,0,32000); - + /*marie 3 goes online now*/ linphone_core_set_network_reachable(marie3->lc,TRUE); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneMessageReceived,1,3000)); - + linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); linphone_core_manager_destroy(pauline); @@ -134,40 +134,40 @@ static void message_forking_with_all_recipients_unreachable(void) { char* to = linphone_address_as_string(marie->identity); LinphoneChatRoom* chat_room = linphone_core_create_chat_room(pauline->lc,to); LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); - + lcs=ms_list_append(lcs,pauline->lc); lcs=ms_list_append(lcs,marie2->lc); lcs=ms_list_append(lcs,marie3->lc); - + /*All marie's device go offline*/ linphone_core_set_network_reachable(marie->lc,FALSE); linphone_core_set_network_reachable(marie2->lc,FALSE); linphone_core_set_network_reachable(marie3->lc,FALSE); - + linphone_chat_room_send_message2(chat_room,message,liblinphone_tester_chat_message_state_change,pauline->lc); - + CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneMessageInProgress,1,5000)); /*flexisip will accept the message with 202 after 16 seconds*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneMessageDelivered,1,18000)); CU_ASSERT_TRUE( marie->stat.number_of_LinphoneMessageReceived==0); CU_ASSERT_TRUE( marie2->stat.number_of_LinphoneMessageReceived==0); CU_ASSERT_TRUE( marie3->stat.number_of_LinphoneMessageReceived==0); - + /*marie 1 goes online */ linphone_core_set_network_reachable(marie->lc,TRUE); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneMessageReceived,1,3000)); - + /*marie 2 goes online */ linphone_core_set_network_reachable(marie2->lc,TRUE); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneMessageReceived,1,3000)); - + /*wait a long time so that all transactions are expired*/ wait_for_list(lcs,NULL,0,32000); - + /*marie 3 goes online now*/ linphone_core_set_network_reachable(marie3->lc,TRUE); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneMessageReceived,1,3000)); - + linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); linphone_core_manager_destroy(pauline); @@ -181,16 +181,16 @@ static void call_forking(void){ LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc"); MSList* lcs=ms_list_append(NULL,pauline->lc); - + lcs=ms_list_append(lcs,marie->lc); lcs=ms_list_append(lcs,marie2->lc); lcs=ms_list_append(lcs,marie3->lc); - + linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); - + linphone_core_invite_address(pauline->lc,marie->identity); /*pauline should hear ringback*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000)); @@ -198,22 +198,22 @@ static void call_forking(void){ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,3000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,3000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallIncomingReceived,1,3000)); - + /*marie accepts the call on its first device*/ linphone_core_accept_call(marie->lc,linphone_core_get_current_call(marie->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,1000)); - + /*other devices should stop ringing*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallEnd,1,1000)); - + linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000)); - + linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); @@ -227,38 +227,38 @@ static void call_forking_with_urgent_reply(void){ LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc"); MSList* lcs=ms_list_append(NULL,pauline->lc); - + lcs=ms_list_append(lcs,marie->lc); lcs=ms_list_append(lcs,marie2->lc); lcs=ms_list_append(lcs,marie3->lc); - + linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); - + CU_ASSERT_TRUE(linphone_core_media_encryption_supported(pauline->lc,LinphoneMediaEncryptionSRTP)); linphone_core_set_media_encryption(pauline->lc,LinphoneMediaEncryptionSRTP); linphone_core_set_network_reachable(marie2->lc,FALSE); linphone_core_set_network_reachable(marie3->lc,FALSE); - + linphone_core_invite_address(pauline->lc,marie->identity); /*pauline should hear ringback, after 5 seconds, when it will retry without SRTP*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,9000)); /*Marie should be ringing*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000)); - + /*marie accepts the call on its first device*/ linphone_core_accept_call(marie->lc,linphone_core_get_current_call(marie->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,1000)); - + linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000)); - + linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); @@ -272,16 +272,16 @@ static void call_forking_cancelled(void){ LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc"); MSList* lcs=ms_list_append(NULL,pauline->lc); - + lcs=ms_list_append(lcs,marie->lc); lcs=ms_list_append(lcs,marie2->lc); lcs=ms_list_append(lcs,marie3->lc); - + linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); - + linphone_core_invite_address(pauline->lc,marie->identity); /*pauline should hear ringback*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000)); @@ -289,16 +289,16 @@ static void call_forking_cancelled(void){ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallIncomingReceived,1,1000)); - + /*pauline finally cancels the call*/ linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000)); - + /*all devices should stop ringing*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallEnd,1,1000)); - + linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); @@ -312,16 +312,16 @@ static void call_forking_declined(bool_t declined_globaly){ LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc"); MSList* lcs=ms_list_append(NULL,pauline->lc); - + lcs=ms_list_append(lcs,marie->lc); lcs=ms_list_append(lcs,marie2->lc); lcs=ms_list_append(lcs,marie3->lc); - + linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); - + linphone_core_invite_address(pauline->lc,marie->identity); /*pauline should hear ringback*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000)); @@ -329,12 +329,12 @@ static void call_forking_declined(bool_t declined_globaly){ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallIncomingReceived,1,1000)); - + /*marie1 finally declines the call*/ linphone_core_decline_call(marie->lc,linphone_core_get_current_call(marie->lc), declined_globaly ? LinphoneReasonDeclined : LinphoneReasonBusy ); - + if (declined_globaly){ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000)); /*all devices should stop ringing*/ @@ -353,7 +353,7 @@ static void call_forking_declined(bool_t declined_globaly){ CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,3000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,3000)); } - + linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); @@ -373,40 +373,40 @@ static void call_forking_with_push_notification_single(void){ MSList* lcs; LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); - + linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); - + lcs=ms_list_append(NULL,pauline->lc); - + lcs=ms_list_append(lcs,marie->lc); - + /*unfortunately marie gets unreachable due to crappy 3G operator or iOS bug...*/ linphone_core_set_network_reachable(marie->lc,FALSE); - + linphone_core_invite_address(pauline->lc,marie->identity); - + /*the server is expected to send a push notification to marie, this will wake up linphone, that will reconnect:*/ linphone_core_set_network_reachable(marie->lc,TRUE); - + /*Marie shall receive the call immediately*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,5000)); /*pauline should hear ringback as well*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,1000)); - + /*marie accepts the call*/ linphone_core_accept_call(marie->lc,linphone_core_get_current_call(marie->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallConnected,1,5000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,1000)); - + liblinphone_tester_check_rtcp(pauline,marie); - + linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,5000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,5000)); - + linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); ms_list_free(lcs); @@ -416,49 +416,49 @@ static void call_forking_with_push_notification_multiple(void){ LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc"); - + MSList* lcs=ms_list_append(NULL,pauline->lc); - + lcs=ms_list_append(lcs,marie->lc); lcs=ms_list_append(lcs,marie2->lc); - + linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); - + /*unfortunately marie gets unreachable due to crappy 3G operator or iOS bug...*/ linphone_core_set_network_reachable(marie2->lc,FALSE); - + linphone_core_invite_address(pauline->lc,marie->identity); - + /*marie1 will ring*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,5000)); /*pauline should hear ringback as well*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,1000)); - + /*the server is expected to send a push notification to marie2, this will wake up linphone, that will reconnect:*/ linphone_core_set_network_reachable(marie2->lc,TRUE); - + /*Marie shall receive the call immediately*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,5000)); - + /*marie2 accepts the call*/ linphone_core_accept_call(marie2->lc,linphone_core_get_current_call(marie2->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallStreamsRunning,1,1000)); - + /*call to marie1 should be cancelled*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000)); - + liblinphone_tester_check_rtcp(pauline,marie2); - + linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc)); - + CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000)); - + linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); @@ -470,16 +470,16 @@ static void call_forking_not_responded(void){ LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc"); MSList* lcs=ms_list_append(NULL,pauline->lc); - + lcs=ms_list_append(lcs,marie->lc); lcs=ms_list_append(lcs,marie2->lc); lcs=ms_list_append(lcs,marie3->lc); - + linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); - + linphone_core_invite_address(pauline->lc,marie->identity); /*pauline should hear ringback*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000)); @@ -487,14 +487,14 @@ static void call_forking_not_responded(void){ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallIncomingReceived,1,1000)); - + /*nobody answers, flexisip should close the call after XX seconds*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallError,1,22000)); /*all devices should stop ringing*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallEnd,1,1000)); - + linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); @@ -516,28 +516,28 @@ static void early_media_call_forking(void) { pol.automatically_accept=1; pol.automatically_initiate=1; - + linphone_core_set_user_agent(marie1->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); - + linphone_core_enable_video(pauline->lc,TRUE,TRUE); - + linphone_core_enable_video(marie1->lc,TRUE,TRUE); linphone_core_set_video_policy(marie1->lc,&pol); - + linphone_core_enable_video(marie2->lc,TRUE,TRUE); linphone_core_set_video_policy(marie2->lc,&pol); linphone_core_set_audio_port_range(marie2->lc,40200,40300); linphone_core_set_video_port_range(marie2->lc,40400,40500); - + lcs=ms_list_append(lcs,marie1->lc); lcs=ms_list_append(lcs,marie2->lc); lcs=ms_list_append(lcs,pauline->lc); linphone_call_params_enable_early_media_sending(params,TRUE); linphone_call_params_enable_video(params,TRUE); - + linphone_core_invite_address_with_params(pauline->lc,marie1->identity,params); linphone_call_params_destroy(params); @@ -545,11 +545,11 @@ static void early_media_call_forking(void) { CU_ASSERT_TRUE(wait_for_list(lcs, &marie2->stat.number_of_LinphoneCallIncomingEarlyMedia,1,3000)); CU_ASSERT_TRUE(wait_for_list(lcs, &pauline->stat.number_of_LinphoneCallOutgoingEarlyMedia,1,3000)); CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneCallOutgoingEarlyMedia,1); - + pauline_call=linphone_core_get_current_call(pauline->lc); marie1_call=linphone_core_get_current_call(marie1->lc); marie2_call=linphone_core_get_current_call(marie2->lc); - + /*wait a bit that streams are established*/ wait_for_list(lcs,&dummy,1,6000); CU_ASSERT_TRUE(linphone_call_get_audio_stats(pauline_call)->download_bandwidth>60 @@ -558,21 +558,21 @@ static void early_media_call_forking(void) { && linphone_call_get_audio_stats(marie1_call)->download_bandwidth<99); CU_ASSERT_TRUE(linphone_call_get_audio_stats(marie2_call)->download_bandwidth>60 && linphone_call_get_audio_stats(marie2_call)->download_bandwidth<99); - + linphone_core_accept_call(marie1->lc,linphone_core_get_current_call(marie1->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie1->stat.number_of_LinphoneCallStreamsRunning,1,3000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,3000)); - + /*marie2 should get her call terminated*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000)); - + /*wait a bit that streams are established*/ wait_for_list(lcs,&dummy,1,3000); CU_ASSERT_TRUE(linphone_call_get_audio_stats(pauline_call)->download_bandwidth>60 && linphone_call_get_audio_stats(pauline_call)->download_bandwidth<99 ); CU_ASSERT_TRUE(linphone_call_get_audio_stats(marie1_call)->download_bandwidth>60 && linphone_call_get_audio_stats(marie1_call)->download_bandwidth<99 ); - + linphone_core_terminate_all_calls(pauline->lc); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,5000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie1->stat.number_of_LinphoneCallEnd,1,5000)); @@ -588,35 +588,35 @@ static void call_with_sips(void){ LinphoneCoreManager* pauline1 = linphone_core_manager_new( "pauline_sips_rc"); LinphoneCoreManager* pauline2 = linphone_core_manager_new( "pauline_tcp_rc"); MSList* lcs=ms_list_append(NULL,marie->lc); - + lcs=ms_list_append(lcs,pauline1->lc); lcs=ms_list_append(lcs,pauline2->lc); - + linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline1->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline2->lc,"Natted Linphone",NULL); - + linphone_core_invite_address(marie->lc,pauline1->identity); /*marie should hear ringback*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallOutgoingRinging,1,3000)); /*Only the sips registered device from pauline should ring*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_LinphoneCallIncomingReceived,1,1000)); - + /*pauline accepts the call */ linphone_core_accept_call(pauline1->lc,linphone_core_get_current_call(pauline1->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_LinphoneCallStreamsRunning,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,1000)); - + /*pauline2 should not have ring*/ CU_ASSERT_TRUE(pauline2->stat.number_of_LinphoneCallIncomingReceived==0); - + linphone_core_terminate_call(pauline1->lc,linphone_core_get_current_call(pauline1->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline1->stat.number_of_LinphoneCallEnd,1,3000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,3000)); - + linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline1); linphone_core_manager_destroy(pauline2); @@ -631,11 +631,11 @@ static void call_with_sips_not_achievable(void){ LinphoneAddress *dest; LinphoneCall *call; const LinphoneErrorInfo *ei; - + lcs=ms_list_append(lcs,pauline1->lc); lcs=ms_list_append(lcs,pauline2->lc); - + dest=linphone_address_clone(pauline1->identity); linphone_address_set_secure(dest,TRUE); call=linphone_core_invite_address(marie->lc,dest); @@ -649,7 +649,7 @@ static void call_with_sips_not_achievable(void){ if (ei){ CU_ASSERT_EQUAL(linphone_error_info_get_reason(ei), LinphoneReasonTemporarilyUnavailable); } - + linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline1); linphone_core_manager_destroy(pauline2); @@ -665,12 +665,12 @@ static void call_with_ipv6(void) { /*calling ortp_init() here is done to have WSAStartup() done, otherwise liblinphone_tester_ipv6_available() will not work.*/ ortp_init(); - + if (!liblinphone_tester_ipv6_available()){ ms_warning("Call with ipv6 not tested, no ipv6 connectivity"); return; } - + belle_sip_object_enable_leak_detector(TRUE); begin=belle_sip_object_get_object_count(); @@ -687,7 +687,7 @@ static void call_with_ipv6(void) { /*check that the remote contact is IPv6*/ const char *contact=linphone_call_get_remote_contact(pauline_call); LinphoneAddress *ct_addr; - + CU_ASSERT_PTR_NOT_NULL(contact); if (contact){ ct_addr=linphone_address_new(contact); @@ -697,7 +697,7 @@ static void call_with_ipv6(void) { } linphone_address_destroy(ct_addr); } - + } liblinphone_tester_check_rtcp(marie,pauline); @@ -722,14 +722,14 @@ static void file_transfer_message_rcs_to_external_body_client(void) { LinphoneContent* content; FILE *file_to_send = NULL; size_t file_size; - char *send_filepath = ms_strdup_printf("%s/images/nowebcamCIF.jpg", liblinphone_tester_file_prefix); - char *receive_filepath = ms_strdup_printf("%s/receive_file.dump", liblinphone_tester_writable_dir_prefix); - + char *send_filepath = ms_strdup_printf("%s/images/nowebcamCIF.jpg", bc_tester_read_dir_prefix); + char *receive_filepath = ms_strdup_printf("%s/receive_file.dump", bc_tester_writable_dir_prefix); + LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); reset_counters(&marie->stat); reset_counters(&pauline->stat); - + linphone_proxy_config_set_custom_header(marie->lc->default_proxy, NULL, NULL); linphone_core_refresh_registers(marie->lc); //TODO: remove the next two lines once linphone core will send the header automatically @@ -780,7 +780,7 @@ static void file_transfer_message_rcs_to_external_body_client(void) { CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageDelivered,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageExtBodyReceived,1); CU_ASSERT_TRUE(compare_files(send_filepath, receive_filepath)); - + linphone_content_unref(content); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); @@ -793,19 +793,19 @@ static void send_file_transfer_message_using_external_body_url(LinphoneCoreManag LinphoneChatMessageCbs *cbs; LinphoneChatRoom *chat_room; LinphoneChatMessage *message; - + /* create a chatroom on pauline's side */ to = linphone_address_as_string(marie->identity); chat_room = linphone_core_create_chat_room(pauline->lc,to); - + message = linphone_chat_room_create_message(chat_room, NULL); - + cbs = linphone_chat_message_get_callbacks(message); linphone_chat_message_cbs_set_msg_state_changed(cbs, liblinphone_tester_chat_message_msg_state_changed); - + linphone_chat_message_set_external_body_url(message, "https://www.linphone.org:444//tmp/54ec58280ace9_c30709218df8eaba61d1.jpg"); linphone_chat_room_send_chat_message(chat_room, message); - + CU_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneMessageReceived, 1)); if (marie->stat.last_received_chat_message) { linphone_chat_message_download_file(marie->stat.last_received_chat_message); @@ -821,12 +821,12 @@ static void file_transfer_message_external_body_to_external_body_client(void) { LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_rc"); reset_counters(&marie->stat); reset_counters(&pauline->stat); - + linphone_proxy_config_set_custom_header(marie->lc->default_proxy, NULL, NULL); linphone_proxy_config_set_custom_header(pauline->lc->default_proxy, NULL, NULL); linphone_core_refresh_registers(marie->lc); linphone_core_refresh_registers(pauline->lc); - + send_file_transfer_message_using_external_body_url(marie, pauline); linphone_core_manager_destroy(marie); @@ -838,13 +838,13 @@ static void file_transfer_message_external_body_to_rcs_client(void) { LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_rc"); reset_counters(&marie->stat); reset_counters(&pauline->stat); - + linphone_proxy_config_set_custom_header(marie->lc->default_proxy, NULL, NULL); linphone_core_refresh_registers(marie->lc); //TODO: remove the next two lines once linphone core will send the header automatically linphone_proxy_config_set_custom_header(pauline->lc->default_proxy, "Accept", "application/sdp, text/plain, application/vnd.gsma.rcs-ft-http+xml"); linphone_core_refresh_registers(pauline->lc); - + send_file_transfer_message_using_external_body_url(marie, pauline); linphone_core_manager_destroy(marie); diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index b97a5632c..d08585841 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -28,6 +28,10 @@ #include #endif + +static FILE * log_file = NULL; +static OrtpLogFunc ortp_log_handler; + #ifdef ANDROID #include @@ -41,7 +45,7 @@ static const char* LogDomain = "liblinphone_tester"; int main(int argc, char** argv); -void linphone_android_log_handler(int prio, const char *fmt, va_list args) { +void liblinphone_android_log_handler(int prio, const char *fmt, va_list args) { char str[4096]; char *current; char *next; @@ -61,17 +65,17 @@ void linphone_android_log_handler(int prio, const char *fmt, va_list args) { } } -static void linphone_android_ortp_log_handler(OrtpLogLevel lev, const char *fmt, va_list args) { +static void liblinphone_android_ortp_log_handler(OrtpLogLevel lev, const char *fmt, va_list args) { int prio; switch(lev){ - case ORTP_DEBUG: prio = ANDROID_LOG_DEBUG; break; - case ORTP_MESSAGE: prio = ANDROID_LOG_INFO; break; - case ORTP_WARNING: prio = ANDROID_LOG_WARN; break; - case ORTP_ERROR: prio = ANDROID_LOG_ERROR; break; - case ORTP_FATAL: prio = ANDROID_LOG_FATAL; break; - default: prio = ANDROID_LOG_DEFAULT; break; + case ORTP_DEBUG: prio = ANDROID_LOG_DEBUG; break; + case ORTP_MESSAGE: prio = ANDROID_LOG_INFO; break; + case ORTP_WARNING: prio = ANDROID_LOG_WARN; break; + case ORTP_ERROR: prio = ANDROID_LOG_ERROR; break; + case ORTP_FATAL: prio = ANDROID_LOG_FATAL; break; + default: prio = ANDROID_LOG_DEFAULT; break; } - linphone_android_log_handler(prio, fmt, args); + liblinphone_android_log_handler(prio, fmt, args); } void cunit_android_trace_handler(int level, const char *fmt, va_list args) { @@ -119,7 +123,6 @@ JNIEXPORT void JNICALL Java_org_linphone_tester_Tester_keepAccounts(JNIEnv *env, JNIEXPORT void JNICALL Java_org_linphone_tester_Tester_clearAccounts(JNIEnv *env, jclass c) { liblinphone_tester_clear_accounts(); } - #endif /* ANDROID */ #ifdef __QNX__ @@ -128,17 +131,72 @@ static void liblinphone_tester_qnx_log_handler(OrtpLogLevel lev, const char *fmt } #endif /* __QNX__ */ +static void log_handler(int lev, const char *fmt, va_list args) { + ortp_set_log_file(stderr); + ortp_log_handler(lev, fmt, args); + if (log_file){ + ortp_set_log_file(log_file); + ortp_log_handler(lev, fmt, args); + } +} + +void liblinphone_tester_init(void) { + ortp_log_handler = ortp_get_log_handler(); +#if defined(ANDROID) + linphone_core_set_log_handler(liblinphone_android_ortp_log_handler); +#elif defined(__QNX__) + linphone_core_set_log_handler(liblinphone_tester_qnx_log_handler); +#else + linphone_core_set_log_handler(ortp_logv_out); +#endif + + bc_tester_init(log_handler, ORTP_MESSAGE, ORTP_ERROR); + + bc_tester_add_suite(&setup_test_suite); + bc_tester_add_suite(®ister_test_suite); + bc_tester_add_suite(&offeranswer_test_suite); + bc_tester_add_suite(&call_test_suite); + bc_tester_add_suite(&multi_call_test_suite); + bc_tester_add_suite(&message_test_suite); + bc_tester_add_suite(&presence_test_suite); +#ifdef UPNP + bc_tester_add_suite(&upnp_test_suite); +#endif + bc_tester_add_suite(&stun_test_suite); + bc_tester_add_suite(&event_test_suite); + bc_tester_add_suite(&flexisip_test_suite); + bc_tester_add_suite(&remote_provisioning_test_suite); + bc_tester_add_suite(&quality_reporting_test_suite); + bc_tester_add_suite(&log_collection_test_suite); + bc_tester_add_suite(&transport_test_suite); + bc_tester_add_suite(&player_test_suite); + bc_tester_add_suite(&dtmf_test_suite); +#if defined(VIDEO_ENABLED) && defined(HAVE_GTK) + bc_tester_add_suite(&video_test_suite); +#endif + bc_tester_add_suite(&multicast_call_test_suite); +} + +void liblinphone_tester_uninit(void) { + bc_tester_uninit(); +} static const char* liblinphone_helper = - "\t\t\t--config \n" - "\t\t\t--domain \n" - "\t\t\t--auth-domain \n" - "\t\t\t--dns-hosts \n"; + "\t\t\t--verbose\n" + "\t\t\t--silent\n" + "\t\t\t--log-file \n" + "\t\t\t--config \n" + "\t\t\t--domain \n" + "\t\t\t--auth-domain \n" + "\t\t\t--dns-hosts \n"; #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) int main (int argc, char *argv[]) { + int i; + int ret; + #ifdef HAVE_GTK gtk_init(&argc, &argv); #if !GLIB_CHECK_VERSION(2,32,0) // backward compatibility with Debian 6 and CentOS 6 @@ -147,17 +205,22 @@ int main (int argc, char *argv[]) gdk_threads_init(); #endif -#if defined(ANDROID) - linphone_core_set_log_handler(linphone_android_ortp_log_handler); -#elif defined(__QNX__) - linphone_core_set_log_handler(liblinphone_tester_qnx_log_handler); -#else - linphone_core_set_log_file(NULL); -#endif - liblinphone_tester_init(); - for(i=1;i0) i += ret; - else return ret; + } else { + int ret = bc_tester_parse_args(argc, argv, i); + if (ret>1) { + i += ret - 1; + continue; + } else if (ret<0) { + bc_tester_helper(argv[0], liblinphone_helper); + } + return ret; } } + + ret = bc_tester_start(); + liblinphone_tester_uninit(); + return ret; } #endif diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index 7afc0dc90..7a65b0dbb 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -22,7 +22,7 @@ -#include "tester_utils.h" +#include "common/bc_tester_utils.h" #include "linphonecore.h" #ifdef HAVE_CONFIG_H #include "config.h" @@ -53,26 +53,8 @@ extern test_suite_t multicast_call_test_suite; extern test_suite_t multi_call_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 int liblinphone_tester_test_suite_index(const char *suite_name); -extern void liblinphone_tester_list_suites(); -extern void liblinphone_tester_list_suite_tests(const char *suite_name); -extern const char * liblinphone_tester_test_name(const char *suite_name, int test_index); -extern int liblinphone_tester_test_index(const char *suite_name, const char *test_name); -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); -extern void liblinphone_tester_set_fileprefix(const char* file_prefix); -extern void liblinphone_tester_set_writable_dir_prefix(const char* writable_dir_prefix); extern int liblinphone_tester_ipv6_available(void); - -extern void liblinphone_tester_enable_xml( bool_t enable ); -extern void liblinphone_tester_set_xml_output(const char *xml_path ); -extern const char* liblinphone_tester_get_xml_output(void); - /** * @brief Tells the tester whether or not to clean the accounts it has created between runs. * @details Setting this to 1 will not clear the list of created accounts between successive @@ -306,10 +288,6 @@ void linphone_core_manager_check_accounts(LinphoneCoreManager *m); void account_manager_destroy(void); LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data); void liblinphone_tester_enable_ipv6(bool_t enabled); -#ifdef ANDROID -void cunit_android_trace_handler(int level, const char *fmt, va_list args) ; -#endif -int liblinphone_tester_fprintf(FILE * stream, const char * format, ...); void linphone_call_cb(LinphoneCall *call,void * user_data); void call_paused_resumed_base(bool_t multicast); void simple_call_base(bool_t enable_multicast_recv_side); diff --git a/tester/log_collection_tester.c b/tester/log_collection_tester.c index 35436bbcd..4bd5cb55e 100644 --- a/tester/log_collection_tester.c +++ b/tester/log_collection_tester.c @@ -94,7 +94,7 @@ static size_t getline(char **lineptr, size_t *n, FILE *stream) { static LinphoneLogCollectionState old_collection_state; static void collect_init() { old_collection_state = linphone_core_log_collection_enabled(); - linphone_core_set_log_collection_path(tester_writable_dir_prefix); + linphone_core_set_log_collection_path(bc_tester_writable_dir_prefix); } static void collect_cleanup(LinphoneCoreManager *marie) { @@ -171,7 +171,7 @@ static time_t check_file(LinphoneCoreManager* mgr) { CU_ASSERT_PTR_NOT_NULL(file); if (!file) return 0; // 1) expect to find folder name in filename path - CU_ASSERT_PTR_NOT_NULL(strstr(filepath, tester_writable_dir_prefix)); + CU_ASSERT_PTR_NOT_NULL(strstr(filepath, bc_tester_writable_dir_prefix)); // 2) check file contents while (getline(&line, &line_size, file) != -1) { diff --git a/tester/message_tester.c b/tester/message_tester.c index 1ed21c964..ebcddd697 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -68,7 +68,7 @@ void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* char receive_file[256]; LinphoneChatRoom *cr = linphone_chat_message_get_chat_room(message); LinphoneCore *lc = linphone_chat_room_get_core(cr); - snprintf(receive_file,sizeof(receive_file), "%s/receive_file.dump", tester_writable_dir_prefix); + snprintf(receive_file,sizeof(receive_file), "%s/receive_file.dump", bc_tester_writable_dir_prefix); if (!linphone_chat_message_get_user_data(message)) { /*first chunk, creating file*/ file = fopen(receive_file,"wb"); @@ -462,8 +462,8 @@ static void file_transfer_message(void) { LinphoneContent* content; FILE *file_to_send = NULL; size_t file_size; - char *send_filepath = ms_strdup_printf("%s/images/nowebcamCIF.jpg", tester_file_prefix); - char *receive_filepath = ms_strdup_printf("%s/receive_file.dump", tester_writable_dir_prefix); + char *send_filepath = ms_strdup_printf("%s/images/nowebcamCIF.jpg", bc_tester_read_dir_prefix); + char *receive_filepath = ms_strdup_printf("%s/receive_file.dump", bc_tester_writable_dir_prefix); LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); @@ -611,7 +611,7 @@ static void lime_file_transfer_message(void) { /* make sure lime is enabled */ linphone_core_set_lime(marie->lc, 1); linphone_core_set_lime(pauline->lc, 1); - + /* set the zid caches files : create two ZID cache from this valid one inserting the auto-generated sip URI for the peer account as keys in ZID cache are indexed by peer sip uri */ ZIDCacheMarieFD = fopen("tmpZIDCacheMarie.xml", "w"); ZIDCachePaulineFD = fopen("tmpZIDCachePauline.xml", "w"); @@ -1174,7 +1174,7 @@ static void lime_unit(void) { /* parse it to an xmlDoc */ cacheBufferAlice = xmlParseDoc(cacheBufferString); ms_free(cacheBufferString); - + /* Load Bob cache file */ CACHE = fopen("ZIDCacheBob.xml", "rb+"); cacheBufferString = (uint8_t *)ms_load_file_content(CACHE, &size); @@ -1391,8 +1391,8 @@ static void message_storage_migration() { char src_db[256]; char tmp_db[256]; MSList* chatrooms; - snprintf(src_db,sizeof(src_db), "%s/messages.db", tester_file_prefix); - snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", tester_writable_dir_prefix); + snprintf(src_db,sizeof(src_db), "%s/messages.db", bc_tester_read_dir_prefix); + snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", bc_tester_writable_dir_prefix); CU_ASSERT_EQUAL_FATAL(message_tester_copy_file(src_db, tmp_db), 0); @@ -1431,8 +1431,8 @@ static void history_range_full_test(){ LinphoneChatRoom *chatroom; char src_db[256]; char tmp_db[256]; - snprintf(src_db,sizeof(src_db), "%s/messages.db", tester_file_prefix); - snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", tester_writable_dir_prefix); + snprintf(src_db,sizeof(src_db), "%s/messages.db", bc_tester_read_dir_prefix); + snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", bc_tester_writable_dir_prefix); CU_ASSERT_EQUAL_FATAL(message_tester_copy_file(src_db, tmp_db), 0); @@ -1473,8 +1473,8 @@ static void history_messages_count() { MSList *messages; char src_db[256]; char tmp_db[256]; - snprintf(src_db,sizeof(src_db), "%s/messages.db", tester_file_prefix); - snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", tester_writable_dir_prefix); + snprintf(src_db,sizeof(src_db), "%s/messages.db", bc_tester_read_dir_prefix); + snprintf(tmp_db,sizeof(tmp_db), "%s/tmp.db", bc_tester_writable_dir_prefix); CU_ASSERT_EQUAL_FATAL(message_tester_copy_file(src_db, tmp_db), 0); diff --git a/tester/player_tester.c b/tester/player_tester.c index 2264ba7dd..e72cac9cd 100644 --- a/tester/player_tester.c +++ b/tester/player_tester.c @@ -71,7 +71,7 @@ static void play_file(const char *filename, bool_t unsupported_format, const cha } static void playing_test(void) { - char *filename = ms_strdup_printf("%s/sounds/hello_opus_h264.mkv", tester_file_prefix); + char *filename = ms_strdup_printf("%s/sounds/hello_opus_h264.mkv", bc_tester_read_dir_prefix); const char *audio_mime = "opus"; const char *video_mime = "h264"; play_file(filename, !linphone_local_player_matroska_supported(), audio_mime, video_mime); diff --git a/tester/register_tester.c b/tester/register_tester.c index 00c98e5fa..ffd54f1a5 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -18,7 +18,6 @@ #include #include "CUnit/Basic.h" -#include "tester_utils.h" #include "linphonecore.h" #include "private.h" #include "liblinphone_tester.h" @@ -751,14 +750,14 @@ static void tls_certificate_failure(){ mgr=linphone_core_manager_new2("pauline_rc",FALSE); lc=mgr->lc; - snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/agent.pem", tester_file_prefix); /*bad root ca*/ + snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/agent.pem", bc_tester_read_dir_prefix); /*bad root ca*/ linphone_core_set_root_ca(mgr->lc,rootcapath); linphone_core_set_network_reachable(lc,TRUE); CU_ASSERT_TRUE(wait_for(mgr->lc,mgr->lc,&mgr->stat.number_of_LinphoneRegistrationFailed,1)); linphone_core_set_root_ca(mgr->lc,NULL); /*no root ca*/ linphone_core_refresh_registers(mgr->lc); CU_ASSERT_TRUE(wait_for(lc,lc,&mgr->stat.number_of_LinphoneRegistrationFailed,2)); - snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", tester_file_prefix); /*goot root ca*/ + snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", bc_tester_read_dir_prefix); /*goot root ca*/ linphone_core_set_root_ca(mgr->lc,rootcapath); linphone_core_refresh_registers(mgr->lc); CU_ASSERT_TRUE(wait_for(lc,lc,&mgr->stat.number_of_LinphoneRegistrationOk,1)); @@ -796,7 +795,7 @@ static void tls_alt_name_register(){ mgr=linphone_core_manager_new2("pauline_alt_rc",FALSE); lc=mgr->lc; - snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", tester_file_prefix); + snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", bc_tester_read_dir_prefix); linphone_core_set_root_ca(mgr->lc,rootcapath); linphone_core_refresh_registers(mgr->lc); CU_ASSERT_TRUE(wait_for(lc,lc,&mgr->stat.number_of_LinphoneRegistrationOk,1)); @@ -811,7 +810,7 @@ static void tls_wildcard_register(){ mgr=linphone_core_manager_new2("pauline_wild_rc",FALSE); lc=mgr->lc; - snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", tester_file_prefix); + snprintf(rootcapath,sizeof(rootcapath), "%s/certificates/cn/cafile.pem", bc_tester_read_dir_prefix); linphone_core_set_root_ca(mgr->lc,rootcapath); linphone_core_refresh_registers(mgr->lc); CU_ASSERT_TRUE(wait_for(lc,lc,&mgr->stat.number_of_LinphoneRegistrationOk,2)); diff --git a/tester/setup_tester.c b/tester/setup_tester.c index 89ebe6438..03cb36a8b 100644 --- a/tester/setup_tester.c +++ b/tester/setup_tester.c @@ -18,7 +18,6 @@ #include #include "CUnit/Basic.h" -#include "tester_utils.h" #include "linphonecore.h" #include "liblinphone_tester.h" #include "lpconfig.h" @@ -129,7 +128,7 @@ static void linphone_lpconfig_from_buffer_zerolen_value(){ static void linphone_lpconfig_from_file_zerolen_value(){ /* parameters that have no value should return NULL, not "". */ const char* zero_rc_file = "zero_length_params_rc"; - char* rc_path = ms_strdup_printf("%s/rcfiles/%s", tester_file_prefix, zero_rc_file); + char* rc_path = ms_strdup_printf("%s/rcfiles/%s", bc_tester_read_dir_prefix, zero_rc_file); LpConfig* conf; /* not using lp_config_new() because it expects a readable file, and iOS (for instance) @@ -150,7 +149,7 @@ static void linphone_lpconfig_from_file_zerolen_value(){ static void linphone_lpconfig_from_xml_zerolen_value(){ const char* zero_xml_file = "remote_zero_length_params_rc"; - char* xml_path = ms_strdup_printf("%s/rcfiles/%s", tester_file_prefix, zero_xml_file); + char* xml_path = ms_strdup_printf("%s/rcfiles/%s", bc_tester_read_dir_prefix, zero_xml_file); LpConfig* conf; LinphoneCoreManager* mgr = linphone_core_manager_new2("empty_rc",FALSE); diff --git a/tester/tester.c b/tester/tester.c index e0c972e1e..231ab6909 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -29,44 +29,18 @@ #include #endif -static test_suite_t **test_suite = NULL; -static int nb_test_suites = 0; - - -#if HAVE_CU_CURSES -static unsigned char curses = 0; -#endif + static bool_t liblinphone_tester_ipv6_enabled=FALSE; + static int liblinphone_tester_keep_accounts_flag = 0; + static int manager_count = 0; 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"; const char* test_route="sip2.linphone.org"; -int liblinphone_tester_use_log_file=0; -static int liblinphone_tester_keep_accounts_flag = 0; -static bool_t liblinphone_tester_ipv6_enabled=FALSE; -static int manager_count = 0; - -static const char* liblinphone_tester_xml_file = NULL; -static int liblinphone_tester_xml_enabled = FALSE; - -#if WINAPI_FAMILY_PHONE_APP -const char *liblinphone_tester_file_prefix="Assets"; -#elif defined(__QNX__) -const char *liblinphone_tester_file_prefix="./app/native/assets/"; -#else -const char *liblinphone_tester_file_prefix="."; -#endif - -/* TODO: have the same "static" for QNX and windows as above? */ -#ifdef ANDROID -const char *liblinphone_tester_writable_dir_prefix = "/data/data/org.linphone.tester/cache"; -#else -const char *liblinphone_tester_writable_dir_prefix = "."; -#endif - const char *userhostsfile = "tester_hosts"; -static void network_reachable(LinphoneCore *lc, bool_t reachable) { + + static void network_reachable(LinphoneCore *lc, bool_t reachable) { stats* counters; ms_message("Network reachable [%s]",reachable?"TRUE":"FALSE"); counters = get_stats(lc); @@ -114,8 +88,6 @@ static void auth_info_requested(LinphoneCore *lc, const char *realm, const char counters->number_of_auth_info_requested++; } - - void reset_counters( stats* counters) { if (counters->last_received_chat_message) linphone_chat_message_unref(counters->last_received_chat_message); memset(counters,0,sizeof(stats)); @@ -279,7 +251,7 @@ LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_f reset_counters(&mgr->stat); if (rc_file) rc_path = ms_strdup_printf("rcfiles/%s", rc_file); - mgr->lc=configure_lc_from(&mgr->v_table, liblinphone_tester_file_prefix, rc_path, mgr); + mgr->lc=configure_lc_from(&mgr->v_table, bc_tester_read_dir_prefix, rc_path, mgr); linphone_core_manager_check_accounts(mgr); /*CU_ASSERT_EQUAL(ms_list_size(linphone_core_get_proxy_config_list(lc)),proxy_count);*/ if (check_for_proxies && rc_file) /**/ @@ -296,10 +268,10 @@ LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_f if( manager_count >= 2){ char hellopath[512]; - char *recordpath = ms_strdup_printf("%s/record_for_lc_%p.wav",liblinphone_tester_writable_dir_prefix,mgr->lc); + char *recordpath = ms_strdup_printf("%s/record_for_lc_%p.wav",bc_tester_writable_dir_prefix,mgr->lc); ms_message("Manager for '%s' using files", rc_file ? rc_file : "--"); linphone_core_use_files(mgr->lc, TRUE); - snprintf(hellopath,sizeof(hellopath), "%s/sounds/hello8000.wav", liblinphone_tester_file_prefix); + snprintf(hellopath,sizeof(hellopath), "%s/sounds/hello8000.wav", bc_tester_read_dir_prefix); linphone_core_set_play_file(mgr->lc,hellopath); linphone_core_set_record_file(mgr->lc,recordpath); ms_free(recordpath); @@ -355,307 +327,6 @@ void linphone_core_manager_destroy(LinphoneCoreManager* mgr) { ms_free(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 *)); - } -} - -static int run_test_suite(test_suite_t *suite) { - int i; - - 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(); - } - } - - return 0; -} - -int liblinphone_tester_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; - } - } - - return -1; -} - -void liblinphone_tester_list_suites() { - int j; - for(j=0;jnb_tests; i++) { - if ((strcmp(test_name, test_suite[j]->tests[i].name) == 0) && (strlen(test_name) == strlen(test_suite[j]->tests[i].name))) { - return i; - } - } - } - - return -1; -} - -int liblinphone_tester_nb_test_suites(void) { - return nb_test_suites; -} - -int liblinphone_tester_nb_tests(const char *suite_name) { - int i = liblinphone_tester_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 = liblinphone_tester_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_set_fileprefix(const char* file_prefix){ - liblinphone_tester_file_prefix = file_prefix; -} - -void liblinphone_tester_set_writable_dir_prefix(const char* writable_dir_prefix){ - liblinphone_tester_writable_dir_prefix = writable_dir_prefix; -} - - -void liblinphone_tester_init(void) { - add_test_suite(&setup_test_suite); - add_test_suite(®ister_test_suite); - add_test_suite(&offeranswer_test_suite); - add_test_suite(&call_test_suite); - add_test_suite(&multi_call_test_suite); - add_test_suite(&message_test_suite); - add_test_suite(&presence_test_suite); -#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); - add_test_suite(&remote_provisioning_test_suite); - add_test_suite(&quality_reporting_test_suite); - add_test_suite(&log_collection_test_suite); - add_test_suite(&transport_test_suite); - add_test_suite(&player_test_suite); - add_test_suite(&dtmf_test_suite); -#if defined(VIDEO_ENABLED) && defined(HAVE_GTK) - add_test_suite(&video_test_suite); -#endif - add_test_suite(&multicast_call_test_suite); -} - -void liblinphone_tester_uninit(void) { - if (test_suite != NULL) { - free(test_suite); - test_suite = NULL; - nb_test_suites = 0; - } -} - -/*derivated from cunit*/ -static void test_complete_message_handler(const CU_pTest pTest, - const CU_pSuite pSuite, - const CU_pFailureRecord pFailureList) { - int i; - CU_pFailureRecord pFailure = pFailureList; - if (pFailure) { - if (liblinphone_tester_use_log_file) ms_warning("Suite [%s], Test [%s] had failures:", pSuite->pName, pTest->pName); - liblinphone_tester_fprintf(stdout,"\nSuite [%s], Test [%s] had failures:", pSuite->pName, pTest->pName); - } else { - if (liblinphone_tester_use_log_file) ms_warning(" passed"); - liblinphone_tester_fprintf(stdout," passed"); - } - for (i = 1 ; (NULL != pFailure) ; pFailure = pFailure->pNext, i++) { - if (liblinphone_tester_use_log_file) ms_warning("\n %d. %s:%u - %s", i, - (NULL != pFailure->strFileName) ? pFailure->strFileName : "", - pFailure->uiLineNumber, - (NULL != pFailure->strCondition) ? pFailure->strCondition : ""); - liblinphone_tester_fprintf(stdout,"\n %d. %s:%u - %s", i, - (NULL != pFailure->strFileName) ? pFailure->strFileName : "", - pFailure->uiLineNumber, - (NULL != pFailure->strCondition) ? pFailure->strCondition : ""); - } - } - - -static void test_all_tests_complete_message_handler(const CU_pFailureRecord pFailure) { -#ifdef HAVE_CU_GET_SUITE - char * results = CU_get_run_results_string(); - if (liblinphone_tester_use_log_file) { - ms_warning("\n\n %s", results); - } - liblinphone_tester_fprintf(stdout,"\n\n %s",results); - ms_free(results); -#endif -} - -static void test_suite_init_failure_message_handler(const CU_pSuite pSuite) { - if (liblinphone_tester_use_log_file) ms_warning("Suite initialization failed for [%s].", pSuite->pName); - liblinphone_tester_fprintf(stdout,"Suite initialization failed for [%s].", pSuite->pName); -} - -static void test_suite_cleanup_failure_message_handler(const CU_pSuite pSuite) { - if (liblinphone_tester_use_log_file) ms_warning("Suite cleanup failed for '%s'.", pSuite->pName); - liblinphone_tester_fprintf(stdout,"Suite cleanup failed for [%s].", pSuite->pName); -} - -#ifdef HAVE_CU_GET_SUITE -static void test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite) { - if (liblinphone_tester_use_log_file) ms_warning("Suite [%s] Test [%s]", pSuite->pName,pTest->pName); - liblinphone_tester_fprintf(stdout,"\nSuite [%s] Test [%s]\n", pSuite->pName,pTest->pName); -} - -static void test_suite_start_message_handler(const CU_pSuite pSuite) { - if (liblinphone_tester_use_log_file) ms_warning("Suite [%s]", pSuite->pName); - liblinphone_tester_fprintf(stdout,"\nSuite [%s]", pSuite->pName); -} -#endif - -int liblinphone_tester_run_tests(const char *suite_name, const char *test_name) { - int i; - int ret; - /* initialize the CUnit test registry */ - if (CUE_SUCCESS != CU_initialize_registry()) - return CU_get_error(); - - for (i = 0; i < liblinphone_tester_nb_test_suites(); i++) { - run_test_suite(test_suite[i]); - } -#ifdef HAVE_CU_GET_SUITE - CU_set_test_start_handler(test_start_message_handler); -#endif - CU_set_test_complete_handler(test_complete_message_handler); - CU_set_all_test_complete_handler(test_all_tests_complete_message_handler); - CU_set_suite_init_failure_handler(test_suite_init_failure_message_handler); - CU_set_suite_cleanup_failure_handler(test_suite_cleanup_failure_message_handler); -#ifdef HAVE_CU_GET_SUITE - CU_set_suite_start_handler(test_suite_start_message_handler); -#endif - if( liblinphone_tester_xml_file != NULL ){ - CU_set_output_filename(liblinphone_tester_xml_file); - } - if( liblinphone_tester_xml_enabled != 0 ){ - CU_automated_run_tests(); - } else { - -#if !HAVE_CU_GET_SUITE - if( suite_name ){ - ms_warning("Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'\n", suite_name); - } -#else - if (!test_name && suite_name && strcmp("Call",suite_name) == 0) { - /*special case for suite Call which is now splitted into simple and multi*/ - CU_run_suite(CU_get_suite("Single call")); - CU_run_suite(CU_get_suite("Multi call")); - CU_run_suite(CU_get_suite("DTMF")); - CU_run_suite(CU_get_suite("Transport")); - } else if (suite_name){ - CU_pSuite suite; - suite=CU_get_suite(suite_name); - if (!suite) { - ms_error("Could not find suite '%s'. Available suites are:", suite_name); - liblinphone_tester_list_suites(); - return -1; - } else if (test_name) { - CU_pTest test=CU_get_test_by_name(test_name, suite); - if (!test) { - ms_error("Could not find test '%s' in suite '%s'. Available tests are:", test_name, suite_name); - // do not use suite_name here, since this method is case sensitive - liblinphone_tester_list_suite_tests(suite->pName); - return -2; - } else { - CU_ErrorCode err= CU_run_test(suite, test); - if (err != CUE_SUCCESS) ms_error("CU_basic_run_test error %d", err); - } - } else { - CU_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_run_all_tests(); - } - } - - } - ret=CU_get_number_of_tests_failed()!=0; - - /* Redisplay list of failed tests on end */ - if (CU_get_number_of_failure_records()){ - CU_basic_show_failures(CU_get_failure_list()); - liblinphone_tester_fprintf(stdout,"\n"); - } - - CU_cleanup_registry(); - - if( liblinphone_tester_keep_accounts_flag == 0){ - liblinphone_tester_clear_accounts(); - } - return ret; -} - -int liblinphone_tester_fprintf(FILE * stream, const char * format, ...) { - int result; - va_list args; - va_start(args, format); -#ifndef ANDROID - result = vfprintf(stream,format,args); - fflush(stream); -#else - /*used by liblinphone tester to retrieve suite list*/ - result = 0; - cunit_android_trace_handler(stream == stderr, format, args); -#endif - va_end(args); - return result; -} - int liblinphone_tester_ipv6_available(void){ struct addrinfo *ai=belle_sip_ip_address_to_addrinfo(AF_INET6,"2a01:e00::2",53); if (ai){ @@ -681,19 +352,3 @@ void liblinphone_tester_keep_accounts( int keep ){ void liblinphone_tester_clear_accounts(void){ account_manager_destroy(); } - -void liblinphone_tester_enable_xml( bool_t enable ){ - liblinphone_tester_xml_enabled = enable; -} - -void liblinphone_tester_set_xml_output(const char *xml_path ) { - liblinphone_tester_xml_file = xml_path; -} - -const char* liblinphone_tester_get_xml_output( void ) { - return liblinphone_tester_xml_file; -} - - - - diff --git a/tester/tester_utils.c b/tester/tester_utils.c deleted file mode 100644 index 341aecd38..000000000 --- a/tester/tester_utils.c +++ /dev/null @@ -1,392 +0,0 @@ -/* -tester - liblinphone test suite -Copyright (C) 2013 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 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. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#define tester_fprintf fprintf -#define ms_warning printf -#define ms_fatal abort - -#include "tester_utils.h" - -#include - -#if WINAPI_FAMILY_PHONE_APP -const char *tester_file_prefix="Assets"; -#elif defined(__QNX__) -const char *tester_file_prefix="./app/native/assets/"; -#else -const char *tester_file_prefix="."; -#endif - -/* TODO: have the same "static" for QNX and windows as above? */ -#ifdef ANDROID -const char *tester_writable_dir_prefix = "/data/data/org.linphone.tester/cache"; -#else -const char *tester_writable_dir_prefix = "."; -#endif - -static test_suite_t **test_suite = NULL; -static int nb_test_suites = 0; - -#if HAVE_CU_CURSES -static unsigned char curses = 0; -#endif - -int tester_use_log_file = 0; -char* tester_xml_file = NULL; -int tester_xml_enabled = FALSE; -char * suite_name; -char * test_name; - -void helper(const char *name, const char* additionnal_helper) { - fprintf(stderr,"%s --help\n" - "\t\t\t--verbose\n" - "\t\t\t--silent\n" - "\t\t\t--list-suites\n" - "\t\t\t--list-tests \n" - "\t\t\t--suite \n" - "\t\t\t--test \n" - "\t\t\t--log-file \n" -#if HAVE_CU_CURSES - "\t\t\t--curses\n" -#endif - "\t\t\t--xml\n" - "\t\t\t--xml-file \n" - "And additionnaly:\n" - "%s" - , name - , additionnal_helper); -} - -int parge_args(int argc, char **argv, int argid, const char * additionnal_helper) -{ - int i = argid; - - if (strcmp(argv[i],"--help")==0){ - helper(argv[0], additionnal_helper); - return -1; -// } else if (strcmp(argv[i],"--verbose")==0){ -// linphone_core_set_log_level(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL); -// } else if (strcmp(argv[i],"--silent")==0){ -// linphone_core_set_log_level(ORTP_FATAL); - } else if (strcmp(argv[i],"--test")==0){ - CHECK_ARG("--test", ++i, argc); - test_name=argv[i]; - }else if (strcmp(argv[i],"--suite")==0){ - CHECK_ARG("--suite", ++i, argc); - suite_name=argv[i]; - } else if (strcmp(argv[i],"--list-suites")==0){ - tester_list_suites(); - return -1; - } else if (strcmp(argv[i],"--list-tests")==0){ - CHECK_ARG("--list-tests", ++i, argc); - suite_name = argv[i]; - tester_list_suite_tests(suite_name); - return -1; - } else if (strcmp(argv[i], "--xml-file") == 0){ - CHECK_ARG("--xml-file", ++i, argc); - tester_xml_file = argv[i]; - tester_xml_enabled = 1; - } else if (strcmp(argv[i], "--xml") == 0){ - tester_xml_enabled = 1; - } else if (strcmp(argv[i],"--log-file")==0){ - CHECK_ARG("--log-file", ++i, argc); - FILE *log_file=fopen(argv[i],"w"); - if (!log_file) { - ms_fatal("Cannot open file [%s] for writting logs because [%s]",argv[i],strerror(errno)); - } else { - tester_use_log_file=1; - tester_fprintf(stdout,"Redirecting traces to file [%s]",argv[i]); - // linphone_core_set_log_file(log_file); - } - }else { - tester_fprintf(stderr, "Unknown option \"%s\"\n", argv[i]); - helper(argv[0], additionnal_helper); - return -2; - } - - if( tester_xml_enabled && (suite_name || test_name) ){ - printf("Cannot use both xml and specific test suite\n"); - return -1; - } - - /* returns number of arguments read */ - return i - argid; -} - -int tester_start() { - int ret; - char * xml_tmp_file; - if( tester_xml_enabled ){ - xml_tmp_file = ms_strdup_printf("%s.tmp", tester_xml_file); - } - - ret = tester_run_tests(suite_name, test_name); - tester_uninit(); - - if ( tester_xml_enabled ) { - /*create real xml file only if tester did not crash*/ - ms_strcat_printf(xml_tmp_file, "-Results.xml"); - rename(xml_tmp_file, tester_xml_file); - ms_free(xml_tmp_file); - } - return ret; -} - - -int tester_test_suite_index(const char *suite_name) { - int i; - - for (i = 0; i < tester_nb_test_suites(); i++) { - if ((strcmp(suite_name, test_suite[i]->name) == 0) && (strlen(suite_name) == strlen(test_suite[i]->name))) { - return i; - } - } - - return -1; -} - -void tester_list_suites() { - int j; - for(j=0;jnb_tests; i++) { - if ((strcmp(test_name, test_suite[j]->tests[i].name) == 0) && (strlen(test_name) == strlen(test_suite[j]->tests[i].name))) { - return i; - } - } - } - - return -1; -} - -int tester_nb_test_suites(void) { - return nb_test_suites; -} - -int tester_nb_tests(const char *suite_name) { - int i = tester_test_suite_index(suite_name); - if (i < 0) return 0; - return test_suite[i]->nb_tests; -} - -const char * tester_test_suite_name(int suite_index) { - if (suite_index >= tester_nb_test_suites()) return NULL; - return test_suite[suite_index]->name; -} - -const char * tester_test_name(const char *suite_name, int test_index) { - int suite_index = tester_test_suite_index(suite_name); - if ((suite_index < 0) || (suite_index >= 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; -} - -static void test_all_tests_complete_message_handler(const CU_pFailureRecord pFailure) { -#ifdef HAVE_CU_GET_SUITE - char * results = CU_get_run_results_string(); - if (liblinphone_tester_use_log_file) { - ms_warning("\n\n %s", results); - } - tester_fprintf(stdout,"\n\n %s",results); - ms_free(results); -#endif -} - -static void test_suite_init_failure_message_handler(const CU_pSuite pSuite) { - if (liblinphone_tester_use_log_file) ms_warning("Suite initialization failed for [%s].", pSuite->pName); - tester_fprintf(stdout,"Suite initialization failed for [%s].", pSuite->pName); -} - -static void test_suite_cleanup_failure_message_handler(const CU_pSuite pSuite) { - if (liblinphone_tester_use_log_file) ms_warning("Suite cleanup failed for '%s'.", pSuite->pName); - tester_fprintf(stdout,"Suite cleanup failed for [%s].", pSuite->pName); -} - -#ifdef HAVE_CU_GET_SUITE -static void test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite) { - if (liblinphone_tester_use_log_file) ms_warning("Suite [%s] Test [%s]", pSuite->pName,pTest->pName); - tester_fprintf(stdout,"\nSuite [%s] Test [%s]\n", pSuite->pName,pTest->pName); -} - -static void test_suite_start_message_handler(const CU_pSuite pSuite) { - if (liblinphone_tester_use_log_file) ms_warning("Suite [%s]", pSuite->pName); - tester_fprintf(stdout,"\nSuite [%s]", pSuite->pName); -} -#endif - -/*derivated from cunit*/ -static void test_complete_message_handler(const CU_pTest pTest, - const CU_pSuite pSuite, - const CU_pFailureRecord pFailureList) { - int i; - CU_pFailureRecord pFailure = pFailureList; - if (pFailure) { - if (liblinphone_tester_use_log_file) ms_warning("Suite [%s], Test [%s] had failures:", pSuite->pName, pTest->pName); - tester_fprintf(stdout,"\nSuite [%s], Test [%s] had failures:", pSuite->pName, pTest->pName); - } else { - if (liblinphone_tester_use_log_file) ms_warning(" passed"); - tester_fprintf(stdout," passed"); - } - for (i = 1 ; (NULL != pFailure) ; pFailure = pFailure->pNext, i++) { - if (liblinphone_tester_use_log_file) ms_warning("\n %d. %s:%u - %s", i, - (NULL != pFailure->strFileName) ? pFailure->strFileName : "", - pFailure->uiLineNumber, - (NULL != pFailure->strCondition) ? pFailure->strCondition : ""); - tester_fprintf(stdout,"\n %d. %s:%u - %s", i, - (NULL != pFailure->strFileName) ? pFailure->strFileName : "", - pFailure->uiLineNumber, - (NULL != pFailure->strCondition) ? pFailure->strCondition : ""); - } -} - -int tester_run_tests(const char *suite_name, const char *test_name) { - int i; - int ret; -/* initialize the CUnit test registry */ - if (CUE_SUCCESS != CU_initialize_registry()) - return CU_get_error(); - - for (i = 0; i < tester_nb_test_suites(); i++) { - tester_run_suite(test_suite[i]); - } -#ifdef HAVE_CU_GET_SUITE - CU_set_test_start_handler(test_start_message_handler); -#endif - CU_set_test_complete_handler(test_complete_message_handler); - CU_set_all_test_complete_handler(test_all_tests_complete_message_handler); - CU_set_suite_init_failure_handler(test_suite_init_failure_message_handler); - CU_set_suite_cleanup_failure_handler(test_suite_cleanup_failure_message_handler); -#ifdef HAVE_CU_GET_SUITE - CU_set_suite_start_handler(test_suite_start_message_handler); -#endif - if( tester_xml_file != NULL ){ - CU_set_output_filename(tester_xml_file); - } - if( tester_xml_enabled != 0 ){ - CU_automated_run_tests(); - } else { - -#if !HAVE_CU_GET_SUITE - if( suite_name ){ - ms_warning("Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'\n", suite_name); - } -#else - if (!test_name && suite_name && strcmp("Call",suite_name) == 0) { - /*special case for suite Call which is now splitted into simple and multi*/ - CU_run_suite(CU_get_suite("Single call")); - CU_run_suite(CU_get_suite("Multi call")); - } else if (suite_name){ - CU_pSuite suite; - suite=CU_get_suite(suite_name); - if (!suite) { - ms_error("Could not find suite '%s'. Available suites are:", suite_name); - liblinphone_tester_list_suites(); - return -1; - } else if (test_name) { - CU_pTest test=CU_get_test_by_name(test_name, suite); - if (!test) { - ms_error("Could not find test '%s' in suite '%s'. Available tests are:", test_name, suite_name); - // do not use suite_name here, since this method is case sensitive - liblinphone_tester_list_suite_tests(suite->pName); - return -2; - } else { - CU_ErrorCode err= CU_run_test(suite, test); - if (err != CUE_SUCCESS) ms_error("CU_basic_run_test error %d", err); - } - } else { - CU_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_run_all_tests(); - } - } - - } - ret=CU_get_number_of_tests_failed()!=0; - -/* Redisplay list of failed tests on end */ - if (CU_get_number_of_failure_records()){ - CU_basic_show_failures(CU_get_failure_list()); - tester_fprintf(stdout,"\n"); - } - - CU_cleanup_registry(); - - return ret; -} - -void tester_add_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 tester_run_suite(test_suite_t *suite) { - int i; - - 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(); - } - } - - return 0; -} - -void tester_uninit() { - if (test_suite != NULL) { - free(test_suite); - test_suite = NULL; - nb_test_suites = 0; - } -} diff --git a/tester/video_tester.c b/tester/video_tester.c index 1e0032211..f21e06989 100644 --- a/tester/video_tester.c +++ b/tester/video_tester.c @@ -306,7 +306,7 @@ static void two_incoming_early_media_video_calls_test(void) { /* Configure early media audio to play ring during early-media and send remote ring back tone. */ linphone_core_set_ring_during_incoming_early_media(marie->lc, TRUE); - ringback_path = ms_strdup_printf("%s/sounds/ringback.wav", tester_file_prefix); + ringback_path = ms_strdup_printf("%s/sounds/ringback.wav", bc_tester_read_dir_prefix); linphone_core_set_remote_ringback_tone(marie->lc, ringback_path); ms_free(ringback_path); From b411d3f5ff0b6c70dad142ca6e473b351164d6d8 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 13 Mar 2015 17:02:21 +0100 Subject: [PATCH 3/4] Tester: fix return value --- mediastreamer2 | 2 +- tester/liblinphone_tester.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mediastreamer2 b/mediastreamer2 index 429161741..1a596c780 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit 42916174111a5db519f60d6b37ec115fef8d0436 +Subproject commit 1a596c780c9631f686cd4245b618035398264654 diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index d08585841..7173d93d3 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -235,7 +235,7 @@ int main (int argc, char *argv[]) userhostsfile=argv[i]; } else { int ret = bc_tester_parse_args(argc, argv, i); - if (ret>1) { + if (ret>0) { i += ret - 1; continue; } else if (ret<0) { From cdec9f9eda2df946f0ea4d52f5686f2f4f04e190 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 16 Mar 2015 16:20:04 +0100 Subject: [PATCH 4/4] Tester: update CMakeLists.txt and use latest changes --- mediastreamer2 | 2 +- tester/CMakeLists.txt | 4 ++++ tester/common/bc_tester_utils.c | 19 ++++++++++--------- tester/common/bc_tester_utils.h | 1 + 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/mediastreamer2 b/mediastreamer2 index 1a596c780..a9374f30b 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit 1a596c780c9631f686cd4245b618035398264654 +Subproject commit a9374f30b2e5098e646608b0562e50a156fba820 diff --git a/tester/CMakeLists.txt b/tester/CMakeLists.txt index 12454c80f..e9583b955 100644 --- a/tester/CMakeLists.txt +++ b/tester/CMakeLists.txt @@ -26,6 +26,8 @@ endif() find_package(GTK2 2.18 COMPONENTS gtk) set(SOURCE_FILES + common/bc_tester_utils.c + common/bc_tester_utils.h accountmanager.c call_tester.c dtmf_tester.c @@ -50,6 +52,8 @@ set(SOURCE_FILES video_tester.c ) +add_definitions(-DBC_CONFIG_FILE="config.h") + add_executable(liblinphone_tester ${SOURCE_FILES}) set_target_properties(liblinphone_tester PROPERTIES LINKER_LANGUAGE CXX) target_include_directories(liblinphone_tester PUBLIC ${CUNIT_INCLUDE_DIRS}) diff --git a/tester/common/bc_tester_utils.c b/tester/common/bc_tester_utils.c index 0c7bb7038..25e92143f 100644 --- a/tester/common/bc_tester_utils.c +++ b/tester/common/bc_tester_utils.c @@ -44,11 +44,12 @@ const char *bc_tester_writable_dir_prefix = "."; static test_suite_t **test_suite = NULL; static int nb_test_suites = 0; -#if HAVE_CU_CURSES +#ifdef HAVE_CU_CURSES +#include "CUnit/CUCurses.h" static unsigned char curses = 0; #endif -char* xml_file = NULL; +char* xml_file = "CUnitAutomated-Results.xml"; int xml_enabled = 0; char * suite_name; char * test_name; @@ -155,8 +156,8 @@ static void test_complete_message_handler(const CU_pTest pTest, const CU_pFailureRecord pFailureList) { int i; char * result = malloc(sizeof(char)*2048);//not very pretty but... - sprintf(result, "Suite [%s] Test [%s]", pSuite->pName, pTest->pName); CU_pFailureRecord pFailure = pFailureList; + sprintf(result, "Suite [%s] Test [%s]", pSuite->pName, pTest->pName); if (pFailure) { strncat(result, " failed:", strlen(" failed:")); for (i = 1 ; (NULL != pFailure) ; pFailure = pFailure->pNext, i++) { @@ -197,7 +198,7 @@ static int tester_run_tests(const char *suite_name, const char *test_name) { CU_automated_run_tests(); } else { -#if !HAVE_CU_GET_SUITE +#ifndef HAVE_CU_GET_SUITE if( suite_name ){ tester_printf(verbosity_info, "Tester compiled without CU_get_suite() function, running all tests instead of suite '%s'", suite_name); } @@ -227,7 +228,7 @@ static int tester_run_tests(const char *suite_name, const char *test_name) { else #endif { -#if HAVE_CU_CURSES +#ifdef HAVE_CU_CURSES if (curses) { /* Run tests using the CUnit curses interface */ CU_curses_run_tests(); @@ -251,7 +252,7 @@ void bc_tester_helper(const char *name, const char* additionnal_helper) { "\t\t\t--list-tests \n" "\t\t\t--suite \n" "\t\t\t--test \n" -#if HAVE_CU_CURSES +#ifdef HAVE_CU_CURSES "\t\t\t--curses\n" #endif "\t\t\t--xml\n" @@ -312,7 +313,7 @@ int bc_tester_start() { int ret; if( xml_enabled ){ char * xml_tmp_file = malloc(sizeof(char) * (strlen(xml_file) + strlen(".tmp") + 1)); - snprintf(xml_tmp_file, sizeof(xml_tmp_file), "%s.tmp", xml_file); + sprintf(xml_tmp_file, "%s.tmp", xml_file); CU_set_output_filename(xml_tmp_file); free(xml_tmp_file); } @@ -342,8 +343,8 @@ void bc_tester_uninit() { if( xml_enabled ){ /*create real xml file only if tester did not crash*/ - char * xml_tmp_file = malloc(sizeof(char) * (strlen(xml_file) + strlen(".tmp") + 1)); - snprintf(xml_tmp_file, sizeof(xml_tmp_file), "%s.tmp", xml_file); + char * xml_tmp_file = malloc(sizeof(char) * (strlen(xml_file) + strlen(".tmp-Results.xml") + 1)); + sprintf(xml_tmp_file, "%s.tmp-Results.xml", xml_file); rename(xml_tmp_file, xml_file); free(xml_tmp_file); } diff --git a/tester/common/bc_tester_utils.h b/tester/common/bc_tester_utils.h index f12916c7f..a8b952d02 100644 --- a/tester/common/bc_tester_utils.h +++ b/tester/common/bc_tester_utils.h @@ -21,6 +21,7 @@ #define TESTER_UTILS_H #include "CUnit/Basic.h" +#include extern const char *bc_tester_read_dir_prefix; extern const char *bc_tester_writable_dir_prefix;