diff --git a/src/backends/scilab/CMakeLists.txt b/src/backends/scilab/CMakeLists.txt --- a/src/backends/scilab/CMakeLists.txt +++ b/src/backends/scilab/CMakeLists.txt @@ -20,4 +20,14 @@ KF5::SyntaxHighlighting ) +if(BUILD_TESTING) + add_executable(testscilab testscilab.cpp) + add_test(NAME testscilab COMMAND testscilab) + target_link_libraries(testscilab + Qt5::Test + cantorlibs + cantortest + ) +endif(BUILD_TESTING) + install(FILES cantor_scilab.knsrc DESTINATION ${KDE_INSTALL_CONFDIR}) diff --git a/src/backends/scilab/testscilab.h b/src/backends/scilab/testscilab.h new file mode 100644 --- /dev/null +++ b/src/backends/scilab/testscilab.h @@ -0,0 +1,42 @@ +/* + 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) 2020 Shubham + */ + +#ifndef TESTSCILAB_H +#define TESTSCILAB_H + +#include "backendtest.h" + +// This class tests some of the basic functions of the Scilab backend + +class TestScilab : public BackendTest +{ + Q_OBJECT + +private Q_SLOTS: + void testSimpleCommand(); + void testVariableDefinition(); + void testInvalidSyntax(); + void testLoginLogout(); + +private: + QString backendName() override; +}; + +#endif // TESTSCILAB_H diff --git a/src/backends/scilab/testscilab.cpp b/src/backends/scilab/testscilab.cpp new file mode 100644 --- /dev/null +++ b/src/backends/scilab/testscilab.cpp @@ -0,0 +1,75 @@ +/* + 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) 2020 Shubham + */ + +#include "backend.h" +#include "expression.h" +#include "result.h" +#include "scilabexpression.h" +#include "session.h" +#include "testscilab.h" + +#include + +QString TestScilab::backendName() +{ + return QLatin1String("scilab"); +} + +void TestScilab::testSimpleCommand() +{ + Cantor::Expression* e=evalExp( QLatin1String("printf(\"Testing\")\n") ); + + QVERIFY( e!=nullptr ); + QVERIFY( e->result()!=nullptr ); + + QCOMPARE( cleanOutput( e->result()->data().toString() ), QLatin1String("Testing") ); +} + +void TestScilab::testVariableDefinition() +{ + Cantor::Expression* e=evalExp( QLatin1String("test = 100 disp(test)") ); + + QVERIFY( e!=nullptr ); + QVERIFY( e->result()!=nullptr ); + + QCOMPARE( cleanOutput(e->result()->data().toString()), QLatin1String("100") ); +} + +void TestScilab::testInvalidSyntax() +{ + Cantor::Expression* e=evalExp( QLatin1String("^invalidvar = 100") ); // invalid variable name, since it starts with ^ + + QVERIFY( e!=nullptr ); + QCOMPARE( e->status(), Cantor::Expression::Error ); +} + +void TestScilab::testLoginLogout() +{ + // Logout from session twice and all must works fine + session()->logout(); + session()->logout(); + + // Login in session twice and all must works fine + session()->login(); + session()->login(); +} + +QTEST_MAIN( TestScilab ) +