Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma Workspace
Commits
df488643
Commit
df488643
authored
Feb 18, 2021
by
Alexander Lohnau
💬
Browse files
calculatorrunner: Add autotests
parent
ef4d5d0f
Changes
3
Hide whitespace changes
Inline
Side-by-side
runners/calculator/CMakeLists.txt
View file @
df488643
...
...
@@ -25,9 +25,9 @@ set(krunner_calculatorrunner_SRCS
)
if
(
QALCULATE_FOUND
)
add_library
(
krunner_
calculator
runner
MODULE
${
qalculate_engine_SRCS
}
${
krunner_calculatorrunner_SRCS
}
)
kcoreaddons_desktop_to_json
(
krunner_
calculator
runner
plasma-runner-calculator.desktop
)
target_link_libraries
(
krunner_
calculator
runner
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_
calculator
runner
MODULE
${
krunner_calculatorrunner_SRCS
}
)
kcoreaddons_desktop_to_json
(
krunner_
calculator
runner
plasma-runner-calculator.desktop
)
target_link_libraries
(
krunner_
calculator
runner
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
()
runners/calculator/autotests/CMakeLists.txt
0 → 100644
View file @
df488643
ecm_add_test
(
calculatorrunnertest.cpp TEST_NAME calculatorrunnertest LINK_LIBRARIES Qt::Test KF5::Runner KF5::KIOCore
)
configure_krunner_test
(
calculatorrunnertest calculator
)
runners/calculator/autotests/calculatorrunnertest.cpp
0 → 100644
View file @
df488643
#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"
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment