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

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/TransferJob>
0009 
0010 #include <QSignalSpy>
0011 #include <QTest>
0012 
0013 class ResponseCodeTest : public QObject
0014 {
0015     Q_OBJECT
0016 private Q_SLOTS:
0017     void testGet();
0018     void testGet_data();
0019 };
0020 
0021 void ResponseCodeTest::testGet_data()
0022 {
0023     QTest::addColumn<QString>("url");
0024     QTest::addColumn<QString>("expectedCode");
0025 
0026     QTest::addRow("200") << "http://localhost:5000/get/html"
0027                          << "200";
0028     QTest::addRow("404") << "http://localhost:5000/get/does-not-exist"
0029                          << "404";
0030 }
0031 
0032 void ResponseCodeTest::testGet()
0033 {
0034     QFETCH(QString, url);
0035     QFETCH(QString, expectedCode);
0036 
0037     auto *job = KIO::get(QUrl(url));
0038 
0039     QSignalSpy spy(job, &KJob::finished);
0040     spy.wait();
0041     QVERIFY(spy.size());
0042 
0043     const QString actualCode = job->queryMetaData("responsecode");
0044 
0045     QCOMPARE(actualCode, expectedCode);
0046 
0047     QCOMPARE(job->error(), KJob::NoError);
0048 }
0049 
0050 QTEST_GUILESS_MAIN(ResponseCodeTest)
0051 
0052 #include "responsecodetest.moc"