2015-11-12 10:42:21 -05:00
|
|
|
/*
|
2014-11-19 09:08:38 -05:00
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-02-26 09:39:33 -05:00
|
|
|
#include <core/idle.h>
|
2015-10-28 04:11:12 -04:00
|
|
|
#include <core/string.h>
|
2015-09-21 09:02:13 -04:00
|
|
|
#include <core/tags/tags.h>
|
2014-11-19 09:08:38 -05:00
|
|
|
#include <core/tags/track.h>
|
2015-11-12 10:42:21 -05:00
|
|
|
#include <tests/test.h>
|
|
|
|
#include <locale.h>
|
2014-12-01 10:33:19 -05:00
|
|
|
|
2014-11-19 09:08:38 -05:00
|
|
|
|
2015-11-08 13:02:09 -05:00
|
|
|
static struct track *test_alloc(const gchar *key)
|
|
|
|
{
|
|
|
|
const struct db_ops *track_ops = test_track_ops();
|
2016-09-12 15:27:02 -04:00
|
|
|
struct db_entry *dbe = track_ops->dbe_alloc(key, 0);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_nonnull(dbe);
|
|
|
|
return TRACK(dbe);
|
2015-11-08 13:02:09 -05:00
|
|
|
}
|
|
|
|
|
2015-10-30 12:45:44 -04:00
|
|
|
static void test_verify_tags(struct track *track)
|
2014-11-19 09:08:38 -05:00
|
|
|
{
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpstr(track->tr_album->al_name, ==, "Hyrule Symphony");
|
|
|
|
g_assert_cmpuint(track->tr_album->al_year, ==, 1998);
|
2016-08-29 11:19:58 -04:00
|
|
|
g_assert_cmpstr(track->tr_album->al_artist->ar_name, ==, "Koji Kondo");
|
|
|
|
g_assert_cmpstr(track->tr_album->al_genre->ge_name, ==, "Game");
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpstr(track->tr_library->li_path, ==, "tests/Music");
|
2014-11-19 09:08:38 -05:00
|
|
|
}
|
|
|
|
|
2015-10-30 12:45:44 -04:00
|
|
|
static void test_verify_track(struct track *track)
|
2014-11-29 09:56:48 -05:00
|
|
|
{
|
2015-09-23 09:33:55 -04:00
|
|
|
const struct db_ops *track_ops = test_track_ops();
|
2015-10-30 12:45:44 -04:00
|
|
|
test_verify_tags(track);
|
|
|
|
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpstr(track->tr_title, ==, "Title Theme");
|
|
|
|
g_assert_cmpstr(track->tr_tokens[0], ==, "title");
|
|
|
|
g_assert_cmpstr(track->tr_tokens[1], ==, "theme");
|
|
|
|
g_assert_null(track->tr_tokens[2]);
|
|
|
|
g_assert_null(track->tr_alts[0]);
|
|
|
|
g_assert_cmpstr(track_ops->dbe_key(&track->tr_dbe), ==,
|
2015-10-30 12:45:44 -04:00
|
|
|
"0/Hyrule Symphony/01 - Title Theme.ogg");
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpstr_free(track_path(track), ==,
|
2015-10-30 12:45:44 -04:00
|
|
|
"tests/Music/Hyrule Symphony/01 - Title Theme.ogg");
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpstr_free(track_last_play(track), ==, "Never");
|
2015-10-31 10:53:40 -04:00
|
|
|
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track->tr_track, ==, 1);
|
|
|
|
g_assert_cmpuint(track->tr_length, ==, 243);
|
|
|
|
g_assert_cmpuint(track->tr_count, ==, 0);
|
2015-10-30 12:45:44 -04:00
|
|
|
}
|
2015-10-31 10:53:40 -04:00
|
|
|
|
2015-10-30 12:45:44 -04:00
|
|
|
static void test_verify_notrack(struct track *track)
|
|
|
|
{
|
2015-09-23 09:33:55 -04:00
|
|
|
const struct db_ops *track_ops = test_track_ops();
|
2015-10-30 12:45:44 -04:00
|
|
|
test_verify_tags(track);
|
|
|
|
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpstr(track->tr_title, ==, "");
|
|
|
|
g_assert_null(track->tr_tokens[0]);
|
|
|
|
g_assert_null(track->tr_alts[0]);
|
|
|
|
g_assert_cmpstr(track_ops->dbe_key(&track->tr_dbe), ==,
|
2015-10-30 12:45:44 -04:00
|
|
|
"0/Hyrule Symphony/00 - No Track.ogg");
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpstr_free(track_path(track), ==,
|
2015-10-30 12:45:44 -04:00
|
|
|
"tests/Music/Hyrule Symphony/00 - No Track.ogg");
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpstr_free(track_last_play(track), ==, "Never");
|
2015-10-30 12:45:44 -04:00
|
|
|
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track->tr_track, ==, 0);
|
|
|
|
g_assert_cmpuint(track->tr_length, ==, 0);
|
|
|
|
g_assert_cmpuint(track->tr_count, ==, 0);
|
2014-11-29 09:56:48 -05:00
|
|
|
}
|
|
|
|
|
2015-10-30 12:45:44 -04:00
|
|
|
static void test_track()
|
2014-11-20 08:22:50 -05:00
|
|
|
{
|
2015-09-30 09:15:15 -04:00
|
|
|
const struct db_ops *track_ops = test_track_ops();
|
2015-10-30 12:45:44 -04:00
|
|
|
time_t rawtime = time(NULL);
|
|
|
|
struct tm *now = localtime(&rawtime);
|
2015-11-12 08:41:46 -05:00
|
|
|
struct track *track;
|
2015-11-12 10:42:21 -05:00
|
|
|
struct file f;
|
2015-10-30 12:45:44 -04:00
|
|
|
gchar *date;
|
2015-08-27 13:17:08 -04:00
|
|
|
|
2016-08-17 14:17:52 -04:00
|
|
|
file_init(&f, "track_tag", 1);
|
2016-09-11 09:52:26 -04:00
|
|
|
g_assert_nonnull(library_find("tests/Music"));
|
|
|
|
date = string_tm2str(now);
|
2014-11-26 08:23:20 -05:00
|
|
|
|
2015-11-08 13:02:09 -05:00
|
|
|
track = test_alloc("0/Hyrule Symphony/01 - Title Theme.ogg");
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_nonnull(track);
|
2015-11-12 08:41:46 -05:00
|
|
|
track->tr_dbe.dbe_index = 0;
|
2015-10-30 12:45:44 -04:00
|
|
|
test_verify_track(track);
|
2014-11-29 09:56:48 -05:00
|
|
|
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_true( track_match_token(track, "title"));
|
|
|
|
g_assert_true( track_match_token(track, "theme"));
|
|
|
|
g_assert_false(track_match_token(track, "hyrule"));
|
2016-05-19 12:27:34 -04:00
|
|
|
|
2015-09-10 09:46:33 -04:00
|
|
|
file_open(&f, OPEN_WRITE);
|
2016-08-12 15:52:00 -04:00
|
|
|
file_writef(&f, "0 0 0 0 0 0 \n");
|
2015-10-30 12:45:44 -04:00
|
|
|
file_writef(&f, "Hyrule Symphony/00 - No Track.ogg\n");
|
2015-11-12 08:41:46 -05:00
|
|
|
track_ops->dbe_write(&f, &track->tr_dbe);
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&f);
|
2014-11-29 09:56:48 -05:00
|
|
|
|
2015-11-12 09:38:35 -05:00
|
|
|
g_free(track->tr_path);
|
2015-11-12 08:41:46 -05:00
|
|
|
track_ops->dbe_free(&track->tr_dbe);
|
2015-10-31 10:53:40 -04:00
|
|
|
|
2015-09-10 09:46:33 -04:00
|
|
|
file_open(&f, OPEN_READ);
|
2016-09-12 15:27:02 -04:00
|
|
|
track = TRACK(track_ops->dbe_read(&f, 0));
|
2015-11-12 08:41:46 -05:00
|
|
|
track->tr_dbe.dbe_index = 0;
|
2015-10-30 12:45:44 -04:00
|
|
|
test_verify_notrack(track);
|
2015-11-12 09:38:35 -05:00
|
|
|
|
|
|
|
g_free(track->tr_path);
|
2015-11-12 08:41:46 -05:00
|
|
|
track_ops->dbe_free(&track->tr_dbe);
|
2015-10-30 12:45:44 -04:00
|
|
|
|
2016-09-12 15:27:02 -04:00
|
|
|
track = TRACK(track_ops->dbe_read(&f, 0));
|
2015-11-12 08:41:46 -05:00
|
|
|
track->tr_dbe.dbe_index = 0;
|
2015-10-30 12:45:44 -04:00
|
|
|
test_verify_track(track);
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&f);
|
2015-10-30 12:45:44 -04:00
|
|
|
|
|
|
|
track_played(track);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track->tr_count, ==, 1);
|
|
|
|
g_assert_cmpstr_free(track_last_play(track), ==, date);
|
2015-10-30 12:45:44 -04:00
|
|
|
|
2015-11-12 09:38:35 -05:00
|
|
|
g_free(track->tr_path);
|
2015-11-12 08:41:46 -05:00
|
|
|
track_ops->dbe_free(&track->tr_dbe);
|
2015-10-30 12:45:44 -04:00
|
|
|
g_free(date);
|
|
|
|
}
|
2014-11-29 09:56:48 -05:00
|
|
|
|
2015-10-30 12:45:44 -04:00
|
|
|
static void test_track_compare()
|
2014-11-29 10:38:27 -05:00
|
|
|
{
|
2015-09-30 09:15:15 -04:00
|
|
|
const struct db_ops *track_ops = test_track_ops();
|
2015-11-08 13:02:09 -05:00
|
|
|
struct track *title = test_alloc("0/Hyrule Symphony/01 - Title Theme.ogg");
|
2016-03-10 08:18:24 -05:00
|
|
|
struct track *kokiri = test_alloc("0/Ocarina of Time/05 - Kokiri Forest.ogg");
|
2015-10-30 12:45:44 -04:00
|
|
|
|
2015-11-17 09:18:12 -05:00
|
|
|
/* Compare artists. */
|
2016-08-29 11:19:58 -04:00
|
|
|
title->tr_album->al_artist = artist_find("Hajime Wakai");
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_ARTIST), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_ARTIST), ==, 1);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_ARTIST), ==, -1);
|
2016-08-29 11:19:58 -04:00
|
|
|
title->tr_album->al_artist = artist_find("Koji Kondo");
|
2015-11-17 09:18:12 -05:00
|
|
|
|
|
|
|
/* Compare albums. */
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_ALBUM), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_ALBUM), ==, -1);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_ALBUM), ==, 1);
|
2015-11-17 09:18:12 -05:00
|
|
|
|
|
|
|
/* Compare play counts. */
|
|
|
|
title->tr_count = 42;
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_COUNT), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_COUNT), ==, 42);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_COUNT), ==, -42);
|
2016-04-01 09:51:53 -04:00
|
|
|
title->tr_count = 0;
|
2015-11-17 09:18:12 -05:00
|
|
|
|
|
|
|
/* Compare genres. */
|
2016-08-29 11:19:58 -04:00
|
|
|
kokiri->tr_album->al_genre = genre_find("Video Game");
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_GENRE), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_GENRE), ==, -1);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_GENRE), ==, 1);
|
2015-11-17 09:18:12 -05:00
|
|
|
|
|
|
|
/* Compare lenghts (title = 243, kokiri = 130). */
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_LENGTH), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_LENGTH), ==, 131);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_LENGTH), ==, -131);
|
2015-11-17 09:18:12 -05:00
|
|
|
|
|
|
|
/* Compare last played dates. */
|
|
|
|
date_set(&kokiri->tr_date, 0, 0, 17);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_PLAYED), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_PLAYED), ==, -17);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_PLAYED), ==, 17);
|
2015-11-17 09:18:12 -05:00
|
|
|
|
|
|
|
date_set(&kokiri->tr_date, 0, 6, 17);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_PLAYED), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_PLAYED), ==, -6);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_PLAYED), ==, 6);
|
2015-11-17 09:18:12 -05:00
|
|
|
|
|
|
|
date_set(&kokiri->tr_date, 1988, 6, 17);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_PLAYED), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_PLAYED), ==, -1988);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_PLAYED), ==, 1988);
|
2015-11-17 09:18:12 -05:00
|
|
|
|
|
|
|
/* Compare titles. */
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_TITLE), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_TITLE), ==, 1);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_TITLE), ==, -1);
|
2015-11-17 09:18:12 -05:00
|
|
|
|
|
|
|
/* Compare track numbers. */
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_TRACK), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_TRACK), ==, -4);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_TRACK), ==, 4);
|
2015-11-17 09:18:12 -05:00
|
|
|
|
|
|
|
/* Compare years. */
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_YEAR), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_YEAR), ==, -1);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_YEAR), ==, 1);
|
2015-11-17 09:18:12 -05:00
|
|
|
|
2016-03-10 08:18:24 -05:00
|
|
|
title->tr_album->al_year += 2;
|
|
|
|
g_assert_cmpint(track_compare(title, title, COMPARE_YEAR), ==, 0);
|
|
|
|
g_assert_cmpint(track_compare(title, kokiri, COMPARE_YEAR), ==, 2);
|
|
|
|
g_assert_cmpint(track_compare(kokiri, title, COMPARE_YEAR), ==, -2);
|
|
|
|
title->tr_album->al_year -= 2;
|
2015-10-30 12:45:44 -04:00
|
|
|
|
2015-11-12 09:38:35 -05:00
|
|
|
g_free(title->tr_path);
|
|
|
|
g_free(kokiri->tr_path);
|
2015-11-12 08:41:46 -05:00
|
|
|
track_ops->dbe_free(&title->tr_dbe);
|
|
|
|
track_ops->dbe_free(&kokiri->tr_dbe);
|
2014-12-01 08:24:56 -05:00
|
|
|
}
|
|
|
|
|
2016-03-10 08:18:24 -05:00
|
|
|
static void __test_track_db_subprocess()
|
2014-12-01 08:24:56 -05:00
|
|
|
{
|
2015-11-12 09:38:35 -05:00
|
|
|
const gchar *path = "tests/Music/Hyrule Symphony/01 - Title Theme.ogg";
|
2015-10-31 10:53:40 -04:00
|
|
|
struct library *library = library_find("tests/Music");
|
2015-11-03 10:39:06 -05:00
|
|
|
const struct db_ops *track_ops = test_track_ops();
|
2015-11-04 12:23:00 -05:00
|
|
|
struct database track_db;
|
2015-10-30 12:45:44 -04:00
|
|
|
struct track *track;
|
2014-11-29 10:38:27 -05:00
|
|
|
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db_count_unplayed(), ==, 0);
|
|
|
|
g_assert_cmpuint(track_db_count_plays(), ==, 0);
|
|
|
|
g_assert_cmpuint(track_db_average_plays(), ==, 0);
|
2015-10-30 12:45:44 -04:00
|
|
|
track = track_add(library, path);
|
|
|
|
test_verify_track(track);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db_count_unplayed(), ==, 1);
|
2014-12-01 09:36:37 -05:00
|
|
|
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_null(track_add(library, path));
|
|
|
|
g_assert(track_get(0) == track);
|
|
|
|
g_assert_null(track_get(1));
|
|
|
|
g_assert_cmpuint(track_db_get()->db_size, ==, 1);
|
|
|
|
g_assert_cmpuint(track_db_count_unplayed(), ==, 1);
|
2014-12-01 08:24:56 -05:00
|
|
|
|
2016-08-17 14:17:52 -04:00
|
|
|
db_init(&track_db, "track.db", false, track_ops, 0);
|
2015-10-30 12:45:44 -04:00
|
|
|
db_load(&track_db);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db.db_size, ==, 0);
|
2014-11-29 11:16:21 -05:00
|
|
|
|
2015-09-28 15:39:26 -04:00
|
|
|
track_db_commit();
|
2015-10-30 12:45:44 -04:00
|
|
|
db_load(&track_db);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db.db_size, ==, 1);
|
2015-11-04 12:23:00 -05:00
|
|
|
test_verify_track(TRACK(db_first(&track_db)));
|
2016-04-01 09:51:53 -04:00
|
|
|
/* Make sure our unplayed count isn't skewed */
|
|
|
|
db_deinit(&track_db);
|
2014-11-29 11:16:21 -05:00
|
|
|
|
2015-10-30 12:45:44 -04:00
|
|
|
track_remove(track);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db_get()->db_size, ==, 0);
|
|
|
|
g_assert_cmpuint(track_db_count_unplayed(), ==, 0);
|
2014-12-01 09:36:37 -05:00
|
|
|
|
2015-10-30 12:45:44 -04:00
|
|
|
track = track_add(library, path);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_nonnull(track);
|
2014-12-01 09:36:37 -05:00
|
|
|
|
2015-10-30 12:45:44 -04:00
|
|
|
track = track_add(library,
|
|
|
|
"tests/Music/Hyrule Symphony/02 - Kokiri Forest.ogg");
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_nonnull(track);
|
|
|
|
g_assert_cmpuint(track_db_get()->db_size, ==, 2);
|
|
|
|
g_assert_cmpuint(track_db_count_unplayed(), ==, 2);
|
2016-04-01 09:51:53 -04:00
|
|
|
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db_count_plays(), ==, 0);
|
|
|
|
g_assert_cmpuint(track_db_average_plays(), ==, 0);
|
2016-04-01 09:51:53 -04:00
|
|
|
track_played(track);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db_count_unplayed(), ==, 1);
|
|
|
|
g_assert_cmpuint(track_db_count_plays(), ==, 1);
|
|
|
|
g_assert_cmpuint(track_db_average_plays(), ==, 1);
|
2016-04-01 09:51:53 -04:00
|
|
|
track_played(track);
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db_count_unplayed(), ==, 1);
|
|
|
|
g_assert_cmpuint(track_db_count_plays(), ==, 2);
|
|
|
|
g_assert_cmpuint(track_db_average_plays(), ==, 2);
|
2014-12-01 09:36:37 -05:00
|
|
|
|
2015-11-12 08:41:46 -05:00
|
|
|
track = track_add(library, "tests/Music/invalid_track");
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_null(track);
|
|
|
|
g_assert_cmpuint(track_db_get()->db_size, ==, 2);
|
|
|
|
g_assert_cmpuint(track_db_count_unplayed(), ==, 1);
|
2016-04-01 09:51:53 -04:00
|
|
|
|
|
|
|
/* Reload the database */
|
|
|
|
track_db_deinit();
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db_count_unplayed(), ==, 0);
|
|
|
|
g_assert_cmpuint(track_db_count_plays(), ==, 0);
|
|
|
|
g_assert_cmpuint(track_db_get()->db_size, ==, 0);
|
2016-04-01 09:51:53 -04:00
|
|
|
track_db_init();
|
|
|
|
while (idle_run_task()) {};
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db_get()->db_size, ==, 2);
|
|
|
|
g_assert_cmpuint(track_db_count_unplayed(), ==, 1);
|
|
|
|
g_assert_cmpuint(track_db_count_plays(), ==, 2);
|
|
|
|
g_assert_cmpuint(track_db_average_plays(), ==, 2);
|
2016-04-01 10:03:33 -04:00
|
|
|
|
|
|
|
track_remove(track_get(2));
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db_count_plays(), ==, 0);
|
|
|
|
g_assert_cmpuint(track_db_average_plays(), ==, 0);
|
2015-11-12 08:41:46 -05:00
|
|
|
|
2016-09-26 15:40:54 -04:00
|
|
|
/* Rekey the database */
|
|
|
|
track_get(1)->tr_library = library_find("tests/Music2");
|
|
|
|
track_db_rekey();
|
|
|
|
g_assert_cmpstr(track_get(1)->tr_path, ==, "1/Hyrule Symphony/01 - Title Theme.ogg");
|
|
|
|
|
|
|
|
track_remove_all(library_get(0));
|
|
|
|
track_remove_all(library_get(1));
|
2016-03-10 08:18:24 -05:00
|
|
|
g_assert_cmpuint(track_db_get()->db_size, ==, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_track_db()
|
|
|
|
{
|
|
|
|
if (g_test_subprocess()) {
|
|
|
|
__test_track_db_subprocess();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_test_trap_subprocess(NULL, 0, 0);
|
|
|
|
g_test_trap_assert_passed();
|
|
|
|
g_test_trap_assert_stderr("*WARNING: Could not read tags for:*");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
setlocale(LC_TIME, "C");
|
2016-09-24 09:57:51 -04:00
|
|
|
idle_init(IDLE_SYNC);
|
2016-03-10 08:18:24 -05:00
|
|
|
tags_init();
|
|
|
|
while (idle_run_task()) {}
|
|
|
|
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
g_test_add_func("/Core/Tags/Track", test_track);
|
|
|
|
g_test_add_func("/Core/Tags/Track/Comparison", test_track_compare);
|
|
|
|
g_test_add_func("/Core/Tags/Track/Database", test_track_db);
|
|
|
|
ret = g_test_run();
|
2014-12-01 10:32:06 -05:00
|
|
|
|
2015-11-12 10:29:36 -05:00
|
|
|
tags_deinit();
|
2016-05-19 12:35:54 -04:00
|
|
|
idle_deinit();
|
2016-03-10 08:18:24 -05:00
|
|
|
return ret;
|
2014-11-26 08:55:06 -05:00
|
|
|
}
|