Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soundsource filetype detection fix #4602

Merged
merged 2 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/sources/soundsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ QString SoundSource::getTypeFromFile(const QFileInfo& fileInfo) {
const QString fileSuffix = fileInfo.suffix();
const QString fileType = fileTypeFromSuffix(fileSuffix);
DEBUG_ASSERT(!fileType.isEmpty() || fileType == QString{});
const QMimeType mimeType = QMimeDatabase().mimeTypeForFile(fileInfo);
const QMimeType mimeType = QMimeDatabase().mimeTypeForFile(
fileInfo, QMimeDatabase::MatchContent);
// According to the documentation mimeTypeForFile always returns a valid
// type, using the generic type application/octet-stream as a fallback.
// This might also occur for missing files as seen on Qt 5.12.
Expand Down
15 changes: 6 additions & 9 deletions src/test/soundproxy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,8 @@ TEST_F(SoundSourceProxyTest, getTypeFromFile) {
tempDir.filePath("file_with_empty_suffix.");
const QString filePathWithUnknownSuffix =
tempDir.filePath("file_with.unknown_suffix");
// TODO: Currently, our SoundSource::getTypeFromFile() can not detect the
// file type of files with a known but wrong file extension properly, so
// this test needs to be disabled.
//const QString filePathWithWrongSuffix =
// tempDir.filePath("file_with_wrong_suffix.wav");
const QString filePathWithWrongSuffix =
tempDir.filePath("file_with_wrong_suffix.wav");
const QString filePathWithUppercaseAndLeadingTrailingWhitespaceSuffix =
tempDir.filePath("file_with_uppercase_suffix. MP3 ");

Expand All @@ -753,7 +750,7 @@ TEST_F(SoundSourceProxyTest, getTypeFromFile) {
mixxxtest::copyFile(validFilePath, filePathWithoutSuffix);
mixxxtest::copyFile(validFilePath, filePathWithEmptySuffix);
mixxxtest::copyFile(validFilePath, filePathWithUnknownSuffix);
//mixxxtest::copyFile(validFilePath, filePathWithWrongSuffix);
mixxxtest::copyFile(validFilePath, filePathWithWrongSuffix);
mixxxtest::copyFile(validFilePath, filePathWithUppercaseAndLeadingTrailingWhitespaceSuffix);

ASSERT_STREQ(qPrintable("mp3"),
Expand All @@ -769,9 +766,9 @@ TEST_F(SoundSourceProxyTest, getTypeFromFile) {
EXPECT_STREQ(qPrintable("mp3"),
qPrintable(mixxx::SoundSource::getTypeFromFile(
QFileInfo(filePathWithUnknownSuffix))));
//EXPECT_STREQ(qPrintable("mp3"),
// qPrintable(mixxx::SoundSource::getTypeFromFile(
// QFileInfo(filePathWithWrongSuffix))));
EXPECT_STREQ(qPrintable("mp3"),
qPrintable(mixxx::SoundSource::getTypeFromFile(
QFileInfo(filePathWithWrongSuffix))));
EXPECT_STREQ(qPrintable("mp3"),
qPrintable(mixxx::SoundSource::getTypeFromFile(
QFileInfo(filePathWithUppercaseAndLeadingTrailingWhitespaceSuffix))));
Expand Down