Commit e3bf3c99 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Add some autotests

parent 67a44694
......@@ -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/)
......
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
)
#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"
......@@ -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(kalklib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/mathengine)
install(TARGETS kalk ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})
Markdown is supported
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