tst_QMimeDatabase: detect executables as shared libraries too

They can be, if compiled with -Wl,-pie. Example:

 $ file /usr/bin/ping
 /usr/bin/ping: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0

And you can't detect via the interpreter, since libraries can have
them too:

 $ file /lib64/libc-2.26.so libQt5Core.so.5.11.0
 /lib64/libc-2.26.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2
 libQt5Core.so.5.11.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.17.0

Change-Id: I940917d6763842499b18fffd15143bb80ce0e531
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Thiago Macieira 2018-02-17 13:57:15 -08:00
parent e83ce91c6a
commit bf87e1cfbd

View File

@ -222,8 +222,10 @@ void tst_QMimeDatabase::mimeTypeForName()
qWarning() << "ls not found";
else {
const QString executableType = QString::fromLatin1("application/x-executable");
const QString sharedLibType = QString::fromLatin1("application/x-sharedlib");
//QTest::newRow("executable") << exePath << executableType;
QCOMPARE(db.mimeTypeForFile(exePath).name(), executableType);
QVERIFY(db.mimeTypeForFile(exePath).name() == executableType ||
db.mimeTypeForFile(exePath).name() == sharedLibType);
}
#endif