diff --git a/test/PipelineSaveTest.cpp b/test/PipelineSaveTest.cpp index 9046191615..d235fba5a7 100644 --- a/test/PipelineSaveTest.cpp +++ b/test/PipelineSaveTest.cpp @@ -1,5 +1,8 @@ #include "simplnx/Core/Application.hpp" #include "simplnx/Pipeline/Pipeline.hpp" +#include "simplnx/Pipeline/PlaceholderFilter.hpp" + +#include "simplnx/UnitTest/UnitTestCommon.hpp" #include "simplnx/unit_test/simplnx_test_dirs.hpp" #include @@ -7,6 +10,88 @@ using namespace nx::core; +namespace +{ +class TestFilter : public IFilter +{ +public: + static constexpr Uuid k_ID = *Uuid::FromString("d01ad5c2-6897-4380-89f1-6d0760b78a22"); + + TestFilter() = default; + ~TestFilter() override = default; + + std::string name() const override + { + return "TestFilter"; + } + + std::string className() const override + { + return "TestFilter"; + } + + nx::core::Uuid uuid() const override + { + return k_ID; + } + + std::string humanName() const override + { + return "Test Filter"; + } + + std::vector defaultTags() const override + { + return {}; + } + + nx::core::Parameters parameters() const override + { + return Parameters(); + } + + UniquePointer clone() const override + { + return std::make_unique(); + } + +protected: + PreflightResult preflightImpl(const nx::core::DataStructure& data, const nx::core::Arguments& args, const MessageHandler& messageHandler, const std::atomic_bool& shouldCancel) const override + { + return {}; + } + nx::core::Result<> executeImpl(nx::core::DataStructure& data, const nx::core::Arguments& args, const PipelineFilter* pipelineNode, const MessageHandler& messageHandler, + const std::atomic_bool& shouldCancel) const override + { + return {}; + } +}; + +class TestPlugin : public AbstractPlugin +{ +public: + static constexpr AbstractPlugin::IdType k_ID = *Uuid::FromString("09721f74-c282-44ac-ada7-1db1a23435dd"); + + TestPlugin() + : AbstractPlugin(k_ID, "TestPlugin", "", "") + { + addFilter([]() { return std::make_unique(); }); + } + ~TestPlugin() override = default; + + TestPlugin(const TestPlugin&) = delete; + TestPlugin(TestPlugin&&) = delete; + + TestPlugin& operator=(const TestPlugin&) = delete; + TestPlugin& operator=(TestPlugin&&) = delete; + + SIMPLMapType getSimplToSimplnxMap() const override + { + return {}; + } +}; +} // namespace + TEST_CASE("Save Filters To Json") { auto app = Application::GetOrCreateInstance(); @@ -63,3 +148,44 @@ TEST_CASE("Save Pipeline To Json") INFO(fmt::format("The pipeline containing every filter did not serialize to json properly!")) REQUIRE_NOTHROW(pipeline.toJson()); } + +TEST_CASE("PlaceholderFilter") +{ + auto app = Application::GetOrCreateInstance(); + FilterList* filterList = app->getFilterList(); + filterList->addPlugin(std::make_shared(std::make_shared())); + REQUIRE(filterList->containsPlugin(TestPlugin::k_ID)); + auto filterHandles = filterList->getFilterHandles(); + auto testFilterIter = std::find_if(filterHandles.cbegin(), filterHandles.cend(), [](const FilterHandle& handle) { return handle.getFilterId() == TestFilter::k_ID; }); + REQUIRE(testFilterIter != filterHandles.cend()); + + Pipeline pipeline; + pipeline.insertAt(0, *testFilterIter); + + nlohmann::json pipelineJson = pipeline.toJson(); + + filterList->removePlugin(TestPlugin::k_ID); + REQUIRE(!filterList->containsPlugin(TestPlugin::k_ID)); + + auto placeholderPipelineResult = Pipeline::FromJson(pipelineJson, true); + SIMPLNX_RESULT_REQUIRE_VALID(placeholderPipelineResult); + + Pipeline placeholderPipeline = std::move(placeholderPipelineResult.value()); + REQUIRE(placeholderPipeline.size() == 1); + REQUIRE(placeholderPipeline.containsPlaceholder()); + + AbstractPipelineNode* node = placeholderPipeline.at(0); + REQUIRE(node != nullptr); + REQUIRE(node->getType() == AbstractPipelineNode::NodeType::Filter); + + auto* filterNode = dynamic_cast(node); + REQUIRE(filterNode != nullptr); + REQUIRE(filterNode->getFilterType() == AbstractPipelineFilter::FilterType::Placeholder); + + auto* placeholderFilter = dynamic_cast(filterNode); + REQUIRE(placeholderFilter != nullptr); + + nlohmann::json placeholderPipelineJson = placeholderPipeline.toJson(); + + REQUIRE(placeholderPipelineJson == pipelineJson); +}