Skip to content

Commit

Permalink
reworked unittesting defines to support unit tests in multiple plugin…
Browse files Browse the repository at this point in the history
…s as well as the legacy unit tests
  • Loading branch information
jpswinski committed Apr 22, 2024
1 parent f874893 commit 25ea18e
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 42 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions packages/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/geo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_RasterSubset.cpp>
)

target_include_directories (slideruleLib
PUBLIC
Expand All @@ -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
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_RasterSubset.h>
DESTINATION
${INCDIR}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
******************************************************************************/

#include "core.h"
#include "GdalRaster.h"
#include "UT_RasterSubset.h"
#include "RemaDemMosaicRaster.h"

/******************************************************************************
* STATIC DATA
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions packages/geo/geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

#include "geo.h"

#ifdef __unittesting__
#include "UT_RasterSubset.h"
#endif

#include <gdal.h>
#include <cpl_conv.h>
#include <proj.h>
Expand Down Expand Up @@ -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}
};

Expand Down
28 changes: 14 additions & 14 deletions packages/legacy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_Dictionary.cpp>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_List.cpp>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_MsgQ.cpp>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_Ordering.cpp>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_Table.cpp>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_TimeLib.cpp>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_String.cpp>
)

target_include_directories (slideruleLib
Expand All @@ -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
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_Dictionary.h>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_List.h>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_MsgQ.h>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_Ordering.h>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_Table.h>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_TimeLib.h>
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/UT_String.h>
DESTINATION
${INCDIR}
)
3 changes: 2 additions & 1 deletion packages/legacy/legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,15 @@ void initlegacy (void)
cmdProc->registerHandler("LUA_INTERPRETER", LuaInterpreter::createUnsafeObject, -1, "<input stream: msgq mode | STDIN: stdin mode | FILE: file mode> [additional lua arguments]");
cmdProc->registerHandler("LUA_SAFE_INTERPRETER", LuaInterpreter::createSafeObject, -1, "<input stream: msgq mode | STDIN: stdin mode | FILE: file mode> [additional lua arguments]");
cmdProc->registerHandler("PUBLISHER_PROCESSOR", CcsdsPublisherProcessorModule::createObject, 1, "<output stream>", 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, "");
cmdProc->registerHandler("UT_ORDERING", UT_Ordering::createObject, 0, "");
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);
Expand Down
2 changes: 2 additions & 0 deletions packages/legacy/legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@
#include "LuaInterpreter.h"
#include "LuaLibraryCmd.h"
#include "StatisticRecord.h"
#ifdef __unittesting__
#include "UT_Dictionary.h"
#include "UT_List.h"
#include "UT_MsgQ.h"
#include "UT_Ordering.h"
#include "UT_Table.h"
#include "UT_TimeLib.h"
#include "UT_String.h"
#endif

/******************************************************************************
* DEFINES
Expand Down
1 change: 0 additions & 1 deletion plugins/icesat2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<$<CONFIG:Debug>:-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
Expand Down
8 changes: 1 addition & 7 deletions plugins/icesat2/plugin/icesat2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/icesat2/plugin/icesat2.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "Icesat2Parms.h"
#include "MeritRaster.h"

#ifdef WITH_UNITTESTS
#ifdef __unittesting__
#include "UT_Atl03Reader.h"
#include "UT_Atl06Dispatch.h"
#endif
Expand Down
2 changes: 1 addition & 1 deletion plugins/icesat2/selftests/plugin_unittest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 --

Expand Down
2 changes: 0 additions & 2 deletions plugins/pgc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/plugin/UT_RasterSubset.cpp>
)

# Include Directories #
Expand All @@ -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
$<$<CONFIG:Debug>:${CMAKE_CURRENT_LIST_DIR}/plugin/UT_RasterSubset.h>
DESTINATION
${INSTALLDIR}/include/sliderule/pgc
)
Expand Down
10 changes: 0 additions & 10 deletions plugins/pgc/plugin/pgc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "core.h"
#include "pgc.h"
#include "PgcWkt.h"
#include "UT_RasterSubset.h"

/******************************************************************************
* DEFINES
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/pgc/selftests/plugin_unittest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 --

Expand All @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 25ea18e

Please sign in to comment.