diff options
author | Konstantin Tokarev <annulen@yandex.ru> | 2019-10-03 22:48:16 +0300 |
---|---|---|
committer | Konstantin Tokarev <annulen@yandex.ru> | 2019-10-04 02:11:52 +0300 |
commit | 3395426ab651a631aca8ee6b0a694a71df19100f (patch) | |
tree | 4d1d20f3630ef5e68ee17fa8b3f3de9f3269ec19 /tests/webkitwidgets/MIMESniffing/tst_MIMESniffing.cpp | |
parent | b47f584d07aec2d78ea4a5a5ccf2c761f44f5585 (diff) | |
download | qtwebkit-3395426ab651a631aca8ee6b0a694a71df19100f.tar.gz |
Import QtWebKit commit 49b749171e786df3adcd7a755df428c1846acd69
Change-Id: I4c82d8030969d941bb78b1cc4e77c0a66db8da2c
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'tests/webkitwidgets/MIMESniffing/tst_MIMESniffing.cpp')
-rw-r--r-- | tests/webkitwidgets/MIMESniffing/tst_MIMESniffing.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/webkitwidgets/MIMESniffing/tst_MIMESniffing.cpp b/tests/webkitwidgets/MIMESniffing/tst_MIMESniffing.cpp new file mode 100644 index 000000000..8c5417f26 --- /dev/null +++ b/tests/webkitwidgets/MIMESniffing/tst_MIMESniffing.cpp @@ -0,0 +1,72 @@ +/* + Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" +#include "MIMESniffing.h" + +#include "TestData.h" + +#include <QtCore/QFile> +#include <QtCore/QString> +#include <QtTest/QtTest> + +class tst_MIMESniffing : public QObject { + Q_OBJECT + +public: + tst_MIMESniffing(); + +private Q_SLOTS: + void testCase1(); +}; + +tst_MIMESniffing::tst_MIMESniffing() +{ +} + +static inline const char* errorText(const TestData& data, const char* sniffedType) +{ + 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(); +} + +void tst_MIMESniffing::testCase1() +{ + + for (int i = 0; i < testListSize; ++i) { + QFile file(testList[i].file); + QVERIFY2(file.open(QIODevice::ReadOnly), QString("unable to open file %1").arg(file.fileName()).toLatin1()); + + MIMESniffer sniffer(testList[i].advertisedType, testList[i].isImage); + QByteArray data = file.peek(sniffer.dataSize()); + + const char* sniffedType = sniffer.sniff(data.constData(), data.size()); + + QVERIFY2(!(sniffedType || testList[i].sniffedType) || (sniffedType && testList[i].sniffedType), errorText(testList[i], sniffedType)); + + if (sniffedType) + QVERIFY2(!strcmp(sniffedType, testList[i].sniffedType), errorText(testList[i], sniffedType)); + + } + + QVERIFY2(true, "Failure"); +} + +QTEST_APPLESS_MAIN(tst_MIMESniffing); + +#include "tst_MIMESniffing.moc" |