File indexing completed on 2024-05-12 05:09:58

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 <KLocalizedString>
0031 
0032 #include <QTest>
0033 #include <QSignalSpy>
0034 #include <QStandardPaths>
0035 
0036 QTEST_GUILESS_MAIN( FetcherTest )
0037 
0038 void FetcherTest::initTestCase() {
0039   QStandardPaths::setTestModeEnabled(true);
0040   KLocalizedString::setApplicationDomain("tellico");
0041   Tellico::Fetch::FetcherInitializer initFetchers;
0042 }
0043 
0044 void FetcherTest::testType() {
0045   auto list = Tellico::Fetch::Manager::self()->fetchers();
0046   QVERIFY(!list.isEmpty());
0047 
0048   auto registry = Tellico::Fetch::Manager::self()->functionRegistry;
0049   auto i = registry.constBegin();
0050   auto end = registry.constEnd();
0051   for( ; i != end; ++i) {
0052     auto f = registry.value(i.key()).create(this);
0053     QVERIFY2(i.key() == f->type(),
0054              qPrintable(QString::fromLatin1("%1 has mismatched type: %2 != %3").arg(f->source(),
0055                                                                                     QString::number(i.key()),
0056                                                                                     QString::number(f->type()))));
0057     QVERIFY(f->uuid().isEmpty());
0058     QVERIFY(!f->isSearching());
0059 
0060     Tellico::Data::Collection::Type cType = Tellico::Data::Collection::Base;
0061     // BoardGame is the last collection type (currently)
0062     while(!f->canFetch(cType) && cType <= Tellico::Data::Collection::BoardGame) {
0063       cType = static_cast<Tellico::Data::Collection::Type>(cType+1);
0064     }
0065     if(cType > Tellico::Data::Collection::BoardGame) {
0066       // no point in trying now. Fetchers like ExecExternal won't match
0067       continue;
0068     }
0069     QSignalSpy spy(f.data(), &Tellico::Fetch::Fetcher::signalDone);
0070     // test invalid search request key
0071     Tellico::Fetch::FetchRequest req(cType, Tellico::Fetch::FetchLast, QString());
0072     f->startSearch(req);
0073     QCOMPARE(spy.count(), 1);
0074   }
0075 }