From 09bf458d7a5d0428c7e3e6d8fca4b842d9e52339 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 1 Dec 2014 10:32:06 -0500 Subject: [PATCH] Track: Rename functional test to locale test This code is really testing date and locale handling, so this patch renames the function to match what it actually does. While I'm at it, I also introduce some cleanups. Signed-off-by: Anna Schumaker --- core/tags/track.cpp | 2 +- tests/core/tags/track.cpp | 74 +++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/core/tags/track.cpp b/core/tags/track.cpp index 43aeeea5..52410eba 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -108,7 +108,7 @@ void Track :: played() _date.month = now->tm_mon + 1; _date.year = now->tm_year + 1900; - //tagdb :: commit(); + tags :: commit_track_db(); } int Track :: compare_date(const Track *rhs) diff --git a/tests/core/tags/track.cpp b/tests/core/tags/track.cpp index e808117a..0a346eaa 100644 --- a/tests/core/tags/track.cpp +++ b/tests/core/tags/track.cpp @@ -143,51 +143,55 @@ static void test_track_tag_lookup() test_equal(library->size(), (unsigned)0); } -static void test_track_tag_functional() +static std::string find_expected_date(const std::string &locale) { + std::stringstream ss; time_t rawtime = time(NULL); struct tm *now = localtime(&rawtime); - std::stringstream ss; - Track track1, track2, track3; - track1 = Track(album, artist, genre, library, - "Hyrule Symphony/6 - Kakariko Village.mp3", - "Kakariko Village", 186, 6); - track1.played(); - test_equal(track1.length_str(), (std::string)"3:06"); - test_equal(track1.count(), (unsigned)1); + if ((now->tm_mon + 1) < 10) + ss << "0"; + ss << (now->tm_mon + 1) << "/"; + if (now->tm_mday < 10) + ss << "0"; + ss << now->tm_mday << "/"; + + if (locale == "C") + ss << (now->tm_year % 100); + else if (locale == "en_US") + ss << (now->tm_year + 1900); + else + ss << "????"; + return ss.str(); +} + +static void test_track_tag_locale() +{ + Track *a, *b; + + a = tags :: add_track(album, artist, genre, library, + MUSIC_DIR + "/Hyrule Symphony/6 - Kakariko Village.mp3", + "Kakariko Village", 186, 6); + test_equal(a->count(), (unsigned)0); + a->played(); + test_equal(a->count(), (unsigned)1); + test_track_tag_load_db(1); std::setlocale(LC_TIME, "C"); - if ((now->tm_mon + 1) < 10) - ss << "0"; - ss << (now->tm_mon + 1) << "/"; - if (now->tm_mday < 10) - ss << "0"; - ss << now->tm_mday << "/" << (now->tm_year % 100); - test_equal(track1.date(), ss.str()); - - + test_equal(a->date(), find_expected_date("C")); std::setlocale(LC_TIME, "en_US"); - ss.str(""); - if ((now->tm_mon + 1) < 10) - ss << "0"; - ss << (now->tm_mon + 1) << "/"; - if (now->tm_mday < 10) - ss << "0"; - ss << now->tm_mday << "/" << now->tm_year + 1900; - test_equal(track1.date(), ss.str()); + test_equal(a->date(), find_expected_date("en_US")); - /* Not an actual track on the album, I just needed something < 1 min. */ - track2 = Track(album, artist, genre, library, - "Hyrule Symphony/0 - intro.mp3", - "Intro", 56, 0); - test_equal(track2.length_str(), (std::string)"0:56"); + b = tags :: add_track(album, artist, genre, library, + MUSIC_DIR + "/Hyrule Symphony/0 - intro.mp3", + "Intro", 56, 0); + test_equal(b->length_str(), (std::string)"0:56"); - test_equal(track1.compare_date(&track1), 0); - test_equal(track1.compare_date(&track2), 2014); - test_equal(track2.compare_date(&track1), -2014); + test_equal(a->compare_date(a), 0); + test_equal(a->compare_date(b), 2014); + test_equal(b->compare_date(a), -2014); } int main(int argc, char **argv) @@ -202,6 +206,6 @@ int main(int argc, char **argv) run_test("Track Tag Constructor Test", test_track_tag_constructor); run_test("Track Tag Destructor Test", test_track_tag_destructor); run_test("Track Tag Lookup Test", test_track_tag_lookup); - run_test("Track Tag Functional Test", test_track_tag_functional); + run_test("Track Tag Locale Test", test_track_tag_locale); return 0; }