File indexing completed on 2024-04-28 03:54:48

0001 /*
0002 
0003     SPDX-FileCopyrightText: 2023 Nicolas Fella <nicolas.fella@gmx.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include <KIO/MimetypeJob>
0009 #include <KIO/TransferJob>
0010 
0011 #include <QSignalSpy>
0012 #include <QTest>
0013 
0014 class HeadTest : public QObject
0015 {
0016     Q_OBJECT
0017 private Q_SLOTS:
0018     void testMimeType();
0019     void testMimeType_data();
0020 };
0021 
0022 void HeadTest::testMimeType_data()
0023 {
0024     QTest::addColumn<QString>("url");
0025     QTest::addColumn<QString>("expectedMimeType");
0026 
0027     QTest::addRow("html") << "http://localhost:5000/mime/html"
0028                           << "text/html";
0029     QTest::addRow("calendar") << "http://localhost:5000/mime/calendar"
0030                               << "text/calendar";
0031 }
0032 
0033 void HeadTest::testMimeType()
0034 {
0035     QFETCH(QString, url);
0036     QFETCH(QString, expectedMimeType);
0037 
0038     auto *job = KIO::mimetype(QUrl(url));
0039 
0040     QSignalSpy mimeTypeFoundSpy(job, &KIO::MimetypeJob::mimeTypeFound);
0041     mimeTypeFoundSpy.wait();
0042     QCOMPARE(mimeTypeFoundSpy.count(), 1);
0043 
0044     auto args = mimeTypeFoundSpy.first();
0045     QCOMPARE(args[1], expectedMimeType);
0046 
0047     QSignalSpy spy(job, &KJob::finished);
0048     spy.wait();
0049     QVERIFY(spy.size());
0050     QCOMPARE(job->mimetype(), expectedMimeType);
0051 }
0052 
0053 QTEST_GUILESS_MAIN(HeadTest)
0054 
0055 #include "headtest.moc"