Commit df488643 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

calculatorrunner: Add autotests

parent ef4d5d0f
......@@ -25,9 +25,9 @@ set(krunner_calculatorrunner_SRCS
)
if ( QALCULATE_FOUND )
add_library(krunner_calculatorrunner MODULE ${qalculate_engine_SRCS} ${krunner_calculatorrunner_SRCS})
kcoreaddons_desktop_to_json(krunner_calculatorrunner plasma-runner-calculator.desktop )
target_link_libraries(krunner_calculatorrunner
add_library(calculator MODULE ${qalculate_engine_SRCS} ${krunner_calculatorrunner_SRCS})
kcoreaddons_desktop_to_json(calculator plasma-runner-calculator.desktop )
target_link_libraries(calculator
${QALCULATE_LIBRARIES}
${CLN_LIBRARIES}
KF5::KIOCore
......@@ -37,9 +37,9 @@ if ( QALCULATE_FOUND )
Qt::Widgets
)
else ()
add_library(krunner_calculatorrunner MODULE ${krunner_calculatorrunner_SRCS})
kcoreaddons_desktop_to_json(krunner_calculatorrunner plasma-runner-calculator.desktop )
target_link_libraries(krunner_calculatorrunner
add_library(calculator MODULE ${krunner_calculatorrunner_SRCS})
kcoreaddons_desktop_to_json(calculator plasma-runner-calculator.desktop )
target_link_libraries(calculator
KF5::Runner
KF5::I18n
Qt::Gui
......@@ -47,4 +47,7 @@ else ()
)
endif ()
install(TARGETS krunner_calculatorrunner DESTINATION "${KDE_INSTALL_PLUGINDIR}/kf5/krunner" )
install(TARGETS calculator DESTINATION "${KDE_INSTALL_PLUGINDIR}/kf5/krunner" )
if(BUILD_TESTING)
add_subdirectory(autotests)
endif()
ecm_add_test(calculatorrunnertest.cpp TEST_NAME calculatorrunnertest LINK_LIBRARIES Qt::Test KF5::Runner KF5::KIOCore)
configure_krunner_test(calculatorrunnertest calculator)
#include <KRunner/AbstractRunnerTest>
#include <KShell>
#include <QMimeData>
#include <QTest>
class CalculatorRunnerTest : public AbstractRunnerTest
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void testQuery();
void test42();
void testApproximation();
void testQuery_data();
};
void CalculatorRunnerTest::initTestCase()
{
initProperties();
}
void CalculatorRunnerTest::testQuery()
{
QFETCH(QString, query);
QFETCH(QString, result);
launchQuery(query);
const QList<Plasma::QueryMatch> matches = manager->matches();
QCOMPARE(matches.size(), 1);
QCOMPARE(matches.first().text(), result);
}
void CalculatorRunnerTest::testQuery_data()
{
QTest::addColumn<QString>("query");
QTest::addColumn<QString>("result");
QTest::newRow("simple addition") << "1+1" << "2";
QTest::newRow("simple subtraction") << "2-1" << "1";
QTest::newRow("simple multiplication") << "2*2" << "4";
QTest::newRow("simple division") << "6/2" << "3";
QTest::newRow("simple power") << "2^3" << "8";
QTest::newRow("x as multiplication sign") << "25x4" << "100";
QTest::newRow("single digit factorial") << "5!" << "120";
QTest::newRow("hex to decimal lower case") << "0xf" << "15";
QTest::newRow("hex to decimal upper case") << "0xF" << "15";
QTest::newRow("hex to decimal with = at beginning") << "=0xF" << "15";
QTest::newRow("decimal to hex") << "hex=15" << "0xF";
QTest::newRow("decimal to hex with addition") << "hex=15+15" << "0x1E";
QTest::newRow("hex additions") << "0xF+0xF" << "30";
QTest::newRow("hex multiplication") << "0xF*0xF" << "225";
// BUG: 431362
QTest::newRow("hex and decimal addition") << "0x12+1" << "19";
QTest::newRow("hex and decimal addition reversed") << "1+0x12" << "19";
}
void CalculatorRunnerTest::testApproximation()
{
launchQuery("5^1234567");
QCOMPARE(manager->matches().size(), 1);
QCOMPARE(manager->matches().constFirst().subtext(), "Approximation");
}
void CalculatorRunnerTest::test42()
{
launchQuery("life");
QCOMPARE(manager->matches().size(), 1);
QCOMPARE(manager->matches().constFirst().text(), "42");
launchQuery("universe");
QCOMPARE(manager->matches().size(), 1);
QCOMPARE(manager->matches().constFirst().text(), "42");
}
QTEST_MAIN(CalculatorRunnerTest)
#include "calculatorrunnertest.moc"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment