2014-11-19 09:08:38 -05:00
|
|
|
/**
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
2015-10-28 04:11:12 -04:00
|
|
|
extern "C" {
|
|
|
|
#include <core/string.h>
|
|
|
|
}
|
2014-12-01 10:33:19 -05:00
|
|
|
#include <core/filter.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-08-27 13:17:08 -04:00
|
|
|
#include "../test.h"
|
2014-12-01 10:33:19 -05:00
|
|
|
|
|
|
|
#include <set>
|
2014-11-27 10:37:46 -05:00
|
|
|
#include <sstream>
|
2014-11-19 09:08:38 -05:00
|
|
|
|
2014-11-28 20:27:08 -05:00
|
|
|
|
2015-10-22 11:28:45 -04:00
|
|
|
static struct artist *artist = NULL;
|
2015-10-22 08:16:53 -04:00
|
|
|
static struct album *album = NULL;
|
2015-10-23 08:19:26 -04:00
|
|
|
static struct genre *genre = NULL;
|
2015-10-23 10:21:12 -04:00
|
|
|
static struct library *library = NULL;
|
2014-11-28 20:27:08 -05:00
|
|
|
const std::string MUSIC_DIR = "/home/Zelda/Music";
|
|
|
|
|
|
|
|
|
2014-11-20 08:22:50 -05:00
|
|
|
static void test_track_tag_default()
|
2014-11-19 09:08:38 -05:00
|
|
|
{
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track track;
|
2014-11-19 09:08:38 -05:00
|
|
|
|
2015-10-27 17:25:18 -04:00
|
|
|
test_equal(track.tr_album, (struct album *)NULL);
|
|
|
|
test_equal(track.tr_artist, (struct artist *)NULL);
|
|
|
|
test_equal(track.tr_genre, (struct genre *)NULL);
|
|
|
|
test_equal(track.tr_library, (struct library *)NULL);
|
2014-11-19 09:08:38 -05:00
|
|
|
|
2015-10-29 03:10:19 -04:00
|
|
|
test_equal(track.tr_title, (std::string)"");
|
|
|
|
test_equal(track.tr_lower, (std::string)"");
|
2014-11-19 09:08:38 -05:00
|
|
|
test_equal(track.primary_key(), (std::string)"");
|
2015-10-29 02:51:19 -04:00
|
|
|
test_equal(track_last_play(&track), (std::string)"Never");
|
2015-10-29 02:43:39 -04:00
|
|
|
test_equal(track_path(&track), (std::string)"");
|
2014-11-19 09:08:38 -05:00
|
|
|
|
2015-10-27 17:34:00 -04:00
|
|
|
test_equal(track.tr_track, (unsigned)0);
|
|
|
|
test_equal(track.tr_length, (unsigned)0);
|
|
|
|
test_equal(track.tr_count, (unsigned)0);
|
2014-11-19 09:08:38 -05:00
|
|
|
}
|
|
|
|
|
2015-10-24 19:34:45 -04:00
|
|
|
static void verify_track_tag(struct track *track, unsigned int size)
|
2014-11-29 09:56:48 -05:00
|
|
|
{
|
2015-10-27 17:25:18 -04:00
|
|
|
test_equal(track->tr_album, album);
|
|
|
|
test_equal(track->tr_artist, artist);
|
|
|
|
test_equal(track->tr_genre, genre);
|
|
|
|
test_equal(track->tr_library, library);
|
2014-11-29 09:56:48 -05:00
|
|
|
|
2015-10-29 03:10:19 -04:00
|
|
|
test_equal(track->tr_title, (std::string)"Legend of Zelda Medley");
|
|
|
|
test_equal(track->tr_lower, (std::string)"legend of zelda medley");
|
2015-10-29 02:51:19 -04:00
|
|
|
test_equal(track_last_play(track), (std::string)"Never");
|
2015-10-29 02:43:39 -04:00
|
|
|
test_equal(track_path(track), (std::string)MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3");
|
2014-11-29 09:56:48 -05:00
|
|
|
test_equal(track->primary_key(), (std::string)"0/Hyrule Symphony/13 - Legend of Zelda Medley.mp3");
|
|
|
|
|
2015-10-27 17:34:00 -04:00
|
|
|
test_equal(track->tr_track, (unsigned)13);
|
|
|
|
test_equal(track->tr_length, (unsigned)288);
|
|
|
|
test_equal(track->tr_count, (unsigned)0);
|
2015-10-23 13:44:31 -04:00
|
|
|
test_equal(library->li_size, size);
|
2014-11-29 09:56:48 -05:00
|
|
|
}
|
|
|
|
|
2014-11-20 08:22:50 -05:00
|
|
|
static void test_track_tag_constructor()
|
|
|
|
{
|
2015-09-10 10:33:24 -04:00
|
|
|
file f;
|
2015-08-27 13:17:08 -04:00
|
|
|
|
2015-09-29 16:25:16 -04:00
|
|
|
filter_init();
|
2015-09-21 09:02:13 -04:00
|
|
|
tags :: init();
|
2015-09-24 11:13:12 -04:00
|
|
|
album = album_find("Hyrule Symphony", 1998);
|
2015-10-22 12:05:28 -04:00
|
|
|
artist = artist_find("Koji Kondo");
|
2015-09-28 08:22:51 -04:00
|
|
|
genre = genre_find("Video Game Music");
|
2015-09-28 10:00:06 -04:00
|
|
|
library = library_find(MUSIC_DIR);
|
2015-08-27 13:17:08 -04:00
|
|
|
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track a(album, artist, genre, library,
|
2014-11-29 10:17:21 -05:00
|
|
|
"Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
|
2014-11-29 09:56:48 -05:00
|
|
|
"Legend of Zelda Medley", 288, 13);
|
2015-10-21 15:57:21 -04:00
|
|
|
struct set search = SET_INIT();
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track b;
|
2014-11-26 08:23:20 -05:00
|
|
|
|
2014-11-29 09:56:48 -05:00
|
|
|
verify_track_tag(&a, 1);
|
|
|
|
|
2015-09-10 10:33:24 -04:00
|
|
|
file_init(&f, "track_tag", 0);
|
2015-09-10 09:46:33 -04:00
|
|
|
file_open(&f, OPEN_WRITE);
|
2014-11-29 09:56:48 -05:00
|
|
|
a.write(f);
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&f);
|
2014-11-29 09:56:48 -05:00
|
|
|
|
2015-09-10 09:46:33 -04:00
|
|
|
file_open(&f, OPEN_READ);
|
2014-11-29 09:56:48 -05:00
|
|
|
b.read(f);
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&f);
|
2014-11-29 09:56:48 -05:00
|
|
|
|
|
|
|
verify_track_tag(&b, 2);
|
2014-12-01 10:33:19 -05:00
|
|
|
|
|
|
|
|
2015-10-21 15:57:21 -04:00
|
|
|
filter :: search("Legend of Zelda Medley", &search);
|
|
|
|
test_equal(set_size(&search), (size_t)1);
|
|
|
|
test_equal(set_has(&search, 0), true);
|
2014-12-01 10:33:19 -05:00
|
|
|
|
2015-10-21 15:57:21 -04:00
|
|
|
filter :: search("Koji Kondo", &search);
|
|
|
|
test_equal(set_size(&search), (size_t)1);
|
|
|
|
test_equal(set_has(&search, 0), true);
|
2014-12-01 10:33:19 -05:00
|
|
|
|
2015-10-21 15:57:21 -04:00
|
|
|
filter :: search("Hyrule Symphony", &search);
|
|
|
|
test_equal(set_size(&search), (size_t)1);
|
|
|
|
test_equal(set_has(&search, 0), true);
|
2014-11-21 08:36:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_track_tag_destructor()
|
|
|
|
{
|
2015-10-23 13:44:31 -04:00
|
|
|
test_equal(library->li_size, (unsigned)0);
|
2014-11-20 08:22:50 -05:00
|
|
|
}
|
|
|
|
|
2014-12-01 08:24:56 -05:00
|
|
|
static void test_track_tag_load_db(unsigned int size)
|
2014-11-29 10:38:27 -05:00
|
|
|
{
|
2015-10-24 19:34:45 -04:00
|
|
|
database<struct track> track_db;
|
2015-09-21 09:02:13 -04:00
|
|
|
db_init(&track_db, "track.db", false);
|
2015-09-17 08:12:25 -04:00
|
|
|
db_load(&track_db);
|
2015-10-17 14:59:06 -04:00
|
|
|
test_equal(track_db.db_size, size);
|
2015-09-21 09:02:13 -04:00
|
|
|
db_deinit(&track_db);
|
2014-12-01 08:24:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_track_tag_lookup()
|
|
|
|
{
|
|
|
|
unsigned int index;
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track *a, *b;
|
2014-11-29 10:38:27 -05:00
|
|
|
|
2015-09-28 16:03:58 -04:00
|
|
|
a = track_add(album, artist, genre, library,
|
2014-11-29 10:38:27 -05:00
|
|
|
MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
|
|
|
|
"Legend of Zelda Medley", 288, 13);
|
2015-10-24 19:34:45 -04:00
|
|
|
test_not_equal(a, (struct track *)NULL);
|
2014-11-29 10:38:27 -05:00
|
|
|
verify_track_tag(a, 1);
|
|
|
|
|
2015-09-28 16:03:58 -04:00
|
|
|
b = track_add(album, artist, genre, library,
|
2014-11-29 10:38:27 -05:00
|
|
|
MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
|
|
|
|
"Legend of Zelda Medley", 288, 13);
|
2015-10-24 19:34:45 -04:00
|
|
|
test_equal(b, (struct track *)NULL);
|
2014-11-29 11:11:49 -05:00
|
|
|
|
2015-09-28 16:03:58 -04:00
|
|
|
b = track_add(album, artist, genre, library,
|
2014-12-01 08:24:56 -05:00
|
|
|
MUSIC_DIR + "/Hyrule Symphony/12 - Ocarina Medley.mp3",
|
|
|
|
"Ocarina Medley", 232, 12);
|
|
|
|
test_not_equal(b, a);
|
2015-10-23 13:44:31 -04:00
|
|
|
test_equal(library->li_size, (unsigned)2);
|
2015-10-25 05:06:23 -04:00
|
|
|
test_equal(track_db_get()->db_size, b->index() + 1);
|
2014-12-01 09:36:37 -05:00
|
|
|
|
2014-12-01 08:24:56 -05:00
|
|
|
|
2015-09-28 15:54:21 -04:00
|
|
|
test_equal(track_get(a->index()), a);
|
|
|
|
test_equal(track_get(a->index() + 1), b);
|
|
|
|
test_equal(track_get(a->index() + 2), (struct track *)NULL);
|
2014-11-29 11:16:21 -05:00
|
|
|
|
2014-12-01 08:24:56 -05:00
|
|
|
test_track_tag_load_db(0);
|
2015-09-28 15:39:26 -04:00
|
|
|
track_db_commit();
|
2014-12-01 08:24:56 -05:00
|
|
|
test_track_tag_load_db(2);
|
2014-11-29 11:16:21 -05:00
|
|
|
|
2014-12-01 09:36:37 -05:00
|
|
|
|
2014-12-01 08:24:56 -05:00
|
|
|
index = a->index();
|
2015-10-25 04:41:03 -04:00
|
|
|
track_remove(a);
|
2015-09-28 15:54:21 -04:00
|
|
|
test_equal(track_get(index), (struct track *)NULL);
|
2014-12-01 08:24:56 -05:00
|
|
|
test_track_tag_load_db(2);
|
2015-09-28 15:39:26 -04:00
|
|
|
track_db_commit();
|
2014-12-01 08:24:56 -05:00
|
|
|
test_track_tag_load_db(1);
|
2015-10-23 13:44:31 -04:00
|
|
|
test_equal(library->li_size, (unsigned)1);
|
2015-10-25 05:06:23 -04:00
|
|
|
test_equal(db_actual_size(track_db_get()), b->index() + 1);
|
2014-12-01 09:36:37 -05:00
|
|
|
|
|
|
|
|
2015-09-28 16:03:58 -04:00
|
|
|
a = track_add(album, artist, genre, library,
|
2014-12-01 09:36:37 -05:00
|
|
|
MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
|
|
|
|
"Legend of Zelda Medley", 288, 13);
|
2015-10-24 19:34:45 -04:00
|
|
|
test_not_equal(a, (struct track *)NULL);
|
2014-12-01 09:36:37 -05:00
|
|
|
verify_track_tag(a, 2);
|
2015-10-25 05:06:23 -04:00
|
|
|
test_equal(db_actual_size(track_db_get()), a->index() + 1);
|
2014-12-01 09:36:37 -05:00
|
|
|
|
2015-10-25 04:43:39 -04:00
|
|
|
track_remove_all(library);
|
2014-12-01 09:36:37 -05:00
|
|
|
test_track_tag_load_db(0);
|
2015-10-23 13:44:31 -04:00
|
|
|
test_equal(library->li_size, (unsigned)0);
|
2014-11-29 10:38:27 -05:00
|
|
|
}
|
|
|
|
|
2015-10-28 04:11:12 -04:00
|
|
|
static void test_track_tag_locale()
|
2014-11-26 08:55:06 -05:00
|
|
|
{
|
2014-11-28 20:27:08 -05:00
|
|
|
time_t rawtime = time(NULL);
|
|
|
|
struct tm *now = localtime(&rawtime);
|
2015-09-28 16:03:58 -04:00
|
|
|
struct track *track = track_add(album, artist, genre, library,
|
2014-12-01 10:32:06 -05:00
|
|
|
MUSIC_DIR + "/Hyrule Symphony/6 - Kakariko Village.mp3",
|
|
|
|
"Kakariko Village", 186, 6);
|
2015-10-28 04:11:12 -04:00
|
|
|
gchar *date;
|
2014-12-01 10:32:06 -05:00
|
|
|
|
|
|
|
std::setlocale(LC_TIME, "C");
|
2015-10-28 04:11:12 -04:00
|
|
|
date = string_tm2str(now);
|
2014-11-26 08:55:06 -05:00
|
|
|
|
2015-10-27 17:34:00 -04:00
|
|
|
test_equal(track->tr_count, (unsigned)0);
|
2015-10-29 02:51:19 -04:00
|
|
|
test_equal(track_last_play(track), "Never");
|
2014-11-28 10:21:35 -05:00
|
|
|
|
2015-09-29 09:34:06 -04:00
|
|
|
track_played(track);
|
2015-10-27 17:34:00 -04:00
|
|
|
test_equal(track->tr_count, (unsigned)1);
|
2015-10-29 02:51:19 -04:00
|
|
|
test_equal(track_last_play(track), date);
|
2015-10-28 04:11:12 -04:00
|
|
|
g_free(date);
|
2014-11-26 08:55:06 -05:00
|
|
|
}
|
|
|
|
|
2015-08-27 13:17:08 -04:00
|
|
|
DECLARE_UNIT_TESTS(
|
|
|
|
UNIT_TEST("Track Tag Default Constructor", test_track_tag_default),
|
|
|
|
UNIT_TEST("Track Tag Constructor", test_track_tag_constructor),
|
|
|
|
UNIT_TEST("Track Tag Destructor Test", test_track_tag_destructor),
|
|
|
|
UNIT_TEST("Track Tag Lookup Test", test_track_tag_lookup),
|
2015-10-28 04:11:12 -04:00
|
|
|
UNIT_TEST("Track Tag Date Test", test_track_tag_locale),
|
2015-08-27 13:17:08 -04:00
|
|
|
);
|