2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-03-13 21:01:24 +01:00
|
|
|
#include "config.h"
|
2013-02-22 23:57:31 +01:00
|
|
|
#include "tagreader.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/song.h"
|
2011-03-25 16:48:54 +01:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
2015-01-17 12:11:33 +01:00
|
|
|
#include "internet/lastfm/lastfmcompat.h"
|
2011-03-25 16:48:54 +01:00
|
|
|
#endif
|
2010-03-01 02:47:50 +01:00
|
|
|
|
2010-03-06 21:08:01 +01:00
|
|
|
#include "gmock/gmock.h"
|
2010-03-01 02:47:50 +01:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2010-03-01 16:40:12 +01:00
|
|
|
#include "test_utils.h"
|
2010-03-01 02:47:50 +01:00
|
|
|
|
2014-10-21 22:04:34 +02:00
|
|
|
#include <QStringList>
|
2010-03-07 16:26:54 +01:00
|
|
|
#include <QTemporaryFile>
|
2010-06-02 14:31:40 +02:00
|
|
|
#include <QTextCodec>
|
2010-03-07 16:26:54 +01:00
|
|
|
|
2011-02-04 14:29:49 +01:00
|
|
|
#include <id3v2tag.h>
|
2010-06-03 14:36:43 +02:00
|
|
|
|
2010-03-01 02:47:50 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class SongTest : public ::testing::Test {
|
2010-03-06 21:08:01 +01:00
|
|
|
protected:
|
|
|
|
static void SetUpTestCase() {
|
|
|
|
// Return something from uninteresting mock functions.
|
|
|
|
testing::DefaultValue<TagLib::String>::Set("foobarbaz");
|
|
|
|
}
|
2013-02-22 23:57:31 +01:00
|
|
|
|
|
|
|
static Song ReadSongFromFile(const QString& filename) {
|
|
|
|
TagReader tag_reader;
|
|
|
|
Song song;
|
2021-02-20 22:20:04 +01:00
|
|
|
::cpb::tagreader::SongMetadata pb_song;
|
2013-02-22 23:57:31 +01:00
|
|
|
|
|
|
|
// We need to init protobuf object from a Song object, to have default
|
|
|
|
// values initialized correctly. For example, Song's rating is -1 by
|
|
|
|
// default: using protobuf directly would lead to 0 by default, which is not
|
|
|
|
// what we want.
|
|
|
|
song.ToProtobuf(&pb_song);
|
|
|
|
tag_reader.ReadFile(filename, &pb_song);
|
|
|
|
song.InitFromProtobuf(pb_song);
|
|
|
|
return song;
|
|
|
|
}
|
2013-02-23 20:12:17 +01:00
|
|
|
|
|
|
|
static void WriteSongToFile(const Song& song, const QString& filename) {
|
|
|
|
TagReader tag_reader;
|
2021-02-20 22:20:04 +01:00
|
|
|
::cpb::tagreader::SongMetadata pb_song;
|
2013-02-23 20:12:17 +01:00
|
|
|
song.ToProtobuf(&pb_song);
|
|
|
|
tag_reader.SaveFile(filename, pb_song);
|
|
|
|
}
|
2013-02-24 18:59:07 +01:00
|
|
|
|
2015-01-17 12:11:33 +01:00
|
|
|
static void WriteSongStatisticsToFile(const Song& song,
|
|
|
|
const QString& filename) {
|
2013-02-24 18:59:07 +01:00
|
|
|
TagReader tag_reader;
|
2021-02-20 22:20:04 +01:00
|
|
|
::cpb::tagreader::SongMetadata pb_song;
|
2013-02-24 18:59:07 +01:00
|
|
|
song.ToProtobuf(&pb_song);
|
|
|
|
tag_reader.SaveSongStatisticsToFile(filename, pb_song);
|
|
|
|
}
|
2013-03-30 23:42:29 +01:00
|
|
|
|
|
|
|
static void WriteSongRatingToFile(const Song& song, const QString& filename) {
|
|
|
|
TagReader tag_reader;
|
2021-02-20 22:20:04 +01:00
|
|
|
::cpb::tagreader::SongMetadata pb_song;
|
2013-03-30 23:42:29 +01:00
|
|
|
song.ToProtobuf(&pb_song);
|
|
|
|
tag_reader.SaveSongRatingToFile(filename, pb_song);
|
|
|
|
}
|
2010-03-01 02:47:50 +01:00
|
|
|
};
|
|
|
|
|
2011-03-13 21:01:24 +01:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
2010-03-01 02:47:50 +01:00
|
|
|
TEST_F(SongTest, InitsFromLastFM) {
|
|
|
|
Song song;
|
|
|
|
lastfm::MutableTrack track;
|
|
|
|
track.setTitle("Foo");
|
|
|
|
lastfm::Artist artist("Bar");
|
|
|
|
track.setArtist(artist);
|
|
|
|
lastfm::Album album(artist, "Baz");
|
|
|
|
track.setAlbum(album);
|
|
|
|
|
|
|
|
song.InitFromLastFM(track);
|
|
|
|
EXPECT_EQ("Foo", song.title());
|
|
|
|
EXPECT_EQ("Baz", song.album());
|
|
|
|
EXPECT_EQ("Bar", song.artist());
|
|
|
|
}
|
2015-01-17 12:11:33 +01:00
|
|
|
#endif // HAVE_LIBLASTFM
|
2010-03-01 02:47:50 +01:00
|
|
|
|
2012-01-08 21:09:44 +01:00
|
|
|
/*TEST_F(SongTest, InitsFromFile) {
|
2010-03-07 16:26:54 +01:00
|
|
|
QTemporaryFile temp;
|
|
|
|
temp.open();
|
|
|
|
mock_factory_.ExpectCall(temp.fileName(), "Foo", "Bar", "Baz");
|
2010-03-06 21:08:01 +01:00
|
|
|
Song song(&mock_factory_);
|
2010-03-07 16:26:54 +01:00
|
|
|
song.InitFromFile(temp.fileName(), 42);
|
2010-03-06 21:08:01 +01:00
|
|
|
EXPECT_EQ("Foo", song.title());
|
|
|
|
EXPECT_EQ("Bar", song.artist());
|
|
|
|
EXPECT_EQ("Baz", song.album());
|
2012-01-08 21:09:44 +01:00
|
|
|
}*/
|
2010-03-01 02:47:50 +01:00
|
|
|
|
2013-02-22 23:57:31 +01:00
|
|
|
TEST_F(SongTest, FMPSRating) {
|
2010-10-17 18:03:49 +02:00
|
|
|
TemporaryResource r(":/testdata/fmpsrating.mp3");
|
2013-02-22 23:57:31 +01:00
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
2010-10-17 18:03:49 +02:00
|
|
|
EXPECT_FLOAT_EQ(0.42, song.rating());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SongTest, FMPSRatingUser) {
|
|
|
|
TemporaryResource r(":/testdata/fmpsratinguser.mp3");
|
2013-02-22 23:57:31 +01:00
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
2010-10-17 18:03:49 +02:00
|
|
|
EXPECT_FLOAT_EQ(0.10, song.rating());
|
2013-02-23 20:12:17 +01:00
|
|
|
|
|
|
|
song.set_rating(0.20);
|
2013-03-30 23:42:29 +01:00
|
|
|
WriteSongRatingToFile(song, r.fileName());
|
2013-02-23 20:12:17 +01:00
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_FLOAT_EQ(0.20, new_song.rating());
|
2010-10-17 18:03:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SongTest, FMPSRatingBoth) {
|
|
|
|
TemporaryResource r(":/testdata/fmpsratingboth.mp3");
|
2013-02-22 23:57:31 +01:00
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
2010-10-17 18:03:49 +02:00
|
|
|
EXPECT_FLOAT_EQ(0.42, song.rating());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SongTest, FMPSPlayCount) {
|
|
|
|
TemporaryResource r(":/testdata/fmpsplaycount.mp3");
|
2013-02-22 23:57:31 +01:00
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
2010-10-17 18:03:49 +02:00
|
|
|
EXPECT_EQ(123, song.playcount());
|
2013-02-23 20:12:17 +01:00
|
|
|
|
|
|
|
song.set_playcount(69);
|
2013-02-24 18:59:07 +01:00
|
|
|
WriteSongStatisticsToFile(song, r.fileName());
|
2013-02-23 20:12:17 +01:00
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_EQ(69, new_song.playcount());
|
2010-10-17 18:03:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SongTest, FMPSPlayCountUser) {
|
|
|
|
TemporaryResource r(":/testdata/fmpsplaycountuser.mp3");
|
2013-02-22 23:57:31 +01:00
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
2010-10-17 18:03:49 +02:00
|
|
|
EXPECT_EQ(42, song.playcount());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SongTest, FMPSPlayCountBoth) {
|
|
|
|
TemporaryResource r(":/testdata/fmpsplaycountboth.mp3");
|
2013-02-22 23:57:31 +01:00
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
2010-10-17 18:03:49 +02:00
|
|
|
EXPECT_EQ(123, song.playcount());
|
2013-02-22 23:57:31 +01:00
|
|
|
}
|
2010-10-17 18:03:49 +02:00
|
|
|
|
2014-10-21 21:49:23 +02:00
|
|
|
TEST_F(SongTest, FMPSUnrated) {
|
|
|
|
QStringList files_to_test;
|
2015-01-17 12:11:33 +01:00
|
|
|
files_to_test << ":/testdata/beep.m4a"
|
|
|
|
<< ":/testdata/beep.mp3"
|
|
|
|
<< ":/testdata/beep.flac"
|
|
|
|
<< ":/testdata/beep.ogg"
|
|
|
|
<< ":/testdata/beep.spx"
|
|
|
|
<< ":/testdata/beep.wav"
|
|
|
|
<< ":/testdata/beep.wma";
|
2014-10-21 21:49:23 +02:00
|
|
|
for (const QString& test_filename : files_to_test) {
|
|
|
|
TemporaryResource r(test_filename);
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
|
|
|
// beep files don't contain rating info, so they should be considered as
|
|
|
|
// "unrated" i.e. rating == -1
|
|
|
|
EXPECT_EQ(-1, song.rating());
|
|
|
|
// Writing -1 i.e. "unrated" to a file shouldn't write anything
|
|
|
|
WriteSongRatingToFile(song, r.fileName());
|
|
|
|
|
|
|
|
// Compare files
|
|
|
|
QFile orig_file(test_filename);
|
|
|
|
orig_file.open(QIODevice::ReadOnly);
|
|
|
|
QByteArray orig_file_data = orig_file.readAll();
|
|
|
|
QFile temp_file(r.fileName());
|
|
|
|
temp_file.open(QIODevice::ReadOnly);
|
|
|
|
QByteArray temp_file_data = temp_file.readAll();
|
|
|
|
EXPECT_TRUE(!orig_file_data.isEmpty());
|
|
|
|
EXPECT_TRUE(!temp_file_data.isEmpty());
|
|
|
|
EXPECT_TRUE(orig_file_data == temp_file_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-15 22:54:59 +01:00
|
|
|
TEST_F(SongTest, FMPSScore) {
|
|
|
|
TemporaryResource r(":/testdata/beep.mp3");
|
|
|
|
{
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
2013-03-18 22:46:11 +01:00
|
|
|
song.set_score(87);
|
2013-03-15 22:54:59 +01:00
|
|
|
|
|
|
|
WriteSongStatisticsToFile(song, r.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
2013-03-18 22:46:11 +01:00
|
|
|
EXPECT_EQ(87, new_song.score());
|
2013-03-15 22:54:59 +01:00
|
|
|
}
|
|
|
|
|
2013-02-28 02:17:15 +01:00
|
|
|
TEST_F(SongTest, POPMRating) {
|
|
|
|
TemporaryResource r(":/testdata/popmrating.mp3");
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_FLOAT_EQ(0.60, song.rating());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SongTest, BothFMPSPOPMRating) {
|
|
|
|
// fmpspopmrating.mp3 contains FMPS with rating 0.42 and POPM with 0x80
|
|
|
|
// (corresponds to 0.60 rating for us): check that FMPS tag has precedence
|
|
|
|
TemporaryResource r(":/testdata/fmpspopmrating.mp3");
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_FLOAT_EQ(0.42, song.rating());
|
|
|
|
}
|
|
|
|
|
2013-03-30 23:42:29 +01:00
|
|
|
TEST_F(SongTest, RatingOgg) {
|
2013-02-28 20:55:21 +01:00
|
|
|
TemporaryResource r(":/testdata/beep.ogg");
|
|
|
|
{
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
|
|
|
song.set_rating(0.20);
|
2013-03-30 23:42:29 +01:00
|
|
|
WriteSongRatingToFile(song, r.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_FLOAT_EQ(0.20, new_song.rating());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SongTest, StatisticsOgg) {
|
|
|
|
TemporaryResource r(":/testdata/beep.ogg");
|
|
|
|
{
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
2013-02-28 20:55:21 +01:00
|
|
|
song.set_playcount(1337);
|
2013-03-15 22:54:59 +01:00
|
|
|
song.set_score(87);
|
2013-02-28 20:55:21 +01:00
|
|
|
|
|
|
|
WriteSongStatisticsToFile(song, r.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_EQ(1337, new_song.playcount());
|
2013-03-15 22:54:59 +01:00
|
|
|
EXPECT_EQ(87, new_song.score());
|
2013-02-28 20:55:21 +01:00
|
|
|
}
|
|
|
|
|
2015-01-17 12:11:33 +01:00
|
|
|
TEST_F(SongTest, TagsOgg) {
|
|
|
|
TemporaryResource r(":/testdata/beep.ogg");
|
|
|
|
{
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
|
|
|
song.set_title("beep title");
|
|
|
|
song.set_artist("beep artist");
|
|
|
|
song.set_album("beep album");
|
|
|
|
song.set_albumartist("beep album artist");
|
|
|
|
song.set_composer("beep composer");
|
|
|
|
song.set_performer("beep performer");
|
|
|
|
song.set_grouping("beep grouping");
|
|
|
|
song.set_genre("beep genre");
|
|
|
|
song.set_comment("beep comment");
|
|
|
|
song.set_track(12);
|
|
|
|
song.set_disc(1234);
|
|
|
|
song.set_year(2015);
|
|
|
|
|
|
|
|
WriteSongToFile(song, r.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_EQ("beep title", new_song.title());
|
|
|
|
EXPECT_EQ("beep artist", new_song.artist());
|
|
|
|
EXPECT_EQ("beep album", new_song.album());
|
|
|
|
EXPECT_EQ("beep album artist", new_song.albumartist());
|
|
|
|
EXPECT_EQ("beep composer", new_song.composer());
|
|
|
|
EXPECT_EQ("beep performer", new_song.performer());
|
|
|
|
EXPECT_EQ("beep grouping", new_song.grouping());
|
|
|
|
EXPECT_EQ("beep genre", new_song.genre());
|
|
|
|
EXPECT_EQ("beep comment", new_song.comment());
|
|
|
|
EXPECT_EQ(12, new_song.track());
|
|
|
|
EXPECT_EQ(1234, new_song.disc());
|
|
|
|
EXPECT_EQ(2015, new_song.year());
|
|
|
|
}
|
|
|
|
|
2013-03-30 23:42:29 +01:00
|
|
|
TEST_F(SongTest, RatingFLAC) {
|
2013-03-02 00:03:51 +01:00
|
|
|
TemporaryResource r(":/testdata/beep.flac");
|
|
|
|
{
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
|
|
|
song.set_rating(0.20);
|
2013-03-30 23:42:29 +01:00
|
|
|
WriteSongRatingToFile(song, r.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_FLOAT_EQ(0.20, new_song.rating());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SongTest, StatisticsFLAC) {
|
|
|
|
TemporaryResource r(":/testdata/beep.flac");
|
|
|
|
{
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
2013-03-02 00:03:51 +01:00
|
|
|
song.set_playcount(1337);
|
2013-03-15 22:54:59 +01:00
|
|
|
song.set_score(87);
|
2013-03-02 00:03:51 +01:00
|
|
|
|
|
|
|
WriteSongStatisticsToFile(song, r.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_EQ(1337, new_song.playcount());
|
2013-03-15 22:54:59 +01:00
|
|
|
EXPECT_EQ(87, new_song.score());
|
2013-03-02 00:03:51 +01:00
|
|
|
}
|
|
|
|
|
2015-01-17 12:11:33 +01:00
|
|
|
TEST_F(SongTest, TagsFLAC) {
|
|
|
|
TemporaryResource r(":/testdata/beep.flac");
|
|
|
|
{
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
|
|
|
song.set_title("beep title");
|
|
|
|
song.set_artist("beep artist");
|
|
|
|
song.set_album("beep album");
|
|
|
|
song.set_albumartist("beep album artist");
|
|
|
|
song.set_composer("beep composer");
|
|
|
|
song.set_performer("beep performer");
|
|
|
|
song.set_grouping("beep grouping");
|
|
|
|
song.set_genre("beep genre");
|
|
|
|
song.set_comment("beep comment");
|
|
|
|
song.set_track(12);
|
|
|
|
song.set_disc(1234);
|
|
|
|
song.set_year(2015);
|
|
|
|
|
|
|
|
WriteSongToFile(song, r.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_EQ("beep title", new_song.title());
|
|
|
|
EXPECT_EQ("beep artist", new_song.artist());
|
|
|
|
EXPECT_EQ("beep album", new_song.album());
|
|
|
|
EXPECT_EQ("beep album artist", new_song.albumartist());
|
|
|
|
EXPECT_EQ("beep composer", new_song.composer());
|
|
|
|
EXPECT_EQ("beep performer", new_song.performer());
|
|
|
|
EXPECT_EQ("beep grouping", new_song.grouping());
|
|
|
|
EXPECT_EQ("beep genre", new_song.genre());
|
|
|
|
EXPECT_EQ("beep comment", new_song.comment());
|
|
|
|
EXPECT_EQ(12, new_song.track());
|
|
|
|
EXPECT_EQ(1234, new_song.disc());
|
|
|
|
EXPECT_EQ(2015, new_song.year());
|
|
|
|
}
|
|
|
|
|
2013-03-02 23:54:54 +01:00
|
|
|
#ifdef TAGLIB_WITH_ASF
|
2013-03-30 23:42:29 +01:00
|
|
|
TEST_F(SongTest, RatingASF) {
|
2013-03-02 23:54:54 +01:00
|
|
|
TemporaryResource r(":/testdata/beep.wma");
|
|
|
|
{
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
|
|
|
song.set_rating(0.20);
|
2013-03-30 23:42:29 +01:00
|
|
|
|
|
|
|
WriteSongRatingToFile(song, r.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_FLOAT_EQ(0.20, new_song.rating());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SongTest, StatisticsASF) {
|
|
|
|
TemporaryResource r(":/testdata/beep.wma");
|
|
|
|
{
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
2013-03-02 23:54:54 +01:00
|
|
|
song.set_playcount(1337);
|
2013-03-15 22:54:59 +01:00
|
|
|
song.set_score(87);
|
2013-03-02 23:54:54 +01:00
|
|
|
|
|
|
|
WriteSongStatisticsToFile(song, r.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_EQ(1337, new_song.playcount());
|
2013-03-15 22:54:59 +01:00
|
|
|
EXPECT_EQ(87, new_song.score());
|
2013-03-02 23:54:54 +01:00
|
|
|
}
|
2015-01-17 12:11:33 +01:00
|
|
|
#endif // TAGLIB_WITH_ASF
|
2013-03-02 23:54:54 +01:00
|
|
|
|
2013-03-30 23:42:29 +01:00
|
|
|
TEST_F(SongTest, RatingMP4) {
|
2013-03-03 00:18:59 +01:00
|
|
|
TemporaryResource r(":/testdata/beep.m4a");
|
|
|
|
{
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
|
|
|
song.set_rating(0.20);
|
2013-03-30 23:42:29 +01:00
|
|
|
|
|
|
|
WriteSongRatingToFile(song, r.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_FLOAT_EQ(0.20, new_song.rating());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SongTest, StatisticsMP4) {
|
|
|
|
TemporaryResource r(":/testdata/beep.m4a");
|
|
|
|
{
|
|
|
|
Song song = ReadSongFromFile(r.fileName());
|
2013-03-03 00:18:59 +01:00
|
|
|
song.set_playcount(1337);
|
2013-03-15 22:54:59 +01:00
|
|
|
song.set_score(87);
|
2013-03-03 00:18:59 +01:00
|
|
|
|
|
|
|
WriteSongStatisticsToFile(song, r.fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Song new_song = ReadSongFromFile(r.fileName());
|
|
|
|
EXPECT_EQ(1337, new_song.playcount());
|
2013-03-15 22:54:59 +01:00
|
|
|
EXPECT_EQ(87, new_song.score());
|
2013-03-03 00:18:59 +01:00
|
|
|
}
|
|
|
|
|
2016-04-18 04:33:52 +02:00
|
|
|
TEST_F(SongTest, MergeUserSetDataTest) {
|
|
|
|
// Suppose we have songs from files and from the DB
|
|
|
|
// Songs from files are the ones that will be imported in the DB after being merged with the
|
|
|
|
// former DB song values
|
|
|
|
Song song_db_with_rating;
|
|
|
|
Song song_db_with_no_rating;
|
|
|
|
Song song_file_with_rating;
|
|
|
|
Song song_file_with_no_rating;
|
|
|
|
|
|
|
|
song_db_with_rating.set_rating(0.42);
|
|
|
|
song_file_with_rating.set_rating(0.43);
|
|
|
|
|
|
|
|
// Merging a DB song with no rating should not update the rating that is in the file song
|
|
|
|
float old_rating_value = song_file_with_rating.rating();
|
|
|
|
song_file_with_rating.MergeUserSetData(song_db_with_no_rating);
|
|
|
|
EXPECT_NE(song_db_with_no_rating.rating(), song_file_with_rating.rating());
|
|
|
|
EXPECT_EQ(song_file_with_rating.rating(), old_rating_value);
|
|
|
|
|
|
|
|
// Merging a DB song with rating should not update the rating that is in the file song...
|
|
|
|
old_rating_value = song_file_with_rating.rating();
|
|
|
|
song_file_with_rating.MergeUserSetData(song_db_with_rating);
|
|
|
|
EXPECT_NE(song_db_with_rating.rating(), song_file_with_rating.rating());
|
|
|
|
EXPECT_EQ(song_file_with_rating.rating(), old_rating_value);
|
|
|
|
|
|
|
|
// ...but DB song's rating shouldn't be erased if the file song has no rating
|
|
|
|
song_file_with_no_rating.MergeUserSetData(song_db_with_rating);
|
|
|
|
EXPECT_EQ(song_file_with_no_rating.rating(), song_db_with_rating.rating());
|
|
|
|
}
|
|
|
|
|
2010-03-01 02:47:50 +01:00
|
|
|
} // namespace
|