tests: Build tags/artist test with ctest
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
1b83978b09
commit
8c875acec9
|
@ -8,6 +8,12 @@
|
||||||
#include <coverart/caa_c.h>
|
#include <coverart/caa_c.h>
|
||||||
#include <musicbrainz5/mb5_c.h>
|
#include <musicbrainz5/mb5_c.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_TESTING
|
||||||
|
#define OCARINA_AGENT "ocarina-test"
|
||||||
|
#else
|
||||||
|
#define OCARINA_AGENT OCARINA_NAME
|
||||||
|
#endif
|
||||||
|
|
||||||
static struct database album_db;
|
static struct database album_db;
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +38,7 @@ static bool __album_fetch_cover(struct album *album, gchar *releaseid)
|
||||||
CaaCoverArt *caa;
|
CaaCoverArt *caa;
|
||||||
gchar error[256];
|
gchar error[256];
|
||||||
|
|
||||||
caa = caa_coverart_new(OCARINA_NAME);
|
caa = caa_coverart_new(OCARINA_AGENT);
|
||||||
if (!caa)
|
if (!caa)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -89,7 +95,7 @@ static bool __album_run_query(struct album *album, gchar *term1,
|
||||||
param = g_strjoin(" AND ", term1, term2, term3, NULL);
|
param = g_strjoin(" AND ", term1, term2, term3, NULL);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
mb5 = mb5_query_new(OCARINA_NAME, NULL, 0);
|
mb5 = mb5_query_new(OCARINA_AGENT, NULL, 0);
|
||||||
if (!mb5)
|
if (!mb5)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,7 @@ add_definitions(${DEBUG_OPTIONS} -DCONFIG_TESTING)
|
||||||
|
|
||||||
# Handle files that depend on CONFIG_TESTING_DIR
|
# Handle files that depend on CONFIG_TESTING_DIR
|
||||||
list(REMOVE_ITEM core ${PROJECT_SOURCE_DIR}/core/file.c)
|
list(REMOVE_ITEM core ${PROJECT_SOURCE_DIR}/core/file.c)
|
||||||
list(REMOVE_ITEM core ${PROJECT_SOURCE_DIR}/core/tags/album.c)
|
|
||||||
list(APPEND corefiles ${PROJECT_SOURCE_DIR}/core/file.c)
|
list(APPEND corefiles ${PROJECT_SOURCE_DIR}/core/file.c)
|
||||||
list(APPEND corefiles ${PROJECT_SOURCE_DIR}/core/tags/album.c)
|
|
||||||
|
|
||||||
add_library(corelib OBJECT EXCLUDE_FROM_ALL ${core})
|
add_library(corelib OBJECT EXCLUDE_FROM_ALL ${core})
|
||||||
add_subdirectory(core/)
|
add_subdirectory(core/)
|
||||||
|
|
|
@ -10,3 +10,5 @@ core_unit_test(File)
|
||||||
core_unit_test(Date)
|
core_unit_test(Date)
|
||||||
core_unit_test(Idle)
|
core_unit_test(Idle)
|
||||||
core_unit_test(Database)
|
core_unit_test(Database)
|
||||||
|
|
||||||
|
add_subdirectory(tags/)
|
||||||
|
|
7
tests/core/tags/CMakeLists.txt
Normal file
7
tests/core/tags/CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Include(../../UnitTest.cmake)
|
||||||
|
|
||||||
|
function(tag_unit_test name)
|
||||||
|
unit_test(Core/Tags ${name} corelib ${corefiles})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
tag_unit_test(Artist)
|
|
@ -11,7 +11,7 @@ def TagTest(name):
|
||||||
return run
|
return run
|
||||||
|
|
||||||
env.UsePackage("taglib_c")
|
env.UsePackage("taglib_c")
|
||||||
res += [ TagTest("artist") ]
|
core_objs += [ env.Object("../../../core/tags/artist.c") ]
|
||||||
res += [ TagTest("album") ]
|
res += [ TagTest("album") ]
|
||||||
res += [ TagTest("genre") ]
|
res += [ TagTest("genre") ]
|
||||||
res += [ TagTest("library") ]
|
res += [ TagTest("library") ]
|
||||||
|
|
|
@ -7,23 +7,23 @@
|
||||||
static void test_verify_empty(struct artist *artist)
|
static void test_verify_empty(struct artist *artist)
|
||||||
{
|
{
|
||||||
const struct db_ops *artist_ops = test_artist_ops();
|
const struct db_ops *artist_ops = test_artist_ops();
|
||||||
test_equal(artist->ar_name, "");
|
g_assert_cmpstr(artist->ar_name, ==, "");
|
||||||
test_equal((void *)artist->ar_tokens[0], NULL);
|
g_assert_null(artist->ar_tokens[0]);
|
||||||
test_equal((void *)artist->ar_alts[0], NULL);
|
g_assert_null(artist->ar_alts[0]);
|
||||||
test_equal(artist->ar_playlist, NULL);
|
g_assert_null(artist->ar_playlist);
|
||||||
test_equal(artist_ops->dbe_key(&artist->ar_dbe), "");
|
g_assert_cmpstr(artist_ops->dbe_key(&artist->ar_dbe), ==, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_verify_koji(struct artist *artist)
|
static void test_verify_koji(struct artist *artist)
|
||||||
{
|
{
|
||||||
const struct db_ops *artist_ops = test_artist_ops();
|
const struct db_ops *artist_ops = test_artist_ops();
|
||||||
test_equal(artist->ar_name, "Koji Kondo");
|
g_assert_cmpstr(artist->ar_name, ==, "Koji Kondo");
|
||||||
test_equal(artist->ar_tokens[0], "koji");
|
g_assert_cmpstr(artist->ar_tokens[0], ==, "koji");
|
||||||
test_equal(artist->ar_tokens[1], "kondo");
|
g_assert_cmpstr(artist->ar_tokens[1], ==, "kondo");
|
||||||
test_equal((void *)artist->ar_tokens[2], NULL);
|
g_assert_null(artist->ar_tokens[2]);
|
||||||
test_equal((void *)artist->ar_alts[0], NULL);
|
g_assert_null(artist->ar_alts[0]);
|
||||||
test_equal(artist->ar_playlist, NULL);
|
g_assert_null(artist->ar_playlist);
|
||||||
test_equal(artist_ops->dbe_key(&artist->ar_dbe), "Koji Kondo");
|
g_assert_cmpstr(artist_ops->dbe_key(&artist->ar_dbe), ==, "Koji Kondo");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_artist()
|
static void test_artist()
|
||||||
|
@ -36,9 +36,9 @@ static void test_artist()
|
||||||
artist = ARTIST(artist_ops->dbe_alloc("Koji Kondo"));
|
artist = ARTIST(artist_ops->dbe_alloc("Koji Kondo"));
|
||||||
|
|
||||||
test_verify_koji(artist);
|
test_verify_koji(artist);
|
||||||
test_equal(artist_match_token(artist, "koji"), (bool)true);
|
g_assert_true( artist_match_token(artist, "koji"));
|
||||||
test_equal(artist_match_token(artist, "kondo"), (bool)true);
|
g_assert_true( artist_match_token(artist, "kondo"));
|
||||||
test_equal(artist_match_token(artist, "hajime"), (bool)false);
|
g_assert_false(artist_match_token(artist, "hajime"));
|
||||||
|
|
||||||
file_init(&f, "artist_tag", 0, 0);
|
file_init(&f, "artist_tag", 0, 0);
|
||||||
file_open(&f, OPEN_WRITE);
|
file_open(&f, OPEN_WRITE);
|
||||||
|
@ -71,9 +71,9 @@ static void test_artist_compare()
|
||||||
koji = ARTIST(artist_ops->dbe_alloc("Koji Kondo"));
|
koji = ARTIST(artist_ops->dbe_alloc("Koji Kondo"));
|
||||||
hajime = ARTIST(artist_ops->dbe_alloc("hajime wakai"));
|
hajime = ARTIST(artist_ops->dbe_alloc("hajime wakai"));
|
||||||
|
|
||||||
test_equal(artist_compare(koji, koji), 0);
|
g_assert_cmpint(artist_compare(koji, koji), ==, 0);
|
||||||
test_equal(artist_compare(koji, hajime), 1);
|
g_assert_cmpint(artist_compare(koji, hajime), ==, 1);
|
||||||
test_equal(artist_compare(hajime, koji), -1);
|
g_assert_cmpint(artist_compare(hajime, koji), ==, -1);
|
||||||
|
|
||||||
g_free(koji->ar_name);
|
g_free(koji->ar_name);
|
||||||
g_free(hajime->ar_name);
|
g_free(hajime->ar_name);
|
||||||
|
@ -87,31 +87,39 @@ static void test_artist_db()
|
||||||
struct database artist_db;
|
struct database artist_db;
|
||||||
struct artist *artist;
|
struct artist *artist;
|
||||||
|
|
||||||
test_not_equal((void *)artist_db_get(), NULL);
|
g_assert_nonnull(artist_db_get());
|
||||||
test_equal(artist_db_get()->db_size, 0);
|
g_assert_cmpuint(artist_db_get()->db_size, ==, 0);
|
||||||
|
|
||||||
artist_db_init();
|
artist_db_init();
|
||||||
artist = artist_lookup("Koji Kondo");
|
artist = artist_lookup("Koji Kondo");
|
||||||
test_equal((void *)artist, NULL);
|
g_assert_null(artist);
|
||||||
artist = artist_find("Koji Kondo");
|
artist = artist_find("Koji Kondo");
|
||||||
test_verify_koji(artist);
|
test_verify_koji(artist);
|
||||||
|
|
||||||
test_equal(artist_db_get()->db_size, 1);
|
g_assert_cmpuint(artist_db_get()->db_size, ==, 1);
|
||||||
test_equal((void *)artist_lookup("Koji Kondo"), (void *)artist);
|
g_assert(artist_lookup("Koji Kondo") == artist);
|
||||||
test_equal((void *)artist_find("Koji Kondo"), (void *)artist);
|
g_assert(artist_find("Koji Kondo") == artist);
|
||||||
test_equal((void *)artist_get(0), (void *)artist);
|
g_assert(artist_get(0) == artist);
|
||||||
test_equal((void *)artist_get(1), (void *)NULL);
|
g_assert_null(artist_get(1));
|
||||||
|
|
||||||
db_init(&artist_db, "artist.db", false, artist_ops);
|
db_init(&artist_db, "artist.db", false, artist_ops);
|
||||||
db_load(&artist_db);
|
db_load(&artist_db);
|
||||||
test_equal(artist_db.db_size, 1);
|
g_assert_cmpuint(artist_db.db_size, ==, 1);
|
||||||
|
|
||||||
db_deinit(&artist_db);
|
db_deinit(&artist_db);
|
||||||
artist_db_deinit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLARE_UNIT_TESTS(
|
int main(int argc, char **argv)
|
||||||
UNIT_TEST("Artist Tag", test_artist),
|
{
|
||||||
UNIT_TEST("Artist Comparison", test_artist_compare),
|
int ret;
|
||||||
UNIT_TEST("Artist Database", test_artist_db),
|
|
||||||
);
|
artist_db_init();
|
||||||
|
g_test_init(&argc, &argv, NULL);
|
||||||
|
g_test_add_func("/Core/Tags/Artist", test_artist);
|
||||||
|
g_test_add_func("/Core/Tags/Artist/Comparison", test_artist_compare);
|
||||||
|
g_test_add_func("/Core/Tags/Artist/Database", test_artist_db);
|
||||||
|
ret = g_test_run();
|
||||||
|
|
||||||
|
artist_db_deinit();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user