From 17491e452e2024080e0cf231d85996821105b455 Mon Sep 17 00:00:00 2001 From: Seungbae Shin Date: Fri, 29 Jun 2018 20:27:57 +0900 Subject: [PATCH] Revise testsuite code rename testsuite and include to package [Version] 0.2.1 [Issue Type] Revision Change-Id: I556a85af08053ea3d3e35a70611bc5e7f2855ca5 --- packaging/capi-media-tone-player.spec | 3 +- test/CMakeLists.txt | 2 + ..._tone_player_test.c => tone_player_test.c} | 89 ++++++++++++++----- 3 files changed, 69 insertions(+), 25 deletions(-) rename test/{multimedia_tone_player_test.c => tone_player_test.c} (58%) diff --git a/packaging/capi-media-tone-player.spec b/packaging/capi-media-tone-player.spec index 0780885..a47a8dd 100755 --- a/packaging/capi-media-tone-player.spec +++ b/packaging/capi-media-tone-player.spec @@ -1,6 +1,6 @@ Name: capi-media-tone-player Summary: A tone player library in Tizen C API -Version: 0.2.0 +Version: 0.2.1 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -50,6 +50,7 @@ make %{?jobs:-j%jobs} %manifest %{name}.manifest %license LICENSE %{_libdir}/libcapi-media-tone-player.so.* +%{_bindir}/* %files devel %manifest %{name}.manifest diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 07a6abf..67b26f3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,3 +16,5 @@ FOREACH(src ${sources}) ADD_EXECUTABLE(${src_name} ${src}) TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS}) ENDFOREACH() + +INSTALL(TARGETS tone_player_test DESTINATION bin) diff --git a/test/multimedia_tone_player_test.c b/test/tone_player_test.c similarity index 58% rename from test/multimedia_tone_player_test.c rename to test/tone_player_test.c index 7aa38dd..0c7ab3f 100755 --- a/test/multimedia_tone_player_test.c +++ b/test/tone_player_test.c @@ -26,21 +26,39 @@ #define TONE_FIRST TONE_TYPE_DTMF_0 #define TONE_LAST TONE_TYPE_USER_DEFINED_HIGH_FRE -static GMainLoop *g_mainloop = NULL; +static GMainLoop *g_mainloop; static GThread *event_thread; -gpointer GmainThread(gpointer data) +static gpointer _g_mainloop_thread(gpointer data) { g_mainloop = g_main_loop_new(NULL, 0); + + g_print("now run mainloop %p\n", g_mainloop); g_main_loop_run(g_mainloop); + g_print("mainloop %p quit...\n", g_mainloop); + + g_main_loop_unref(g_mainloop); return NULL; } -void help() +static gboolean _g_timeout_cb(gpointer data) +{ + int id = (int)data; + int ret = 0; + + g_print("< Stopping id(%d), ", id); + ret = tone_player_stop(id); + g_print("Done! ret=0x%X >", ret); + + return FALSE; +} + + +static void _help() { - printf("Usage : "); - printf("multimedia_tone_player_test [OPTION]\n\n" + g_print("Usage : "); + g_print("tone_player_test [OPTION]\n\n" " -f, --from from which tone type\n" " -t, --to to which tone type\n" " -d, --duration duration(ms)\n" @@ -48,42 +66,56 @@ void help() " -h, --help help\n"); } -static void stream_focus_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, +static void _stream_focus_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason, int sound_behavior, const char *extra_info, void *user_data) { + g_print("stream focus callback invoked...\n"); return; } -void tone_play_test(int from, int to, int duration, int sleep_time) +static void _tone_play_test(int from, int to, int duration, int sleep_time) { - int i; - sound_stream_info_h stream_info; + int i, j; + int id = -1; + sound_stream_info_h stream_info = NULL; - printf("From : %2d, To : %2d, Duration : %4d, sleep_time : %4d\n", from, to, duration, sleep_time); + g_print("From : %2d, To : %2d, Duration : %4d, sleep_time : %4d\n", from, to, duration, sleep_time); if (from < TONE_FIRST || to < TONE_FIRST || duration < 0 || from > to || from > TONE_LAST || to > TONE_LAST || sleep_time < 0) { - printf("Wrong Parameter\n"); + g_print("Wrong Parameter\n"); return; } - - if (sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, stream_focus_cb, NULL, &stream_info)) { - printf("failed to create stream info\n"); + + if (sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, _stream_focus_cb, NULL, &stream_info)) { + g_print("failed to create stream info\n"); return; } for (i = from; i <= to; i++) { - printf("Play Tone : %d\n", i); - tone_player_start_new(i, stream_info, duration, NULL); - usleep(sleep_time * 1000); + g_print("* Playing Tone : %3d -> ", i); + tone_player_start_new(i, stream_info, duration, &id); + g_print("id(%d) ", id); + + if (duration != sleep_time) + g_timeout_add(sleep_time, _g_timeout_cb, (void *)id); + + for (j = 0; j < sleep_time / 100; j++) { + g_print("."); + usleep(100*1000); + } + + usleep(1000*1000); + g_print(" *\n"); } - + sound_manager_destroy_stream_information(stream_info); + + g_main_loop_quit(g_mainloop); } int main(int argc, char **argv) { - GError *gerr = NULL; int from = TONE_TYPE_DTMF_0, to = TONE_TYPE_DTMF_S; int duration = 500, sleep_time = -1; @@ -106,9 +138,17 @@ int main(int argc, char **argv) switch (opt) { case 'f': from = atoi(optarg); + if (from < TONE_FIRST) + from = TONE_FIRST; + else if (from > TONE_LAST) + from = TONE_LAST; break; case 't': to = atoi(optarg); + if (to < TONE_FIRST) + to = TONE_FIRST; + else if (to > TONE_LAST) + to = TONE_LAST; break; case 'd': duration = atoi(optarg); @@ -118,7 +158,7 @@ int main(int argc, char **argv) break; case 'h': default: - help(); + _help(); return 0; } } @@ -126,12 +166,13 @@ int main(int argc, char **argv) if (sleep_time == -1) sleep_time = duration; - if (!g_thread_supported()) - g_thread_init(NULL); + event_thread = g_thread_new(NULL, _g_mainloop_thread, NULL); - event_thread = g_thread_create(GmainThread, NULL, 1, &gerr); + _tone_play_test(from, to, duration, sleep_time); - tone_play_test(from, to, duration, sleep_time); + g_print("Now join the thread, "); + g_thread_join(event_thread); + g_print("Done, QUIT testsuite\n"); return 0; } -- 2.34.1