Newer
Older
#ifndef MANTID_CUSTOMINTERFACES_REFLMEASURETRANSFERSTRATEGYTEST_H_
#define MANTID_CUSTOMINTERFACES_REFLMEASURETRANSFERSTRATEGYTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidQtCustomInterfaces/ReflMeasureTransferStrategy.h"
#include "MantidQtCustomInterfaces/ReflMeasurementSource.h"
#include <memory>
#include <gmock/gmock.h>
using namespace MantidQt::CustomInterfaces;
class MockReflMeasurementSource
: public MantidQt::CustomInterfaces::ReflMeasurementSource {
public:
MOCK_CONST_METHOD2(obtain, MantidQt::CustomInterfaces::Measurement(
const std::string &, const std::string &));
MOCK_CONST_METHOD0(clone, MockReflMeasurementSource *());
~MockReflMeasurementSource() {}
};
class ReflMeasureTransferStrategyTest : 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 ReflMeasureTransferStrategyTest *createSuite() {
return new ReflMeasureTransferStrategyTest();
}
static void destroySuite(ReflMeasureTransferStrategyTest *suite) {
delete suite;
}
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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));
}
// Sub component ICatalogInfo will be cloned
auto pCatInfo = new MockICatalogInfo;
EXPECT_CALL(*pCatInfo, clone()).WillOnce(Return(new MockICatalogInfo));
// Sub component Measurment source will be cloned
auto pMeasurementSource = new MockReflMeasurementSource;
EXPECT_CALL(*pMeasurementSource, clone())
.WillOnce(Return(new MockReflMeasurementSource));
// Create it
ReflMeasureTransferStrategy strategy(
std::move(std::unique_ptr<MockICatalogInfo>(pCatInfo)),
std::move(
std::unique_ptr<MockReflMeasurementSource>(pMeasurementSource)));
// Clone it
auto *clone = strategy.clone();
TS_ASSERT(dynamic_cast<ReflMeasureTransferStrategy *>(clone));
delete clone;
}
void test_filtering() {
ReflMeasureTransferStrategy strategy(
std::unique_ptr<MockICatalogInfo>(new MockICatalogInfo),
std::unique_ptr<MockReflMeasurementSource>(
new MockReflMeasurementSource));
// ISIS nexus format files can have the right logs.
TSM_ASSERT("Yes this transfer mechanism should know about nexus formats",
strategy.knownFileType("madeup.nxs"));
// Raw files do not have the necessary logs
TSM_ASSERT("No this transfer mechanism should know about anything but "
"nexus formats",
!strategy.knownFileType("madeup.raw"));
}
};
#endif /* MANTID_CUSTOMINTERFACES_REFLMEASURETRANSFERSTRATEGYTEST_H_ */