From 8fef03dc1e1f0b895c0eab5eece6325c11353261 Mon Sep 17 00:00:00 2001 From: EndrII Date: Sat, 14 Oct 2023 12:05:14 +0200 Subject: [PATCH] added new testcore lib for testing private sections of the modules --- .gitignore | 1 + CMakeLists.txt | 4 +++ src/RENAME_ME/CMakeLists.txt | 6 +++- src/RENAME_ME/src/public/RENAME_ME/global.h | 2 +- src/example/deploy/RENAME_ME.json | 6 ++-- src/testcore/CMakeLists.txt | 32 +++++++++++++++++++ src/testcore/testcore/global.h | 20 ++++++++++++ src/testcore/testcore/global.h.in | 20 ++++++++++++ src/testcore/testcore/itest.h | 16 ++++++++++ .../testcore/testcore}/testutils.cpp | 4 ++- .../testcore/testcore}/testutils.h | 7 ++-- tests/tstMain.cpp | 4 +-- tests/units/exampletest.h | 7 ++-- tests/units/test.cpp | 9 ------ tests/units/test.h | 20 ------------ 15 files changed, 116 insertions(+), 42 deletions(-) create mode 100644 src/testcore/CMakeLists.txt create mode 100644 src/testcore/testcore/global.h create mode 100644 src/testcore/testcore/global.h.in create mode 100644 src/testcore/testcore/itest.h rename {tests/units => src/testcore/testcore}/testutils.cpp (98%) rename {tests/units => src/testcore/testcore}/testutils.h (91%) delete mode 100644 tests/units/test.cpp delete mode 100644 tests/units/test.h diff --git a/.gitignore b/.gitignore index ee7aa1b..a121ef2 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,4 @@ AndroidManifest.xml src/Example/Deploy/RENAME_ME.json src/Library/src/public/RENAME_ME/global.h doxygen.conf +Distro diff --git a/CMakeLists.txt b/CMakeLists.txt index be0dfe1..56c1018 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,10 @@ make_directory(Distro) initAll() +if (RENAME_ME_TESTS) + add_subdirectory(src/testcore) +endif() + add_subdirectory(src/RENAME_ME) if (DEFINED RENAME_ME_EXAMPLE) diff --git a/src/RENAME_ME/CMakeLists.txt b/src/RENAME_ME/CMakeLists.txt index 214135e..e2a0894 100644 --- a/src/RENAME_ME/CMakeLists.txt +++ b/src/RENAME_ME/CMakeLists.txt @@ -25,7 +25,11 @@ set(PRIVATE_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/private") add_library(${CURRENT_PROJECT} ${SOURCE_CPP} ${SOURCE_QRC}) -target_link_libraries(${CURRENT_PROJECT} PUBLIC Qt${QT_VERSION_MAJOR}::Core ) +if (RENAME_ME_TESTS) + target_link_libraries(${CURRENT_PROJECT} PUBLIC ${PROJECT_NAME}testcore) +else() + target_link_libraries(${CURRENT_PROJECT} PUBLIC Qt${QT_VERSION_MAJOR}::Core ) +endif() target_include_directories(${CURRENT_PROJECT} PUBLIC ${PUBLIC_INCUDE_DIR}) target_include_directories(${CURRENT_PROJECT} PRIVATE ${PRIVATE_INCUDE_DIR}) diff --git a/src/RENAME_ME/src/public/RENAME_ME/global.h b/src/RENAME_ME/src/public/RENAME_ME/global.h index c99334a..0771b9a 100644 --- a/src/RENAME_ME/src/public/RENAME_ME/global.h +++ b/src/RENAME_ME/src/public/RENAME_ME/global.h @@ -10,7 +10,7 @@ #include -#define RENAME_ME_VERSION "0.88.6523639" +#define RENAME_ME_VERSION "0.89.ae3db6a" #if defined(RENAME_ME_LIBRARY) # define RENAME_ME_EXPORT Q_DECL_EXPORT diff --git a/src/example/deploy/RENAME_ME.json b/src/example/deploy/RENAME_ME.json index a0e8bac..1e18b18 100644 --- a/src/example/deploy/RENAME_ME.json +++ b/src/example/deploy/RENAME_ME.json @@ -1,7 +1,7 @@ { "bin": [ - "src/build/Debug/RENAME_MEEaxample", - "src/build/Debug/RENAME_MEEaxample.exe" + "src/example/RENAME_ME_example", + "src/example/RENAME_ME_example.exe" ], "clear": true, "binPrefix": "/media/D/builds/build-CMakeProject-Desktop_Qt_6_5_2_GCC_64bit-Debug", @@ -21,7 +21,7 @@ ], "extraLib": "crypto", "targetDir": "/media/D/builds/CMakeProject/Distro", - "deployVersion": "0.87.648a8dc", + "deployVersion": "0.89.ae3db6a" } diff --git a/src/testcore/CMakeLists.txt b/src/testcore/CMakeLists.txt new file mode 100644 index 0000000..1a23423 --- /dev/null +++ b/src/testcore/CMakeLists.txt @@ -0,0 +1,32 @@ +# +# Copyright (C) 2020-2023 QuasarApp. +# Distributed under the GPLv3 software license, see the accompanying +# Everyone is permitted to copy and distribute verbatim copies +# of this license document, but changing it is not allowed. +# + +cmake_minimum_required(VERSION 3.19) + +set(CURRENT_PROJECT "${PROJECT_NAME}testcore") +add_definitions(-DTEST_CORE_LIBRARY) + + +file(GLOB_RECURSE SOURCE_CPP + "*.cpp" + "*.h" +) + +file(GLOB_RECURSE SOURCE_QRC + "*.qrc" +) + +set(PUBLIC_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + +add_library(${CURRENT_PROJECT} ${SOURCE_CPP} ${SOURCE_QRC}) + +target_link_libraries(${CURRENT_PROJECT} PUBLIC Qt${QT_VERSION_MAJOR}::Core ) + +target_include_directories(${CURRENT_PROJECT} PUBLIC ${PUBLIC_INCUDE_DIR}) +target_include_directories(${CURRENT_PROJECT} PRIVATE ${PRIVATE_INCUDE_DIR}) + +configure_file_in(${CURRENT_PROJECT} "${CMAKE_CURRENT_SOURCE_DIR}/testcore/global.h") diff --git a/src/testcore/testcore/global.h b/src/testcore/testcore/global.h new file mode 100644 index 0000000..d2e43c1 --- /dev/null +++ b/src/testcore/testcore/global.h @@ -0,0 +1,20 @@ +//# +//# Copyright (C) 2018-2023 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#ifndef TEST_CORE_GLOBAL_H +#define TEST_CORE_GLOBAL_H + +#include + +#if defined(TEST_CORE_LIBRARY) +# define TEST_CORE_EXPORT Q_DECL_EXPORT +#else +# define TEST_CORE_EXPORT Q_DECL_IMPORT +#endif + +#endif //TEST_CORE_GLOBAL_H + diff --git a/src/testcore/testcore/global.h.in b/src/testcore/testcore/global.h.in new file mode 100644 index 0000000..d2e43c1 --- /dev/null +++ b/src/testcore/testcore/global.h.in @@ -0,0 +1,20 @@ +//# +//# Copyright (C) 2018-2023 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#ifndef TEST_CORE_GLOBAL_H +#define TEST_CORE_GLOBAL_H + +#include + +#if defined(TEST_CORE_LIBRARY) +# define TEST_CORE_EXPORT Q_DECL_EXPORT +#else +# define TEST_CORE_EXPORT Q_DECL_IMPORT +#endif + +#endif //TEST_CORE_GLOBAL_H + diff --git a/src/testcore/testcore/itest.h b/src/testcore/testcore/itest.h new file mode 100644 index 0000000..f756a08 --- /dev/null +++ b/src/testcore/testcore/itest.h @@ -0,0 +1,16 @@ +#ifndef ITEST_H +#define ITEST_H + +#include "testcore/global.h" + +namespace testcore { + +class TEST_CORE_EXPORT ITest { +public: + ITest() = default; + virtual ~ITest() = default; + + virtual void test() = 0; +}; +} +#endif // ITEST_H diff --git a/tests/units/testutils.cpp b/src/testcore/testcore/testutils.cpp similarity index 98% rename from tests/units/testutils.cpp rename to src/testcore/testcore/testutils.cpp index 844fdc0..a605032 100644 --- a/tests/units/testutils.cpp +++ b/src/testcore/testcore/testutils.cpp @@ -12,6 +12,8 @@ #include #include +namespace testcore { + bool TestUtils::funcPrivateConnect(const std::function &requestFunc, const std::function &checkFunc, const std::function &connectFunction) const { @@ -50,4 +52,4 @@ bool TestUtils::wait(const std::function &forWait, int msec) const { QCoreApplication::processEvents(); return forWait(); } - +} diff --git a/tests/units/testutils.h b/src/testcore/testcore/testutils.h similarity index 91% rename from tests/units/testutils.h rename to src/testcore/testcore/testutils.h index 0b1a1fd..b48d055 100644 --- a/tests/units/testutils.h +++ b/src/testcore/testcore/testutils.h @@ -11,8 +11,11 @@ #include "functional" #include +#include "testcore/global.h" -class TestUtils +namespace testcore { + +class TEST_CORE_EXPORT TestUtils { public: TestUtils(); @@ -28,5 +31,5 @@ public: const std::function &checkFunc) const; }; - +} #endif // TESTUTILS_H diff --git a/tests/tstMain.cpp b/tests/tstMain.cpp index 3beb3ee..593d274 100644 --- a/tests/tstMain.cpp +++ b/tests/tstMain.cpp @@ -41,7 +41,7 @@ private: * @brief initTest This method prepare @a test for run in the QApplication loop. * @param test are input test case class. */ - void initTest(Test* test); + void initTest(testcore::ITest* test); QCoreApplication *_app = nullptr; }; @@ -71,7 +71,7 @@ tstMain::~tstMain() { delete _app; } -void tstMain::initTest(Test *test) { +void tstMain::initTest(testcore::ITest *test) { QTimer::singleShot(0, this, [this, test]() { test->test(); delete test; diff --git a/tests/units/exampletest.h b/tests/units/exampletest.h index d0efc53..ea2bc2e 100644 --- a/tests/units/exampletest.h +++ b/tests/units/exampletest.h @@ -8,12 +8,13 @@ #ifndef EXAMPLE_TEST_H #define EXAMPLE_TEST_H -#include "test.h" -#include "testutils.h" + +#include +#include "testcore/testutils.h" #include -class ExampleTest: public Test, protected TestUtils +class ExampleTest: public testcore::ITest, protected testcore::TestUtils { public: ExampleTest(); diff --git a/tests/units/test.cpp b/tests/units/test.cpp deleted file mode 100644 index ea1c3c3..0000000 --- a/tests/units/test.cpp +++ /dev/null @@ -1,9 +0,0 @@ -//# -//# Copyright (C) 2020-2023 QuasarApp. -//# Distributed under the GPLv3 software license, see the accompanying -//# Everyone is permitted to copy and distribute verbatim copies -//# of this license document, but changing it is not allowed. -//# - - -#include "test.h" diff --git a/tests/units/test.h b/tests/units/test.h deleted file mode 100644 index 0289d7a..0000000 --- a/tests/units/test.h +++ /dev/null @@ -1,20 +0,0 @@ -//# -//# Copyright (C) 2020-2023 QuasarApp. -//# Distributed under the GPLv3 software license, see the accompanying -//# Everyone is permitted to copy and distribute verbatim copies -//# of this license document, but changing it is not allowed. -//# - - -#ifndef TEST_H -#define TEST_H - -class Test -{ -public: - Test() = default; - virtual ~Test() = default; - virtual void test() = 0; -}; - -#endif // TEST_H