Commit fa0587c3 authored by Bart van der Velden's avatar Bart van der Velden

Yet anoteher attempt (#65)

parent ff5824e4
...@@ -12,6 +12,26 @@ using namespace std; ...@@ -12,6 +12,26 @@ using namespace std;
using namespace mc::collection; using namespace mc::collection;
using namespace TagLib; using namespace TagLib;
class TestFileName
{
public:
TestFileName(const QString& fileName) : m_fileName(fileName)
{
}
TagLib::FileName TagLibFileName() const
{
#ifdef WIN32
return reinterpret_cast<const wchar_t*> (m_fileName.constData());
#else
return QFile::encodeName(path).constData();
#endif
}
private:
QString m_fileName;
};
QString datapath(const QString& relPath) QString datapath(const QString& relPath)
{ {
return QDir::toNativeSeparators(QString(MUSICCOLLECTION_TEST_DIR) + '/' + relPath ); return QDir::toNativeSeparators(QString(MUSICCOLLECTION_TEST_DIR) + '/' + relPath );
...@@ -29,24 +49,24 @@ TagLib::FileName QStringToFileName(const QString& path) ...@@ -29,24 +49,24 @@ TagLib::FileName QStringToFileName(const QString& path)
TEST(FileTypeResolverTest, EmptyPath) TEST(FileTypeResolverTest, EmptyPath)
{ {
FileTypeResolver ftr; FileTypeResolver ftr;
QString fileName = ""; TestFileName fileName = "";
File* file = ftr.createFile(QStringToFileName(fileName)); File* file = ftr.createFile(fileName.TagLibFileName());
EXPECT_EQ(0, file); EXPECT_EQ(0, file);
} }
TEST(FileTypeResolverTest, FileDoesNotExist) TEST(FileTypeResolverTest, FileDoesNotExist)
{ {
FileTypeResolver ftr; FileTypeResolver ftr;
QString fileName = "ThisDoesNotExist"; TestFileName fileName = "ThisDoesNotExist";
File* file = ftr.createFile(QStringToFileName(fileName)); File* file = ftr.createFile(fileName.TagLibFileName());
EXPECT_EQ(0, file); EXPECT_EQ(0, file);
} }
TEST(FileTypeResolverTest, FileDoesNotExistMp3Ext) TEST(FileTypeResolverTest, FileDoesNotExistMp3Ext)
{ {
FileTypeResolver ftr; FileTypeResolver ftr;
QString fileName = "ThisDoesNotExist.mp3"; TestFileName fileName = "ThisDoesNotExist.mp3";
File* file = ftr.createFile(QStringToFileName(fileName)); File* file = ftr.createFile(fileName.TagLibFileName());
ASSERT_TRUE(file != 0); ASSERT_TRUE(file != 0);
ASSERT_TRUE(dynamic_cast<MPEG::File*>(file) != 0); ASSERT_TRUE(dynamic_cast<MPEG::File*>(file) != 0);
ASSERT_FALSE(file->isOpen()); ASSERT_FALSE(file->isOpen());
...@@ -55,8 +75,8 @@ TEST(FileTypeResolverTest, FileDoesNotExistMp3Ext) ...@@ -55,8 +75,8 @@ TEST(FileTypeResolverTest, FileDoesNotExistMp3Ext)
TEST(FileTypeResolverTest, OggFileExists) TEST(FileTypeResolverTest, OggFileExists)
{ {
FileTypeResolver ftr; FileTypeResolver ftr;
QString fileName = datapath("test.ogg"); TestFileName fileName = datapath("test.ogg");
File* file = ftr.createFile(QStringToFileName(fileName)); File* file = ftr.createFile(fileName.TagLibFileName());
ASSERT_TRUE(file != 0); ASSERT_TRUE(file != 0);
ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0); ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0);
ASSERT_TRUE(file->isOpen()); ASSERT_TRUE(file->isOpen());
...@@ -65,8 +85,8 @@ TEST(FileTypeResolverTest, OggFileExists) ...@@ -65,8 +85,8 @@ TEST(FileTypeResolverTest, OggFileExists)
TEST(FileTypeResolverTest, JapaneseOggFile) TEST(FileTypeResolverTest, JapaneseOggFile)
{ {
FileTypeResolver ftr; FileTypeResolver ftr;
QString fileName = datapath("テスト.ogg"); TestFileName fileName = datapath("テスト.ogg");
File* file = ftr.createFile(QStringToFileName(fileName)); File* file = ftr.createFile(fileName.TagLibFileName());
ASSERT_TRUE(file != 0); ASSERT_TRUE(file != 0);
ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0); ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0);
ASSERT_TRUE(file->isOpen()); ASSERT_TRUE(file->isOpen());
...@@ -75,8 +95,8 @@ TEST(FileTypeResolverTest, JapaneseOggFile) ...@@ -75,8 +95,8 @@ TEST(FileTypeResolverTest, JapaneseOggFile)
TEST(FileTypeResolverTest, ArabicOggFile) TEST(FileTypeResolverTest, ArabicOggFile)
{ {
FileTypeResolver ftr; FileTypeResolver ftr;
QString fileName = datapath("اختبار.ogg"); TestFileName fileName = datapath("اختبار.ogg");
File* file = ftr.createFile(QStringToFileName(fileName)); File* file = ftr.createFile(fileName.TagLibFileName());
ASSERT_TRUE(file != 0); ASSERT_TRUE(file != 0);
ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0); ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0);
ASSERT_TRUE(file->isOpen()); ASSERT_TRUE(file->isOpen());
...@@ -85,8 +105,8 @@ TEST(FileTypeResolverTest, ArabicOggFile) ...@@ -85,8 +105,8 @@ TEST(FileTypeResolverTest, ArabicOggFile)
TEST(FileTypeResolverTest, RussianOggFile) TEST(FileTypeResolverTest, RussianOggFile)
{ {
FileTypeResolver ftr; FileTypeResolver ftr;
QString fileName = datapath("тест.ogg"); TestFileName fileName = datapath("тест.ogg");
File* file = ftr.createFile(QStringToFileName(fileName)); File* file = ftr.createFile(fileName.TagLibFileName());
ASSERT_TRUE(file != 0); ASSERT_TRUE(file != 0);
ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0); ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0);
ASSERT_TRUE(file->isOpen()); ASSERT_TRUE(file->isOpen());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment