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

Attempt to fix non-working unit tests on Windows (#65)

parent cb09716b
......@@ -39,6 +39,15 @@ using namespace std;
using namespace mc::collection;
using namespace TagLib;
QString FileNameToQString(const TagLib::FileName& fileName)
{
#ifdef WIN32
return QString::fromStdWString(fileName.wstr());
#else
return QFile::decodeName(fileName);
#endif
}
/* createFile creates the derived File type, e.g. TagLib::MPEG::File, based on
* fileName's extension and/or content.
*/
......@@ -50,7 +59,7 @@ File* FileTypeResolver::createFile(
File* result = 0;
QMimeDatabase mimeDatabase;
QString fn = QFile::decodeName(fileName);
QString fn = FileNameToQString(fileName);
QMimeType mimeType = mimeDatabase.mimeTypeForFile(fn);
QString mtn = mimeType.name();
......
......@@ -17,26 +17,33 @@ QString datapath(const QString& relPath)
return QDir::toNativeSeparators(QString(MUSICCOLLECTION_TEST_DIR) + '/' + relPath );
}
TagLib::FileName QStringToFileName(const QString& path)
{
#ifdef WIN32
return reinterpret_cast<const wchar_t*> (path.constData());
#else
return QFile::encodeName(path).constData();
#endif
}
TEST(FileTypeResolverTest, EmptyPath)
{
FileTypeResolver ftr;
File* file = ftr.createFile("");
EXPECT_EQ(0, file);
file = ftr.createFile("ThisDoesNotExist");
File* file = ftr.createFile(QStringToFileName(""));
EXPECT_EQ(0, file);
}
TEST(FileTypeResolverTest, FileDoesNotExist)
{
FileTypeResolver ftr;
File* file = ftr.createFile("ThisDoesNotExist");
File* file = ftr.createFile(QStringToFileName("ThisDoesNotExist"));
EXPECT_EQ(0, file);
}
TEST(FileTypeResolverTest, FileDoesNotExistMp3Ext)
{
FileTypeResolver ftr;
File* file = ftr.createFile("ThisDoesNotExist.mp3");
File* file = ftr.createFile(QStringToFileName("ThisDoesNotExist.mp3"));
ASSERT_TRUE(file != 0);
ASSERT_TRUE(dynamic_cast<MPEG::File*>(file) != 0);
ASSERT_FALSE(file->isOpen());
......@@ -45,7 +52,8 @@ TEST(FileTypeResolverTest, FileDoesNotExistMp3Ext)
TEST(FileTypeResolverTest, OggFileExists)
{
FileTypeResolver ftr;
File* file = ftr.createFile(QFile::encodeName(datapath("test.ogg")).constData());
//File* file = ftr.createFile(QFile::encodeName(datapath("test.ogg")).constData());
File* file = ftr.createFile(QStringToFileName(datapath("test.ogg")));
ASSERT_TRUE(file != 0);
ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0);
ASSERT_TRUE(file->isOpen());
......@@ -54,7 +62,7 @@ TEST(FileTypeResolverTest, OggFileExists)
TEST(FileTypeResolverTest, JapaneseOggFile)
{
FileTypeResolver ftr;
File* file = ftr.createFile(QFile::encodeName(datapath("テスト.ogg")).constData());
File* file = ftr.createFile(QStringToFileName(datapath("テスト.ogg")));
ASSERT_TRUE(file != 0);
ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0);
ASSERT_TRUE(file->isOpen());
......@@ -63,7 +71,7 @@ TEST(FileTypeResolverTest, JapaneseOggFile)
TEST(FileTypeResolverTest, ArabicOggFile)
{
FileTypeResolver ftr;
File* file = ftr.createFile(QFile::encodeName(datapath("اختبار.ogg")).constData());
File* file = ftr.createFile(QStringToFileName(datapath("اختبار.ogg")));
ASSERT_TRUE(file != 0);
ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0);
ASSERT_TRUE(file->isOpen());
......@@ -72,7 +80,7 @@ TEST(FileTypeResolverTest, ArabicOggFile)
TEST(FileTypeResolverTest, RussianOggFile)
{
FileTypeResolver ftr;
File* file = ftr.createFile(QFile::encodeName(datapath("тест.ogg")).constData());
File* file = ftr.createFile(QStringToFileName(datapath("тест.ogg")));
ASSERT_TRUE(file != 0);
ASSERT_TRUE(dynamic_cast<Ogg::Vorbis::File*>(file) != 0);
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