Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve TRE unitesting #599

Merged
merged 38 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4a0b61e
merge develop/preload-TREs
Nov 8, 2023
33f26bf
fix build errors
Nov 9, 2023
8bb07e8
#including some TREs
Nov 13, 2023
844685a
"export" TRE routines as "static"
Nov 13, 2023
27cdcb0
struct for pre-loaded TREs rather than "void*"
Nov 13, 2023
29a31d1
start working on resolving preloaded TREs
Nov 13, 2023
2983c1b
retrievePreloadedTREHandler() to match nitf_PluginRegistry_retrieveTR…
Nov 13, 2023
910db14
preload a TRE
Nov 13, 2023
28465b4
preload several TREs
Nov 13, 2023
ff86423
fix duplicate defs
Nov 13, 2023
78b021f
fix compiler warning
Nov 13, 2023
5e64418
use macros to remove multiple-defined symbols
Nov 13, 2023
120c8cc
keep a few TREs as plugins for testing
Nov 13, 2023
f649edf
preloaded TRE stuff needs to be in PluginHandler so that nitf_PluginR…
Nov 13, 2023
398c329
remove another multiple-defined symbols
Nov 13, 2023
f5d23fb
assume plug-in that fails is "preloaded"
Nov 13, 2023
ff64f82
remove VCXPROJ for TREs that are preloaded
Nov 13, 2023
fd6829c
don't preload ANY TREs to preserve existing behavior
Nov 13, 2023
49dfc90
be sure all nrt_DLL fields are initialized
Nov 13, 2023
f9aaa5f
revert whitespace changes
Nov 13, 2023
d0b6301
Merge branch 'main' into feature/preload-TREs
Nov 13, 2023
3d682f5
Merge branch 'main' into feature/preload-TREs
Nov 14, 2023
fd4f65d
added a preloaded TEST_PRELOADED_DES TRE
Nov 14, 2023
9cda2fa
the TRE id could have underscores in it, so search from the end.
Nov 14, 2023
3f36db7
preload TREs, but disable them
Nov 14, 2023
dc28173
allow preloaded TREs to be enabled/disabled
Nov 14, 2023
04fc627
allow all TREs to be enabled (or disabled)
Nov 14, 2023
35b8e5d
don't need to call setNitfPluginPath() as much with preloaded TREs
Nov 14, 2023
87c5293
always build TEST_DES as a DLL
Nov 15, 2023
ee4dd53
strongly-typed TEST_DES TRE
Nov 15, 2023
a45b5fe
strongly-typed TEST_DES TRE
Nov 15, 2023
c5d44de
Merge branch 'feature/preload-TREs' of github.com:mdaus/nitro into fe…
Nov 15, 2023
2b01788
set things up so a different set of preloaded handlers could be used
Nov 15, 2023
18de46b
Merge branch 'main' into feature/preload-TREs
Nov 15, 2023
2f97a1c
Merge branch 'main' into feature/preload-TREs
Nov 15, 2023
b58fc1c
call nitf_PluginRegistry_PreloadedTREHandlerEnable() for TREs used in…
Nov 15, 2023
490fe33
Merge branch 'feature/preload-TREs' of github.com:mdaus/nitro into fe…
Nov 15, 2023
8dc388f
only one chance to set NITF_PLUGIN_PATH
Nov 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions UnitTest/UnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// https://learn.microsoft.com/en-us/visualstudio/test/microsoft-visualstudio-testtools-cppunittestframework-api-reference?view=vs-2022
TEST_MODULE_INITIALIZE(methodName)
{
nitf_PluginRegistry_PreloadedTREHandlersEnable(NRT_TRUE);

// module initialization code
nitf_PluginRegistry_PreloadedTREHandlersEnable(NRT_TRUE);
nitf::Test::j2kSetNitfPluginPath();
}
2 changes: 2 additions & 0 deletions modules/c++/nitf/unittests/test_load_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ TEST_CASE(test_retrieveTREHandler)

TEST_CASE(test_load_PTPRAA)
{
TEST_ASSERT_TRUE(nitf_PluginRegistry_PreloadedTREHandlerEnable("PTPRAA", NRT_TRUE));
retrieveTREHandler(testName, "PTPRAA");
}
TEST_CASE(test_load_ENGRDA)
{
TEST_ASSERT_TRUE(nitf_PluginRegistry_PreloadedTREHandlerEnable("ENGRDA", NRT_TRUE));
retrieveTREHandler(testName, "ENGRDA");
}

Expand Down
3 changes: 1 addition & 2 deletions modules/c++/nitf/unittests/test_tre_create++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TEST_CASE(test_tre_create_329)
{
// https://github.com/mdaus/nitro/issues/329

TEST_ASSERT_TRUE(nitf_PluginRegistry_PreloadedTREHandlerEnable("HISTOA", NRT_TRUE));
nitf::TRE tre("HISTOA", "HISTOA"); // allocates fields SYSTEM .. NEVENTS
tre.setField("SYSTYPE", "M1");
TEST_ASSERT_TRUE(true);
Expand Down Expand Up @@ -39,8 +40,6 @@ TEST_CASE(test_tre_clone_329)
}

TEST_MAIN(
nitf::Test::setNitfPluginPath();

TEST_CHECK(test_tre_create_329);
TEST_CHECK(test_tre_clone_329);
)
13 changes: 11 additions & 2 deletions modules/c++/nitf/unittests/test_tre_mods++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ struct /*namespace*/ TREs

TEST_CASE(setFields)
{
// create an ACFTA TRE
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("ACFTA", NRT_TRUE) );
nitf::TRE tre("ACFTA");

// set a field
Expand All @@ -179,6 +179,7 @@ TEST_CASE(setFields)

TEST_CASE(setBinaryFields)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("RPFHDR", NRT_TRUE) );
nitf::TRE tre("RPFHDR");
const int value = 123;
tre.setField("LOCSEC", value);
Expand All @@ -190,6 +191,7 @@ TEST_CASE(setBinaryFields)

TEST_CASE(cloneTRE)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("JITCID", NRT_TRUE) );
nitf::TRE tre("JITCID");
tre.setField("FILCMT", "fyi");

Expand All @@ -203,6 +205,7 @@ TEST_CASE(cloneTRE)

TEST_CASE(basicIteration)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("ACCPOB", NRT_TRUE) );
nitf::TRE tre("ACCPOB");

// The entire TRE is one loop, and we haven't told it
Expand Down Expand Up @@ -253,7 +256,6 @@ TEST_CASE(use_TEST_DES)
TEST_ASSERT_EQ(test_preloaded_des.INCREMENT, 67);

/***********************************************************/
nitf::Test::setNitfPluginPath();

nitf::TRE des("TEST_DES", "TEST_DES");
test_des_(testName, des, "TEST_DES_");
Expand All @@ -269,6 +271,7 @@ TEST_CASE(use_TEST_DES)

TEST_CASE(use_ENGRDA)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("ENGRDA", NRT_TRUE) );
nitf::TRE engrda("ENGRDA", "ENGRDA");

engrda.setField("RESRC", "HSS");
Expand All @@ -293,6 +296,7 @@ TEST_CASE(use_ENGRDA)

TEST_CASE(use_ENGRDA_typed_fields)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("ENGRDA", NRT_TRUE) );
nitf::TRE engrda("ENGRDA", "ENGRDA");

nitf::TREField_BCS_A<20> RESRC(engrda, "RESRC");
Expand Down Expand Up @@ -325,6 +329,7 @@ TEST_CASE(use_ENGRDA_typed_fields)

TEST_CASE(use_typed_ENGRDA)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("ENGRDA", NRT_TRUE) );
TREs::ENGRDA engrda; // nitf::TRE engrda("ENGRDA", "ENGRDA");

engrda.RESRC = "HSS"; // engrda.setField("RESRC", "HSS");
Expand Down Expand Up @@ -373,6 +378,7 @@ TEST_CASE(use_typed_ENGRDA)

TEST_CASE(use_CSEXRB_typed_fields)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("CSEXRB", NRT_TRUE) );
nitf::TRE tre("CSEXRB", "CSEXRB");

constexpr auto length = 12;
Expand All @@ -386,6 +392,7 @@ TEST_CASE(use_CSEXRB_typed_fields)

TEST_CASE(populateWhileIterating)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("ACCPOB", NRT_TRUE) );
nitf::TRE tre("ACCPOB");
size_t numFields = 0;
for (auto it = tre.begin(); it != tre.end(); ++it)
Expand All @@ -410,6 +417,7 @@ TEST_CASE(populateWhileIterating)

TEST_CASE(overflowingNumericFields)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("CSCRNA", NRT_TRUE) );
nitf::TRE tre("CSCRNA");

// This field has a length of 9, so check that it's properly
Expand Down Expand Up @@ -438,6 +446,7 @@ TEST_CASE(overflowingNumericFields)
}

TEST_MAIN(
// must be set before making any NITRO calls
nitf::Test::setNitfPluginPath();

TEST_CHECK(setFields);
Expand Down
30 changes: 17 additions & 13 deletions modules/c++/nitf/unittests/test_tre_mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

TEST_CASE(testNestedMod)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("ACCHZB", NRT_TRUE) );

nitf_Error error;
NITF_BOOL exists;
nitf_TRE* tre = nitf_TRE_construct("ACCHZB", NULL, &error);
Expand Down Expand Up @@ -59,6 +61,8 @@ TEST_CASE(testNestedMod)

TEST_CASE(testIncompleteCondMod)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("ACCPOB", NRT_TRUE) );

nitf_Error error;
NITF_BOOL exists;
nitf_TRE* tre = nitf_TRE_construct("ACCPOB", NULL, &error);
Expand Down Expand Up @@ -90,6 +94,7 @@ TEST_CASE(testClone)
nitf_Field* clonedField = NULL;
nitf_Error error;

TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("JITCID", NRT_TRUE) );
nitf_TRE* tre = nitf_TRE_construct("JITCID", NULL, &error);
TEST_ASSERT(tre != NULL);

Expand All @@ -110,13 +115,14 @@ TEST_CASE(testClone)

TEST_CASE(testBasicMod)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("ACFTA", NRT_TRUE) );

/* construct a tre */
NITF_BOOL exists;
nitf_Error error;
nitf_Field* field;
nitf_TRE *tre = nitf_TRE_construct("ACFTA", "ACFTA_132", &error);
TEST_ASSERT(tre != NULL);
field = (nitf_TRE_getField(tre, "AC_MSN_ID"));
nitf_Field* field = (nitf_TRE_getField(tre, "AC_MSN_ID"));
TEST_ASSERT_EQ_STR(field->raw, " ");

exists = nitf_TRE_setField(tre, "AC_MSN_ID", "fly-by", 6, &error);
Expand All @@ -139,6 +145,7 @@ TEST_CASE(testBasicMod)

TEST_CASE(testSize)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("AIMIDB", NRT_TRUE) );
nitf_Error error;
int treLength;
nitf_TRE* tre = nitf_TRE_construct("AIMIDB", NULL, &error);
Expand Down Expand Up @@ -174,18 +181,17 @@ TEST_CASE(iterateUnfilled)

TEST_CASE(populateThenIterate)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("ACCPOB", NRT_TRUE) );
nitf_Error error;
nitf_TRECursor cursor;
nitf_TRE* tre = nitf_TRE_construct("ACCPOB", NULL, &error);
uint32_t numFields = 0;
TEST_ASSERT(tre != NULL);
TEST_ASSERT_NOT_NULL(tre);

uint32_t numFields = 0;
nitf_TRE_setField(tre, "NUMACPO", "2", 1, &error);
nitf_TRE_setField(tre, "NUMPTS[0]", "3", 1, &error);
nitf_TRE_setField(tre, "NUMPTS[1]", "2", 1, &error);

cursor = nitf_TRECursor_begin(tre);

nitf_TRECursor cursor = nitf_TRECursor_begin(tre);
while (!nitf_TRECursor_isDone(&cursor))
{
TEST_ASSERT(nitf_TRECursor_iterate(&cursor, &error) != 0);
Expand All @@ -200,13 +206,13 @@ TEST_CASE(populateThenIterate)

TEST_CASE(populateWhileIterating)
{
TEST_ASSERT_TRUE( nitf_PluginRegistry_PreloadedTREHandlerEnable("ACCPOB", NRT_TRUE) );
nitf_Error error;
nitf_TRECursor cursor;
nitf_TRE* tre = nitf_TRE_construct("ACCPOB", NULL, &error);
uint32_t numFields = 0;
TEST_ASSERT(tre != NULL);
TEST_ASSERT_NOT_NULL(tre);

cursor = nitf_TRECursor_begin(tre);
uint32_t numFields = 0;
nitf_TRECursor cursor = nitf_TRECursor_begin(tre);
while (!nitf_TRECursor_isDone(&cursor))
{
TEST_ASSERT(nitf_TRECursor_iterate(&cursor, &error) != 0);
Expand All @@ -231,8 +237,6 @@ TEST_CASE(populateWhileIterating)
}

TEST_MAIN(
nitf::Test::setNitfPluginPath();

TEST_CHECK(testClone);
TEST_CHECK(testSize);
TEST_CHECK(testBasicMod);
Expand Down
1 change: 0 additions & 1 deletion modules/c/nitf/include/nitf/PluginIdentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ typedef struct _nitf_TREPreloaded
NITF_PLUGIN_TRE_HANDLER_FUNCTION handler;
NITF_BOOL enabled; // most preloaded TREs are disabled by default
} nitf_TREPreloaded;
extern nitf_TREPreloaded preloadedTREs[];

/*
\brief NITF_PLUGIN_COMPRESSION_HANDLER_FUNCTION - Function pointer for
Expand Down
Loading