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

Add Unit test for empty Help Strings in filters. Clean up empty help Strings #744

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,18 @@ Parameters ConvertHexGridToSquareGridFilter::parameters() const

// Create the parameter descriptors that are needed for this filter
params.insertSeparator(Parameters::Separator{"Orientation Source Data"});
params.insertLinkableParameter(std::make_unique<BoolParameter>(k_MultipleFiles_Key, "Convert Multiple Files", "", false));
params.insertLinkableParameter(std::make_unique<BoolParameter>(k_MultipleFiles_Key, "Convert Multiple Files", "True=Convert a list of files, False, just convert a single file", false));
params.insert(std::make_unique<VectorFloat32Parameter>(k_Spacing_Key, "Spacing", "Specifies the new spacing values", std::vector<float32>{1.0f, 1.0f}, std::vector<std::string>{"X", "Y"}));
params.insert(
std::make_unique<FileSystemPathParameter>(k_InputPath_Key, "Input File", "", fs::path(""), FileSystemPathParameter::ExtensionsType{}, FileSystemPathParameter::PathType::InputFile, true));
params.insert(std::make_unique<GeneratedFileListParameter>(k_GeneratedFileList_Key, "Generated File List", "", GeneratedFileListParameter::ValueType{}));
params.insert(std::make_unique<FileSystemPathParameter>(k_InputPath_Key, "Input File", "Path to the single file to convert", fs::path(""), FileSystemPathParameter::ExtensionsType{},
FileSystemPathParameter::PathType::InputFile, true));
params.insert(std::make_unique<GeneratedFileListParameter>(k_GeneratedFileList_Key, "Generated File List",
"The values that are used to generate the input file list. See GeneratedFileListParameter for more information.",
GeneratedFileListParameter::ValueType{}));

params.insertSeparator(Parameters::Separator{"Output Parameters"});
params.insert(
std::make_unique<FileSystemPathParameter>(k_OutputPath_Key, "Output Directory", "", fs::path(""), FileSystemPathParameter::ExtensionsType{}, FileSystemPathParameter::PathType::OutputDir, true));
params.insert(std::make_unique<StringParameter>(k_OutputPrefix_Key, "Output Prefix", "", "Sqr_"));
params.insert(std::make_unique<FileSystemPathParameter>(k_OutputPath_Key, "Output Directory", "The path to store the converted file. Should NOT be in the same directory.", fs::path(""),
FileSystemPathParameter::ExtensionsType{}, FileSystemPathParameter::PathType::OutputDir, true));
params.insert(std::make_unique<StringParameter>(k_OutputPrefix_Key, "Output Prefix", "A string to prepend the name of each converted file", "Sqr_"));

// Link Parameters
params.linkParameters(k_MultipleFiles_Key, k_GeneratedFileList_Key, true);
Expand Down
9 changes: 5 additions & 4 deletions src/Plugins/TestOne/src/TestOne/Filters/ExampleFilter1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,16 @@ Parameters ExampleFilter1::parameters() const
params.insert(std::make_unique<NumericTypeParameter>(k_Param6, "Numeric Type", "Example numeric type help text", NumericType::int32));

params.insertSeparator({"Big Parameters"});
params.insert(std::make_unique<GeneratedFileListParameter>(k_Param4, "Input File List", "Data needed to generate the input file list", GeneratedFileListParameter::ValueType{}));
params.insert(std::make_unique<GeneratedFileListParameter>(
k_Param4, "Input File List", "The values that are used to generate the input file list. See GeneratedFileListParameter for more information.", GeneratedFileListParameter::ValueType{}));

params.insert(std::make_unique<ArrayThresholdsParameter>(k_Param7, "Data Thresholds", "DataArray thresholds to mask", ArrayThresholdSet{}));

// param10 should be active if either param8 OR param9 are the correct value
params.insertSeparator({"Multiple Linked Parameters"});
params.insertLinkableParameter(std::make_unique<BoolParameter>(k_Param8, "Bool Parameter", "", true));
params.insertLinkableParameter(std::make_unique<ChoicesParameter>(k_Param9, "Choices Parameter", "", 0, ChoicesParameter::Choices{"0", "1", "2"}));
params.insert(std::make_unique<Int32Parameter>(k_Param10, "Int32 Parameter", "", 42));
params.insertLinkableParameter(std::make_unique<BoolParameter>(k_Param8, "Bool Parameter", "A boolean Parameter", true));
params.insertLinkableParameter(std::make_unique<ChoicesParameter>(k_Param9, "Choices Parameter", "A choices parameter", 0, ChoicesParameter::Choices{"0", "1", "2"}));
params.insert(std::make_unique<Int32Parameter>(k_Param10, "Int32 Parameter", "An Integer Parameter", 42));
params.linkParameters(k_Param8, k_Param10, true);
params.linkParameters(k_Param9, k_Param10, std::make_any<ChoicesParameter::ValueType>(1));

Expand Down
3 changes: 2 additions & 1 deletion src/Plugins/TestOne/src/TestOne/Filters/TestFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ complex::Parameters TestFilter::parameters() const
Parameters params;
params.insert(std::make_unique<Float32Parameter>(k_Param1, "Parameter 1", "The 1st parameter", 0.1234f));
params.insert(std::make_unique<BoolParameter>(k_Param2, "Parameter 2", "The 2nd parameter", false));
params.insert(std::make_unique<GeneratedFileListParameter>(k_Param3, "Input File List", "Data needed to generate the input file list", GeneratedFileListParameter::ValueType{}));
params.insert(std::make_unique<GeneratedFileListParameter>(
k_Param3, "Input File List", "The values that are used to generate the input file list. See GeneratedFileListParameter for more information.", GeneratedFileListParameter::ValueType{}));
return params;
}

Expand Down
87 changes: 72 additions & 15 deletions test/PluginTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <catch2/catch.hpp>

#include <sstream>
#include <string>

using namespace complex;
Expand All @@ -27,17 +28,17 @@ TEST_CASE("Test Loading Plugins")
Application app;
app.loadPlugins(unit_test::k_BuildDir.view());

auto* filterList = Application::Instance()->getFilterList();
const auto& filterHandles = filterList->getFilterHandles();
auto plugins = filterList->getLoadedPlugins();
auto* filterListPtr = Application::Instance()->getFilterList();
const auto& filterHandles = filterListPtr->getFilterHandles();
auto plugins = filterListPtr->getLoadedPlugins();

if(plugins.size() != COMPLEX_PLUGIN_COUNT)
{
std::cout << "Incorrect number of plugins were loaded.\n"
<< "Expected: " << COMPLEX_PLUGIN_COUNT << "\nLoaded: " << plugins.size() << "\nLoaded Plugins are:\n";
for(auto const& plugin : plugins)
{
std::cout << plugin->getName() << std::endl;
std::cout << plugin->getName() << "\n";
}
}

Expand All @@ -47,13 +48,13 @@ TEST_CASE("Test Loading Plugins")
DataStructure dataStructure;
{

IFilter::UniquePointer filter = filterList->createFilter(k_TestFilterHandle);
IFilter::UniquePointer filter = filterListPtr->createFilter(k_TestFilterHandle);
REQUIRE(filter != nullptr);
REQUIRE(filter->humanName() == "Test Filter");
filter->execute(dataStructure, {});
}
{
IFilter::UniquePointer filter2 = filterList->createFilter(k_Test2FilterHandle);
IFilter::UniquePointer filter2 = filterListPtr->createFilter(k_Test2FilterHandle);
REQUIRE(filter2 != nullptr);
REQUIRE(filter2->humanName() == "Test Filter 2");
filter2->execute(dataStructure, {});
Expand All @@ -62,14 +63,14 @@ TEST_CASE("Test Loading Plugins")

TEST_CASE("Test Singleton")
{
Application* app = new Application();
app->loadPlugins(unit_test::k_BuildDir.view());
Application* appPtr = new Application();
appPtr->loadPlugins(unit_test::k_BuildDir.view());

REQUIRE(app != nullptr);
REQUIRE(appPtr != nullptr);

auto* filterList = app->getFilterList();
const auto& filterHandles = filterList->getFilterHandles();
auto plugins = filterList->getLoadedPlugins();
auto* filterListPtr = appPtr->getFilterList();
const auto& filterHandles = filterListPtr->getFilterHandles();
auto plugins = filterListPtr->getLoadedPlugins();

// Check plugins were loaded
if(plugins.size() != COMPLEX_PLUGIN_COUNT)
Expand All @@ -78,7 +79,7 @@ TEST_CASE("Test Singleton")
<< "Expected: " << COMPLEX_PLUGIN_COUNT << "\nLoaded: " << plugins.size() << "\nLoaded Plugins are:\n";
for(auto const& plugin : plugins)
{
std::cout << plugin->getName() << std::endl;
std::cout << plugin->getName() << "\n";
}
}
REQUIRE(plugins.size() == COMPLEX_PLUGIN_COUNT);
Expand All @@ -89,13 +90,13 @@ TEST_CASE("Test Singleton")
// Create and execute filters
DataStructure dataStructure;
{
IFilter::UniquePointer filter = filterList->createFilter(k_TestFilterHandle);
IFilter::UniquePointer filter = filterListPtr->createFilter(k_TestFilterHandle);
REQUIRE(filter != nullptr);
REQUIRE(filter->humanName() == "Test Filter");
filter->execute(dataStructure, {});
}
{
IFilter::UniquePointer filter2 = filterList->createFilter(k_Test2FilterHandle);
IFilter::UniquePointer filter2 = filterListPtr->createFilter(k_Test2FilterHandle);
REQUIRE(filter2 != nullptr);
REQUIRE(filter2->humanName() == "Test Filter 2");
filter2->execute(dataStructure, {});
Expand All @@ -104,3 +105,59 @@ TEST_CASE("Test Singleton")
delete Application::Instance();
REQUIRE(Application::Instance() == nullptr);
}

TEST_CASE("Test Filter Help Text")
{
Application* appPtr = new Application();
REQUIRE(appPtr != nullptr);

appPtr->loadPlugins(unit_test::k_BuildDir.view());
auto* filterListPtr = Application::Instance()->getFilterList();
const auto pluginListPtr = Application::Instance()->getPluginList();

std::stringstream output;

// Loop on each Plugin
for(const auto& plugin : pluginListPtr)
{
const std::string plugName = plugin->getName();

const auto& pluginFilterHandles = plugin->getFilterHandles();

// Loop on each Filter
for(const auto& filterHandle : pluginFilterHandles)
{
const std::string filterClassName = filterHandle.getClassName();
IFilter::UniquePointer filter = filterListPtr->createFilter(filterHandle);

const auto& parameters = filter->parameters();
// Loop over each Parameter
for(const auto& parameter : parameters)
{
auto const& paramValue = parameter.second;
if(paramValue->helpText().empty())
{
output << plugName << "->" << filter->name() << "->" << paramValue->name() << ": Human Name: '" << paramValue->humanName() << "' The Help Text is empty\n";
}

for(const auto& letter : paramValue->name())
{
if(::isupper(letter) != 0)
{
output << plugName << "->" << filter->name() << "->" << paramValue->name() << ". This parameter key has CAPITAL Letters. All parameter keys should be 'lower_snake_case' style\n";
break;
}
}
}
}
}

delete Application::Instance();
REQUIRE(Application::Instance() == nullptr);

if(!output.str().empty())
{
std::cout << output.str();
}
REQUIRE(output.str().empty() == true);
}
Loading