diff --git a/src/backends/R/CMakeLists.txt b/src/backends/R/CMakeLists.txt index d4485615..5930d740 100644 --- a/src/backends/R/CMakeLists.txt +++ b/src/backends/R/CMakeLists.txt @@ -1,30 +1,41 @@ include_directories(${R_INCLUDEDIR}) LINK_DIRECTORIES(${R_SHAREDLIBDIR}) add_subdirectory(rserver) set( RBackend_SRCS rbackend.cpp rsession.cpp rexpression.cpp rextensions.cpp rcompletionobject.cpp rhighlighter.cpp rkeywords.cpp rsettingswidget.cpp rvariablemodel.cpp ) kconfig_add_kcfg_files(RBackend_SRCS rserver/settings.kcfgc) set(network_xml rserver/org.kde.Cantor.R.xml) QT5_ADD_DBUS_INTERFACE(RBackend_SRCS ${network_xml} rserver_interface ) ki18n_wrap_ui(RBackend_SRCS settings.ui) add_backend(rbackend ${RBackend_SRCS}) set_target_properties( cantor_rbackend PROPERTIES INSTALL_RPATH_USE_LINK_PATH false) target_link_libraries( cantor_rbackend ${R_USED_LIBS} KF5::SyntaxHighlighting) +if(BUILD_TESTING) + add_executable( testr testr.cpp) + add_test(testr testr) + ecm_mark_as_test(testr) + target_link_libraries( testr + Qt5::Test + cantorlibs + cantortest + ) +endif(BUILD_TESTING) + install( FILES cantor_r.knsrc DESTINATION ${KDE_INSTALL_CONFDIR} ) diff --git a/src/backends/R/testr.cpp b/src/backends/R/testr.cpp new file mode 100644 index 00000000..86612119 --- /dev/null +++ b/src/backends/R/testr.cpp @@ -0,0 +1,88 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + --- + Copyright (C) 2019 Sirgienko Nikita + */ + +#include "testr.h" + +#include "session.h" +#include "backend.h" +#include "expression.h" +#include "result.h" +#include "completionobject.h" +#include "defaultvariablemodel.h" + +#include + + +QString TestR::backendName() +{ + return QLatin1String("R"); +} + +void TestR::testVariablesCreatingFromCode() +{ + QAbstractItemModel* model = session()->variableModel(); + QVERIFY(model != nullptr); + + Cantor::Expression* e=evalExp(QLatin1String("a1 = 15; b1 = 'S'; d1 = c(1,2,3)")); + QVERIFY(e!=nullptr); + + while(session()->status() != Cantor::Session::Done) + waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status))); + + QCOMPARE(3, model->rowCount()); + + QCOMPARE(model->index(0,0).data().toString(), QLatin1String("a1")); + QCOMPARE(model->index(0,1).data().toString(), QLatin1String("15")); + + QCOMPARE(model->index(1,0).data().toString(), QLatin1String("b1")); + QCOMPARE(model->index(1,1).data().toString(), QLatin1String("S")); + + QCOMPARE(model->index(2,0).data().toString(), QLatin1String("d1")); + QCOMPARE(model->index(2,1).data().toString(), QLatin1String("1, 2, 3")); + + evalExp(QLatin1String("rm(a1,b1,d1)")); +} + +void TestR::testVariableCleanupAfterRestart() +{ + Cantor::DefaultVariableModel* model = static_cast(session()->variableModel()); + QVERIFY(model != nullptr); + + while(session()->status() != Cantor::Session::Done) + waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status))); + + QCOMPARE(static_cast(model)->rowCount(), 0); + + Cantor::Expression* e=evalExp(QLatin1String("h1 = 15; h2 = 'S';")); + QVERIFY(e!=nullptr); + + while(session()->status() != Cantor::Session::Done) + waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status))); + + QCOMPARE(static_cast(model)->rowCount(), 2); + + session()->logout(); + session()->login(); + + QCOMPARE(static_cast(model)->rowCount(), 0); +} + +QTEST_MAIN( TestR ) + diff --git a/src/backends/R/testr.h b/src/backends/R/testr.h new file mode 100644 index 00000000..9c09e175 --- /dev/null +++ b/src/backends/R/testr.h @@ -0,0 +1,39 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + --- + Copyright (C) 2019 Sirgienko Nikita + */ + +#ifndef _TESTR_H +#define _TESTR_H + +#include "backendtest.h" + +class TestR : public BackendTest +{ + Q_OBJECT + +private Q_SLOTS: + //tests variable model + void testVariablesCreatingFromCode(); + void testVariableCleanupAfterRestart(); + +private: + QString backendName() override; +}; + +#endif /* _TESTR_H */