File indexing completed on 2024-04-28 04:42:40
0001 /* 0002 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <kweathercore/locationquery.h> 0008 #include <kweathercore/locationqueryreply.h> 0009 0010 #include <QSignalSpy> 0011 #include <QStandardPaths> 0012 #include <QTest> 0013 0014 using namespace KWeatherCore; 0015 0016 class LocationQueryTest : public QObject 0017 { 0018 Q_OBJECT 0019 private Q_SLOTS: 0020 void initTestCase() 0021 { 0022 QStandardPaths::setTestModeEnabled(true); 0023 } 0024 0025 void testLocate() 0026 { 0027 LocationQuery queryMgr; 0028 auto reply = queryMgr.locate(); 0029 QVERIFY(reply); 0030 0031 QSignalSpy finished_spy(reply, &LocationQueryReply::finished); 0032 auto ret = finished_spy.wait(30000); 0033 0034 // if failed to located, abort 0035 if (!ret) { 0036 return; 0037 } 0038 0039 if (reply->error() == LocationQueryReply::NoError) { 0040 const auto location = reply->result().front(); 0041 QVERIFY(!location.name().isEmpty()); 0042 } else { 0043 QCOMPARE(reply->error(), LocationQueryReply::NoService); 0044 } 0045 0046 reply->deleteLater(); 0047 } 0048 0049 void testQuery() 0050 { 0051 LocationQuery queryMgr; 0052 auto reply = queryMgr.query(QStringLiteral("London")); 0053 QVERIFY(reply); 0054 0055 QSignalSpy finished_spy(reply, &LocationQueryReply::finished); 0056 QVERIFY(finished_spy.wait(30000)); 0057 QVERIFY(reply->error() != LocationQueryReply::NoError || !reply->result().empty()); 0058 reply->deleteLater(); 0059 } 0060 }; 0061 0062 QTEST_MAIN(LocationQueryTest) 0063 0064 #include "locationquerytest.moc"