diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp index 10d20b57a763b8efd27288176a3e8bb78f35a629..fda76c12cb6bc844ee21cf0b97e781670aef51fa 100644 --- a/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp +++ b/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp @@ -30,7 +30,6 @@ #include <Poco/Exception.h> #include <Poco/File.h> #include <Poco/Path.h> -#include <Poco/DateTimeFormatter.h> #include <boost/make_shared.hpp> #include <boost/algorithm/string/replace.hpp> #include <sstream> @@ -165,14 +164,15 @@ namespace Geometry * */ std::string InstrumentDefinitionParser::getMangledName() { - if(!this->m_xmlFile->exists()) - { + if (!pDoc) throw std::runtime_error("Call InstrumentDefinitionParser::initialize() before getMangledName."); + std::string lastModified = pRootElem->getAttribute("last-modified"); + if (lastModified.length() == 0) + { + g_log.warning() << "The IDF that you are using doesn't contain a 'last-modified' field. "; + g_log.warning() << "You may not get the correct definition file loaded." << std::endl ; } - - auto timeString = Poco::DateTimeFormatter::format(m_xmlFile->getLastModified(), "%Y: %dd %H:%M:%S.%i"); - - return m_xmlFile->getFileNameOnly() + timeString; + return m_xmlFile->getFileNameOnly() + lastModified; } //---------------------------------------------------------------------------------------------- diff --git a/Code/Mantid/Framework/Geometry/test/IDFObjectTest.h b/Code/Mantid/Framework/Geometry/test/IDFObjectTest.h index b495f5c1f8523419d3488920cac1d404725df05f..255359a01754faf7a0bcf5a80a35db56e94afd0e 100644 --- a/Code/Mantid/Framework/Geometry/test/IDFObjectTest.h +++ b/Code/Mantid/Framework/Geometry/test/IDFObjectTest.h @@ -4,9 +4,7 @@ #include <cxxtest/TestSuite.h> #include "MantidKernel/ConfigService.h" #include "MantidGeometry/Instrument/IDFObject.h" -#include "MantidTestHelpers/ScopedFileHelper.h" #include <Poco/Path.h> -#include <Poco/Thread.h> using Mantid::Geometry::IDFObject; using Mantid::Kernel::ConfigService; @@ -66,7 +64,7 @@ public: TS_ASSERT_EQUALS(".xml", obj.getExtension()); } - void testGetFileNameOnly() + void testGetLastModified() { const std::string filenameonly = "IDF_for_UNIT_TESTING.xml"; const std::string filename = ConfigService::Instance().getInstrumentDirectory() + "/IDFs_for_UNIT_TESTING/" + filenameonly; @@ -83,35 +81,6 @@ public: TS_ASSERT_EQUALS(file.getLastModified(), obj.getLastModified()); } - // Test that the last modified date fetched on each platform does actually make sense! - void testGetModifiedTimestampAfterChange() - { - const std::string fileName = "check_last_modified_date.xml"; - const std::string fileContents = "some_idf_contents_that_donesn't_matter"; - // Create a file. - ScopedFileHelper::ScopedFile file(fileContents, fileName); - IDFObject IDF(file.getFileName()); - // Record the modification timestamp - Poco::Timestamp timeOfCreation = IDF.getLastModified(); - // Delay - const int delay = 1; - Poco::Thread::sleep(delay); - // Modify the file. - std::ofstream modIDF; - modIDF.open(IDF.getFileFullPathStr(), std::ios::out | std::ios::app); - if (!modIDF.is_open()) - { - throw std::runtime_error("Cannot run test since file cannot be opened."); - } - modIDF << "\nchange" << std::endl; - modIDF.close(); - // Record the modification timestamp. - Poco::Timestamp timeOfModification = IDF.getLastModified(); - - // Compare the modification dates. - TSM_ASSERT("The file modification dates do not reflect the fact that the file has been modified." , timeOfModification >= (timeOfCreation + delay)); - } - void testGetFileFullPathStr() { const std::string filename = ConfigService::Instance().getInstrumentDirectory() + "/IDFs_for_UNIT_TESTING/IDF_for_UNIT_TESTING.xml"; diff --git a/Code/Mantid/Framework/Geometry/test/InstrumentDefinitionParserTest.h b/Code/Mantid/Framework/Geometry/test/InstrumentDefinitionParserTest.h index a36832fb8b2a5948b94940b5d5585b350d6233f1..82b3b35c8e96ea6647be6a3b9ce8059b6eb6807a 100644 --- a/Code/Mantid/Framework/Geometry/test/InstrumentDefinitionParserTest.h +++ b/Code/Mantid/Framework/Geometry/test/InstrumentDefinitionParserTest.h @@ -16,7 +16,7 @@ #include "MantidTestHelpers/ScopedFileHelper.h" #include <gmock/gmock.h> -#include <boost/tuple/tuple.hpp> +#include "boost/tuple/tuple.hpp" using namespace Mantid; using namespace Mantid::Kernel; @@ -156,6 +156,9 @@ public: TS_ASSERT_THROWS_NOTHING( parser.initialize(filename, "For Unit Testing", xmlText); ); TS_ASSERT_THROWS_NOTHING( i = parser.parseXML(NULL); ); + // Check the mangled name + TS_ASSERT_EQUALS( parser.getMangledName(), "IDF_for_UNIT_TESTING.xmlHello!"); + // Remove it for clean test try { Poco::File vtpFile(vtpFilename); @@ -759,6 +762,8 @@ void testLoadingAndParsing() TS_ASSERT_THROWS_NOTHING( parser.initialize(filename, "For Unit Testing", xmlText); ); TS_ASSERT_THROWS_NOTHING( i = parser.parseXML(NULL); ); + // Check the mangled name + TS_ASSERT_EQUALS( parser.getMangledName(), "IDF_for_UNIT_TESTING.xmlHello!"); // Remove it for clean test try { diff --git a/Code/Mantid/Framework/TestHelpers/src/ScopedFileHelper.cpp b/Code/Mantid/Framework/TestHelpers/src/ScopedFileHelper.cpp index 5c7f95f7275790f02bfd28a3afd961c34d7f76a3..75cdd81b294fbc8476a23cfcd8ec8e40dbab9a83 100644 --- a/Code/Mantid/Framework/TestHelpers/src/ScopedFileHelper.cpp +++ b/Code/Mantid/Framework/TestHelpers/src/ScopedFileHelper.cpp @@ -71,8 +71,8 @@ namespace ScopedFileHelper } /** - Getter for the filename with path. - @return File name and path. + Getter for the filename + @return File name only. */ std::string ScopedFile::getFileName() const {