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 Mobile
Kalk
Commits
e3bf3c99
Commit
e3bf3c99
authored
May 03, 2021
by
Albert Astals Cid
Browse files
Add some autotests
parent
67a44694
Changes
4
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
e3bf3c99
...
...
@@ -81,6 +81,10 @@ add_subdirectory(src)
configure_file
(
config-kcalc.h.cmake
${
CMAKE_CURRENT_BINARY_DIR
}
/config-kcalc.h
)
add_subdirectory
(
knumber
)
if
(
BUILD_TESTING
)
add_subdirectory
(
autotests
)
endif
()
install
(
PROGRAMS org.kde.kalk.desktop DESTINATION
${
KDE_INSTALL_APPDIR
}
)
install
(
FILES org.kde.kalk.appdata.xml DESTINATION
${
KDE_INSTALL_METAINFODIR
}
)
install
(
FILES kalk.svg DESTINATION
${
KDE_INSTALL_FULL_ICONDIR
}
/hicolor/scalable/apps/
)
...
...
autotests/CMakeLists.txt
0 → 100644
View file @
e3bf3c99
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
/../src
${
CMAKE_CURRENT_SOURCE_DIR
}
/../knumber
)
ecm_add_test
(
inputmanagertest.cpp
TEST_NAME
"inputmanagertest"
LINK_LIBRARIES Qt5::Test knumber kalklib
)
autotests/inputmanagertest.cpp
0 → 100644
View file @
e3bf3c99
#include
<QTest>
#include
"inputmanager.h"
class
InputManagerTest
:
public
QObject
{
Q_OBJECT
private
slots
:
void
init
();
void
testAddition
();
void
testMultiplication
();
void
testDivision
();
void
testNonIntegerDivision
();
};
#ifndef Q_OS_WIN
void
initLocale
()
{
setenv
(
"LC_ALL"
,
"C"
,
1
);
}
Q_CONSTRUCTOR_FUNCTION
(
initLocale
)
#endif
void
InputManagerTest
::
init
()
{
InputManager
::
inst
()
->
clear
();
}
void
InputManagerTest
::
testAddition
()
{
InputManager
::
inst
()
->
append
(
"4"
);
InputManager
::
inst
()
->
append
(
"+"
);
InputManager
::
inst
()
->
append
(
"2"
);
QCOMPARE
(
InputManager
::
inst
()
->
result
(),
"6"
);
InputManager
::
inst
()
->
equal
();
InputManager
::
inst
()
->
append
(
"+"
);
InputManager
::
inst
()
->
append
(
"3"
);
QCOMPARE
(
InputManager
::
inst
()
->
result
(),
"9"
);
}
void
InputManagerTest
::
testMultiplication
()
{
InputManager
::
inst
()
->
append
(
"4"
);
InputManager
::
inst
()
->
append
(
"*"
);
InputManager
::
inst
()
->
append
(
"2"
);
QCOMPARE
(
InputManager
::
inst
()
->
result
(),
"8"
);
InputManager
::
inst
()
->
equal
();
InputManager
::
inst
()
->
append
(
"*"
);
InputManager
::
inst
()
->
append
(
"7"
);
QCOMPARE
(
InputManager
::
inst
()
->
result
(),
"56"
);
}
void
InputManagerTest
::
testDivision
()
{
InputManager
::
inst
()
->
append
(
"70"
);
InputManager
::
inst
()
->
append
(
"÷"
);
InputManager
::
inst
()
->
append
(
"5"
);
QCOMPARE
(
InputManager
::
inst
()
->
result
(),
"14"
);
InputManager
::
inst
()
->
equal
();
InputManager
::
inst
()
->
append
(
"*"
);
InputManager
::
inst
()
->
append
(
"5"
);
QCOMPARE
(
InputManager
::
inst
()
->
result
(),
"70"
);
}
void
InputManagerTest
::
testNonIntegerDivision
()
{
InputManager
::
inst
()
->
append
(
"70"
);
InputManager
::
inst
()
->
append
(
"÷"
);
InputManager
::
inst
()
->
append
(
"9"
);
QVERIFY
(
InputManager
::
inst
()
->
result
().
startsWith
(
"7.77777"
));
InputManager
::
inst
()
->
equal
();
InputManager
::
inst
()
->
append
(
"*"
);
InputManager
::
inst
()
->
append
(
"9"
);
QCOMPARE
(
InputManager
::
inst
()
->
result
(),
"70"
);
}
QTEST_GUILESS_MAIN
(
InputManagerTest
)
#include
"inputmanagertest.moc"
src/CMakeLists.txt
View file @
e3bf3c99
...
...
@@ -24,15 +24,22 @@
bison_target
(
MyParser
${
CMAKE_CURRENT_SOURCE_DIR
}
/mathengine/parser.yy
${
CMAKE_CURRENT_BINARY_DIR
}
/parser.cc
)
flex_target
(
MyScanner
${
CMAKE_CURRENT_SOURCE_DIR
}
/mathengine/scanner.ll
${
CMAKE_CURRENT_BINARY_DIR
}
/scanner.cc
)
set
(
kalk_SRCS
main.cpp
add_library
(
kalklib STATIC
historymanager.cpp
unitmodel.cpp
mathengine.cpp
inputmanager.cpp
mathengine.cpp
mathengine/driver.cc
${
CMAKE_CURRENT_BINARY_DIR
}
/parser.cc
${
CMAKE_CURRENT_BINARY_DIR
}
/scanner.cc
mathengine/driver.cc
)
target_link_libraries
(
kalklib
Qt5::Core
knumber
)
set
(
kalk_SRCS
main.cpp
unitmodel.cpp
calculator.qrc
)
add_executable
(
kalk
${
kalk_SRCS
}
)
...
...
@@ -47,8 +54,9 @@ target_link_libraries(kalk
KF5::ConfigCore
KF5::I18n
KF5::CoreAddons
kalklib
knumber
)
target_include_directories
(
kalk PRIVATE
${
CMAKE_CURRENT_SOURCE_DIR
}
/mathengine
)
target_include_directories
(
kalk
lib
PRIVATE
${
CMAKE_CURRENT_SOURCE_DIR
}
/mathengine
)
install
(
TARGETS kalk
${
KF5_INSTALL_TARGETS_DEFAULT_ARGS
}
)
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