diff --git a/core/tags.cpp b/core/tags.cpp index 7f8cd579..7095076a 100644 --- a/core/tags.cpp +++ b/core/tags.cpp @@ -14,45 +14,6 @@ Database track_db("track.db", false); -/** - * - * Track tag - * - */ - -void Track :: read(File &f) -{ - unsigned int library_id, artist_id, album_id, genre_id; - - f >> library_id >> artist_id >> album_id >> genre_id; - f >> _track >> _date.year >> _date.month >> _date.day; - f >> _count >> _length; - - GenericTag :: read(f); - _path = f.getline(); - - _library = tags :: get_library(library_id); - _artist = tags :: get_artist(artist_id); - _album = tags :: get_album(album_id); - _genre = tags :: get_genre(genre_id); - - filter :: add(name(), index()); - filter :: add(_artist->name(), index()); - filter :: add(_album->name(), index()); - _library->inc_size(); -} - -void Track :: write(File &f) -{ - f << _library->index() << " " << _artist->index() << " "; - f << _album->index() << " " << _genre->index() << " " << _track << " "; - f << _date.year << " " << _date.month << " " << _date.day << " "; - f << _count << " " << _length << " "; - GenericTag :: write(f); - f << std::endl << _path << std::endl; -} - - /** * * Tagdb functions diff --git a/core/tags/track.cpp b/core/tags/track.cpp index b6c3b6f5..39815d10 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -110,3 +110,35 @@ int Track :: compare_date(const Track *rhs) } return ret; } + +void Track :: read(File &f) +{ + unsigned int library_id, artist_id, album_id, genre_id; + + f >> library_id >> artist_id >> album_id >> genre_id; + f >> _track >> _date.year >> _date.month >> _date.day; + f >> _count >> _length; + + GenericTag :: read(f); + _path = f.getline(); + + _library = tags :: get_library(library_id); + _artist = tags :: get_artist(artist_id); + _album = tags :: get_album(album_id); + _genre = tags :: get_genre(genre_id); + + //filter :: add(name(), index()); + //filter :: add(_artist->name(), index()); + //filter :: add(_album->name(), index()); + _library->inc_size(); +} + +void Track :: write(File &f) +{ + f << _library->index() << " " << _artist->index() << " "; + f << _album->index() << " " << _genre->index() << " " << _track << " "; + f << _date.year << " " << _date.month << " " << _date.day << " "; + f << _count << " " << _length << " "; + GenericTag :: write(f); + f << std::endl << _path << std::endl; +} diff --git a/tests/core/tags/track.cpp b/tests/core/tags/track.cpp index 79c1c2d1..ebf13fab 100644 --- a/tests/core/tags/track.cpp +++ b/tests/core/tags/track.cpp @@ -66,10 +66,11 @@ static void test_track_tag_destructor() static void test_track_tag_functional() { + File f("track_tag", 0); time_t rawtime = time(NULL); struct tm *now = localtime(&rawtime); std::stringstream ss; - Track track1, track2; + Track track1, track2, track3; track1 = Track(album, artist, genre, library, MUSIC_DIR + "/Hyrule Symphony/6 - Kakariko Village.mp3", @@ -109,6 +110,31 @@ static void test_track_tag_functional() test_equal(track1.compare_date(&track1), 0); test_equal(track1.compare_date(&track2), 2014); test_equal(track2.compare_date(&track1), -2014); + + + f.open(OPEN_WRITE); + track1.write(f); + f.close(); + + f.open(OPEN_READ); + track3.read(f); + f.close(); + + test_equal(track1.album(), track3.album()); + test_equal(track1.artist(), track3.artist()); + test_equal(track1.genre(), track3.genre()); + test_equal(track1.library(), track3.library()); + + test_equal(track1.name(), track3.name()); + test_equal(track1.lowercase(), track3.lowercase()); + test_equal(track1.primary_key(), track3.primary_key()); + test_equal(track1.date(), track3.date()); + test_equal(track1.path(), track3.path()); + test_equal(track1.length_str(), track3.length_str()); + + test_equal(track1.track(), track3.track()); + test_equal(track1.length(), track3.length()); + test_equal(track1.count(), track3.count()); } int main(int argc, char **argv)