diff --git a/kerfuffle/archive_kerfuffle.h b/kerfuffle/archive_kerfuffle.h --- a/kerfuffle/archive_kerfuffle.h +++ b/kerfuffle/archive_kerfuffle.h @@ -37,6 +37,8 @@ #include #include +#include + class KJob; namespace Kerfuffle @@ -130,6 +132,11 @@ Q_OBJECT public: + + static bool comparePlugins(const KService::Ptr &p1, const KService::Ptr &p2); + static QString determineMimeType(const QString& filename); + static KService::List findPluginOffers(const QString& filename, const QString& fixedMimeType); + static Archive *create(const QString &fileName, QObject *parent = 0); static Archive *create(const QString &fileName, const QString &fixedMimeType, QObject *parent = 0); ~Archive(); diff --git a/kerfuffle/archive_kerfuffle.cpp b/kerfuffle/archive_kerfuffle.cpp --- a/kerfuffle/archive_kerfuffle.cpp +++ b/kerfuffle/archive_kerfuffle.cpp @@ -39,14 +39,16 @@ #include #include -#include -static bool comparePlugins(const KService::Ptr &p1, const KService::Ptr &p2) +namespace Kerfuffle +{ + +bool Archive::comparePlugins(const KService::Ptr &p1, const KService::Ptr &p2) { return (p1->property(QLatin1String( "X-KDE-Priority" )).toInt()) > (p2->property(QLatin1String( "X-KDE-Priority" )).toInt()); } -static QString determineMimeType(const QString& filename) +QString Archive::determineMimeType(const QString& filename) { QMimeDatabase db; QMimeType mimeFromExtension = db.mimeTypeForFile(filename, QMimeDatabase::MatchExtension); @@ -79,7 +81,7 @@ return mimeFromContent.name(); } -static KService::List findPluginOffers(const QString& filename, const QString& fixedMimeType) +KService::List Archive::findPluginOffers(const QString& filename, const QString& fixedMimeType) { KService::List offers; @@ -99,9 +101,6 @@ return offers; } -namespace Kerfuffle -{ - QDebug operator<<(QDebug d, const fileRootNodePair &pair) { d.nospace() << "fileRootNodePair(" << pair.file << "," << pair.rootNode << ")"; diff --git a/kerfuffle/tests/CMakeLists.txt b/kerfuffle/tests/CMakeLists.txt --- a/kerfuffle/tests/CMakeLists.txt +++ b/kerfuffle/tests/CMakeLists.txt @@ -20,4 +20,5 @@ KERFUFFLE_UNIT_TESTS( archivetest jobstest + mimetypetest ) diff --git a/kerfuffle/tests/data/zip_with_wrong_extension.rar b/kerfuffle/tests/data/zip_with_wrong_extension.rar new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "kerfuffle/archive_kerfuffle.h" + +#include + +using namespace Kerfuffle; + +class MimeTypeTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void testEmptyFilename(); + void testTarDetection(); + void testWrongZipExtension(); + +}; + +QTEST_GUILESS_MAIN(MimeTypeTest) + +void MimeTypeTest::testEmptyFilename() +{ + QCOMPARE(Archive::determineMimeType(QString()), QStringLiteral("application/octet-stream")); +} + +void MimeTypeTest::testTarDetection() +{ + const QString testFile = QFINDTESTDATA("data/simplearchive.tar.gz"); + QCOMPARE(Archive::determineMimeType(testFile), QStringLiteral("application/x-compressed-tar")); +} + +void MimeTypeTest::testWrongZipExtension() +{ + const QString testFile = QFINDTESTDATA("data/zip_with_wrong_extension.rar"); + QCOMPARE(Archive::determineMimeType(testFile), QStringLiteral("application/zip")); +} + +#include "mimetypetest.moc"