tests: Build tags/library test with ctest

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-03-09 10:55:07 -05:00 committed by Anna Schumaker
parent ca2f35a848
commit 921a04e28e
3 changed files with 41 additions and 33 deletions

View File

@ -7,3 +7,4 @@ endfunction()
tag_unit_test(Artist)
tag_unit_test(Album)
tag_unit_test(Genre)
tag_unit_test(Library)

View File

@ -14,8 +14,7 @@ env.UsePackage("taglib_c")
core_objs += [ env.Object("../../../core/tags/artist.c") ]
core_objs += [ env.Object("../../../core/tags/album.c") ]
core_objs += [ env.Object("../../../core/tags/genre.c") ]
res += [ TagTest("library") ]
core_objs += [ env.Object("../../../core/tags/library.c") ]
core_objs += [ env.Object("../../../core/tags/tags.c") ]
res += [ TagTest("track") ]

View File

@ -7,19 +7,19 @@
static void test_verify_zelda(struct library *library)
{
const struct db_ops *library_ops = test_library_ops();
test_equal(library->li_enabled, (bool)true);
test_equal(library->li_size, 0);
test_equal(library->li_playlist, NULL);
test_equal(library_ops->dbe_key(&library->li_dbe), "/home/Zelda/Music");
g_assert_true(library->li_enabled);
g_assert_cmpuint(library->li_size, ==, 0);
g_assert_null(library->li_playlist);
g_assert_cmpstr(library_ops->dbe_key(&library->li_dbe), ==, "/home/Zelda/Music");
}
static void test_verify_link(struct library *library)
{
const struct db_ops *library_ops = test_library_ops();
test_equal(library->li_enabled, (bool)false);
test_equal(library->li_size, 0);
test_equal(library->li_playlist, NULL);
test_equal(library_ops->dbe_key(&library->li_dbe), "/home/Link/Music");
g_assert_false(library->li_enabled);
g_assert_cmpuint(library->li_size, ==, 0);
g_assert_null(library->li_playlist);
g_assert_cmpstr(library_ops->dbe_key(&library->li_dbe), ==, "/home/Link/Music");
}
static void test_library()
@ -48,16 +48,16 @@ static void test_library()
file_open(&f, OPEN_READ);
library = LIBRARY(library_ops->dbe_read(&f));
test_verify_link(library);
test_str_equal(library_file(library, "navi.mp3"),
"/home/Link/Music/navi.mp3");
g_assert_cmpstr_free(library_file(library, "navi.mp3"), ==,
"/home/Link/Music/navi.mp3");
g_free(library->li_path);
library_ops->dbe_free(&library->li_dbe);
library = LIBRARY(library_ops->dbe_read(&f));
file_close(&f);
test_verify_zelda(library);
test_str_equal(library_file(library, "impa.ogg"),
"/home/Zelda/Music/impa.ogg");
g_assert_cmpstr_free(library_file(library, "impa.ogg"), ==,
"/home/Zelda/Music/impa.ogg");
g_free(link->li_path);
g_free(zelda->li_path);
@ -73,43 +73,51 @@ static void test_library_db()
struct library *library, *library2;
struct database library_db;
test_not_equal((void *)library_db_get(), NULL);
test_equal(library_db_get()->db_size, 0);
g_assert_nonnull(library_db_get());
g_assert_cmpuint(library_db_get()->db_size, ==, 0);
library_db_init();
library = library_lookup("/home/Zelda/Music");
test_equal((void *)library, NULL);
g_assert_null(library);
library = library_find("/home/Zelda/Music");
test_verify_zelda(library);
test_equal(library_db_get()->db_size, 1);
test_equal((void *)library_lookup("/home/Zelda/Music"), (void *)library);
test_equal((void *)library_find("/home/Zelda/Music"), (void *)library);
test_equal((void *)library_get(0), (void *)library);
test_equal((void *)library_get(1), NULL);
g_assert_cmpuint(library_db_get()->db_size, ==, 1);
g_assert(library_lookup("/home/Zelda/Music") == library);
g_assert(library_find("/home/Zelda/Music") == library);
g_assert(library_get(0) == library);
g_assert_null(library_get(1));
db_init(&library_db, "library.db", false, library_ops);
db_load(&library_db);
test_equal(library_db.db_size, 1);
test_equal(db_actual_size(&library_db), 1);
g_assert_cmpuint(library_db.db_size, ==, 1);
g_assert_cmpuint(db_actual_size(&library_db), ==, 1);
library2 = LIBRARY(db_at(&library_db, 0));
test_not_equal((void *)library2, NULL);
g_assert_nonnull(library2);
test_verify_zelda(library2);
library_remove(library);
test_equal((void *)library_get(0), (void *)NULL);
test_equal(library_db_get()->db_size, 0);
g_assert_null(library_get(0));
g_assert_cmpuint(library_db_get()->db_size, ==, 0);
library_db_deinit();
db_deinit(&library_db);
library_db.db_entries = g_ptr_array_new();
db_load(&library_db);
test_equal(library_db.db_size, 0);
g_assert_cmpuint(library_db.db_size, ==, 0);
g_ptr_array_free(library_db.db_entries, true);
}
DECLARE_UNIT_TESTS(
UNIT_TEST("Library Tag", test_library),
UNIT_TEST("Library Database", test_library_db),
);
int main(int argc, char **argv)
{
int ret;
library_db_init();
g_test_init(&argc, &argv, NULL);
g_test_add_func("/Core/Tags/Library", test_library);
g_test_add_func("/Core/Tags/Library/Database", test_library_db);
ret = g_test_run();
library_db_deinit();
return ret;
}