diff --git a/autotests/unittests/CMakeLists.txt b/autotests/unittests/CMakeLists.txt index fa6190e..bddab00 100644 --- a/autotests/unittests/CMakeLists.txt +++ b/autotests/unittests/CMakeLists.txt @@ -1,120 +1,136 @@ ### # Copyright 2013-2019 Andreas Cord-Landwehr # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ### include_directories( ../../src/ ../../ ../mocks/ ${CMAKE_CURRENT_BINARY_DIR} ) # copy test data file(COPY ../testdata/courses/de.xml DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data/courses/de/) # copy test files file(COPY ../testdata/courses/fr.xml DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data/courses/fr/) # copy test files file(COPY ../testdata/contributorrepository/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data/contributorrepository/) # copy test files set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) # repository tests set(TestResourceRepository_SRCS resourcerepository/test_resourcerepository.cpp) qt5_add_resources(TestResourceRepository_SRCS ../../data/languages.qrc) add_executable(test_resourcerepository ${TestResourceRepository_SRCS}) target_link_libraries(test_resourcerepository artikulatecore Qt5::Test ) add_test(NAME test_resourcerepository COMMAND test_resourcerepository) ecm_mark_as_test(test_resourcerepository) # training session tests set(TestTrainingSession_SRCS trainingsession/test_trainingsession.cpp) add_executable(test_trainingsession ${TestTrainingSession_SRCS}) target_link_libraries(test_trainingsession artikulatecore Qt5::Test ) add_test(NAME test_trainingsession COMMAND test_trainingsession) ecm_mark_as_test(test_trainingsession) # editor session tests set(TestEditorSession_SRCS editorsession/test_editorsession.cpp ../mocks/editablerepositorystub.cpp ) add_executable(test_editorsession ${TestEditorSession_SRCS}) target_link_libraries(test_editorsession artikulatecore Qt5::Test ) add_test(NAME test_editorsession COMMAND test_editorsession) ecm_mark_as_test(test_editorsession) # test course resource class set(TestCourseResource_SRCS courseresource/test_courseresource.cpp ../mocks/resourcerepositorystub.cpp ) qt5_add_resources(TestCourseResource_SRCS ../../data/languages.qrc) add_executable(test_courseresource ${TestCourseResource_SRCS} ) target_link_libraries(test_courseresource artikulatecore Qt5::Test ) add_test(NAME test_courseresource COMMAND test_courseresource) ecm_mark_as_test(test_courseresource) # test skeleton resource class set(TestSkeletonResource_SRCS skeletonresource/test_skeletonresource.cpp ../mocks/resourcerepositorystub.cpp ) qt5_add_resources(TestSkeletonResource_SRCS ../../data/languages.qrc) add_executable(test_skeletonresource ${TestSkeletonResource_SRCS} ) target_link_libraries(test_skeletonresource artikulatecore Qt5::Test ) add_test(NAME test_skeletonresource COMMAND test_skeletonresource) ecm_mark_as_test(test_skeletonresource) # test editable course resource class set(TestEditableCourseResource_SRCS editablecourseresource/test_editablecourseresource.cpp ../mocks/resourcerepositorystub.cpp ) qt5_add_resources(TestEditableCourseResource_SRCS ../../data/languages.qrc) qt5_add_resources(TestEditableCourseResource_SRCS ../testdata/testdata.qrc) add_executable(test_editablecourseresource ${TestEditableCourseResource_SRCS} ) target_link_libraries(test_editablecourseresource artikulatecore Qt5::Test ) add_test(NAME test_editablecourseresource COMMAND test_editablecourseresource) ecm_mark_as_test(test_editablecourseresource) + + +# test course model class +set(TestCourseModel_SRCS + coursemodel/test_coursemodel.cpp + ../mocks/resourcerepositorystub.cpp +) +qt5_add_resources(TestCourseModel_SRCS ../../data/languages.qrc) +qt5_add_resources(TestCourseModel_SRCS ../testdata/testdata.qrc) +add_executable(test_coursemodel ${TestCourseModel_SRCS} ) +target_link_libraries(test_coursemodel + artikulatecore + Qt5::Test +) +add_test(NAME test_coursemodel COMMAND test_coursemodel) +ecm_mark_as_test(test_coursemodel) diff --git a/autotests/unittests/coursemodel/test_coursemodel.cpp b/autotests/unittests/coursemodel/test_coursemodel.cpp new file mode 100644 index 0000000..a321f2b --- /dev/null +++ b/autotests/unittests/coursemodel/test_coursemodel.cpp @@ -0,0 +1,96 @@ +/* + * Copyright 2019 Andreas Cord-Landwehr + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#include "test_coursemodel.h" +#include "src/core/icourse.h" +#include +#include + +// assumption: during a training session the units and phrases of a course do not change +// any change of such a course shall result in a reload of a training session + +class CourseStub : public ICourse +{ +public: + CourseStub(std::shared_ptr language, QVector> units) + : m_language(language) + , m_units(units) + { + } + ~CourseStub() override; + + void setSelf(std::shared_ptr self) override + { + m_self = self; + } + + QString id() const override + { + return "courseid"; + } + QString foreignId() const override + { + return "foreigncourseid"; + } + QString title() const override + { + return "title"; + } + QString i18nTitle() const override + { + return "i18n title"; + } + QString description() const override + { + return "description of the course"; + } + std::shared_ptr language() const override + { + return m_language; + } + QVector> units() override + { + return m_units; + } + QUrl file() const override + { + return QUrl(); + } + +private: + std::weak_ptr m_self; + std::shared_ptr m_language; + QVector> m_units; +}; + +// define one virtual method out of line to pin CourseStub to this translation unit +CourseStub::~CourseStub() = default; + +void TestCourseModel::init() +{ + // TODO initialization of test case +} + +void TestCourseModel::cleanup() +{ + // TODO cleanup after test run +} + +QTEST_GUILESS_MAIN(TestCourseModel) diff --git a/autotests/unittests/coursemodel/test_coursemodel.h b/autotests/unittests/coursemodel/test_coursemodel.h new file mode 100644 index 0000000..93b2d0a --- /dev/null +++ b/autotests/unittests/coursemodel/test_coursemodel.h @@ -0,0 +1,45 @@ +/* + * Copyright 2019 Andreas Cord-Landwehr + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#ifndef TEST_COURSEMODEL_H +#define TEST_COURSEMODEL_H + +#include + +class TestCourseModel : public QObject +{ + Q_OBJECT + +public: + TestCourseModel() = default; + +private Q_SLOTS: + /** + * Called before every test case. + */ + void init(); + + /** + * Called after every test case. + */ + void cleanup(); +}; + +#endif