Tester: create tester_utils which contain factorized code for all testers (in progress, continuing)

parent dfdfc13e
......@@ -45,3 +45,4 @@ tester/recorded_hello8000-1s.wav
tester/recorded_hello16000-1s.wav
*.vcxproj.*
tools/msaudiocmp
tester/dtmfgen_file.raw
......@@ -31,18 +31,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <ortp/str_utils.h>
#if WINAPI_FAMILY_PHONE_APP
const char *tester_file_prefix="Assets";
const char *bc_tester_read_dir_prefix="Assets";
#elif defined(__QNX__)
const char *tester_file_prefix="./app/native/assets/";
const char *bc_tester_read_dir_prefix="./app/native/assets/";
#else
const char *tester_file_prefix=".";
const char *bc_tester_read_dir_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";
const char *bc_tester_writable_dir_prefix = "/data/data/org.linphone.tester/cache";
#else
const char *tester_writable_dir_prefix = ".";
const char *bc_tester_writable_dir_prefix = ".";
#endif
static test_suite_t **test_suite = NULL;
......@@ -52,9 +52,9 @@ static int nb_test_suites = 0;
static unsigned char curses = 0;
#endif
int tester_use_log_file = 0;
char* tester_xml_file = NULL;
int tester_xml_enabled = 0;
int use_log_file = 0;
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);
......@@ -66,7 +66,7 @@ static void tester_printf(int level, const char *fmt, ...) {
va_end (args);
}
void tester_helper(const char *name, const char* additionnal_helper) {
void bc_tester_helper(const char *name, const char* additionnal_helper) {
fprintf(stderr,"%s --help\n"
"\t\t\t--list-suites\n"
"\t\t\t--list-tests <suite>\n"
......@@ -84,11 +84,11 @@ void tester_helper(const char *name, const char* additionnal_helper) {
, additionnal_helper);
}
void tester_init(void (*ftester_printf)(int level, const char *fmt, va_list args)) {
void bc_tester_init(void (*ftester_printf)(int level, const char *fmt, va_list args)) {
tester_printf_va = ftester_printf;
}
int tester_parse_args(int argc, char **argv, int argid)
int bc_tester_parse_args(int argc, char **argv, int argid)
{
int i = argid;
......@@ -101,19 +101,19 @@ int tester_parse_args(int argc, char **argv, int argid)
CHECK_ARG("--suite", ++i, argc);
suite_name=argv[i];
} else if (strcmp(argv[i],"--list-suites")==0){
tester_list_suites();
bc_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);
bc_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;
xml_file = argv[i];
xml_enabled = 1;
} else if (strcmp(argv[i], "--xml") == 0){
tester_xml_enabled = 1;
xml_enabled = 1;
} else if (strcmp(argv[i],"--log-file")==0){
CHECK_ARG("--log-file", ++i, argc);
FILE *log_file=fopen(argv[i],"w");
......@@ -121,7 +121,7 @@ int tester_parse_args(int argc, char **argv, int argid)
fprintf(stderr, "Cannot open file [%s] for writing logs because [%s]",argv[i],strerror(errno));
return -2;
} else {
tester_use_log_file=1;
use_log_file=1;
tester_printf(BELLE_SIP_LOG_MESSAGE,"Redirecting traces to file [%s]",argv[i]);
// linphone_core_set_log_file(log_file);
}
......@@ -130,7 +130,7 @@ int tester_parse_args(int argc, char **argv, int argid)
return -2;
}
if( tester_xml_enabled && (suite_name || test_name) ){
if( xml_enabled && (suite_name || test_name) ){
fprintf(stderr, "Cannot use both XML and specific test suite\n");
return -2;
}
......@@ -139,30 +139,23 @@ int tester_parse_args(int argc, char **argv, int argid)
return i - argid;
}
int tester_start() {
int bc_tester_start() {
int ret;
char * xml_tmp_file;
if( tester_xml_enabled ){
xml_tmp_file = API_PREFIX(strdup_printf("%s.tmp", tester_xml_file));
if( xml_enabled ){
xml_tmp_file = API_PREFIX(strdup_printf("%s.tmp", xml_file));
}
ret = tester_run_tests(suite_name, test_name);
tester_uninit();
ret = bc_tester_run_tests(suite_name, test_name);
if ( tester_xml_enabled ) {
/*create real xml file only if tester did not crash*/
xml_tmp_file = API_PREFIX(strdup_printf("%s.tmp", tester_xml_file));
rename(xml_tmp_file, tester_xml_file);
API_PREFIX(free(xml_tmp_file));
}
return ret;
}
int tester_test_suite_index(const char *suite_name) {
int bc_tester_test_suite_index(const char *suite_name) {
int i;
for (i = 0; i < tester_nb_test_suites(); i++) {
for (i = 0; i < bc_tester_nb_test_suites(); i++) {
if ((strcmp(suite_name, test_suite[i]->name) == 0) && (strlen(suite_name) == strlen(test_suite[i]->name))) {
return i;
}
......@@ -171,25 +164,25 @@ int tester_test_suite_index(const char *suite_name) {
return -1;
}
void tester_list_suites() {
void bc_tester_list_suites() {
int j;
for(j=0;j<tester_nb_test_suites();j++) {
tester_printf(BELLE_SIP_LOG_MESSAGE, "%s", tester_test_suite_name(j));
for(j=0;j<bc_tester_nb_test_suites();j++) {
tester_printf(BELLE_SIP_LOG_MESSAGE, "%s", bc_tester_test_suite_name(j));
}
}
void tester_list_suite_tests(const char *suite_name) {
void bc_tester_list_suite_tests(const char *suite_name) {
int j;
for( j = 0; j < tester_nb_tests(suite_name); j++) {
const char *test_name = tester_test_name(suite_name, j);
for( j = 0; j < bc_tester_nb_tests(suite_name); j++) {
const char *test_name = bc_tester_test_name(suite_name, j);
tester_printf(BELLE_SIP_LOG_MESSAGE, "%s", test_name);
}
}
int tester_test_index(const char *suite_name, const char *test_name) {
int bc_tester_test_index(const char *suite_name, const char *test_name) {
int j,i;
j = tester_test_suite_index(suite_name);
j = bc_tester_test_suite_index(suite_name);
if(j != -1) {
for (i = 0; i < test_suite[j]->nb_tests; i++) {
if ((strcmp(test_name, test_suite[j]->tests[i].name) == 0) && (strlen(test_name) == strlen(test_suite[j]->tests[i].name))) {
......@@ -201,24 +194,24 @@ int tester_test_index(const char *suite_name, const char *test_name) {
return -1;
}
int tester_nb_test_suites(void) {
int bc_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);
int bc_tester_nb_tests(const char *suite_name) {
int i = bc_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;
const char * bc_tester_test_suite_name(int suite_index) {
if (suite_index >= bc_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;
const char * bc_tester_test_name(const char *suite_name, int test_index) {
int suite_index = bc_tester_test_suite_index(suite_name);
if ((suite_index < 0) || (suite_index >= bc_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;
}
......@@ -274,15 +267,15 @@ static void test_complete_message_handler(const CU_pTest pTest,
}
#endif
int tester_run_tests(const char *suite_name, const char *test_name) {
int bc_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]);
for (i = 0; i < bc_tester_nb_test_suites(); i++) {
bc_tester_run_suite(test_suite[i]);
}
#ifdef HAVE_CU_GET_SUITE
CU_set_suite_start_handler(suite_start_message_handler);
......@@ -294,10 +287,10 @@ int tester_run_tests(const char *suite_name, const char *test_name) {
CU_set_suite_init_failure_handler(suite_init_failure_message_handler);
CU_set_suite_cleanup_failure_handler(suite_cleanup_failure_message_handler);
if( tester_xml_file != NULL ){
CU_set_output_filename(tester_xml_file);
if( xml_file != NULL ){
CU_set_output_filename(xml_file);
}
if( tester_xml_enabled != 0 ){
if( xml_enabled != 0 ){
CU_automated_run_tests();
} else {
......@@ -311,14 +304,14 @@ int tester_run_tests(const char *suite_name, const char *test_name) {
suite=CU_get_suite(suite_name);
if (!suite) {
tester_printf(BELLE_SIP_LOG_ERROR, "Could not find suite '%s'. Available suites are:", suite_name);
tester_list_suites();
bc_tester_list_suites();
return -1;
} else if (test_name) {
CU_pTest test=CU_get_test_by_name(test_name, suite);
if (!test) {
tester_printf(BELLE_SIP_LOG_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);
bc_tester_list_suite_tests(suite->pName);
return -2;
} else {
CU_ErrorCode err= CU_run_test(suite, test);
......@@ -358,7 +351,7 @@ int tester_run_tests(const char *suite_name, const char *test_name) {
return ret;
}
void tester_add_suite(test_suite_t *suite) {
void bc_tester_add_suite(test_suite_t *suite) {
if (test_suite == NULL) {
test_suite = (test_suite_t **)malloc(10 * sizeof(test_suite_t *));
}
......@@ -369,7 +362,7 @@ void tester_add_suite(test_suite_t *suite) {
}
}
int tester_run_suite(test_suite_t *suite) {
int bc_tester_run_suite(test_suite_t *suite) {
int i;
CU_pSuite pSuite = CU_add_suite(suite->name, suite->init_func, suite->cleanup_func);
......@@ -383,7 +376,14 @@ int tester_run_suite(test_suite_t *suite) {
return 0;
}
void tester_uninit() {
void bc_tester_uninit() {
if ( xml_enabled ) {
/*create real xml file only if tester did not crash*/
char * xml_tmp_file = API_PREFIX(strdup_printf("%s.tmp", xml_file));
rename(xml_tmp_file, xml_file);
API_PREFIX(free(xml_tmp_file));
}
if (test_suite != NULL) {
free(test_suite);
test_suite = NULL;
......
......@@ -22,8 +22,8 @@
#include "CUnit/Basic.h"
extern const char *tester_file_prefix;
extern const char *tester_writable_dir_prefix;
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);
......@@ -52,26 +52,26 @@ fprintf(stderr, "Missing argument for \"%s\"\n", argument); \
return -1; \
} \
void tester_init(void (*tester_printf)(int level, const char *fmt, va_list args));
void tester_helper(const char *name, const char* additionnal_helper);
int tester_parse_args(int argc, char** argv, int argid);
int tester_start();
void bc_tester_init(void (*bc_tester_printf)(int level, const char *fmt, va_list args));
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();
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);
int bc_tester_test_suite_index(const char *suite_name);
void bc_tester_list_suites();
void bc_tester_list_suite_tests(const char *suite_name);
int bc_tester_test_index(const char *suite_name, const char *test_name);
int bc_tester_nb_test_suites(void);
int bc_tester_nb_tests(const char *suite_name);
const char * bc_tester_test_suite_name(int suite_index);
const char * bc_tester_test_name(const char *suite_name, int test_index);
int bc_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 bc_tester_add_suite(test_suite_t *suite);
int bc_tester_run_suite(test_suite_t *suite);
void tester_uninit();
void bc_tester_uninit();
#ifdef __cplusplus
......
......@@ -202,8 +202,8 @@ void start_adaptive_stream(MSFormatType type, stream_manager_t ** pmarielle, str
stream_manager_t *marielle=*pmarielle=stream_manager_new(type);
stream_manager_t *margaux=*pmargaux=stream_manager_new(type);
char* file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_16K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_16K_1S_FILE);
char* file = ms_strdup_printf("%s/%s", bc_tester_read_dir_prefix, HELLO_16K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", bc_tester_writable_dir_prefix, RECORDED_16K_1S_FILE);
marielle->user_data = recorded_file;
params.enabled=TRUE;
......@@ -310,7 +310,8 @@ static void event_queue_cb(MediaStream *ms, void *user_pointer) {
if (rb&&ortp_loss_rate_estimator_process_report_block(ctx->estimator,&ms->sessions.rtp_session->rtp,rb)){
float diff = fabs(ortp_loss_rate_estimator_get_value(ctx->estimator) - ctx->loss_rate);
CU_ASSERT_IN_RANGE(diff, 0, 10);
CU_ASSERT_TRUE(diff >= 0);
CU_ASSERT_TRUE(diff <= 10);
}
} while (rtcp_next_packet(evd->packet));
}
......@@ -404,7 +405,8 @@ void upload_bitrate(const char* codec, int payload, int target_bw, int expect_bw
media_stream_enable_adaptive_bitrate_control(&marielle->audio_stream->ms,FALSE);
iterate_adaptive_stream(marielle, margaux, 15000, NULL, 0);
upload_bw=media_stream_get_up_bw(&marielle->audio_stream->ms) / 1000;
CU_ASSERT_IN_RANGE(upload_bw, expect_bw-2, expect_bw+2);
CU_ASSERT_TRUE(upload_bw >= expect_bw-2);
CU_ASSERT_TRUE(upload_bw <= expect_bw+2);
stop_adaptive_stream(marielle,margaux);
}
}
......@@ -452,8 +454,10 @@ void adaptive_video(int max_bw, int exp_min_bw, int exp_max_bw, int loss_rate, i
stream_manager_t * marielle, * margaux;
start_adaptive_stream(MSVideo, &marielle, &margaux, VP8_PAYLOAD_TYPE, 300*1000, max_bw*1000, loss_rate, 50,0);
iterate_adaptive_stream(marielle, margaux, 100000, &marielle->rtcp_count, 7);
CU_ASSERT_IN_RANGE(marielle->adaptive_stats.loss_estim, exp_min_loss, exp_max_loss);
CU_ASSERT_IN_RANGE(marielle->adaptive_stats.congestion_bw_estim, exp_min_bw, exp_max_bw);
CU_ASSERT_TRUE(marielle->adaptive_stats.loss_estim >= exp_min_loss);
CU_ASSERT_TRUE(marielle->adaptive_stats.loss_estim <= exp_max_loss);
CU_ASSERT_TRUE(marielle->adaptive_stats.congestion_bw_estim >= exp_min_bw);
CU_ASSERT_TRUE(marielle->adaptive_stats.congestion_bw_estim <= exp_max_bw);
stop_adaptive_stream(marielle,margaux);
} else {
/*ortp_loss_estimator rely on the fact that we receive some packets: however when
......
......@@ -132,8 +132,8 @@ static void basic_audio_stream_base( const char* marielle_local_ip
AudioStream * margaux = audio_stream_new2 (margaux_local_ip, margaux_local_rtp_port,margaux_local_rtcp_port);
stats_t margaux_stats;
RtpProfile* profile = rtp_profile_new("default profile");
char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE);
char* hello_file = ms_strdup_printf("%s/%s", bc_tester_read_dir_prefix, HELLO_8K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", bc_tester_writable_dir_prefix, RECORDED_8K_1S_FILE);
int dummy=0;
rtp_session_set_multicast_loopback(marielle->ms.sessions.rtp_session,TRUE);
rtp_session_set_multicast_loopback(margaux->ms.sessions.rtp_session,TRUE);
......@@ -212,8 +212,8 @@ static void encrypted_audio_stream_base( bool_t change_ssrc,
AudioStream * marielle = audio_stream_new (MARIELLE_RTP_PORT, MARIELLE_RTCP_PORT,FALSE);
AudioStream * margaux = audio_stream_new (MARGAUX_RTP_PORT,MARGAUX_RTCP_PORT, FALSE);
RtpProfile* profile = rtp_profile_new("default profile");
char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE);
char* hello_file = ms_strdup_printf("%s/%s", bc_tester_read_dir_prefix, HELLO_8K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", bc_tester_writable_dir_prefix, RECORDED_8K_1S_FILE);
stats_t marielle_stats;
stats_t margaux_stats;
int dummy=0;
......@@ -391,8 +391,8 @@ static void codec_change_for_audio_stream(void) {
AudioStream *margaux = audio_stream_new2(MARGAUX_IP, MARGAUX_RTP_PORT, MARGAUX_RTCP_PORT);
stats_t margaux_stats;
RtpProfile *profile = rtp_profile_new("default profile");
char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE);
char* hello_file = ms_strdup_printf("%s/%s", bc_tester_read_dir_prefix, HELLO_8K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", bc_tester_writable_dir_prefix, RECORDED_8K_1S_FILE);
uint64_t marielle_rtp_sent = 0;
int dummy=0;
......
......@@ -210,7 +210,7 @@ static void dtmfgen_filerec_fileplay_tonedet(void) {
unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_FILEREC
| FILTER_MASK_FILEPLAY | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK;
bool_t send_silence = TRUE;
char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), DTMFGEN_FILE_NAME);
char* recorded_file = ms_strdup_printf("%s/%s", bc_tester_writable_dir_prefix, DTMFGEN_FILE_NAME);
ms_filter_reset_statistics();
ms_tester_create_ticker();
......
......@@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2_tester.h"
#include "mediastreamer2/msmediaplayer.h"
#include "mediastreamer2/mediastream.h"
static int tester_init() {
ms_init();
......@@ -134,9 +135,9 @@ static void play_file(const char *filepath, bool_t unsupported_format, bool_t se
}
static void play_root_file(const char *filepath, bool_t unsupported_format, bool_t seeking_test, bool_t play_twice){
char* file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), filepath);
char* file = ms_strdup_printf("%s/%s", bc_tester_read_dir_prefix, filepath);
play_file(file, unsupported_format, seeking_test, play_twice);
ms_free(file);
ms_free(file);
}
static void play_hello_8000_wav(void) {
......
......@@ -189,7 +189,7 @@ static void fileplay_soundwrite(const char *filename) {
}
static void fileplay_soundwrite_from_file(const char *filepath){
char* file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), filepath);
char* file = ms_strdup_printf("%s/%s", bc_tester_read_dir_prefix, filepath);
fileplay_soundwrite(file);
ms_free(file);
}
......@@ -366,7 +366,7 @@ static void soundread_filerec_fileplay_soundwrite(void) {
int playback_sample_rate = 8000;
int capture_nchannels = 1;
int playback_nchannels = 1;
char *writable_filename = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), SOUNDREAD_FILE_NAME);
char *writable_filename = ms_strdup_printf("%s/%s", bc_tester_writable_dir_prefix, SOUNDREAD_FILE_NAME);
ms_filter_reset_statistics();
ms_tester_create_ticker();
......
......@@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2_tester.h"
#include "mediastreamer2_tester_private.h"
#include "common/tester_utils.h"
#include <mediastreamer2/mediastream.h>
#if HAVE_CONFIG_H
#include <mediastreamer-config.h>
......@@ -36,277 +38,52 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
static test_suite_t **test_suite = NULL;
static int nb_test_suites = 0;
static const char* tester_fileroot = SOUND_FILE_PATH;
static const char* tester_writable_dir= WRITE_FILE_PATH;
static unsigned char xml = 0;
static const char *xml_file = "CUnitAutomated-Results.xml";
static char *xml_tmp_file = NULL;
static FILE * log_file = NULL;
static OrtpLogFunc ortp_log_handler;
#if HAVE_CU_CURSES
static unsigned char curses = 0;
#endif
// static const char* tester_fileroot = SOUND_FILE_PATH;
// static const char* tester_writable_dir= WRITE_FILE_PATH;
static void add_test_suite(test_suite_t *suite) {
if (test_suite == NULL) {
test_suite = (test_suite_t **)malloc(10 * sizeof(test_suite_t *));
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);
}
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;
}
static int test_suite_index(const char *suite_name) {
int i;
for (i = 0; i < mediastreamer2_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;
}
#if HAVE_CU_GET_SUITE
static void list_suite_tests(const char *suite_name) {
int j;
for( j = 0; j < mediastreamer2_tester_nb_tests(suite_name); j++) {
const char *test_name = mediastreamer2_tester_test_name(suite_name, j);
fprintf(stdout, "%s\n", test_name);
}
}
static void list_suites() {
int j;
for(j = 0; j < mediastreamer2_tester_nb_test_suites(); j++) {
const char *suite_name = mediastreamer2_tester_test_suite_name(j);
fprintf(stdout, "%s\n", suite_name);
}
}
#endif
const char* mediastreamer2_tester_get_file_root(){
return tester_fileroot;
}
void mediastreamer2_tester_set_file_root(const char* fileroot){
tester_fileroot = fileroot;
}
const char* mediastreamer2_tester_get_writable_dir(){
return tester_writable_dir;
}
void mediastreamer2_tester_set_writable_dir(const char* writable_dir){
tester_writable_dir = writable_dir;
}
int mediastreamer2_tester_nb_test_suites(void) {
return nb_test_suites;
}
int mediastreamer2_tester_nb_tests(const char *suite_name) {
int i = test_suite_index(suite_name);
if (i < 0) return 0;
return test_suite[i]->nb_tests;
}
const char * mediastreamer2_tester_test_suite_name(int suite_index) {
if (suite_index >= mediastreamer2_tester_nb_test_suites()) return NULL;
return test_suite[suite_index]->name;
}
const char * mediastreamer2_tester_test_name(const char *suite_name, int test_index) {
int suite_index = test_suite_index(suite_name);
if ((suite_index < 0) || (suite_index >= mediastreamer2_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 mediastreamer2_tester_init(void) {
int i;
ortp_log_handler = ortp_get_log_handler();
ortp_set_log_handler(ortp_logv_out);