tests: add optional GoogleTest-based smoke-tests and CMake support (BUILD_GTEST_SMOKE)
This commit is contained in:
1 parent
f4d1602d87
commit
b44bb09891
4 files changed
+82
-3
No files matched your search
@@ -6,29 +6,79 @@
|
||||
|
||||
# Option to force-building smoke-tests even when real test targets exist.
|
||||
option(BUILD_SMOKE_TESTS "Build smoke-tests even if real test executables are present" OFF)
|
||||
option(BUILD_GTEST_SMOKE "Build GoogleTest-based smoke-tests for core logic" OFF)
|
||||
|
||||
# Try to find GoogleTest if requested
|
||||
if(BUILD_GTEST_SMOKE)
|
||||
find_package(GTest QUIET)
|
||||
if(NOT GTest_FOUND)
|
||||
message(STATUS "GoogleTest not found via find_package; will attempt to use FetchContent fallback if enabled later.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
include(CTest)
|
||||
|
||||
# Generic data tests smoke
|
||||
# Generic data tests smoke (QtTest)
|
||||
if(BUILD_SMOKE_TESTS OR NOT TARGET ddsGenericDataTests)
|
||||
add_executable(ddsGenericDataTests_smoke ddsGenericDataTests_smoke.cpp)
|
||||
target_link_libraries(ddsGenericDataTests_smoke PRIVATE Qt5::Core Qt5::Test)
|
||||
add_test(NAME ddsGenericDataTests COMMAND $<TARGET_FILE:ddsGenericDataTests_smoke>)
|
||||
endif()
|
||||
|
||||
# Data topic tests smoke
|
||||
# Data topic tests smoke (QtTest)
|
||||
if(BUILD_SMOKE_TESTS OR NOT TARGET ddsDataTopicTests)
|
||||
add_executable(ddsDataTopicTests_smoke ddsDataTopicTests_smoke.cpp)
|
||||
target_link_libraries(ddsDataTopicTests_smoke PRIVATE Qt5::Core Qt5::Test)
|
||||
add_test(NAME ddsDataTopicTests COMMAND $<TARGET_FILE:ddsDataTopicTests_smoke>)
|
||||
endif()
|
||||
|
||||
# Function topic tests smoke
|
||||
# Function topic tests smoke (QtTest)
|
||||
if(BUILD_SMOKE_TESTS OR NOT TARGET ddsFunctionTopicTests)
|
||||
add_executable(ddsFunctionTopicTests_smoke ddsFunctionTopicTests_smoke.cpp)
|
||||
target_link_libraries(ddsFunctionTopicTests_smoke PRIVATE Qt5::Core Qt5::Test)
|
||||
add_test(NAME ddsFunctionTopicTests COMMAND $<TARGET_FILE:ddsFunctionTopicTests_smoke>)
|
||||
endif()
|
||||
|
||||
# GoogleTest-based smoke-tests for core logic (optional)
|
||||
if(BUILD_GTEST_SMOKE)
|
||||
if(NOT GTest_FOUND)
|
||||
# FetchContent fallback if GTest not found on system
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz
|
||||
)
|
||||
FetchContent_GetProperties(googletest)
|
||||
if(NOT googletest_POPULATED)
|
||||
FetchContent_Populate(googletest)
|
||||
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(TARGET GTest::gtest_main OR TARGET gtest_main)
|
||||
# Generic data tests gtest
|
||||
if(NOT TARGET ddsGenericDataTests)
|
||||
add_executable(ddsGenericDataTests_gtest ddsGenericDataTests_gtest.cpp)
|
||||
target_link_libraries(ddsGenericDataTests_gtest PRIVATE GTest::gtest_main)
|
||||
add_test(NAME ddsGenericDataTests_gtest COMMAND $<TARGET_FILE:ddsGenericDataTests_gtest>)
|
||||
endif()
|
||||
|
||||
if(NOT TARGET ddsDataTopicTests)
|
||||
add_executable(ddsDataTopicTests_gtest ddsDataTopicTests_gtest.cpp)
|
||||
target_link_libraries(ddsDataTopicTests_gtest PRIVATE GTest::gtest_main)
|
||||
add_test(NAME ddsDataTopicTests_gtest COMMAND $<TARGET_FILE:ddsDataTopicTests_gtest>)
|
||||
endif()
|
||||
|
||||
if(NOT TARGET ddsFunctionTopicTests)
|
||||
add_executable(ddsFunctionTopicTests_gtest ddsFunctionTopicTests_gtest.cpp)
|
||||
target_link_libraries(ddsFunctionTopicTests_gtest PRIVATE GTest::gtest_main)
|
||||
add_test(NAME ddsFunctionTopicTests_gtest COMMAND $<TARGET_FILE:ddsFunctionTopicTests_gtest>)
|
||||
endif()
|
||||
|
||||
else()
|
||||
message(WARNING "GTest targets not available even after fallback; skipping GTest smoke-tests.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endif()
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(DataTopicSmokeGTest, Format) {
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "%d-%s", 42, "abc");
|
||||
EXPECT_STREQ(buf, "42-abc");
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <map>
|
||||
|
||||
TEST(FunctionTopicSmokeGTest, Containers) {
|
||||
std::map<std::string,int> m;
|
||||
m["one"] = 1;
|
||||
m["two"] = 2;
|
||||
EXPECT_EQ(m["two"], 2);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(GenericSmokeGTest, BasicStringOps) {
|
||||
std::string s = "MiXeD";
|
||||
for (auto &c : s) c = (char)std::tolower(c);
|
||||
EXPECT_EQ(s, "mixed");
|
||||
}
|
||||
|
||||
TEST(GenericSmokeGTest, VariantLike) {
|
||||
// simulate basic core logic check
|
||||
int v = 42;
|
||||
EXPECT_EQ(v + 1, 43);
|
||||
}
|
||||
Reference in new issue
Block a user