diff --git a/CMakeLists.txt b/CMakeLists.txt index f91d7dba00..ab3dbf3cbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,8 @@ enable_vcpkg_manifest_feature(TEST_VAR SIMPLNX_BUILD_PYTHON FEATURE "python") option(SIMPLNX_BUILD_TESTS "Enable buildingtests" ON) enable_vcpkg_manifest_feature(TEST_VAR SIMPLNX_BUILD_TESTS FEATURE "tests") +option(SIMPLNX_STORE_COPY_STRICT_FORMAT "Reject a requested storage format when no registered factory supports the requested store type. Applies to numeric array creation, import planning, and store copies." OFF) + # ------------------------------------------------------------------------------ # are multithreading algorithms enabled # ------------------------------------------------------------------------------ @@ -318,6 +320,10 @@ configure_file( ${simplnx_SOURCE_DIR}/cmake/SimplnxConfig.hpp.in ${SIMPLNX_GENERATED_DIR}/simplnx/Common/SimplnxConfig.hpp @ONLY) +configure_file( + ${simplnx_SOURCE_DIR}/cmake/StoreCopyConfig.hpp.in + ${SIMPLNX_GENERATED_DIR}/simplnx/Common/StoreCopyConfig.hpp + @ONLY) set(SIMPLNX_GENERATED_HEADER_DIR ${simplnx_BINARY_DIR}/generated/simplnx) set(SIMPLNX_EXPORT_HEADER ${SIMPLNX_GENERATED_HEADER_DIR}/simplnx_export.hpp) @@ -668,6 +674,7 @@ set(SIMPLNX_HDRS ) set(SIMPLNX_GENERATED_HEADERS + ${SIMPLNX_GENERATED_DIR}/simplnx/Common/StoreCopyConfig.hpp ${SIMPLNX_EXPORT_HEADER} ) @@ -982,6 +989,11 @@ endif() # ------------------------------------------------------------------------------ # CLI Executables (nxrunner, nxinfo) # ------------------------------------------------------------------------------ +# Define BUILD_TESTING before configuring directories and tests that use it. +if(SIMPLNX_BUILD_TESTS) + include(CTest) +endif() + add_subdirectory(${simplnx_SOURCE_DIR}/src/apps) #------------------------------------------------------------------------------ @@ -1163,7 +1175,6 @@ if(SIMPLNX_ENABLE_PACKAGING) endif() if(SIMPLNX_BUILD_TESTS) - include(CTest) target_compile_definitions(simplnx PUBLIC "SIMPLNX_BUILD_TESTS=1") add_subdirectory(test) endif() diff --git a/cmake/StoreCopyConfig.hpp.in b/cmake/StoreCopyConfig.hpp.in new file mode 100644 index 0000000000..67ea4dc09e --- /dev/null +++ b/cmake/StoreCopyConfig.hpp.in @@ -0,0 +1,6 @@ +#pragma once + +// When enabled, reject a requested storage format when no registered factory +// supports the requested store type. This applies to numeric array creation, +// import planning, and store copies. +#cmakedefine01 SIMPLNX_STORE_COPY_STRICT_FORMAT diff --git a/cmake/Summary.cmake b/cmake/Summary.cmake index c06a749497..57a60ff142 100644 --- a/cmake/Summary.cmake +++ b/cmake/Summary.cmake @@ -65,6 +65,7 @@ else() endif() message(STATUS "* -------------- Simplnx Configuration Options -------------------------------------") +message(STATUS "* SIMPLNX_STORE_COPY_STRICT_FORMAT: ${SIMPLNX_STORE_COPY_STRICT_FORMAT}") message(STATUS "* SIMPLNX_BUILD_TESTS: ${SIMPLNX_BUILD_TESTS}") message(STATUS "* SIMPLNX_ENABLE_MULTICORE: ${SIMPLNX_ENABLE_MULTICORE}") message(STATUS "* SIMPLNX_ENABLE_COMPRESSORS: ${SIMPLNX_ENABLE_COMPRESSORS}") diff --git a/src/apps/CMakeLists.txt b/src/apps/CMakeLists.txt index 1747596d73..75e792bb6e 100644 --- a/src/apps/CMakeLists.txt +++ b/src/apps/CMakeLists.txt @@ -146,9 +146,6 @@ simplnx_enable_warnings(TARGET nxinfo) # tests depend on it through a ctest fixture. # ----------------------------------------------------------------------- if(SIMPLNX_BUILD_TESTS) - # This directory is configured before the top-level include(CTest) call. - enable_testing() - set(NXINFO_TEST_INPUT "${SIMPLNX_TEST_OUTPUT_DIR}/nxinfo_ctest_input.dream3d") set(NXINFO_TEST_INVALID_INPUT "${SIMPLNX_TEST_OUTPUT_DIR}/nxinfo_ctest_invalid.dream3d") set(NXINFO_TEST_OUTPUT "${SIMPLNX_TEST_OUTPUT_DIR}/nxinfo_dump.json") diff --git a/src/simplnx/Utilities/StoreCopyUtilities.cpp b/src/simplnx/Utilities/StoreCopyUtilities.cpp index 4100d95829..37c3acdaa5 100644 --- a/src/simplnx/Utilities/StoreCopyUtilities.cpp +++ b/src/simplnx/Utilities/StoreCopyUtilities.cpp @@ -1,5 +1,6 @@ #include "StoreCopyUtilities.hpp" +#include "simplnx/Common/StoreCopyConfig.hpp" #include "simplnx/Core/Application.hpp" #include "simplnx/Core/Preferences.hpp" #include "simplnx/DataStructure/DataPath.hpp" @@ -18,10 +19,6 @@ #include #include -#ifndef SIMPLNX_STORE_COPY_STRICT_FORMAT -#define SIMPLNX_STORE_COPY_STRICT_FORMAT 0 -#endif - namespace nx::core { namespace diff --git a/test/DataArrayTest.cpp b/test/DataArrayTest.cpp index 903400c094..81e9b90846 100644 --- a/test/DataArrayTest.cpp +++ b/test/DataArrayTest.cpp @@ -1,6 +1,7 @@ #include "simplnx/DataStructure/DataArray.hpp" #include "simplnx/Common/Array.hpp" #include "simplnx/Common/ScopeGuard.hpp" +#include "simplnx/Common/StoreCopyConfig.hpp" #include "simplnx/Common/Types.hpp" #include "simplnx/Common/TypesUtility.hpp" #include "simplnx/Core/Application.hpp" @@ -1839,7 +1840,7 @@ TEST_CASE("Unknown store-copy formats obey the compiled build policy", "[simplnx ListStore lists(ShapeType{3}); lists.setList(0, std::vector{4, 5}); StringStore strings({"first", "second"}, {2}); -#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT +#if SIMPLNX_STORE_COPY_STRICT_FORMAT REQUIRE_THROWS_WITH(numeric.deepCopy(unknown), Catch::Contains(unknown)); REQUIRE_THROWS_WITH(placeholderResult.value()->deepCopy(unknown), Catch::Contains(unknown)); REQUIRE_THROWS_WITH(lists.deepCopy(unknown), Catch::Contains(unknown)); diff --git a/test/MemorySafetyTest.cpp b/test/MemorySafetyTest.cpp index fab5a735df..be2ce10288 100644 --- a/test/MemorySafetyTest.cpp +++ b/test/MemorySafetyTest.cpp @@ -1,5 +1,6 @@ #include +#include "simplnx/Common/StoreCopyConfig.hpp" #include "simplnx/Core/Application.hpp" #include "simplnx/DataStructure/DataGroup.hpp" #include "simplnx/DataStructure/DataStructure.hpp" @@ -9,8 +10,9 @@ #include "simplnx/Filter/Parameters.hpp" #include "simplnx/Utilities/ArrayCreationUtilities.hpp" -#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT -#include "SimplnxOoc/OocDataIOManager.hpp" +#if SIMPLNX_STORE_COPY_STRICT_FORMAT +#include "simplnx/UnitTest/PlaceholderPlanManager.hpp" +#include "simplnx/UnitTest/UnitTestCommon.hpp" #endif #include @@ -21,10 +23,11 @@ using namespace nx::core; namespace { -void RegisterOocManagerForStrictBuild() +void RegisterPlaceholderManagerForStrictBuild() { -#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT - SimplnxOoc::registerIOManager(Application::GetOrCreateInstance()->getIOCollection()); +#if SIMPLNX_STORE_COPY_STRICT_FORMAT + auto registration = UnitTest::RegisterPlaceholderPlanManager(Application::GetOrCreateInstance()->getIOCollection(), "HDF5-OOC"); + SIMPLNX_RESULT_REQUIRE_VALID(registration); #endif } } // namespace @@ -59,7 +62,7 @@ TEST_CASE("MemorySafety: WouldExceedAvailableMemory pure overload", "[MemorySafe TEST_CASE("MemorySafety: EmptyDataStore::memoryUsage in-core vs OOC", "[MemorySafety]") { - RegisterOocManagerForStrictBuild(); + RegisterPlaceholderManagerForStrictBuild(); using StoreT = EmptyDataStore; const ShapeType tupleShape{100}; // 100 tuples const ShapeType compShape{4}; // x4 components @@ -70,7 +73,7 @@ TEST_CASE("MemorySafety: EmptyDataStore::memoryUsage in-core vs OOC", "[MemorySa REQUIRE(inCore.valid()); REQUIRE(inCore.value()->memoryUsage() == logicalBytes); -#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT +#if SIMPLNX_STORE_COPY_STRICT_FORMAT // Non-empty format (OOC placeholder) -> 0 (data lives on disk). auto ooc = StoreT::Create(tupleShape, compShape, "HDF5-OOC"); REQUIRE(ooc.valid()); @@ -85,7 +88,7 @@ TEST_CASE("MemorySafety: EmptyDataStore::memoryUsage in-core vs OOC", "[MemorySa TEST_CASE("MemorySafety: CreateArray preflight emits -271 only for over-available in-core arrays", "[MemorySafety]") { - RegisterOocManagerForStrictBuild(); + RegisterPlaceholderManagerForStrictBuild(); // A tuple count whose float32 size (~4 PB) exceeds available RAM on any machine, // but is far below uint64 overflow. Preflight never allocates, so this is safe. const std::vector hugeTupleShape{uint64{1} * 1000 * 1000 * 1000 * 1000}; // 1e12 tuples @@ -113,7 +116,7 @@ TEST_CASE("MemorySafety: CreateArray preflight emits -271 only for over-availabl Result<> r = ArrayCreationUtilities::CreateArray(ds, hugeTupleShape, compShape, path, IDataAction::Mode::Preflight, "HDF5-OOC"); REQUIRE_FALSE(r.invalid()); const auto count = std::count_if(r.warnings().cbegin(), r.warnings().cend(), [](const Warning& w) { return w.code == -271; }); -#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT +#if SIMPLNX_STORE_COPY_STRICT_FORMAT REQUIRE(count == 0); #else REQUIRE(count == 1); @@ -134,7 +137,7 @@ TEST_CASE("MemorySafety: CreateArray preflight emits -271 only for over-availabl TEST_CASE("MemorySafety: DataStructure::memoryUsage counts OOC preflight arrays as 0", "[MemorySafety]") { - RegisterOocManagerForStrictBuild(); + RegisterPlaceholderManagerForStrictBuild(); DataStructure ds; DataGroup::Create(ds, "Group"); const std::vector tupleShape{1000}; @@ -145,7 +148,7 @@ TEST_CASE("MemorySafety: DataStructure::memoryUsage counts OOC preflight arrays REQUIRE_FALSE(ArrayCreationUtilities::CreateArray(ds, tupleShape, compShape, DataPath({"Group", "Ooc"}), IDataAction::Mode::Preflight, "HDF5-OOC").invalid()); // In-core builds normalize an unavailable OOC request to memory. Strict OOC builds preserve the OOC plan. -#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT +#if SIMPLNX_STORE_COPY_STRICT_FORMAT REQUIRE(ds.memoryUsage() == inCoreBytes); #else REQUIRE(ds.memoryUsage() == 2 * inCoreBytes); diff --git a/test/StorageFormatPlanTest.cpp b/test/StorageFormatPlanTest.cpp index f5451503cd..b4a83c26f4 100644 --- a/test/StorageFormatPlanTest.cpp +++ b/test/StorageFormatPlanTest.cpp @@ -1,5 +1,6 @@ #include "simplnx/Common/Result.hpp" #include "simplnx/Common/ScopeGuard.hpp" +#include "simplnx/Common/StoreCopyConfig.hpp" #include "simplnx/Core/Application.hpp" #include "simplnx/Core/Preferences.hpp" #include "simplnx/DataStructure/BaseGroup.hpp" @@ -30,9 +31,7 @@ #include "simplnx/Utilities/StoreCopyUtilities.hpp" #include -#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT -#include "SimplnxOoc/OocDataIOManager.hpp" -#endif +#include "simplnx/UnitTest/PlaceholderPlanManager.hpp" #include "simplnx/unit_test/simplnx_test_dirs.hpp" @@ -137,22 +136,6 @@ class ThrowingFormatResolver : public IDataStoreFormatResolver bool m_ThrowBadAllocation = false; }; -class PlaceholderPlanManager : public IDataIOManager -{ -public: - PlaceholderPlanManager() - { - addDataStoreCreationFnc(k_SelectedFormat.str(), [](DataType, const ShapeType&, const ShapeType&, const std::optional&, DataStoreInitializationMode) -> std::unique_ptr { - throw std::runtime_error("The metadata-only import must not invoke the value-store factory"); - }); - } - - std::string formatName() const override - { - return k_SelectedFormat.str(); - } -}; - struct ScopedTempFile { explicit ScopedTempFile(fs::path filePath) @@ -213,9 +196,32 @@ void CreateLargeMetadataFile(const fs::path& filePath) } } // namespace +TEST_CASE("StorageFormatPlan: placeholder registration preserves an existing manager", "[simplnx][StorageFormatPlan]") +{ + DataIOCollection collection; + const std::string format = "HDF5-OOC"; + auto registration = UnitTest::RegisterPlaceholderPlanManager(collection, format); + SIMPLNX_RESULT_REQUIRE_VALID(registration); + auto firstManager = collection.getManager(format); + REQUIRE(firstManager != nullptr); + REQUIRE(firstManager->hasDataStoreCreationFnc(format)); + + auto repeatedRegistration = UnitTest::RegisterPlaceholderPlanManager(collection, format); + SIMPLNX_RESULT_REQUIRE_VALID(repeatedRegistration); + REQUIRE(collection.getManager(format) == firstManager); + + // Model an application-provided manager replacing the placeholder. + auto applicationManager = std::make_shared(format); + auto applicationRegistration = collection.addIOManager(applicationManager); + SIMPLNX_RESULT_REQUIRE_VALID(applicationRegistration); + auto preservedRegistration = UnitTest::RegisterPlaceholderPlanManager(collection, format); + SIMPLNX_RESULT_REQUIRE_VALID(preservedRegistration); + REQUIRE(collection.getManager(format) == applicationManager); +} + TEST_CASE("StorageFormatPlan: numeric selection validates capability without allocating", "[StorageFormatPlan][T04][T08][T09]") { - auto manager = std::make_shared(); + auto manager = std::make_shared(k_SelectedFormat.str()); auto managerRegistrationResult = Application::GetOrCreateInstance()->getIOCollection().addIOManager(manager); SIMPLNX_RESULT_REQUIRE_VALID(managerRegistrationResult); @@ -264,7 +270,7 @@ TEST_CASE("StorageFormatPlan: numeric selection reports unsupported formats and { const std::string unavailableFormat = "storage-format-plan-unavailable"; auto unavailable = ValidateNumericStorageFormat(unavailableFormat); -#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT +#if SIMPLNX_STORE_COPY_STRICT_FORMAT REQUIRE(unavailable.invalid()); REQUIRE(unavailable.errors().size() == 1); REQUIRE(unavailable.errors()[0].code == -10600); @@ -312,7 +318,7 @@ TEST_CASE("StorageFormatPlan: factory creates validated memory and registered OO REQUIRE(namedMemoryResult.value()->getDataFormat().empty()); REQUIRE(namedMemoryResult.value()->memoryUsage() == 48); - auto manager = std::make_shared(); + auto manager = std::make_shared(k_SelectedFormat.str()); auto managerRegistrationResult = Application::GetOrCreateInstance()->getIOCollection().addIOManager(manager); SIMPLNX_RESULT_REQUIRE_VALID(managerRegistrationResult); auto registeredResult = EmptyDataStore::Create(ShapeType{6}, ShapeType{1}, k_SelectedFormat.str()); @@ -322,8 +328,9 @@ TEST_CASE("StorageFormatPlan: factory creates validated memory and registered OO REQUIRE(registeredResult.value()->getDataFormat() == k_SelectedFormat.str()); REQUIRE(registeredResult.value()->memoryUsage() == 0); -#if defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) && SIMPLNX_STORE_COPY_STRICT_FORMAT - SimplnxOoc::registerIOManager(Application::GetOrCreateInstance()->getIOCollection()); +#if SIMPLNX_STORE_COPY_STRICT_FORMAT + auto placeholderRegistration = UnitTest::RegisterPlaceholderPlanManager(Application::GetOrCreateInstance()->getIOCollection(), "HDF5-OOC"); + SIMPLNX_RESULT_REQUIRE_VALID(placeholderRegistration); auto oocResult = EmptyDataStore::Create(ShapeType{2, 3}, ShapeType{2}, "HDF5-OOC"); SIMPLNX_RESULT_REQUIRE_VALID(oocResult); REQUIRE(oocResult.value()->getStoreType() == IDataStore::StoreType::Empty); @@ -443,7 +450,7 @@ TEST_CASE("StorageFormatPlan: obsolete store getters are unavailable", "[Storage TEST_CASE("StorageFormatPlan: common getter preserves the recorded source plan", "[StorageFormatPlan]") { - auto manager = std::make_shared(); + auto manager = std::make_shared(k_SelectedFormat.str()); REQUIRE(Application::GetOrCreateInstance()->getIOCollection().addIOManager(manager).valid()); auto sourceResult = EmptyDataStore::Create(ShapeType{4}, ShapeType{1}, k_SelectedFormat.str()); SIMPLNX_RESULT_REQUIRE_VALID(sourceResult); @@ -454,7 +461,7 @@ TEST_CASE("StorageFormatPlan: common getter preserves the recorded source plan", TEST_CASE("StorageFormatPlan: Empty conversion selects metadata without allocating values", "[StorageFormatPlan][T20]") { - auto manager = std::make_shared(); + auto manager = std::make_shared(k_SelectedFormat.str()); REQUIRE(Application::GetOrCreateInstance()->getIOCollection().addIOManager(manager).valid()); auto sourceResult = EmptyDataStore::Create(ShapeType{3}, ShapeType{1}, ""); SIMPLNX_RESULT_REQUIRE_VALID(sourceResult); @@ -493,7 +500,7 @@ TEST_CASE("StorageFormatPlan: import resolver receives 100 GB logical bytes from DataStructure::setDefaultFormatResolver(inMemoryResolver); }); - auto manager = std::make_shared(); + auto manager = std::make_shared(k_SelectedFormat.str()); auto managerRegistrationResult = Application::GetOrCreateInstance()->getIOCollection().addIOManager(manager); SIMPLNX_RESULT_REQUIRE_VALID(managerRegistrationResult); DataStructure::setDefaultFormatResolver(std::make_shared(k_SelectedFormat.str())); @@ -741,7 +748,7 @@ void CheckSelectedImportDefaultResolver(const std::shared_ptrgetIOCollection().addIOManager(std::make_shared()); + const auto registration = Application::GetOrCreateInstance()->getIOCollection().addIOManager(std::make_shared(k_SelectedFormat.str())); SIMPLNX_RESULT_REQUIRE_VALID(registration); const auto incomingResolver = std::make_shared(k_SelectedFormat.str()); const auto restoreIncoming = UnitTest::SetDefaultFormatResolverForScope(incomingResolver); @@ -821,7 +828,7 @@ TEST_CASE("StorageFormatPlan: selected import does not consult process policy", TEST_CASE("StorageFormatPlan: destination policy sees all selected metadata before values", "[StorageFormatPlan][SelectedImportPolicy]") { UnitTest::LoadPlugins(); - const auto registration = Application::GetOrCreateInstance()->getIOCollection().addIOManager(std::make_shared()); + const auto registration = Application::GetOrCreateInstance()->getIOCollection().addIOManager(std::make_shared(k_SelectedFormat.str())); SIMPLNX_RESULT_REQUIRE_VALID(registration); const auto incomingResolver = std::make_shared(k_SelectedFormat.str()); const auto restoreIncoming = UnitTest::SetDefaultFormatResolverForScope(incomingResolver); @@ -928,7 +935,7 @@ class LaterImportPlanFailure : public CompleteImportContextResolver TEST_CASE("Selected import test context restores nested resolver ownership", "[StorageFormatPlan][SelectedImportPolicy][FormatResolver]") { UnitTest::LoadPlugins(); - const auto registration = Application::GetOrCreateInstance()->getIOCollection().addIOManager(std::make_shared()); + const auto registration = Application::GetOrCreateInstance()->getIOCollection().addIOManager(std::make_shared(k_SelectedFormat.str())); SIMPLNX_RESULT_REQUIRE_VALID(registration); const bool throwFromNestedScope = GENERATE(false, true); CAPTURE(throwFromNestedScope); @@ -1255,7 +1262,6 @@ TEST_CASE("C8 rollback preserves an existing destination parent and its other ch } #endif -#if !defined(SIMPLNX_STORE_COPY_STRICT_FORMAT) || !SIMPLNX_STORE_COPY_STRICT_FORMAT namespace { const DataPath k_C8FinalizerLists({"SelectedGroup", "Lists"}); @@ -1522,11 +1528,14 @@ class C8WarningPlanResolver : public RecordingFormatResolver TEST_CASE("C8 single active finalizer observes complete plans and exact leaves once", "[C8][SelectedImportFinalizer]") { - const auto application = Application::GetOrCreateInstance(); + auto& collection = Application::GetOrCreateInstance()->getIOCollection(); + if(collection.anyManagerFinalizesImport()) + { + WARN("Skipping because an import finalizer is already active."); + return; + } SelectedImportTestContext context("c8_single_finalizer.dream3d"); WriteC8FinalizerFile(context.file.path); - auto& collection = application->getIOCollection(); - REQUIRE_FALSE(collection.anyManagerFinalizesImport()); const auto manager = std::make_shared(); const auto disable = MakeScopeGuard([manager]() noexcept { manager->active = false; }); auto registration = collection.addIOManager(manager); @@ -1582,6 +1591,12 @@ TEST_CASE("C8 single active finalizer observes complete plans and exact leaves o TEST_CASE("C8 publication handoff preserves warning order and exact destination state", "[C8][SelectedImportPublication][SelectedImportFinalizer]") { UnitTest::LoadPlugins(); + auto& collection = Application::GetOrCreateInstance()->getIOCollection(); + if(collection.anyManagerFinalizesImport()) + { + WARN("Skipping because an import finalizer is already active."); + return; + } static_assert(noexcept(std::declval().swap(std::declval()))); static_assert(std::is_nothrow_move_constructible_v); enum class Outcome : uint8 @@ -1593,11 +1608,8 @@ TEST_CASE("C8 publication handoff preserves warning order and exact destination }; const auto outcome = GENERATE(Outcome::OrdinarySuccess, Outcome::InstrumentedSuccess, Outcome::PublicationFailure, Outcome::AllocationFailure); CAPTURE(static_cast(outcome)); - const auto application = Application::GetOrCreateInstance(); const SelectedImportTestContext context("c8_publication_warning_handoff.dream3d"); WriteC8LegacyPlanWarningFile(context.file.path); - auto& collection = application->getIOCollection(); - REQUIRE_FALSE(collection.anyManagerFinalizesImport()); const auto manager = std::make_shared(); const auto disable = MakeScopeGuard([manager]() noexcept { manager->active = false; }); auto registration = collection.addIOManager(manager); @@ -1711,14 +1723,17 @@ TEST_CASE("C8 publication handoff preserves warning order and exact destination TEST_CASE("C8 planning and second leaf failures retain earlier warnings without publication", "[C8][SelectedImportFinalizer]") { + auto& collection = Application::GetOrCreateInstance()->getIOCollection(); + if(collection.anyManagerFinalizesImport()) + { + WARN("Skipping because an import finalizer is already active."); + return; + } const bool planningFailure = GENERATE(false, true); const bool warm = GENERATE(false, true); CAPTURE(planningFailure, warm); - const auto application = Application::GetOrCreateInstance(); SelectedImportTestContext context("c8_failure_warning_order.dream3d"); WriteC8LegacyPlanWarningFile(context.file.path); - auto& collection = application->getIOCollection(); - REQUIRE_FALSE(collection.anyManagerFinalizesImport()); const auto manager = std::make_shared(); const auto disable = MakeScopeGuard([manager]() noexcept { manager->active = false; }); auto registration = collection.addIOManager(manager); @@ -1785,4 +1800,3 @@ TEST_CASE("C8 planning and second leaf failures retain earlier warnings without CHECK(&destination.formatResolver() == resolver.get()); CheckImportPolicyMarker(destination, marker, markerStore); } -#endif diff --git a/test/UnitTestCommon/include/simplnx/UnitTest/PlaceholderPlanManager.hpp b/test/UnitTestCommon/include/simplnx/UnitTest/PlaceholderPlanManager.hpp new file mode 100644 index 0000000000..41997dd277 --- /dev/null +++ b/test/UnitTestCommon/include/simplnx/UnitTest/PlaceholderPlanManager.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include "simplnx/DataStructure/IO/Generic/DataIOCollection.hpp" +#include "simplnx/DataStructure/IO/Generic/IDataIOManager.hpp" + +#include +#include +#include +#include + +namespace nx::core::UnitTest +{ +// Advertises numeric-store capability for metadata planning without allocating storage. +class PlaceholderPlanManager : public IDataIOManager +{ +public: + explicit PlaceholderPlanManager(std::string format) + : m_Format(std::move(format)) + { + addDataStoreCreationFnc(m_Format, [](DataType, const ShapeType&, const ShapeType&, const std::optional&, DataStoreInitializationMode) -> std::unique_ptr { + throw std::runtime_error("The metadata-only import must not invoke the value-store factory"); + }); + } + + ~PlaceholderPlanManager() noexcept override = default; + PlaceholderPlanManager(const PlaceholderPlanManager&) = delete; + PlaceholderPlanManager(PlaceholderPlanManager&&) = delete; + PlaceholderPlanManager& operator=(const PlaceholderPlanManager&) = delete; + PlaceholderPlanManager& operator=(PlaceholderPlanManager&&) = delete; + + std::string formatName() const override + { + return m_Format; + } + +private: + std::string m_Format; +}; + +// Registration replaces matching names, so retain any manager already provided by the application. +[[nodiscard]] inline Result<> RegisterPlaceholderPlanManager(DataIOCollection& collection, const std::string& format) +{ + if(collection.getManager(format) != nullptr) + { + return {}; + } + return collection.addIOManager(std::make_shared(format)); +} +} // namespace nx::core::UnitTest