2 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "MIMESniffing.h"
25 #include <QtCore/QFile>
26 #include <QtCore/QString>
27 #include <QtTest/QtTest>
29 class tst_MIMESniffing : public QObject {
39 tst_MIMESniffing::tst_MIMESniffing()
43 static inline const char* errorText(const TestData& data, const char* sniffedType)
45 return QString("file: %1, advertised: %2, image: %3. sniffed mime type was expected to be \"%4\" but instead was \"%5\"").arg(data.file).arg(data.advertisedType).arg(data.isImage).arg(data.sniffedType).arg(sniffedType).toLatin1();
48 void tst_MIMESniffing::testCase1()
51 for (int i = 0; i < testListSize; ++i) {
52 QFile file(testList[i].file);
53 QVERIFY2(file.open(QIODevice::ReadOnly), QString("unable to open file %1").arg(file.fileName()).toLatin1());
55 MIMESniffer sniffer(testList[i].advertisedType, testList[i].isImage);
56 QByteArray data = file.peek(sniffer.dataSize());
58 const char* sniffedType = sniffer.sniff(data.constData(), data.size());
60 QVERIFY2(!(sniffedType || testList[i].sniffedType) || (sniffedType && testList[i].sniffedType), errorText(testList[i], sniffedType));
63 QVERIFY2(!strcmp(sniffedType, testList[i].sniffedType), errorText(testList[i], sniffedType));
67 QVERIFY2(true, "Failure");
70 QTEST_APPLESS_MAIN(tst_MIMESniffing);
72 #include "tst_MIMESniffing.moc"