diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -457,5 +457,16 @@ add_subdirectory(src) +enable_testing() + +# Tell CMake to run moc when necessary: +set(CMAKE_AUTOMOC ON) + +# As moc files are generated in the binary dir, tell CMake +# to always look for includes there: +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +add_subdirectory(tests) + add_custom_target(binaries) add_dependencies(binaries ${GCOMPRIS_EXECUTABLE_NAME} rcc_core rcc_menu rcc_activities all_activities) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -76,6 +76,20 @@ qt5_use_modules(${GCOMPRIS_EXECUTABLE_NAME} Qml Quick Gui Multimedia Network XmlPatterns Svg Xml Sensors Core) endif() + +add_library(GCompris_core SHARED ${gcompris_SRCS} ${gcompris_MOC} ${gcompris_RES}) +target_link_libraries(GCompris_core + Qt5::Qml + Qt5::Quick + Qt5::Gui + Qt5::Multimedia + Qt5::Core + Qt5::Svg + Qt5::Xml + Qt5::XmlPatterns + Qt5::Sensors +) + GCOMPRIS_ADD_RCC(core *.qml *.js resource/*.${COMPRESSED_AUDIO} resource/*.gif resource/*.png resource/*.svg resource/bonus/* resource/sounds/* resource/fonts/* qmldir COPYING) # Installation diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(core) diff --git a/tests/core/ActivityInfoTest.cpp b/tests/core/ActivityInfoTest.cpp new file mode 100644 --- /dev/null +++ b/tests/core/ActivityInfoTest.cpp @@ -0,0 +1,105 @@ +/* GCompris - ActivityInfoTest.cpp + * + * Copyright (C) 2018 Himanshu Vishwakarma + * + * Authors: + * Himanshu Vishwakarma + * + * 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 3 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, see . + */ + +#include +#include + +#include "src/core/ActivityInfo.h" + +#define ACTIVITY_INFO_TEST_ATTRIBUTE(attributeName, accessorName, attributeType) \ +{ \ + QFETCH(attributeType, attributeName); \ + QSignalSpy spy(&activityinfo, &ActivityInfo::attributeName ## Changed); \ + QVERIFY(spy.count() == 0); \ + activityinfo.set ## accessorName(attributeName); \ + QVERIFY(spy.count() == 1); \ + QCOMPARE(activityinfo.attributeName(), attributeName); \ +} + +class CoreActivityInfoTest : public QObject +{ + Q_OBJECT +private slots: + void ActivityInfoTest(); + void ActivityInfoTest_data(); +}; + +void CoreActivityInfoTest::ActivityInfoTest_data() +{ + QTest::addColumn("name"); + QTest::addColumn("section"); + QTest::addColumn("difficulty"); + QTest::addColumn("icon"); + QTest::addColumn("author"); + QTest::addColumn("demo"); + QTest::addColumn("title"); + QTest::addColumn("description"); + QTest::addColumn("goal"); + QTest::addColumn("prerequisite"); + QTest::addColumn("manual"); + QTest::addColumn("credit"); + QTest::addColumn("favorite"); + QTest::addColumn("enabled"); + QTest::addColumn("createdInVersion"); + + QTest::newRow("ActivityInfo") << "Name" << "section" << (unsigned int)3 << "icon" << "author" << true << "title" << "description" << "goal" << "prerequisite" << "manual" << "credit" << false << false << 2 ; + QTest::newRow("UnknownInfo") << "Unknown" << "Unknown" << (unsigned int)5 << "Unknown" << "Unknown" << false << "Unknown" << "Unknown" << "Unknown" << "Unknown" << "Unknown" << "Unknown" << true << true << 10 ; + QTest::newRow("Empty") << "" << "" << (unsigned int)0 << "" << "" << false << "" << "" << "" << "" << "" << "" << true << true << 0 ; +} + +void CoreActivityInfoTest::ActivityInfoTest() +{ + ActivityInfo activityinfo; + + QCOMPARE(activityinfo.name(), QStringLiteral("")); + QCOMPARE(activityinfo.section(), QStringLiteral("")); + QCOMPARE(activityinfo.icon(), QStringLiteral("")); + QCOMPARE(activityinfo.author(), QStringLiteral("")); + QVERIFY(activityinfo.demo()); + QCOMPARE(activityinfo.title(), QStringLiteral("")); + QCOMPARE(activityinfo.description(), QStringLiteral("")); + QCOMPARE(activityinfo.goal(), QStringLiteral("")); + QCOMPARE(activityinfo.prerequisite(), QStringLiteral("")); + QCOMPARE(activityinfo.manual(), QStringLiteral("")); + QCOMPARE(activityinfo.credit(), QStringLiteral("")); + QVERIFY(!activityinfo.favorite()); + QVERIFY(activityinfo.enabled()); + QCOMPARE(activityinfo.createdInVersion(), 0); + + ACTIVITY_INFO_TEST_ATTRIBUTE(name, Name, QString); + ACTIVITY_INFO_TEST_ATTRIBUTE(section, Section, QString); + ACTIVITY_INFO_TEST_ATTRIBUTE(difficulty, Difficulty, unsigned int); + ACTIVITY_INFO_TEST_ATTRIBUTE(icon, Icon, QString); + ACTIVITY_INFO_TEST_ATTRIBUTE(author, Author, QString); + ACTIVITY_INFO_TEST_ATTRIBUTE(demo, Demo, bool); + ACTIVITY_INFO_TEST_ATTRIBUTE(title, Title, QString); + ACTIVITY_INFO_TEST_ATTRIBUTE(description, Description, QString); + ACTIVITY_INFO_TEST_ATTRIBUTE(goal, Goal, QString); + ACTIVITY_INFO_TEST_ATTRIBUTE(prerequisite, Prerequisite, QString); + ACTIVITY_INFO_TEST_ATTRIBUTE(manual, Manual, QString); + ACTIVITY_INFO_TEST_ATTRIBUTE(credit, Credit, QString); + ACTIVITY_INFO_TEST_ATTRIBUTE(favorite, Favorite, bool); + ACTIVITY_INFO_TEST_ATTRIBUTE(enabled, Enabled, bool); + ACTIVITY_INFO_TEST_ATTRIBUTE(createdInVersion, CreatedInVersion, int); +} + +QTEST_MAIN(CoreActivityInfoTest) +#include "ActivityInfoTest.moc" diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/tests/core/CMakeLists.txt @@ -0,0 +1,13 @@ +find_package(Qt5 REQUIRED COMPONENTS Test) + +include_directories(${CMAKE_SOURCE_DIR}) + +set(CORE_TEST_LIBRARIES + GCompris_core + Qt5::Core + Qt5::Test +) + +add_executable( CoreActivityInfoTest ActivityInfoTest.cpp ) +target_link_libraries( CoreActivityInfoTest ${CORE_TEST_LIBRARIES} ) +add_test( NAME CoreActivityInfoTest COMMAND $ )