From 8f8e4a44596475d9137f08bc64ae190360cd5bc4 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 16 Mar 2016 10:34:49 -0400 Subject: [PATCH] tests: Build audio test with ctest Signed-off-by: Anna Schumaker --- tests/core/CMakeLists.txt | 1 + tests/core/Sconscript | 2 +- tests/core/audio.c | 224 +++++++++++++++++++------------------- 3 files changed, 115 insertions(+), 112 deletions(-) diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index acd5af0b..e2c34e52 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -16,3 +16,4 @@ core_unit_test(Queue) add_subdirectory(playlists/) core_unit_test(Tempq) +core_unit_test(Audio) diff --git a/tests/core/Sconscript b/tests/core/Sconscript index e80b1a1d..c45a822f 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -37,7 +37,7 @@ res += SConscript("playlists/Sconscript") core_objs += [ env.Object("../../core/playlist.c") ] core_objs += [ env.Object("../../core/tempq.c") ] core_objs += [ env.Object("../../core/core.c") ] -res += [ CoreTest("audio") ] +core_objs += [ env.Object("../../core/audio.c") ] ignore.close() Return("res") diff --git a/tests/core/audio.c b/tests/core/audio.c index eaeae3ab..bfc7abde 100644 --- a/tests/core/audio.c +++ b/tests/core/audio.c @@ -55,32 +55,32 @@ static struct core_init_data test_init_data = { static void test_init() { - test_equal((void *)test_audio_player(), NULL); - test_equal((void *)audio_cur_track(), NULL); - test_equal(audio_cur_state(), GST_STATE_NULL); - test_equal((void *)audio_next(), NULL); + g_assert_null(test_audio_player()); + g_assert_null(audio_cur_track()); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_NULL); + g_assert_null(audio_next()); core_init(NULL, NULL, &test_init_data); - test_equal(audio_load(NULL), (bool)false); - test_equal((void *)audio_next(), NULL); - test_equal((void *)audio_prev(), NULL); + g_assert_false(audio_load(NULL)); + g_assert_null(audio_next()); + g_assert_null(audio_prev()); test_send_error(); - test_equal(audio_play(), (bool)false); - test_equal(audio_pause(), (bool)false); - test_equal(audio_seek(7), (bool)false); - test_equal(audio_position(), 0); - test_equal(audio_duration(), 0); - test_equal((void *)audio_cur_track(), NULL); - test_equal(audio_cur_state(), GST_STATE_NULL); - test_equal(load_count, 0); - test_equal(state_count, 0); + g_assert_false(audio_play()); + g_assert_false(audio_pause()); + g_assert_false(audio_seek(7)); + g_assert_cmpuint(audio_position(), ==, 0); + g_assert_cmpuint(audio_duration(), ==, 0); + g_assert_null(audio_cur_track()); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_NULL); + g_assert_cmpuint(load_count, ==, 0); + g_assert_cmpuint(state_count, ==, 0); playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony"); while (idle_run_task()) {}; - test_equal((void *)audio_cur_track(), NULL); - test_not_equal((void *)test_audio_player(), NULL); + g_assert_null(audio_cur_track()); + g_assert_nonnull(test_audio_player()); } static void test_playback() @@ -89,35 +89,37 @@ static void test_playback() unsigned int i; for (i = 0; i < 3; i++) { - test_loop_equal(audio_load(tracks[i]), (bool)(i == 0), i); - test_loop_equal(playlist_size(PL_SYSTEM, "History"), 1, i); - test_loop_equal(load_count, 1, i); - test_loop_equal(state_count, 1, i); - test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i); - test_loop_equal((void *)audio_cur_track(), (void *)tracks[0], i); - test_loop_equal(audio_duration(), - tracks[0]->tr_length * GST_SECOND, i); - } test_loop_passed(); + if (i == 0) + g_assert_true(audio_load(tracks[i])); + else + g_assert_false(audio_load(tracks[i])); + g_assert_cmpuint(playlist_size(PL_SYSTEM, "History"), ==, 1); + g_assert_cmpuint(load_count, ==, 1); + g_assert_cmpuint(state_count, ==, 1); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING); + g_assert(audio_cur_track() == tracks[0]); + g_assert_cmpuint(audio_duration(), ==, tracks[0]->tr_length * GST_SECOND); + } - test_equal(audio_pause(), (bool)true); - test_equal(audio_pause(), (bool)false); - test_equal(state_count, 2); - test_equal(audio_cur_state(), GST_STATE_PAUSED); + g_assert_true(audio_pause()); + g_assert_false(audio_pause()); + g_assert_cmpuint(state_count, ==, 2); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PAUSED); - test_equal(test_audio_seek(5 * GST_SECOND), (bool)true); - test_equal(audio_position(), 5 * GST_SECOND); - test_equal(test_audio_seek(42 * GST_SECOND), (bool)true); - test_equal(audio_position(), 42 * GST_SECOND); + g_assert_true(test_audio_seek(5 * GST_SECOND)); + g_assert_cmpuint(audio_position(), ==, 5 * GST_SECOND); + g_assert_true(test_audio_seek(42 * GST_SECOND)); + g_assert_cmpuint(audio_position(), ==, 42 * GST_SECOND); - test_equal(audio_play(), (bool)true); - test_equal(audio_play(), (bool)false); - test_equal(state_count, 3); - test_equal(audio_pause(), (bool)true); - test_equal(state_count, 4); - test_equal(audio_cur_state(), GST_STATE_PAUSED); + g_assert_true(audio_play()); + g_assert_false(audio_play()); + g_assert_cmpuint(state_count, ==, 3); + g_assert_true(audio_pause()); + g_assert_cmpuint(state_count, ==, 4); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PAUSED); /* Check duration again now that track is fully loaded. */ - test_equal(audio_duration(), track_get(0)->tr_length * GST_SECOND); + g_assert_cmpuint(audio_duration(), ==, track_get(0)->tr_length * GST_SECOND); } static void test_next() @@ -133,31 +135,29 @@ static void test_next() queue_add(temp_q, track_get(0)); for (i = 2; i >= 0; i--) { - test_loop_equal(queue_size(temp_q), i + 1, i); - if (i > 0) { - test_loop_equal(audio_next()->tr_track, track_get(i)->tr_track, i); - } else /* Simulate an error. */ + g_assert_cmpuint(queue_size(temp_q), ==, i + 1); + if (i > 0) + g_assert_cmpuint(audio_next()->tr_track, ==, track_get(i)->tr_track); + else /* Simulate an error. */ test_send_error(); - test_loop_equal((void *)queue_at(history_q, 0), - (void *)track_get(i), i); - test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i); - test_loop_equal((void *)audio_cur_track(), - (void *)track_get(i), i); - } test_loop_passed(); - test_equal(state_count, 3); - test_equal((void *)tempq_get(0), NULL); + g_assert(queue_at(history_q, 0) == track_get(i)); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING); + g_assert(audio_cur_track() == track_get(i)); + } + g_assert_cmpuint(state_count, ==, 3); + g_assert_null(tempq_get(0)); /* Tracks should now be picked from the collection. */ for (i = 1; i <= 3; i++) { - if (i < 3) { - test_loop_equal(audio_next()->tr_track, i, i); - } else /* Simulate an error. */ + if (i < 3) + g_assert_cmpuint(audio_next()->tr_track, ==, i); + else /* Simulate an error. */ test_send_error(); - test_loop_equal(queue_at(history_q, 0)->tr_track, i, i); - test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i); - test_loop_equal(audio_cur_track()->tr_track, i, i); - } test_loop_passed(); - test_equal(state_count, 6); + g_assert_cmpuint(queue_at(history_q, 0)->tr_track, ==, i); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING); + g_assert_cmpuint(audio_cur_track()->tr_track, ==, i); + } + g_assert_cmpuint(state_count, ==, 6); } static void test_prev() @@ -166,36 +166,36 @@ static void test_prev() struct track *track = queue_at(history_q, 0); state_count = 0; - test_equal(audio_prev()->tr_track, 2); - test_equal((void *)queue_at(history_q, 0), (void *)track); - test_equal(audio_cur_state(), GST_STATE_PLAYING); - test_equal(audio_cur_track()->tr_track, 2); - test_equal(state_count, 1); + g_assert_cmpuint(audio_prev()->tr_track, ==, 2); + g_assert(queue_at(history_q, 0) == track); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING); + g_assert_cmpuint(audio_cur_track()->tr_track, ==, 2); + g_assert_cmpuint(state_count, ==, 1); - test_equal(audio_prev()->tr_track, 1); - test_equal((void *)queue_at(history_q, 0), (void *)track); - test_equal(audio_cur_state(), GST_STATE_PLAYING); - test_equal(audio_cur_track()->tr_track, 1); - test_equal(state_count, 2); + g_assert_cmpuint(audio_prev()->tr_track, ==, 1); + g_assert(queue_at(history_q, 0) == track); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING); + g_assert_cmpuint(audio_cur_track()->tr_track, ==, 1); + g_assert_cmpuint(state_count, ==, 2); - test_equal(audio_pause(), (bool)true); - test_equal(audio_prev()->tr_track, track_get(0)->tr_track); - test_equal((void *)queue_at(history_q, 0), (void *)track); - test_equal(audio_cur_state(), GST_STATE_PLAYING); - test_equal(audio_cur_track()->tr_track, track_get(0)->tr_track); - test_equal(state_count, 4); + g_assert_true(audio_pause()); + g_assert_cmpuint(audio_prev()->tr_track, ==, track_get(0)->tr_track); + g_assert(queue_at(history_q, 0) == track); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING); + g_assert_cmpuint(audio_cur_track()->tr_track, ==, track_get(0)->tr_track); + g_assert_cmpuint(state_count, ==, 4); - test_equal(audio_prev()->tr_track, track_get(1)->tr_track); - test_equal((void *)queue_at(history_q, 0), (void *)track); - test_equal(audio_cur_state(), GST_STATE_PLAYING); - test_equal(audio_cur_track()->tr_track, track_get(1)->tr_track); - test_equal(state_count, 5); + g_assert_cmpuint(audio_prev()->tr_track, ==, track_get(1)->tr_track); + g_assert(queue_at(history_q, 0) == track); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING); + g_assert_cmpuint(audio_cur_track()->tr_track, ==, track_get(1)->tr_track); + g_assert_cmpuint(state_count, ==, 5); - test_equal(audio_prev()->tr_track, track_get(2)->tr_track); - test_equal((void *)queue_at(history_q, 0), (void *)track); - test_equal(audio_cur_state(), GST_STATE_PLAYING); - test_equal(audio_cur_track()->tr_track, track_get(2)->tr_track); - test_equal(state_count, 6); + g_assert_cmpuint(audio_prev()->tr_track, ==, track_get(2)->tr_track); + g_assert(queue_at(history_q, 0) == track); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING); + g_assert_cmpuint(audio_cur_track()->tr_track, ==, track_get(2)->tr_track); + g_assert_cmpuint(state_count, ==, 6); } void test_autopause() @@ -204,47 +204,49 @@ void test_autopause() int i; audio_pause_after(3); - test_equal(pause_count, 3); + g_assert_cmpuint(pause_count, ==, 3); pause_count = 0; audio_pause_after(3); - test_equal(pause_count, 0); + g_assert_cmpuint(pause_count, ==, 0); audio_pause_after(5); - test_equal(pause_count, 5); + g_assert_cmpuint(pause_count, ==, 5); state_count = 0; for (i = 4; i > -1; i--) { audio_eos(); - test_loop_equal(pause_count, i, i); - test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i); - test_loop_equal((void *)queue_at(history_q, 0), - (void *)audio_cur_track(), i); - } test_loop_passed(); - test_equal(state_count, 5); + g_assert_cmpuint(pause_count, ==, i); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING); + g_assert(queue_at(history_q, 0) == audio_cur_track()); + } + g_assert_cmpuint(state_count, ==, 5); audio_eos(); - test_equal(pause_count, -1); - test_equal(audio_cur_state(), GST_STATE_PAUSED); - test_equal(state_count, 6); + g_assert_cmpint(pause_count, ==, -1); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PAUSED); + g_assert_cmpuint(state_count, ==, 6); test_send_error(); - test_equal(audio_cur_state(), GST_STATE_PAUSED); + g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PAUSED); } static void test_deinit() { core_deinit(); - test_equal((void *)audio_cur_track(), NULL); - test_equal((void *)test_audio_player(), NULL); + g_assert_null(audio_cur_track()); + g_assert_null(test_audio_player()); } -DECLARE_UNIT_TESTS( - UNIT_TEST("Audio Initialization", test_init), - UNIT_TEST("Audio Playback", test_playback), - UNIT_TEST("Audio Next", test_next), - UNIT_TEST("Audio Previous", test_prev), - UNIT_TEST("Audio Automatic Pausing", test_autopause), - UNIT_TEST("Audio Deinitialization", test_deinit), -); +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/Core/Audio/Initialization", test_init); + g_test_add_func("/Core/Audio/Playback", test_playback); + g_test_add_func("/Core/Audio/Next", test_next); + g_test_add_func("/Core/Audio/Previous", test_prev); + g_test_add_func("/Core/Audio/Automatic Pausing", test_autopause); + g_test_add_func("/Core/Audio/Deinitialization", test_deinit); + return g_test_run(); +}