2015-11-11 10:49:23 -05:00
|
|
|
/*
|
2014-11-08 13:43:23 -05:00
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/tags/artist.h>
|
2015-11-11 10:49:23 -05:00
|
|
|
#include <tests/test.h>
|
2014-11-08 13:43:23 -05:00
|
|
|
|
2015-10-22 11:28:45 -04:00
|
|
|
static void test_verify_empty(struct artist *artist)
|
2014-11-08 13:43:23 -05:00
|
|
|
{
|
2015-09-23 09:33:55 -04:00
|
|
|
const struct db_ops *artist_ops = test_artist_ops();
|
2016-03-09 09:49:34 -05:00
|
|
|
g_assert_cmpstr(artist->ar_name, ==, "");
|
|
|
|
g_assert_null(artist->ar_tokens[0]);
|
|
|
|
g_assert_null(artist->ar_alts[0]);
|
|
|
|
g_assert_null(artist->ar_playlist);
|
|
|
|
g_assert_cmpstr(artist_ops->dbe_key(&artist->ar_dbe), ==, "");
|
2014-11-08 13:43:23 -05:00
|
|
|
}
|
|
|
|
|
2015-10-22 11:28:45 -04:00
|
|
|
static void test_verify_koji(struct artist *artist)
|
2015-10-22 11:12:40 -04:00
|
|
|
{
|
2015-09-23 09:33:55 -04:00
|
|
|
const struct db_ops *artist_ops = test_artist_ops();
|
2016-03-09 09:49:34 -05:00
|
|
|
g_assert_cmpstr(artist->ar_name, ==, "Koji Kondo");
|
|
|
|
g_assert_cmpstr(artist->ar_tokens[0], ==, "koji");
|
|
|
|
g_assert_cmpstr(artist->ar_tokens[1], ==, "kondo");
|
|
|
|
g_assert_null(artist->ar_tokens[2]);
|
|
|
|
g_assert_null(artist->ar_alts[0]);
|
|
|
|
g_assert_null(artist->ar_playlist);
|
|
|
|
g_assert_cmpstr(artist_ops->dbe_key(&artist->ar_dbe), ==, "Koji Kondo");
|
2015-10-22 11:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_artist()
|
|
|
|
{
|
2015-11-02 16:59:55 -05:00
|
|
|
const struct db_ops *artist_ops = test_artist_ops();
|
|
|
|
struct artist *artist;
|
2015-10-22 11:12:40 -04:00
|
|
|
unsigned int i;
|
2015-11-11 10:49:23 -05:00
|
|
|
struct file f;
|
2015-10-22 11:12:40 -04:00
|
|
|
|
2015-11-11 10:04:03 -05:00
|
|
|
artist = ARTIST(artist_ops->dbe_alloc("Koji Kondo"));
|
2016-05-19 14:31:50 -04:00
|
|
|
|
2015-10-22 11:12:40 -04:00
|
|
|
test_verify_koji(artist);
|
2016-03-09 09:49:34 -05:00
|
|
|
g_assert_true( artist_match_token(artist, "koji"));
|
|
|
|
g_assert_true( artist_match_token(artist, "kondo"));
|
|
|
|
g_assert_false(artist_match_token(artist, "hajime"));
|
2015-10-22 11:12:40 -04:00
|
|
|
|
2016-08-17 14:17:52 -04:00
|
|
|
file_init(&f, "artist_tag", 0);
|
2015-10-22 11:12:40 -04:00
|
|
|
file_open(&f, OPEN_WRITE);
|
2015-11-11 10:42:17 -05:00
|
|
|
file_writef(&f, "1 \n2 ");
|
2015-11-11 10:04:03 -05:00
|
|
|
artist_ops->dbe_write(&f, &artist->ar_dbe);
|
2015-10-22 11:12:40 -04:00
|
|
|
file_close(&f);
|
2015-11-11 10:42:17 -05:00
|
|
|
g_free(artist->ar_name);
|
2015-11-11 10:04:03 -05:00
|
|
|
artist_ops->dbe_free(&artist->ar_dbe);
|
2015-10-22 11:12:40 -04:00
|
|
|
|
|
|
|
file_open(&f, OPEN_READ);
|
|
|
|
file_readf(&f, "%u", &i);
|
2015-11-11 10:04:03 -05:00
|
|
|
artist = ARTIST(artist_ops->dbe_read(&f));
|
2015-10-22 11:12:40 -04:00
|
|
|
test_verify_empty(artist);
|
2015-11-11 10:42:17 -05:00
|
|
|
g_free(artist->ar_name);
|
2015-11-11 10:04:03 -05:00
|
|
|
artist_ops->dbe_free(&artist->ar_dbe);
|
2015-10-22 11:12:40 -04:00
|
|
|
|
|
|
|
file_readf(&f, "%u", &i);
|
2015-11-11 10:04:03 -05:00
|
|
|
artist = ARTIST(artist_ops->dbe_read(&f));
|
2015-10-22 11:12:40 -04:00
|
|
|
file_close(&f);
|
|
|
|
test_verify_koji(artist);
|
2015-11-11 10:42:17 -05:00
|
|
|
g_free(artist->ar_name);
|
2015-11-11 10:04:03 -05:00
|
|
|
artist_ops->dbe_free(&artist->ar_dbe);
|
2015-10-22 11:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_artist_compare()
|
|
|
|
{
|
2015-11-02 16:59:55 -05:00
|
|
|
const struct db_ops *artist_ops = test_artist_ops();
|
|
|
|
struct artist *koji, *hajime;
|
|
|
|
|
2015-11-11 10:04:03 -05:00
|
|
|
koji = ARTIST(artist_ops->dbe_alloc("Koji Kondo"));
|
|
|
|
hajime = ARTIST(artist_ops->dbe_alloc("hajime wakai"));
|
2015-10-22 11:12:40 -04:00
|
|
|
|
2016-03-09 09:49:34 -05:00
|
|
|
g_assert_cmpint(artist_compare(koji, koji), ==, 0);
|
|
|
|
g_assert_cmpint(artist_compare(koji, hajime), ==, 1);
|
|
|
|
g_assert_cmpint(artist_compare(hajime, koji), ==, -1);
|
2015-10-22 11:12:40 -04:00
|
|
|
|
2015-11-11 10:42:17 -05:00
|
|
|
g_free(koji->ar_name);
|
|
|
|
g_free(hajime->ar_name);
|
2015-11-11 10:04:03 -05:00
|
|
|
artist_ops->dbe_free(&koji->ar_dbe);
|
|
|
|
artist_ops->dbe_free(&hajime->ar_dbe);
|
2015-10-22 11:12:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_artist_db()
|
2014-11-16 10:08:12 -05:00
|
|
|
{
|
2015-11-03 10:39:06 -05:00
|
|
|
const struct db_ops *artist_ops = test_artist_ops();
|
2015-11-04 12:23:00 -05:00
|
|
|
struct database artist_db;
|
2015-10-22 11:28:45 -04:00
|
|
|
struct artist *artist;
|
2015-09-21 09:02:13 -04:00
|
|
|
|
2016-03-09 09:49:34 -05:00
|
|
|
g_assert_nonnull(artist_db_get());
|
|
|
|
g_assert_cmpuint(artist_db_get()->db_size, ==, 0);
|
2016-05-15 10:17:30 -04:00
|
|
|
|
2015-10-22 13:06:12 -04:00
|
|
|
artist_db_init();
|
2016-05-15 09:47:05 -04:00
|
|
|
artist = artist_lookup("Koji Kondo");
|
2016-03-09 09:49:34 -05:00
|
|
|
g_assert_null(artist);
|
2015-10-22 12:05:28 -04:00
|
|
|
artist = artist_find("Koji Kondo");
|
2015-10-22 11:12:40 -04:00
|
|
|
test_verify_koji(artist);
|
2014-11-16 10:08:12 -05:00
|
|
|
|
2016-03-09 09:49:34 -05:00
|
|
|
g_assert_cmpuint(artist_db_get()->db_size, ==, 1);
|
|
|
|
g_assert(artist_lookup("Koji Kondo") == artist);
|
|
|
|
g_assert(artist_find("Koji Kondo") == artist);
|
|
|
|
g_assert(artist_get(0) == artist);
|
|
|
|
g_assert_null(artist_get(1));
|
2014-11-16 10:08:12 -05:00
|
|
|
|
2016-08-17 14:17:52 -04:00
|
|
|
db_init(&artist_db, "artist.db", false, artist_ops, 0);
|
2015-09-17 08:12:25 -04:00
|
|
|
db_load(&artist_db);
|
2016-03-09 09:49:34 -05:00
|
|
|
g_assert_cmpuint(artist_db.db_size, ==, 1);
|
2015-10-22 11:12:40 -04:00
|
|
|
|
|
|
|
db_deinit(&artist_db);
|
2016-09-28 15:52:58 -04:00
|
|
|
artist_db_deinit();
|
2014-11-16 10:08:12 -05:00
|
|
|
}
|
|
|
|
|
2016-03-09 09:49:34 -05:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
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);
|
2016-09-28 15:52:58 -04:00
|
|
|
return g_test_run();
|
2016-03-09 09:49:34 -05:00
|
|
|
}
|