From 25ea18e479d309952d746dfe6e7824681ebc7c52 Mon Sep 17 00:00:00 2001 From: JP Swinski Date: Mon, 22 Apr 2024 15:14:29 +0000 Subject: [PATCH] reworked unittesting defines to support unit tests in multiple plugins as well as the legacy unit tests --- CMakeLists.txt | 4 +++ packages/core/core.cpp | 7 +++++ packages/geo/CMakeLists.txt | 4 ++- .../geo}/UT_RasterSubset.cpp | 2 +- .../plugin => packages/geo}/UT_RasterSubset.h | 0 packages/geo/geo.cpp | 7 +++++ packages/legacy/CMakeLists.txt | 28 +++++++++---------- packages/legacy/legacy.cpp | 3 +- packages/legacy/legacy.h | 2 ++ plugins/icesat2/CMakeLists.txt | 1 - plugins/icesat2/plugin/icesat2.cpp | 8 +----- plugins/icesat2/plugin/icesat2.h | 2 +- plugins/icesat2/selftests/plugin_unittest.lua | 2 +- plugins/pgc/CMakeLists.txt | 2 -- plugins/pgc/plugin/pgc.cpp | 10 ------- plugins/pgc/selftests/plugin_unittest.lua | 6 ++-- 16 files changed, 46 insertions(+), 42 deletions(-) rename {plugins/pgc/plugin => packages/geo}/UT_RasterSubset.cpp (99%) rename {plugins/pgc/plugin => packages/geo}/UT_RasterSubset.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0207fd66..ba291c3ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,10 @@ endif () set_property(GLOBAL APPEND PROPERTY platform "#define LIBID \"${TGTVER}\"\n") set_property(GLOBAL APPEND PROPERTY platform "#define CONFDIR \"${RUNTIMEDIR}\"\n") +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set_property(GLOBAL APPEND PROPERTY platform "#define __unittesting__\n") +endif() + if(${ENABLE_TRACING}) message (STATUS "Enabling trace points") set_property(GLOBAL APPEND PROPERTY platform "#define __tracing__\n") diff --git a/packages/core/core.cpp b/packages/core/core.cpp index 5ec7a742b..454f54e15 100644 --- a/packages/core/core.cpp +++ b/packages/core/core.cpp @@ -151,6 +151,13 @@ static int core_open (lua_State *L) LuaEngine::setAttrInt (L, "RTE_EMPTY_SUBSET", RTE_EMPTY_SUBSET); LuaEngine::setAttrInt (L, "RTE_SIMPLIFY", RTE_SIMPLIFY); + #ifdef __unittesting__ + LuaEngine::setAttrBool(L, "UNITTEST", true); + #else + LuaEngine::setAttrBool(L, "UNITTEST", false); + #endif + + return 1; } diff --git a/packages/geo/CMakeLists.txt b/packages/geo/CMakeLists.txt index 761e90ea8..11157a67c 100644 --- a/packages/geo/CMakeLists.txt +++ b/packages/geo/CMakeLists.txt @@ -35,7 +35,8 @@ if (GDAL_FOUND AND PROJ_FOUND AND TIFF_FOUND) ${CMAKE_CURRENT_LIST_DIR}/RasterSubset.cpp ${CMAKE_CURRENT_LIST_DIR}/GeoParms.cpp ${CMAKE_CURRENT_LIST_DIR}/GeoLib.cpp - ) + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_RasterSubset.cpp> + ) target_include_directories (slideruleLib PUBLIC @@ -57,6 +58,7 @@ if (GDAL_FOUND AND PROJ_FOUND AND TIFF_FOUND) ${CMAKE_CURRENT_LIST_DIR}/RasterSubset.h ${CMAKE_CURRENT_LIST_DIR}/GeoParms.h ${CMAKE_CURRENT_LIST_DIR}/GeoLib.h + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_RasterSubset.h> DESTINATION ${INCDIR} ) diff --git a/plugins/pgc/plugin/UT_RasterSubset.cpp b/packages/geo/UT_RasterSubset.cpp similarity index 99% rename from plugins/pgc/plugin/UT_RasterSubset.cpp rename to packages/geo/UT_RasterSubset.cpp index bad3eafec..a412c141a 100644 --- a/plugins/pgc/plugin/UT_RasterSubset.cpp +++ b/packages/geo/UT_RasterSubset.cpp @@ -34,8 +34,8 @@ ******************************************************************************/ #include "core.h" +#include "GdalRaster.h" #include "UT_RasterSubset.h" -#include "RemaDemMosaicRaster.h" /****************************************************************************** * STATIC DATA diff --git a/plugins/pgc/plugin/UT_RasterSubset.h b/packages/geo/UT_RasterSubset.h similarity index 100% rename from plugins/pgc/plugin/UT_RasterSubset.h rename to packages/geo/UT_RasterSubset.h diff --git a/packages/geo/geo.cpp b/packages/geo/geo.cpp index ca11acd8c..339375f89 100644 --- a/packages/geo/geo.cpp +++ b/packages/geo/geo.cpp @@ -35,6 +35,10 @@ #include "geo.h" +#ifdef __unittesting__ +#include "UT_RasterSubset.h" +#endif + #include #include #include @@ -244,6 +248,9 @@ int geo_open (lua_State* L) {"parms", GeoParms::luaCreate}, {"calcutm", GeoLib::luaCalcUTM}, {"tiff", GeoLib::TIFFImage::luaCreate}, +#ifdef __unittesting__ + {"ut_subset", UT_RasterSubset::luaCreate}, +#endif {NULL, NULL} }; diff --git a/packages/legacy/CMakeLists.txt b/packages/legacy/CMakeLists.txt index bde845c78..6e971bf7f 100644 --- a/packages/legacy/CMakeLists.txt +++ b/packages/legacy/CMakeLists.txt @@ -18,13 +18,13 @@ target_sources (slideruleLib ${CMAKE_CURRENT_LIST_DIR}/CosmosInterface.cpp ${CMAKE_CURRENT_LIST_DIR}/LuaInterpreter.cpp ${CMAKE_CURRENT_LIST_DIR}/LuaLibraryCmd.cpp - ${CMAKE_CURRENT_LIST_DIR}/UT_Dictionary.cpp - ${CMAKE_CURRENT_LIST_DIR}/UT_List.cpp - ${CMAKE_CURRENT_LIST_DIR}/UT_MsgQ.cpp - ${CMAKE_CURRENT_LIST_DIR}/UT_Ordering.cpp - ${CMAKE_CURRENT_LIST_DIR}/UT_Table.cpp - ${CMAKE_CURRENT_LIST_DIR}/UT_TimeLib.cpp - ${CMAKE_CURRENT_LIST_DIR}/UT_String.cpp + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_Dictionary.cpp> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_List.cpp> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_MsgQ.cpp> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_Ordering.cpp> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_Table.cpp> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_TimeLib.cpp> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_String.cpp> ) target_include_directories (slideruleLib @@ -50,13 +50,13 @@ install ( ${CMAKE_CURRENT_LIST_DIR}/LuaInterpreter.h ${CMAKE_CURRENT_LIST_DIR}/LuaLibraryCmd.h ${CMAKE_CURRENT_LIST_DIR}/StatisticRecord.h - ${CMAKE_CURRENT_LIST_DIR}/UT_Dictionary.h - ${CMAKE_CURRENT_LIST_DIR}/UT_List.h - ${CMAKE_CURRENT_LIST_DIR}/UT_MsgQ.h - ${CMAKE_CURRENT_LIST_DIR}/UT_Ordering.h - ${CMAKE_CURRENT_LIST_DIR}/UT_Table.h - ${CMAKE_CURRENT_LIST_DIR}/UT_TimeLib.h - ${CMAKE_CURRENT_LIST_DIR}/UT_String.h + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_Dictionary.h> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_List.h> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_MsgQ.h> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_Ordering.h> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_Table.h> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_TimeLib.h> + $<$:${CMAKE_CURRENT_LIST_DIR}/UT_String.h> DESTINATION ${INCDIR} ) diff --git a/packages/legacy/legacy.cpp b/packages/legacy/legacy.cpp index 978d01841..f07183900 100644 --- a/packages/legacy/legacy.cpp +++ b/packages/legacy/legacy.cpp @@ -254,6 +254,7 @@ void initlegacy (void) cmdProc->registerHandler("LUA_INTERPRETER", LuaInterpreter::createUnsafeObject, -1, " [additional lua arguments]"); cmdProc->registerHandler("LUA_SAFE_INTERPRETER", LuaInterpreter::createSafeObject, -1, " [additional lua arguments]"); cmdProc->registerHandler("PUBLISHER_PROCESSOR", CcsdsPublisherProcessorModule::createObject, 1, "", true); +#ifdef __unittesting__ cmdProc->registerHandler("UT_DICTIONARY", UT_Dictionary::createObject, 0, ""); cmdProc->registerHandler("UT_LIST", UT_List::createObject, 0, ""); cmdProc->registerHandler("UT_MSGQ", UT_MsgQ::createObject, 0, ""); @@ -261,7 +262,7 @@ void initlegacy (void) cmdProc->registerHandler("UT_TABLE" , UT_Table::createObject, 0, ""); cmdProc->registerHandler("UT_TIMELIB", UT_TimeLib::createObject, 0, ""); cmdProc->registerHandler("UT_STRING", UT_String::createObject, 0, ""); - +#endif /* Add Lua Extension */ LuaLibraryCmd::lcmd_init(cmdProc); LuaEngine::extend(LuaLibraryCmd::LUA_CMDLIBNAME, LuaLibraryCmd::luaopen_cmdlib); diff --git a/packages/legacy/legacy.h b/packages/legacy/legacy.h index c6841a753..c25cd5499 100644 --- a/packages/legacy/legacy.h +++ b/packages/legacy/legacy.h @@ -52,6 +52,7 @@ #include "LuaInterpreter.h" #include "LuaLibraryCmd.h" #include "StatisticRecord.h" +#ifdef __unittesting__ #include "UT_Dictionary.h" #include "UT_List.h" #include "UT_MsgQ.h" @@ -59,6 +60,7 @@ #include "UT_Table.h" #include "UT_TimeLib.h" #include "UT_String.h" +#endif /****************************************************************************** * DEFINES diff --git a/plugins/icesat2/CMakeLists.txt b/plugins/icesat2/CMakeLists.txt index 5a142b753..ba74232d3 100644 --- a/plugins/icesat2/CMakeLists.txt +++ b/plugins/icesat2/CMakeLists.txt @@ -25,7 +25,6 @@ target_compile_definitions (icesat2 PUBLIC BUILDINFO="${BUILDINFO}") # Compile Definitions # target_compile_definitions (icesat2 PUBLIC BINID="${TGTVER}") -target_compile_options (icesat2 PUBLIC "$<$:-DWITH_UNITTESTS>") target_compile_options (icesat2 PUBLIC -Wall) # turn on "all" warnings target_compile_options (icesat2 PUBLIC -Wextra) # turn on "extra" warnings target_compile_options (icesat2 PUBLIC -Wreorder) # turn on warning for object initializer list order enforcement diff --git a/plugins/icesat2/plugin/icesat2.cpp b/plugins/icesat2/plugin/icesat2.cpp index 568e83c4e..4f1135e08 100644 --- a/plugins/icesat2/plugin/icesat2.cpp +++ b/plugins/icesat2/plugin/icesat2.cpp @@ -70,7 +70,7 @@ int icesat2_open (lua_State *L) {"atl06", Atl06Dispatch::luaCreate}, {"atl06s", Atl06Reader::luaCreate}, {"atl08", Atl08Dispatch::luaCreate}, -#ifdef WITH_UNITTESTS +#ifdef __unittesting__ {"ut_atl06", UT_Atl06Dispatch::luaCreate}, {"ut_atl03", UT_Atl03Reader::luaCreate}, #endif @@ -109,12 +109,6 @@ int icesat2_open (lua_State *L) LuaEngine::setAttrInt(L, "ATL08_TOP_OF_CANOPY", Icesat2Parms::ATL08_TOP_OF_CANOPY); LuaEngine::setAttrInt(L, "ATL08_UNCLASSIFIED", Icesat2Parms::ATL08_UNCLASSIFIED); - #ifdef WITH_UNITTESTS - LuaEngine::setAttrBool(L, "UNITTEST", true); - #else - LuaEngine::setAttrBool(L, "UNITTEST", false); - #endif - return 1; } diff --git a/plugins/icesat2/plugin/icesat2.h b/plugins/icesat2/plugin/icesat2.h index e956df349..ed25eb944 100644 --- a/plugins/icesat2/plugin/icesat2.h +++ b/plugins/icesat2/plugin/icesat2.h @@ -49,7 +49,7 @@ #include "Icesat2Parms.h" #include "MeritRaster.h" -#ifdef WITH_UNITTESTS +#ifdef __unittesting__ #include "UT_Atl03Reader.h" #include "UT_Atl06Dispatch.h" #endif diff --git a/plugins/icesat2/selftests/plugin_unittest.lua b/plugins/icesat2/selftests/plugin_unittest.lua index b1ad2bf36..b76ead183 100644 --- a/plugins/icesat2/selftests/plugin_unittest.lua +++ b/plugins/icesat2/selftests/plugin_unittest.lua @@ -2,7 +2,7 @@ local runner = require("test_executive") local console = require("console") -- Check If Present -- -if not icesat2.UNITTEST then return end +if not core.UNITTEST then return end -- Setup -- diff --git a/plugins/pgc/CMakeLists.txt b/plugins/pgc/CMakeLists.txt index ebc375fd7..5cf06bd40 100644 --- a/plugins/pgc/CMakeLists.txt +++ b/plugins/pgc/CMakeLists.txt @@ -44,7 +44,6 @@ target_sources(pgc ${CMAKE_CURRENT_LIST_DIR}/plugin/pgc.cpp ${CMAKE_CURRENT_LIST_DIR}/plugin/PgcWkt.cpp ${CMAKE_CURRENT_LIST_DIR}/plugin/PgcDemStripsRaster.cpp - $<$:${CMAKE_CURRENT_LIST_DIR}/plugin/UT_RasterSubset.cpp> ) # Include Directories # @@ -68,7 +67,6 @@ install ( ${CMAKE_CURRENT_LIST_DIR}/plugin/RemaDemMosaicRaster.h ${CMAKE_CURRENT_LIST_DIR}/plugin/ArcticDemStripsRaster.h ${CMAKE_CURRENT_LIST_DIR}/plugin/RemaDemStripsRaster.h - $<$:${CMAKE_CURRENT_LIST_DIR}/plugin/UT_RasterSubset.h> DESTINATION ${INSTALLDIR}/include/sliderule/pgc ) diff --git a/plugins/pgc/plugin/pgc.cpp b/plugins/pgc/plugin/pgc.cpp index 9b0e6bf39..5616235a3 100644 --- a/plugins/pgc/plugin/pgc.cpp +++ b/plugins/pgc/plugin/pgc.cpp @@ -36,7 +36,6 @@ #include "core.h" #include "pgc.h" #include "PgcWkt.h" -#include "UT_RasterSubset.h" /****************************************************************************** * DEFINES @@ -70,21 +69,12 @@ int pgc_open (lua_State *L) { static const struct luaL_Reg pgc_functions[] = { {"version", pgc_version}, -#ifdef WITH_UNITTESTS - {"ut_subset", UT_RasterSubset::luaCreate}, -#endif {NULL, NULL} }; /* Set Library */ luaL_newlib(L, pgc_functions); -#ifdef WITH_UNITTESTS - LuaEngine::setAttrBool(L, "UNITTEST", true); -#else - LuaEngine::setAttrBool(L, "UNITTEST", false); -#endif - return 1; } diff --git a/plugins/pgc/selftests/plugin_unittest.lua b/plugins/pgc/selftests/plugin_unittest.lua index c9ba97ec2..9b08c4371 100644 --- a/plugins/pgc/selftests/plugin_unittest.lua +++ b/plugins/pgc/selftests/plugin_unittest.lua @@ -7,7 +7,7 @@ local assets = asset.loaddir() -- sys.setlvl(core.LOG, core.DEBUG) -- Check If Present -- -if not pgc.UNITTEST then return end +if not core.UNITTEST then return end -- Setup -- @@ -19,7 +19,7 @@ print('\n------------------\nTest01 RasterSubset::rema-mosaic \n---------------- local demType = "rema-mosaic" local dem = geo.raster(geo.parms({asset=demType, algorithm="NearestNeighbour", radius=50, zonal_stats=true})) runner.check(dem ~= nil) -local ut = pgc.ut_subset(dem) +local ut = geo.ut_subset(dem) runner.check(ut ~= nil) local status = ut:test() runner.check(status, "Failed subset test") @@ -30,7 +30,7 @@ print('\n------------------\nTest02 RasterSubset::rema-strips \n---------------- demType = "rema-strips" dem = geo.raster(geo.parms({asset=demType, algorithm="NearestNeighbour", radius=50, zonal_stats=true})) runner.check(dem ~= nil) -ut = pgc.ut_subset(dem) +ut = geo.ut_subset(dem) runner.check(ut ~= nil) status = ut:test() runner.check(status, "Failed subset test")