Newer
Older
Gigg, Martyn Anthony
committed
#ifndef MANTID_API_ALGORITHMHASPROPERTYTEST_H_
#define MANTID_API_ALGORITHMHASPROPERTYTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidAPI/AlgorithmHasProperty.h"
#include "MantidAPI/Algorithm.h"
#include "MantidKernel/BoundedValidator.h"
using namespace Mantid::API;
class AlgorithmHasPropertyTest : public CxxTest::TestSuite {
Gigg, Martyn Anthony
committed
private:
class AlgorithmWithWorkspace : public Algorithm {
Gigg, Martyn Anthony
committed
public:
const std::string name() const override { return "AlgorithmWithWorkspace"; }
int version() const override { return 1; }
const std::string category() const override { return "Cat"; }
const std::string summary() const override { return "Test summary"; }
void init() override { declareProperty("OutputWorkspace", ""); }
void exec() override {}
Gigg, Martyn Anthony
committed
};
class AlgorithmWithNoWorkspace : public Algorithm {
Gigg, Martyn Anthony
committed
public:
const std::string name() const override {
return "AlgorithmWithNoWorkspace";
}
int version() const override { return 1; }
const std::string category() const override { return "Cat"; }
const std::string summary() const override { return "Test summary"; }
void init() override { declareProperty("NotOutputWorkspace", ""); }
void exec() override {}
Gigg, Martyn Anthony
committed
};
class AlgorithmWithInvalidProperty : public Algorithm {
Gigg, Martyn Anthony
committed
public:
const std::string name() const override {
return "AlgorithmWithInvalidProperty";
}
int version() const override { return 1; }
const std::string category() const override { return "Cat"; }
const std::string summary() const override { return "Test summary"; }
auto lower = boost::make_shared<Mantid::Kernel::BoundedValidator<int>>();
Gigg, Martyn Anthony
committed
lower->setLower(0);
declareProperty("OutputValue", -1, lower);
Gigg, Martyn Anthony
committed
}
Gigg, Martyn Anthony
committed
};
public:
void test_Algorithm_With_Correct_Property_Is_Valid() {
AlgorithmHasProperty check("OutputWorkspace");
Gigg, Martyn Anthony
committed
IAlgorithm_sptr tester(new AlgorithmWithWorkspace);
tester->initialize();
tester->execute();
TS_ASSERT_EQUALS(check.isValid(tester), "");
Gigg, Martyn Anthony
committed
}
void test_Algorithm_Without_Property_Is_Invalid() {
AlgorithmHasProperty check("OutputWorkspace");
Gigg, Martyn Anthony
committed
IAlgorithm_sptr tester(new AlgorithmWithNoWorkspace);
tester->initialize();
tester->execute();
TS_ASSERT_EQUALS(check.isValid(tester), "Algorithm object does not have "
"the required property "
"\"OutputWorkspace\"");
Gigg, Martyn Anthony
committed
}
void test_Algorithm_With_Invalid_Property_Is_Invalid() {
AlgorithmHasProperty check("OutputValue");
Gigg, Martyn Anthony
committed
IAlgorithm_sptr tester(new AlgorithmWithInvalidProperty);
tester->initialize();
TS_ASSERT_EQUALS(
check.isValid(tester),
"Algorithm object contains the required property \"OutputValue\" but "
"it has an invalid value: -1");
Gigg, Martyn Anthony
committed
}
};
#endif /* MANTID_API_ALGORITHMHASPROPERTY_H_ */