diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index b3f2c98da..d9dc9b914 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -225,7 +225,8 @@ const char *liblinphone_tester_get_subscribe_content(void); const char *liblinphone_tester_get_notify_content(void); void liblinphone_tester_chat_message_state_change(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud); void liblinphone_tester_check_rtcp(LinphoneCoreManager* caller, LinphoneCoreManager* callee); - +void liblinphone_tester_clock_start(MSTimeSpec *start); +bool_t liblinphone_tester_clock_elapsed(const MSTimeSpec *start, int value_ms); #endif /* LIBLINPHONE_TESTER_H_ */ diff --git a/tester/tester.c b/tester/tester.c index fdab1e3c5..9eedb0ed1 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -51,6 +51,18 @@ const char *liblinphone_tester_file_prefix="."; const char *userhostsfile = "tester_hosts"; +void liblinphone_tester_clock_start(MSTimeSpec *start){ + ms_get_cur_time(start); +} + +bool_t liblinphone_tester_clock_elapsed(const MSTimeSpec *start, int value_ms){ + MSTimeSpec current; + ms_get_cur_time(¤t); + if ((((current.tv_sec-start->tv_sec)*1000LL) + ((current.tv_nsec-start->tv_nsec)/1000000LL))>=value_ms) + return TRUE; + return FALSE; +} + LinphoneAddress * create_linphone_address(const char * domain) { LinphoneAddress *addr = linphone_address_new(NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(addr); @@ -133,12 +145,14 @@ bool_t wait_for(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value) { } bool_t wait_for_list(MSList* lcs,int* counter,int value,int timeout_ms) { - int retry=0; MSList* iterator; - while ((counter==NULL || *counternext) { - linphone_core_iterate((LinphoneCore*)(iterator->data)); - } + MSTimeSpec start; + + liblinphone_tester_clock_start(&start); + while ((counter==NULL || *counternext) { + linphone_core_iterate((LinphoneCore*)(iterator->data)); + } ms_usleep(100000); } if(counter && *counterv_table.registration_state_changed=registration_state_changed; mgr->v_table.auth_info_requested=auth_info_requested; @@ -202,10 +215,8 @@ LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_f else proxy_count=0; - while (mgr->stat.number_of_LinphoneRegistrationOk2?(proxy_count-2)*10:0))) { - linphone_core_iterate(mgr->lc); - ms_usleep(100000); - } + if (proxy_count) + wait_for_until(mgr->lc,NULL,&mgr->stat.number_of_LinphoneRegistrationOk,proxy_count,3000*proxy_count); CU_ASSERT_EQUAL(mgr->stat.number_of_LinphoneRegistrationOk,proxy_count); enable_codec(mgr->lc,"PCMU",8000);