From 978d95bf07607bf1b3a8a5d27f5cd347394efcf7 Mon Sep 17 00:00:00 2001 From: Owen Arnold <owen.arnold@stfc.ac.uk> Date: Fri, 16 Nov 2012 11:43:05 +0000 Subject: [PATCH] Revert "refs #6105. Use actual modified date instead." This reverts commit 86fcf7ca4b749342846ee0dd20eb6ae063509a5a. --- .../Instrument/InstrumentDefinitionParser.cpp | 14 ++++---- .../Framework/Geometry/test/IDFObjectTest.h | 33 +------------------ .../test/InstrumentDefinitionParserTest.h | 7 +++- .../TestHelpers/src/ScopedFileHelper.cpp | 4 +-- 4 files changed, 16 insertions(+), 42 deletions(-) diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp index 10d20b57a76..fda76c12cb6 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 b495f5c1f85..255359a0175 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 a36832fb8b2..82b3b35c8e9 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 5c7f95f7275..75cdd81b294 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 { -- GitLab