From d4c76523389a3921817bcdb5c2a65385ef37ae5f Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 11 Sep 2015 10:09:10 +0200 Subject: [PATCH] tools: move test_lsd test_ecc test_numbers from coreapi to tools folder --- .gitignore | 6 +- coreapi/Makefile.am | 16 ----- coreapi/test_lsd.c | 104 ------------------------------ tools/Makefile.am | 16 +++++ {coreapi => tools}/test_ecc.c | 35 +++++----- tools/test_lsd.c | 103 +++++++++++++++++++++++++++++ {coreapi => tools}/test_numbers.c | 37 ++++++----- 7 files changed, 160 insertions(+), 157 deletions(-) delete mode 100644 coreapi/test_lsd.c rename {coreapi => tools}/test_ecc.c (64%) create mode 100644 tools/test_lsd.c rename {coreapi => tools}/test_numbers.c (52%) diff --git a/.gitignore b/.gitignore index 36ee91daf..b38bd2977 100644 --- a/.gitignore +++ b/.gitignore @@ -50,8 +50,6 @@ coreapi/help/chatroom coreapi/help/doc/ coreapi/help/helloworld coreapi/help/registration -coreapi/test_ecc -coreapi/test_lsd gtk/version_date.h specs.c *.orig @@ -62,7 +60,9 @@ specs.c *.swp .deps .libs -coreapi/test_numbers +tools/test_ecc +tools/test_lsd +tools/test_numbers coreapi/help/notify share/fresh-rootca.pem share/certdata.txt diff --git a/coreapi/Makefile.am b/coreapi/Makefile.am index d4c4516ce..8219cc1f6 100644 --- a/coreapi/Makefile.am +++ b/coreapi/Makefile.am @@ -144,22 +144,6 @@ liblinphone_la_LIBADD= \ $(ZLIB_LIBS) -if ENABLE_TESTS -noinst_PROGRAMS=test_lsd test_ecc test_numbers - -test_lsd_SOURCES=test_lsd.c - -test_lsd_LDADD=liblinphone.la $(liblinphone_la_LIBADD) - -test_ecc_SOURCES=test_ecc.c - -test_ecc_LDADD=liblinphone.la $(liblinphone_la_LIBADD) - -test_numbers_SOURCES=test_numbers.c - -test_numbers_LDADD=liblinphone.la $(liblinphone_la_LIBADD) -endif - AM_CPPFLAGS=\ -I$(top_srcdir) -I$(top_srcdir)/include -I$(builddir) \ $(ORTP_CFLAGS) \ diff --git a/coreapi/test_lsd.c b/coreapi/test_lsd.c deleted file mode 100644 index a4e78ea11..000000000 --- a/coreapi/test_lsd.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -linphone -Copyright (C) 2010 Simon MORLAT (simon.morlat@linphone.org) - -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, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -/* Linphone Sound Daemon: is a lightweight utility to play sounds to speaker during a conversation. - This is useful for embedded platforms, where sound apis are not performant enough to allow - simultaneous sound access. - - This file is a test program that plays several sound files and places a call simultatenously. -*/ - -#include "linphonecore_utils.h" - - -static void play_finished(LsdPlayer *p){ - const char *filename=(const char *)lsd_player_get_user_pointer (p); - ms_message("Playing of %s is finished.",filename); - if (!lsd_player_loop_enabled (p)){ - linphone_sound_daemon_release_player (lsd_player_get_daemon(p),p); - } -} - -static void wait_a_bit(LinphoneCore *lc, int seconds){ - time_t orig=ms_time(NULL); - while(ms_time(NULL)-orig1){ - linphone_core_invite(lc,argv[1]); - wait_a_bit(lc,10); - linphone_core_terminate_call(lc,NULL); - } - linphone_core_use_sound_daemon(lc,NULL); - linphone_sound_daemon_destroy(lsd); - linphone_core_destroy(lc); - - return 0; -} diff --git a/tools/Makefile.am b/tools/Makefile.am index ecd6cab5a..71a222e8b 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -50,4 +50,20 @@ lp_autoanswer_LDADD=\ endif +if ENABLE_TESTS +noinst_PROGRAMS=test_lsd test_ecc test_numbers + +test_lsd_SOURCES=test_lsd.c +test_lsd_CFLAGS=$(COMMON_CFLAGS) +test_lsd_LDADD=$(top_builddir)/coreapi/liblinphone.la + +test_ecc_SOURCES=test_ecc.c +test_ecc_CFLAGS=$(COMMON_CFLAGS) +test_ecc_LDADD=$(top_builddir)/coreapi/liblinphone.la + +test_numbers_SOURCES=test_numbers.c +test_numbers_CFLAGS=$(COMMON_CFLAGS) +test_numbers_LDADD=$(top_builddir)/coreapi/liblinphone.la + +endif diff --git a/coreapi/test_ecc.c b/tools/test_ecc.c similarity index 64% rename from coreapi/test_ecc.c rename to tools/test_ecc.c index 8d383b625..35c989416 100644 --- a/coreapi/test_ecc.c +++ b/tools/test_ecc.c @@ -18,47 +18,46 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #include "linphonecore.h" #include "linphonecore_utils.h" #if _MSC_VER #include #endif -static void calibration_finished(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay, void *data){ - ms_message("echo calibration finished %s.",status==LinphoneEcCalibratorDone ? "successfully" : "with faillure"); - if (status==LinphoneEcCalibratorDone) ms_message("Measured delay is %i",delay); +static void calibration_finished(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay, void *data) { + ms_message("echo calibration finished %s.", status == LinphoneEcCalibratorDone ? "successfully" : "with faillure"); + if (status == LinphoneEcCalibratorDone) + ms_message("Measured delay is %i", delay); } - static char config_file[1024]; -void parse_args(int argc, char *argv[]){ +void parse_args(int argc, char *argv[]) { #ifndef F_OK #define F_OK 4 #endif - if (argc != 3 || strncmp("-c",argv[1], 2) || access(argv[2],F_OK)!=0) { + if (argc != 3 || strncmp("-c", argv[1], 2) || access(argv[2], F_OK) != 0) { printf("Usage: test_ecc [-c config_file] where config_file will be written with the detected value\n"); exit(-1); } - strncpy(config_file,argv[2],1024); + strncpy(config_file, argv[2], 1024); } -int main(int argc, char *argv[]){ - int count=0; - LinphoneCoreVTable vtable={0}; +int main(int argc, char *argv[]) { + int count = 0; + LinphoneCoreVTable vtable = {0}; LinphoneCore *lc; - if (argc>1) parse_args(argc,argv); - lc=linphone_core_new(&vtable,config_file,NULL,NULL); - + if (argc > 1) + parse_args(argc, argv); + lc = linphone_core_new(&vtable, config_file, NULL, NULL); + linphone_core_enable_logs(NULL); - linphone_core_start_echo_calibration(lc,calibration_finished,NULL,NULL,NULL); - - while(count++<1000){ + linphone_core_start_echo_calibration(lc, calibration_finished, NULL, NULL, NULL); + + while (count++ < 1000) { linphone_core_iterate(lc); ms_usleep(10000); } linphone_core_destroy(lc); return 0; } - diff --git a/tools/test_lsd.c b/tools/test_lsd.c new file mode 100644 index 000000000..ed38fedde --- /dev/null +++ b/tools/test_lsd.c @@ -0,0 +1,103 @@ +/* +linphone +Copyright (C) 2010 Simon MORLAT (simon.morlat@linphone.org) + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +/* Linphone Sound Daemon: is a lightweight utility to play sounds to speaker during a conversation. + This is useful for embedded platforms, where sound apis are not performant enough to allow + simultaneous sound access. + + This file is a test program that plays several sound files and places a call simultatenously. +*/ + +#include "linphonecore_utils.h" + +static void play_finished(LsdPlayer *p) { + const char *filename = (const char *)lsd_player_get_user_pointer(p); + ms_message("Playing of %s is finished.", filename); + if (!lsd_player_loop_enabled(p)) { + linphone_sound_daemon_release_player(lsd_player_get_daemon(p), p); + } +} + +static void wait_a_bit(LinphoneCore *lc, int seconds) { + time_t orig = ms_time(NULL); + while (ms_time(NULL) - orig < seconds) { + /* we need to call iterate to receive notifications */ + linphone_core_iterate(lc); + ms_usleep(50000); + } +} + +int main(int argc, char *argv[]) { + LinphoneCore *lc; + LinphoneCoreVTable vtable = {0}; + LinphoneSoundDaemon *lsd; + LsdPlayer *p; + + linphone_core_enable_logs(stdout); + lc = linphone_core_new(&vtable, NULL, NULL, NULL); + lsd = linphone_sound_daemon_new(NULL, 44100, 1); + + linphone_core_use_sound_daemon(lc, lsd); + + /* start a play */ + p = linphone_sound_daemon_get_player(lsd); + lsd_player_set_callback(p, play_finished); + lsd_player_set_user_pointer(p, "share/hello8000.wav"); + lsd_player_play(p, "share/hello8000.wav"); + wait_a_bit(lc, 2); + + /*start another one */ + p = linphone_sound_daemon_get_player(lsd); + lsd_player_set_callback(p, play_finished); + lsd_player_set_user_pointer(p, "share/hello16000.wav"); + lsd_player_enable_loop(p, TRUE); + lsd_player_play(p, "share/hello16000.wav"); + + /* after a few seconds decrease the volume */ + wait_a_bit(lc, 3); + lsd_player_set_gain(p, 0.3); + wait_a_bit(lc, 5); + + /*now play some stereo music*/ + p = linphone_sound_daemon_get_player(lsd); + lsd_player_set_callback(p, play_finished); + lsd_player_set_user_pointer(p, "share/rings/rock.wav"); + lsd_player_play(p, "share/rings/rock.wav"); + wait_a_bit(lc, 2); + + /*now play some stereo music at 22khz in order to test + stereo resampling */ + p = linphone_sound_daemon_get_player(lsd); + lsd_player_set_callback(p, play_finished); + lsd_player_set_user_pointer(p, "share/rings/bigben.wav"); + lsd_player_play(p, "share/rings/bigben.wav"); + wait_a_bit(lc, 6); + + /* now place an outgoing call if sip address argument is given */ + if (argc > 1) { + linphone_core_invite(lc, argv[1]); + wait_a_bit(lc, 10); + linphone_core_terminate_call(lc, NULL); + } + linphone_core_use_sound_daemon(lc, NULL); + linphone_sound_daemon_destroy(lsd); + linphone_core_destroy(lc); + + return 0; +} diff --git a/coreapi/test_numbers.c b/tools/test_numbers.c similarity index 52% rename from coreapi/test_numbers.c rename to tools/test_numbers.c index 4bfa2c77a..f6d3baaf3 100644 --- a/coreapi/test_numbers.c +++ b/tools/test_numbers.c @@ -18,34 +18,39 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #include "linphonecore.h" #include "linphonecore_utils.h" -int main(int argc , char *argv[]){ +int main(int argc, char *argv[]) { LinphoneProxyConfig *cfg; char *normalized_number; - if (argc<2){ - fprintf(stderr,"Usage:\n%s [] [--escape-plus]\nReturns normalized number.", argv[0]); + if (argc < 2) { + fprintf(stderr, "Usage:\n%s [] [--escape-plus]\nReturns normalized number.", + argv[0]); return -1; } linphone_core_enable_logs(stderr); - cfg=linphone_proxy_config_new(); - if (argc>2) - linphone_proxy_config_set_dial_prefix(cfg,argv[2]); - if (argc>3 && strcmp(argv[3],"--escape-plus")==0) - linphone_proxy_config_set_dial_escape_plus(cfg,TRUE); - normalized_number = linphone_proxy_config_normalize_phone_number(cfg,argv[1]); + linphone_core_set_log_level(ORTP_DEBUG); + cfg = linphone_proxy_config_new(); + if (argc > 2) + linphone_proxy_config_set_dial_prefix(cfg, argv[2]); + if (argc > 3 && strcmp(argv[3], "--escape-plus") == 0) + linphone_proxy_config_set_dial_escape_plus(cfg, TRUE); + normalized_number = linphone_proxy_config_normalize_phone_number(cfg, argv[1]); if (!normalized_number) { - printf("Invalid phone number: %s\n", normalized_number); + printf("Invalid phone number: %s\n", argv[1]); } else { - printf("Normalized number is %s\n",normalized_number); + printf("Normalized number is %s\n", normalized_number); /*check extracted ccc*/ - if (linphone_dial_plan_lookup_ccc_from_e164(normalized_number) != atoi(linphone_proxy_config_get_dial_prefix(cfg))) { - printf("Error ccc [%i] not correctly parsed\n",linphone_dial_plan_lookup_ccc_from_e164(normalized_number)); - } else { - printf("Extracted ccc is [%i] \n",linphone_dial_plan_lookup_ccc_from_e164(normalized_number)); + if (linphone_proxy_config_get_dial_prefix(cfg) != NULL) { + if (linphone_dial_plan_lookup_ccc_from_e164(normalized_number) != + atoi(linphone_proxy_config_get_dial_prefix(cfg))) { + printf("Error ccc [%i] not correctly parsed\n", + linphone_dial_plan_lookup_ccc_from_e164(normalized_number)); + } else { + printf("Extracted ccc is [%i] \n", linphone_dial_plan_lookup_ccc_from_e164(normalized_number)); + } } } return 0;