diff --git a/Framework/DataHandling/inc/MantidDataHandling/SaveNXSPE.h b/Framework/DataHandling/inc/MantidDataHandling/SaveNXSPE.h index fbce5510abd0..c64c7035d1a2 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/SaveNXSPE.h +++ b/Framework/DataHandling/inc/MantidDataHandling/SaveNXSPE.h @@ -63,6 +63,8 @@ class MANTID_DATAHANDLING_DLL SaveNXSPE final : public API::Algorithm { void init() override; /// Execution code void exec() override; + /// Validate Inputs code + std::map validateInputs() override; // Some constants to be written for masked values. /// Value for data if pixel is masked diff --git a/Framework/DataHandling/src/SaveNXSPE.cpp b/Framework/DataHandling/src/SaveNXSPE.cpp index b0e0624fd646..11afeea34bb3 100644 --- a/Framework/DataHandling/src/SaveNXSPE.cpp +++ b/Framework/DataHandling/src/SaveNXSPE.cpp @@ -74,6 +74,15 @@ void SaveNXSPE::init() { See [[FindDetectorsPar]] description for the details."); } +std::map SaveNXSPE::validateInputs() { + std::map issues; + std::string inputWS = getPropertyValue("InputWorkspace"); + if (inputWS.find("/") != std::string::npos) { + issues["InputWorkspace"] = "The input workspace name cannot contain a '/' character."; + } + return issues; +} + /** * Execute the algorithm */ diff --git a/Framework/DataHandling/test/SaveNXSPETest.h b/Framework/DataHandling/test/SaveNXSPETest.h index daa8a5c72b8d..c4fe758d0d5c 100644 --- a/Framework/DataHandling/test/SaveNXSPETest.h +++ b/Framework/DataHandling/test/SaveNXSPETest.h @@ -8,6 +8,7 @@ #include +#include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/NumericAxis.h" #include "MantidDataHandling/LoadInstrument.h" @@ -190,6 +191,20 @@ class SaveNXSPETest : public CxxTest::TestSuite { Poco::File(outputFile).remove(); } + void test_WorkspaceNameData() { + auto saver = setupWithWSName("data"); + TS_ASSERT_THROWS_NOTHING(saver->execute()); + TS_ASSERT(saver->isExecuted()); + } + + void test_WorkspaceBadName() { + auto saver = setupWithWSName("bad/name"); + TS_ASSERT_THROWS_EQUALS(saver->execute(), const std::runtime_error &e, std::string(e.what()), + "Some invalid Properties found: \n" + " InputWorkspace: The input workspace name cannot contain a \'/\' character."); + TS_ASSERT(!saver->isExecuted()); + } + private: MatrixWorkspace_sptr makeWS_direct(MatrixWorkspace_sptr inputWS, double ei = 12.0) { std::unique_ptr> mode( @@ -305,4 +320,21 @@ class SaveNXSPETest : public CxxTest::TestSuite { return boost::make_tuple(dims, signal, error, efixed); } + + SaveNXSPE *setupWithWSName(const std::string &workspaceName) { + MatrixWorkspace_sptr input = makeWorkspace(); + Mantid::API::AnalysisDataService::Instance().add(workspaceName, input); + + auto *saver = new SaveNXSPE(); + saver->initialize(); + saver->setChild(true); + TS_ASSERT_THROWS_NOTHING(saver->setProperty("InputWorkspace", workspaceName)); + TS_ASSERT_EQUALS(saver->getPropertyValue("InputWorkspace"), workspaceName); + std::string outputFile("SaveNXSPETest_testEXEC.nxspe"); + TS_ASSERT_THROWS_NOTHING(saver->setPropertyValue("Filename", outputFile)); + outputFile = saver->getPropertyValue("Filename"); // get absolute path + TS_ASSERT_THROWS_NOTHING(saver->setProperty("Psi", 0.0)); + TS_ASSERT_THROWS_NOTHING(saver->setProperty("KiOverKfScaling", true)); + return saver; + } }; diff --git a/Framework/Nexus/inc/MantidNexus/nxstack.h b/Framework/Nexus/inc/MantidNexus/nxstack.h index bb10b6674af4..5deeb0aa1c7e 100644 --- a/Framework/Nexus/inc/MantidNexus/nxstack.h +++ b/Framework/Nexus/inc/MantidNexus/nxstack.h @@ -45,7 +45,7 @@ void setCloseID(pFileStack self, const NXlink &id); int fileStackDepth(pFileStack self); -void pushPath(pFileStack self, const char *name); +void pushPath(pFileStack self, const char *name, bool isdata = false); void popPath(pFileStack self); int buildPath(pFileStack self, char *path, int pathlen); diff --git a/Framework/Nexus/src/napi.cpp b/Framework/Nexus/src/napi.cpp index e7868d8b9f18..9c429b276b8a 100644 --- a/Framework/Nexus/src/napi.cpp +++ b/Framework/Nexus/src/napi.cpp @@ -675,7 +675,7 @@ NXstatus NXopendata(NXhandle fid, CONSTCHAR *name) { status = LOCKED_CALL(pFunc->nxopendata(pFunc->pNexusData, name)); if (status == NXstatus::NX_OK) { - pushPath(fileStack, name); + pushPath(fileStack, name, true); } char nxurl[1024]; diff --git a/Framework/Nexus/src/nxstack.cpp b/Framework/Nexus/src/nxstack.cpp index e4f37319ca7c..135d46255b57 100644 --- a/Framework/Nexus/src/nxstack.cpp +++ b/Framework/Nexus/src/nxstack.cpp @@ -84,8 +84,8 @@ void setCloseID(pFileStack self, const NXlink &id) { self->fileStack[self->fileS /*----------------------------------------------------------------------*/ int fileStackDepth(pFileStack self) { return self->fileStackPointer; } /*----------------------------------------------------------------------*/ -void pushPath(pFileStack self, const char *name) { - if (self->pathPointer >= 0 && name == self->pathStack[self->pathPointer]) { +void pushPath(pFileStack self, const char *name, bool isdata) { + if (self->pathPointer >= 0 && name == self->pathStack[self->pathPointer] && isdata) { return; } self->pathPointer++; diff --git a/Framework/Nexus/test/NeXusFileTest.h b/Framework/Nexus/test/NeXusFileTest.h index 3f35e6880b08..5ab7d1c0c3ba 100644 --- a/Framework/Nexus/test/NeXusFileTest.h +++ b/Framework/Nexus/test/NeXusFileTest.h @@ -137,6 +137,20 @@ class NeXusFileTest : public CxxTest::TestSuite { TS_ASSERT_THROWS_NOTHING(file.makeGroup(grp, cls)); } + void test_same_make_group() { + cout << "\ntest same makeGroup\n"; + FileResource resource("test_nexus_file_grp.h5"); + std::string filename = resource.fullPath(); + NeXus::File file(filename, NXACC_CREATE5); + + string grp("test_group"); + + // check that we can make '/test_group/test_group' + TS_ASSERT_THROWS_NOTHING(file.makeGroup(grp, "NXsample", true)); + TS_ASSERT_THROWS_NOTHING(file.makeGroup(grp, "NXdata", true)); + TS_ASSERT_EQUALS(file.getPath(), "/test_group/test_group"); + } + void test_open_group() { cout << "\ntest openGroup\n"; FileResource resource("test_nexus_file_grp.h5"); diff --git a/buildconfig/CMake/CppCheck_Suppressions.txt.in b/buildconfig/CMake/CppCheck_Suppressions.txt.in index cfc57328ec2a..b35a327551bf 100644 --- a/buildconfig/CMake/CppCheck_Suppressions.txt.in +++ b/buildconfig/CMake/CppCheck_Suppressions.txt.in @@ -291,7 +291,7 @@ constVariableReference:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/SaveCanSAS uselessCallsSubstr:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/SaveFocusedXYE.cpp:73 constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/SaveGSS.cpp:432 constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/SaveGSS.cpp:566 -constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/SaveNXSPE.cpp:324 +constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/SaveNXSPE.cpp:333 constVariableReference:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/SaveNXTomo.cpp:150 knownConditionTrueFalse:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/SaveNexusProcessed.cpp:572 syntaxError:${CMAKE_SOURCE_DIR}/Framework/DataObjects/inc/MantidDataObjects/MortonIndex/CoordinateConversion.h:109