2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/song.h"
|
|
|
|
#include "radio/fixlastfm.h"
|
2010-03-01 02:47:50 +01:00
|
|
|
#include <lastfm/Track>
|
|
|
|
|
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-06 21:08:01 +01:00
|
|
|
#include "mock_taglib.h"
|
2010-03-01 02:47:50 +01:00
|
|
|
|
2010-03-07 16:26:54 +01:00
|
|
|
#include <QTemporaryFile>
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
MockFileRefFactory mock_factory_;
|
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());
|
|
|
|
}
|
|
|
|
|
2010-03-06 21:08:01 +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());
|
|
|
|
}
|
2010-03-01 02:47:50 +01:00
|
|
|
|
2010-05-11 14:03:55 +02:00
|
|
|
TEST_F(SongTest, DetectsWindows1251) {
|
|
|
|
char cp1251[] = { 0xc2, 0xfb, 0xe4, 0xfb, 0xf5, 0xe0, 0xe9, 0x00 }; // Выдыхай
|
|
|
|
UniversalEncodingHandler handler;
|
|
|
|
TagLib::ByteVector bytes(cp1251);
|
|
|
|
TagLib::String str = handler.parse(bytes);
|
|
|
|
EXPECT_FALSE(str.isAscii());
|
|
|
|
EXPECT_FALSE(str.isLatin1());
|
|
|
|
EXPECT_STREQ("Выдыхай", str.to8Bit(true).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SongTest, LeavesASCIIAlone) {
|
2010-05-26 00:19:30 +02:00
|
|
|
const char* ascii = "foobar";
|
2010-05-11 14:03:55 +02:00
|
|
|
UniversalEncodingHandler handler;
|
|
|
|
TagLib::ByteVector bytes(ascii);
|
|
|
|
TagLib::String str = handler.parse(bytes);
|
|
|
|
EXPECT_TRUE(str.isAscii());
|
|
|
|
EXPECT_TRUE(str.isLatin1());
|
|
|
|
EXPECT_STREQ("foobar", str.to8Bit(false).c_str());
|
|
|
|
}
|
|
|
|
|
2010-03-01 02:47:50 +01:00
|
|
|
} // namespace
|