From 7e52c9b364bd6ec99a6f658e19e3f90ad4993404 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 19 Nov 2014 09:08:38 -0500 Subject: [PATCH] Track: Move the default constructor to a new cpp file I also use this opportunity to create a new default constructor test for the Track tag. This patch also disables the tags test since the tagdb will be going away soon. Signed-off-by: Anna Schumaker --- core/tags.cpp | 4 ++-- core/tags/track.cpp | 12 ++++++++++++ include/core/tags/track.h | 6 +++++- tests/core/Sconscript | 2 ++ tests/core/tags/.gitignore | 1 + tests/core/tags/track.cpp | 37 +++++++++++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 core/tags/track.cpp create mode 100644 tests/core/tags/track.cpp diff --git a/core/tags.cpp b/core/tags.cpp index 9843bc78..0401be9f 100644 --- a/core/tags.cpp +++ b/core/tags.cpp @@ -21,8 +21,6 @@ Database track_db("track.db", false); * */ -Track :: Track() : library(NULL), artist(NULL), album(NULL), genre(NULL){} - Track :: Track(const std::string &f, Library *l) : library(l), artist(NULL), album(NULL), genre(NULL), play_count(0), last_year(0), last_month(0), last_day(0), @@ -134,6 +132,8 @@ bool Track :: tag() const std::string Track :: path() const { + if (!library) + return ""; return library->primary_key() + "/" + filepath; } diff --git a/core/tags/track.cpp b/core/tags/track.cpp new file mode 100644 index 00000000..adbcf4aa --- /dev/null +++ b/core/tags/track.cpp @@ -0,0 +1,12 @@ +/** + * @file + * Copyright 2014 (c) Anna Schumaker. + */ +#include + + +Track :: Track() + : GenericTag(), + library(NULL), artist(NULL), album(NULL), genre(NULL), + track(0), length(0), play_count(0), last_year(0), last_month(0), last_day(0) +{} diff --git a/include/core/tags/track.h b/include/core/tags/track.h index 956b48a5..7f2a86fb 100644 --- a/include/core/tags/track.h +++ b/include/core/tags/track.h @@ -6,6 +6,10 @@ #define OCARINA_CORE_TAGS_TRACK_H #include +#include +#include +#include +#include /** @@ -33,7 +37,7 @@ enum sort_t { }; -class Track : public DatabaseEntry { +class Track : public GenericTag { private: void set_length_str(); diff --git a/tests/core/Sconscript b/tests/core/Sconscript index dc02ec96..6df419e1 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -23,6 +23,8 @@ test( "tags/library" ) test_env.UsePackage("taglib") objs += [ get_test_obj("tags", "core") ] objs += [ get_test_obj("tags/tags", "core") ] +test( "tags/track" ) + #test( "tags" ) test( "random" ) diff --git a/tests/core/tags/.gitignore b/tests/core/tags/.gitignore index 896e634a..c343ba0d 100644 --- a/tests/core/tags/.gitignore +++ b/tests/core/tags/.gitignore @@ -3,3 +3,4 @@ artist generic genre library +track diff --git a/tests/core/tags/track.cpp b/tests/core/tags/track.cpp new file mode 100644 index 00000000..f71bf4d8 --- /dev/null +++ b/tests/core/tags/track.cpp @@ -0,0 +1,37 @@ +/** + * @file + * Copyright 2014 (c) Anna Schumaker. + */ +#include +#include + +static void test_track_tag() +{ + Track track; + + test_equal(track.library, (Library *)NULL); + test_equal(track.artist, (Artist *)NULL); + test_equal(track.album, (Album *)NULL); + test_equal(track.genre, (Genre *)NULL); + + test_equal(track.name(), (std::string)""); + test_equal(track.lowercase(), (std::string)""); + test_equal(track.primary_key(), (std::string)""); + test_equal(track.title, (std::string)""); + test_equal(track.title_lower, (std::string)""); + test_equal(track.filepath, (std::string)""); + test_equal(track.length_str, (std::string)""); + + test_equal(track.track, (unsigned)0); + test_equal(track.length, (unsigned)0); + test_equal(track.play_count, (unsigned)0); + test_equal(track.last_year, (unsigned)0); + test_equal(track.last_month, (unsigned)0); + test_equal(track.last_day, (unsigned)0); +} + +int main(int argc, char **argv) +{ + run_test("Track Tag Test", test_track_tag); + return 0; +}