diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -13,6 +13,12 @@ LINK_LIBRARIES Qt5::Test NAME_PREFIX "kpat-" ) +ecm_add_test( + solve_by_name.cpp + TEST_NAME SolveByVariantName + LINK_LIBRARIES Qt5::Test + NAME_PREFIX "kpat-" +) ecm_add_test( "../dealer.cpp" "../dealerinfo.cpp" diff --git a/autotests/solve_by_name.cpp b/autotests/solve_by_name.cpp new file mode 100644 --- /dev/null +++ b/autotests/solve_by_name.cpp @@ -0,0 +1,44 @@ +/* Copyright (c) 2019 Shlomi Fish + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +#include +#include + +class TestSolver: public QObject +{ + Q_OBJECT +private slots: + void runSolver(); +}; + +void TestSolver::runSolver() +{ + QProcess kpat; + kpat.start(QStringLiteral("../kpat"), QStringList() << QStringLiteral("--start") << "1" << QStringLiteral("--end") << "3" << QStringLiteral("--solve") << QStringLiteral("Freecell")); + QCOMPARE(kpat.waitForFinished(), true); + QCOMPARE(kpat.exitStatus(), QProcess::NormalExit); + QCOMPARE(kpat.exitCode(), 0); +} + +QTEST_MAIN(TestSolver) +#include "solve_by_name.moc" diff --git a/main.cpp b/main.cpp --- a/main.cpp +++ b/main.cpp @@ -62,20 +62,20 @@ #include #include -static DealerScene *getDealer( int wanted_game ) +static DealerScene *getDealer( int wanted_game , QString name ) { foreach ( DealerInfo * di, DealerInfoList::self()->games() ) { - if ( di->providesId( wanted_game ) ) + if ( (wanted_game < 0) ? (QString::fromUtf8(di->untranslatedBaseName()) == name) : di->providesId( wanted_game ) ) { DealerScene * d = di->createGame(); Q_ASSERT( d ); d->setDeck( new KCardDeck( KCardTheme(), d ) ); d->initialize(); if ( !d->solver() ) { - qCCritical(KPAT_LOG) << "There is no solver for" << di->nameForId( wanted_game );; + qCCritical(KPAT_LOG) << "There is no solver for" << di->baseName(); return nullptr; } @@ -211,7 +211,7 @@ QDomDocument doc; doc.setContent(&of); - DealerScene *f = getDealer( doc.documentElement().attribute(QStringLiteral("id")).toInt() ); + DealerScene *f = getDealer( doc.documentElement().attribute(QStringLiteral("id")).toInt(), "" ); f->loadLegacyFile( &of ); f->solver()->translate_layout(); @@ -231,7 +231,7 @@ qsrand(std::time(nullptr)); if ( parser.isSet(QStringLiteral("generate")) ) { for (int dealer = 0; dealer < 20; dealer++) { - DealerScene *f = getDealer( dealer ); + DealerScene *f = getDealer( dealer, "" ); if (!f) continue; int count = 100; QTime mytime; @@ -265,9 +265,17 @@ } bool ok = false; + QString wanted_name; int wanted_game = -1; if ( parser.isSet( QStringLiteral("solve") ) ) - wanted_game = parser.value(QStringLiteral("solve")).toInt( &ok ); + { + wanted_name = parser.value(QStringLiteral("solve")); + ok = true; + bool isInt = false; + wanted_game = wanted_name.toInt( &isInt ); + if (!isInt) + wanted_game = -1; + } if ( ok ) { ok = false; @@ -287,7 +295,7 @@ if ( end_index == -1 ) end_index = start_index; } - DealerScene *f = getDealer( wanted_game ); + DealerScene *f = getDealer( wanted_game , wanted_name ); if ( !f ) return 1;