diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 29587cff..acd5af0b 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -15,3 +15,4 @@ add_subdirectory(tags/) core_unit_test(Queue) add_subdirectory(playlists/) +core_unit_test(Tempq) diff --git a/tests/core/Sconscript b/tests/core/Sconscript index a2759115..e80b1a1d 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -35,9 +35,7 @@ core_objs += [ env.Object("../../core/queue.c") ] res += SConscript("playlists/Sconscript") core_objs += [ env.Object("../../core/playlist.c") ] -res += [ CoreTest("playlist") ] -res += [ CoreTest("tempq") ] - +core_objs += [ env.Object("../../core/tempq.c") ] core_objs += [ env.Object("../../core/core.c") ] res += [ CoreTest("audio") ] diff --git a/tests/core/tempq.c b/tests/core/tempq.c index 1b0b7916..85489f9c 100644 --- a/tests/core/tempq.c +++ b/tests/core/tempq.c @@ -10,20 +10,16 @@ static void test_init() { - idle_init_sync(); - tags_init(); - playlist_init(NULL); - - test_equal((void *)tempq_next(), NULL); + g_assert_null(tempq_next()); tempq_init(NULL); while (idle_run_task()) {}; - test_equal((void *)tempq_next(), NULL); + g_assert_null(tempq_next()); tempq_move(NULL, 1); - test_equal((void *)tempq_get(0), NULL); - test_equal(tempq_count(), 0); - test_equal(tempq_index(NULL), (unsigned int)-1); + g_assert_null(tempq_get(0)); + g_assert_cmpuint(tempq_count(), ==, 0); + g_assert_cmpuint(tempq_index(NULL), ==, (unsigned int)-1); } static void test_alloc() @@ -31,36 +27,36 @@ static void test_alloc() struct queue *q0, *q1; q0 = tempq_alloc(0); - test_not_equal((void *)q0, NULL); - test_equal(queue_has_flag(q0, Q_ENABLED), (bool)true); - test_equal(queue_has_flag(q0, Q_RANDOM), (bool)false); - test_equal(queue_has_flag(q0, Q_SAVE_SORT), (bool)true); - test_equal(queue_has_flag(q0, Q_SAVE_FLAGS), (bool)true); - test_equal((void *)tempq_get(0), (void *)q0); - test_equal(tempq_count(), 1); - test_equal(tempq_index(q0), 0); + g_assert_nonnull(q0); + g_assert_true(queue_has_flag(q0, Q_ENABLED)); + g_assert_false(queue_has_flag(q0, Q_RANDOM)); + g_assert_true(queue_has_flag(q0, Q_SAVE_SORT)); + g_assert_true(queue_has_flag(q0, Q_SAVE_FLAGS)); + g_assert(tempq_get(0) == q0); + g_assert_cmpuint(tempq_count(), ==, 1); + g_assert_cmpuint(tempq_index(q0), ==, 0); q1 = tempq_alloc(Q_RANDOM); - test_not_equal((void *)q1, NULL); - test_equal(queue_has_flag(q1, Q_ENABLED), (bool)true); - test_equal(queue_has_flag(q1, Q_RANDOM), (bool)true); - test_equal(queue_has_flag(q1, Q_SAVE_SORT), (bool)true); - test_equal(queue_has_flag(q1, Q_SAVE_FLAGS), (bool)true); - test_equal((void *)tempq_get(1), (void *)q1); - test_equal(tempq_count(), 2); - test_equal(tempq_index(q1), 1); + g_assert_nonnull(q1); + g_assert_true(queue_has_flag(q1, Q_ENABLED)); + g_assert_true(queue_has_flag(q1, Q_RANDOM)); + g_assert_true(queue_has_flag(q1, Q_SAVE_SORT)); + g_assert_true(queue_has_flag(q1, Q_SAVE_FLAGS)); + g_assert(tempq_get(1) == q1); + g_assert_cmpuint(tempq_count(), ==, 2); + g_assert_cmpuint(tempq_index(q1), ==, 1); tempq_deinit(); - test_equal(tempq_count(), 0); + g_assert_cmpuint(tempq_count(), ==, 0); tempq_init(NULL); - test_equal(tempq_count(), 0); + g_assert_cmpuint(tempq_count(), ==, 0); while (idle_run_task()) {}; - test_equal(tempq_count(), 2); + g_assert_cmpuint(tempq_count(), ==, 2); q0 = tempq_get(0); q1 = tempq_get(1); - test_equal(queue_has_flag(q0, Q_RANDOM), (bool)false); - test_equal(queue_has_flag(q1, Q_RANDOM), (bool)true); + g_assert_false(queue_has_flag(q0, Q_RANDOM)); + g_assert_true(queue_has_flag(q1, Q_RANDOM)); } static void test_move() @@ -71,24 +67,24 @@ static void test_move() tempq_move(NULL, 0); tempq_move(q1, 0); - test_equal((void *)tempq_get(0), (void *)q1); - test_equal((void *)tempq_get(1), (void *)q0); - test_equal((void *)tempq_get(2), NULL); + g_assert(tempq_get(0) == q1); + g_assert(tempq_get(1) == q0); + g_assert_null(tempq_get(2)); tempq_move(q0, 1); - test_equal((void *)tempq_get(0), (void *)q1); - test_equal((void *)tempq_get(1), (void *)q0); - test_equal((void *)tempq_get(2), NULL); + g_assert(tempq_get(0) == q1); + g_assert(tempq_get(1) == q0); + g_assert_null(tempq_get(2)); tempq_deinit(); - test_equal(tempq_count(), 0); + g_assert_cmpuint(tempq_count(), ==, 0); tempq_init(NULL); while (idle_run_task()) {}; q0 = tempq_get(1); q1 = tempq_get(0); - test_equal(queue_has_flag(q0, Q_RANDOM), (bool)false); - test_equal(queue_has_flag(q1, Q_RANDOM), (bool)true); + g_assert_false(queue_has_flag(q0, Q_RANDOM)); + g_assert_true(queue_has_flag(q1, Q_RANDOM)); } static void test_free() @@ -97,16 +93,16 @@ static void test_free() struct queue *q1 = tempq_get(0); tempq_free(q0); - test_equal((void *)tempq_get(0), (void *)q1); - test_equal(tempq_count(), 1); + g_assert(tempq_get(0) == q1); + g_assert_cmpuint(tempq_count(), ==, 1); tempq_free(q1); - test_equal((void *)tempq_get(0), NULL); - test_equal(tempq_count(), 0); + g_assert_null(tempq_get(0)); + g_assert_cmpuint(tempq_count(), ==, 0); tempq_deinit(); tempq_init(NULL); - test_equal(tempq_count(), 0); + g_assert_cmpuint(tempq_count(), ==, 0); } static void test_next() @@ -129,40 +125,51 @@ static void test_next() tempq_deinit(); tempq_init(NULL); while (idle_run_task()) {}; - test_equal(tempq_count(), 2); + g_assert_cmpuint(tempq_count(), ==, 2); q0 = tempq_get(0); q1 = tempq_get(1); for (i = 0; i < track_db->db_size; i++) { - test_loop_equal(queue_size(q0), track_db->db_size - i, i); - test_loop_equal((void *)tempq_next(), (void *)track_get(i), i); - } test_loop_passed(); - test_equal((void *)tempq_get(0), (void *)q1); - test_equal(tempq_count(), 1); - test_equal(queue_size(q1), track_db->db_size); + g_assert_cmpuint(queue_size(q0), ==, track_db->db_size - i); + g_assert(tempq_next() == track_get(i)); + } + g_assert(tempq_get(0) == q1); + g_assert_cmpuint(tempq_count(), ==, 1); + g_assert_cmpuint(queue_size(q1), ==, track_db->db_size); tempq_deinit(); tempq_init(NULL); while (idle_run_task()) {}; - test_equal(tempq_count(), 1); + g_assert_cmpuint(tempq_count(), ==, 1); q1 = tempq_get(0); for (i = 0; i < track_db->db_size; i++) { - test_loop_equal(queue_size(q1), track_db->db_size - i, i); - test_loop_equal((void *)tempq_next(), (void *)track_get(i), i); - } test_loop_passed(); - test_equal((void *)tempq_get(0), NULL); - test_equal(tempq_count(), 0); + g_assert_cmpuint(queue_size(q1), ==, track_db->db_size - i); + g_assert(tempq_next() == track_get(i)); + } + g_assert_null(tempq_get(0)); + g_assert_cmpuint(tempq_count(), ==, 0); +} + +int main(int argc, char **argv) +{ + int ret; + + idle_init_sync(); + tags_init(); + playlist_init(NULL); + + g_test_init(&argc, &argv, NULL); + g_test_add_func("/Core/Temporary Queue/Initialization", test_init); + g_test_add_func("/Core/Temporary Queue/Alloc", test_alloc); + g_test_add_func("/Core/Temporary Queue/Move", test_move); + g_test_add_func("/Core/Temporary Queue/Free", test_free); + g_test_add_func("/Core/Temporary Queue/Next Track", test_next); + ret = g_test_run(); tempq_deinit(); playlist_deinit(); tags_deinit(); + idle_deinit(); + return ret; } - -DECLARE_UNIT_TESTS( - UNIT_TEST("Temporary Queue Initialization", test_init), - UNIT_TEST("Temporary Queue Alloc", test_alloc), - UNIT_TEST("Temporary Queue Move", test_move), - UNIT_TEST("Temporary Queue Free", test_free), - UNIT_TEST("Temporary Queue Next Track", test_next), -);