diff --git a/Framework/Kernel/inc/MantidKernel/ICatalogInfo.h b/Framework/Kernel/inc/MantidKernel/ICatalogInfo.h index 780a261e5e29988332c1e1fbd7f59099ae38688f..39851dddf580dd23e99b1c1a66cb1d749d157cb2 100644 --- a/Framework/Kernel/inc/MantidKernel/ICatalogInfo.h +++ b/Framework/Kernel/inc/MantidKernel/ICatalogInfo.h @@ -49,7 +49,7 @@ public: /// Clone virtual ICatalogInfo *clone() const = 0; /// Transform's the archive path based on operating system used. - std::string transformArchivePath(const std::string &path) const; + virtual std::string transformArchivePath(const std::string &path) const; /// virtual destructor virtual ~ICatalogInfo(); diff --git a/MantidQt/CustomInterfaces/CMakeLists.txt b/MantidQt/CustomInterfaces/CMakeLists.txt index 099c5731b8a3a130e954309f03a7cf0317a7cc6f..5972cf588b65b4c4f3dd8b2c82ef840ab7fe4f96 100644 --- a/MantidQt/CustomInterfaces/CMakeLists.txt +++ b/MantidQt/CustomInterfaces/CMakeLists.txt @@ -47,6 +47,7 @@ set ( SRC_FILES src/Indirect/Stretch.cpp src/MantidEV.cpp src/MantidEVWorker.cpp + src/Measurement.cpp src/MultiDatasetFit/MDFAddWorkspaceDialog.cpp src/MultiDatasetFit/MDFDataController.cpp src/MultiDatasetFit/MDFDatasetPlotData.cpp @@ -164,6 +165,7 @@ set ( INC_FILES inc/MantidQtCustomInterfaces/Indirect/Stretch.h inc/MantidQtCustomInterfaces/MantidEV.h inc/MantidQtCustomInterfaces/MantidEVWorker.h + inc/MantidQtCustomInterfaces/Measurement.h inc/MantidQtCustomInterfaces/MultiDatasetFit/MDFAddWorkspaceDialog.h inc/MantidQtCustomInterfaces/MultiDatasetFit/MDFDataController.h inc/MantidQtCustomInterfaces/MultiDatasetFit/MDFDatasetPlotData.h @@ -406,6 +408,7 @@ set ( TEST_FILES EnggDiffractionPresenterTest.h IO_MuonGroupingTest.h ImageROIPresenterTest.h + MeasurementTest.h MuonAnalysisHelperTest.h ParseKeyValueStringTest.h ReflGenerateNotebookTest.h diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Measurement.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Measurement.h new file mode 100644 index 0000000000000000000000000000000000000000..97e52fc99662f9e8330e5a0d17e24605e8e979b0 --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Measurement.h @@ -0,0 +1,70 @@ +#ifndef MANTIDQT_CUSTOMINTERFACES_MEASUREMENT_H_ +#define MANTIDQT_CUSTOMINTERFACES_MEASUREMENT_H_ + +#include "MantidQtCustomInterfaces/DllConfig.h" +#include <String> + +namespace MantidQt { +namespace CustomInterfaces { + +/** Measurement : Immutable measurement type + + Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://github.com/mantidproject/mantid> + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class MANTIDQT_CUSTOMINTERFACES_DLL Measurement { + +public: + /// Constructor + Measurement(const std::string &measurementId, const std::string &subId, + const std::string &label, const std::string &type); + + /// Constructional method + static Measurement InvalidMeasurement(); + + /// Copy constructor + Measurement(const Measurement &other); + + /// Destructor + ~Measurement(); + + bool isUseable() const; + std::string id() const; + std::string subId() const; + std::string type() const; + std::string label() const; + +private: + /// Constructor + Measurement(); + const std::string m_measurementId; + const std::string m_subId; + const std::string m_label; + const std::string m_type; + bool m_valid; + /// Not assignable + Measurement &operator=(const Measurement &); +}; + +} // namespace CustomInterfaces +} // namespace MantidQt + +#endif /* MANTIDQT_CUSTOMINTERFACES_MEASUREMENT_H_ */ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMeasurementSource.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMeasurementSource.h index 2f2cb98f177aed8d96a6a4f8153153ad893b5d46..72722824ea3e9427335dc02ea5258956cdf368b3 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMeasurementSource.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMeasurementSource.h @@ -2,20 +2,12 @@ #define MANTIDQT_CUSTOMINTERFACES_REFLMEASUREMENTSOURCE_H_ #include "MantidQtCustomInterfaces/DllConfig.h" +#include "MantidQtCustomInterfaces/Measurement.h" #include <string> namespace MantidQt { namespace CustomInterfaces { -/** - * Measurement block - */ -struct Measurement { - std::string measurementId; - std::string subId; - std::string label; - std::string type; -}; /** ReflMeasurementSource : Repository pattern abstracting data mapping from domain. Specifically for accessing @@ -44,8 +36,9 @@ struct Measurement { */ class MANTIDQT_CUSTOMINTERFACES_DLL ReflMeasurementSource { public: - /// Get the measurement somehow using location - virtual Measurement obtain(const std::string &location) const = 0; + /// Get the measurement somehow using location, or fuzzy path + virtual Measurement obtain(const std::string &definedPath, + const std::string &fuzzyName) const = 0; /// Virtual destructor virtual ReflMeasurementSource *clone() const = 0; /// Destructor diff --git a/MantidQt/CustomInterfaces/src/Measurement.cpp b/MantidQt/CustomInterfaces/src/Measurement.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0c9f1d54033c4d0ee2cadcfdbe1268af506c1ccb --- /dev/null +++ b/MantidQt/CustomInterfaces/src/Measurement.cpp @@ -0,0 +1,63 @@ +#include "MantidQtCustomInterfaces/Measurement.h" + +namespace MantidQt { +namespace CustomInterfaces { + +/** + * Constructor + * @param measurementId + * @param subId + * @param label + * @param type + */ +Measurement::Measurement(const std::string &measurementId, + const std::string &subId, const std::string &label, + const std::string &type) + : m_measurementId(measurementId), m_subId(subId), m_label(label), + m_type(type), m_valid(true) { + + if (m_measurementId.empty()) { + m_valid = false; + } else if (m_subId.empty()) { + m_valid = false; + } else if (m_label.empty()) { + m_valid = false; + } else if (m_type.empty()) { + m_valid = false; + } +} + +/** + * Constructor making an invalid Measurement + */ +Measurement::Measurement() : m_valid(false) {} + +/** + * Copy constructor + * @param other + */ +Measurement::Measurement(const Measurement &other) + : m_measurementId(other.m_measurementId), m_subId(other.m_subId), + m_label(other.m_label), m_type(other.m_type), m_valid(other.m_valid) {} + +/// Destructor +Measurement::~Measurement() {} + +/** + * InvalidMeasurement static creational method + * @return Invalid measurement + */ +Measurement Measurement::InvalidMeasurement() { return Measurement(); } + +bool Measurement::isUseable() const { return m_valid; } + +std::string Measurement::id() const { return m_measurementId; } + +std::string Measurement::subId() const { return m_subId; } + +std::string Measurement::label() const { return m_label; } + +std::string Measurement::type() const { return m_type; } + +} // namespace CustomInterfaces +} // namespace Mantid diff --git a/MantidQt/CustomInterfaces/src/ReflMeasureTransferStrategy.cpp b/MantidQt/CustomInterfaces/src/ReflMeasureTransferStrategy.cpp index 99de3eef1b0439a3e92629f050e0a4440ee661da..31d4c93ddcbda3ea7a1bbc06bc7439613978e2e1 100644 --- a/MantidQt/CustomInterfaces/src/ReflMeasureTransferStrategy.cpp +++ b/MantidQt/CustomInterfaces/src/ReflMeasureTransferStrategy.cpp @@ -40,11 +40,11 @@ MantidQt::CustomInterfaces::ReflMeasureTransferStrategy::transferRuns( for (auto it = searchResults.begin(); it != searchResults.end(); ++it) { const auto location = it->second.location; - const auto run = it->first; + const auto fuzzyName = it->first; - const auto loadPath = m_catInfo->transformArchivePath(location); + const auto definedPath = m_catInfo->transformArchivePath(location); - Measurement metaData = m_measurementSource->obtain(loadPath); + Measurement metaData = m_measurementSource->obtain(definedPath, fuzzyName); /* const Poco::File filePath(loadPath); if (filePath.exists() && filePath.isFile()) { diff --git a/MantidQt/CustomInterfaces/test/MeasurementTest.h b/MantidQt/CustomInterfaces/test/MeasurementTest.h new file mode 100644 index 0000000000000000000000000000000000000000..fba52c20ba94bd3046377b372f2f4271ddc7895b --- /dev/null +++ b/MantidQt/CustomInterfaces/test/MeasurementTest.h @@ -0,0 +1,70 @@ +#ifndef MANTIDQT_CUSTOMINTERFACES_MEASUREMENTTEST_H_ +#define MANTIDQT_CUSTOMINTERFACES_MEASUREMENTTEST_H_ + +#include <cxxtest/TestSuite.h> + +#include "MantidQtCustomInterfaces/Measurement.h" + +using namespace MantidQt::CustomInterfaces; + +class MeasurementTest : public CxxTest::TestSuite { +public: + // This pair of boilerplate methods prevent the suite being created statically + // This means the constructor isn't called when running other tests + static MeasurementTest *createSuite() { return new MeasurementTest(); } + static void destroySuite(MeasurementTest *suite) { delete suite; } + + void test_invalid_construction_via_constructional_method() { + auto measure = Measurement::InvalidMeasurement(); + TS_ASSERT(!measure.isUseable()); + } + + void test_valid_construction_via_constructor() { + const std::string measurementId = "a"; + const std::string measurementSubId = "s"; + const std::string measurementLabel = "l"; + const std::string measurementType = "t"; + + Measurement measurement(measurementId, measurementSubId, measurementLabel, + measurementType); + + TS_ASSERT(measurement.isUseable()); + TS_ASSERT_EQUALS(measurementId, measurement.id()); + TS_ASSERT_EQUALS(measurementSubId, measurement.subId()); + TS_ASSERT_EQUALS(measurementLabel, measurement.label()); + TS_ASSERT_EQUALS(measurementType, measurement.type()); + } + + void test_invalid_construction_when_measurementId_empty() { + + Measurement measurement("", "measurementSubId", "measurementLabel", + "measurementType"); + + TS_ASSERT(!measurement.isUseable()); + } + + void test_invalid_construction_when_measurementSubId_empty() { + + Measurement measurement("measurementId", "", "measurementLabel", + "measurementType"); + + TS_ASSERT(!measurement.isUseable()); + } + + void test_invalid_construction_when_label_empty() { + + Measurement measurement("measurementId", "measurementSubId", "", + "measurementType"); + + TS_ASSERT(!measurement.isUseable()); + } + + void test_invalid_construction_when_type_empty() { + Measurement measurement("measurementId", "measurementSubId", + "measurementLabel", ""); + + TS_ASSERT(!measurement.isUseable()); + } +}; + +#endif /* MANTIDQT_CUSTOMINTERFACES_MEASUREMENTTEST_H_ */ diff --git a/MantidQt/CustomInterfaces/test/ReflMainViewMockObjects.h b/MantidQt/CustomInterfaces/test/ReflMainViewMockObjects.h index 57af42cab9ce788d4ae936510bea99902bfba062..cab4af2569ff3e9dca5d5d86de0e5909f8c2cc77 100644 --- a/MantidQt/CustomInterfaces/test/ReflMainViewMockObjects.h +++ b/MantidQt/CustomInterfaces/test/ReflMainViewMockObjects.h @@ -91,6 +91,7 @@ public: MOCK_CONST_METHOD0(macPrefix, const std::string()); MOCK_CONST_METHOD0(linuxPrefix, const std::string()); MOCK_CONST_METHOD0(clone, ICatalogInfo *()); + MOCK_CONST_METHOD1(transformArchivePath, std::string(const std::string &)); virtual ~MockICatalogInfo() {} }; diff --git a/MantidQt/CustomInterfaces/test/ReflMeasureTransferStrategyTest.h b/MantidQt/CustomInterfaces/test/ReflMeasureTransferStrategyTest.h index 9a906ee390849a9dd4e555bffed1d8cc8583cfef..71070def522326800f34ea12dd8fccf0dcb3519b 100644 --- a/MantidQt/CustomInterfaces/test/ReflMeasureTransferStrategyTest.h +++ b/MantidQt/CustomInterfaces/test/ReflMeasureTransferStrategyTest.h @@ -7,20 +7,20 @@ #include "MantidQtCustomInterfaces/ReflMeasurementSource.h" #include <memory> #include <gmock/gmock.h> +#include <utility> using namespace testing; +using namespace MantidQt::CustomInterfaces; class MockReflMeasurementSource : public MantidQt::CustomInterfaces::ReflMeasurementSource { public: - MOCK_CONST_METHOD1( - obtain, MantidQt::CustomInterfaces::Measurement(const std::string &)); + MOCK_CONST_METHOD2(obtain, MantidQt::CustomInterfaces::Measurement( + const std::string &, const std::string &)); MOCK_CONST_METHOD0(clone, MockReflMeasurementSource *()); ~MockReflMeasurementSource() {} }; -using MantidQt::CustomInterfaces::ReflMeasureTransferStrategy; - class ReflMeasureTransferStrategyTest : public CxxTest::TestSuite { public: // This pair of boilerplate methods prevent the suite being created statically @@ -32,6 +32,40 @@ public: delete suite; } + void test_obtain_single_measurement() { + + SearchResultMap data; + data.insert(std::make_pair<std::string, SearchResult>( + "111", SearchResult("descr", "location"))); + + auto mockMeasurementSource = new MockReflMeasurementSource; + // We expect that we are going to fetch the measurement data for every + // search result. + EXPECT_CALL(*mockMeasurementSource, obtain(_, _)) + .Times(Exactly(data.size())) + .WillRepeatedly(Return(Measurement("a", "s_a", "l", "t"))); + + auto mockCatInfo = new MockICatalogInfo; + // We expect that every location will be translated/transformed to make it + // os specific + EXPECT_CALL(*mockCatInfo, transformArchivePath(_)) + .Times(Exactly(data.size())) + .WillRepeatedly(Return(std::string())); + + MockProgressBase progress; + EXPECT_CALL(progress, doReport(_)).Times(Exactly(data.size())); + + ReflMeasureTransferStrategy strategy( + std::move(std::unique_ptr<MockICatalogInfo>(mockCatInfo)), + std::move( + std::unique_ptr<MockReflMeasurementSource>(mockMeasurementSource))); + + strategy.transferRuns(data, progress); + + TS_ASSERT(Mock::VerifyAndClear(mockCatInfo)); + TS_ASSERT(Mock::VerifyAndClear(mockMeasurementSource)); + } + void test_clone() { // Sub component ICatalogInfo will be cloned