File indexing completed on 2024-05-19 16:19:09
0001 /*************************************************************************** 0002 Copyright (C) 2021 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #include "fetchertest.h" 0026 0027 #include "../fetch/fetchmanager.h" 0028 #include "../fetch/fetcherinitializer.h" 0029 0030 #include <QTest> 0031 #include <QSignalSpy> 0032 #include <QStandardPaths> 0033 0034 QTEST_GUILESS_MAIN( FetcherTest ) 0035 0036 void FetcherTest::initTestCase() { 0037 QStandardPaths::setTestModeEnabled(true); 0038 Tellico::Fetch::FetcherInitializer initFetchers; 0039 } 0040 0041 void FetcherTest::testType() { 0042 auto list = Tellico::Fetch::Manager::self()->fetchers(); 0043 QVERIFY(!list.isEmpty()); 0044 0045 auto registry = Tellico::Fetch::Manager::self()->functionRegistry; 0046 auto i = registry.constBegin(); 0047 auto end = registry.constEnd(); 0048 for( ; i != end; ++i) { 0049 auto f = registry.value(i.key()).create(this); 0050 QVERIFY2(i.key() == f->type(), 0051 qPrintable(QString::fromLatin1("Mismatched type: %1 != %2").arg(QString::number(i.key()), 0052 QString::number(f->type())))); 0053 QVERIFY(f->uuid().isEmpty()); 0054 QVERIFY(!f->isSearching()); 0055 0056 Tellico::Data::Collection::Type cType = Tellico::Data::Collection::Base; 0057 // BoardGame is the last collection type (currently) 0058 while(!f->canFetch(cType) && cType <= Tellico::Data::Collection::BoardGame) { 0059 cType = static_cast<Tellico::Data::Collection::Type>(cType+1); 0060 } 0061 if(cType > Tellico::Data::Collection::BoardGame) { 0062 // no point in trying now. Fetchers like ExecExternal won't match 0063 continue; 0064 } 0065 QSignalSpy spy(f.data(), &Tellico::Fetch::Fetcher::signalDone); 0066 // test invalid search request key 0067 Tellico::Fetch::FetchRequest req(cType, Tellico::Fetch::FetchLast, QString()); 0068 f->startSearch(req); 0069 QCOMPARE(spy.count(), 1); 0070 } 0071 }