Newer
Older
#ifndef MANDATORYVALIDATORTEST_H_
#define MANDATORYVALIDATORTEST_H_
#include <string>
#include <cxxtest/TestSuite.h>
#include "MantidKernel/MandatoryValidator.h"
#include "MantidKernel/OptionalBool.h"
class MandatoryValidatorTest : public CxxTest::TestSuite {
Russell Taylor
committed
TS_ASSERT_THROWS_NOTHING(MandatoryValidator<std::string> nsv)
TS_ASSERT_THROWS_NOTHING(MandatoryValidator<std::vector<int>> nsv)
TS_ASSERT_THROWS_NOTHING(MandatoryValidator<std::vector<double>> nsv)
TS_ASSERT_THROWS_NOTHING(MandatoryValidator<std::vector<std::string>> nsv)
}
void testClone() {
IValidator_sptr v = boost::make_shared<MandatoryValidator<std::string>>();
IValidator_sptr vv = v->clone();
TS_ASSERT_DIFFERS(v, vv);
TS_ASSERT(boost::dynamic_pointer_cast<MandatoryValidator<std::string>>(vv));
Russell Taylor
committed
IValidator_sptr i =
boost::make_shared<MandatoryValidator<std::vector<int>>>();
IValidator_sptr ii = i->clone();
TS_ASSERT_DIFFERS(i, ii)
TS_ASSERT(
boost::dynamic_pointer_cast<MandatoryValidator<std::vector<int>>>(ii))
Russell Taylor
committed
IValidator_sptr d =
boost::make_shared<MandatoryValidator<std::vector<double>>>();
IValidator_sptr dd = d->clone();
TS_ASSERT_DIFFERS(d, dd);
TS_ASSERT(
boost::dynamic_pointer_cast<MandatoryValidator<std::vector<double>>>(
dd));
Russell Taylor
committed
IValidator_sptr s =
boost::make_shared<MandatoryValidator<std::vector<std::string>>>();
IValidator_sptr ss = s->clone();
TS_ASSERT_DIFFERS(s, ss);
TS_ASSERT(boost::dynamic_pointer_cast<
MandatoryValidator<std::vector<std::string>>>(ss));
}
Russell Taylor
committed
MandatoryValidator<std::string> p;
Steve Williams
committed
TS_ASSERT_EQUALS(p.isValid("AZ"), "");
TS_ASSERT_EQUALS(p.isValid("B"), "");
TS_ASSERT_EQUALS(p.isValid(""),
"A value must be entered for this parameter");
TS_ASSERT_EQUALS(p.isValid("ta"), "");
Russell Taylor
committed
MandatoryValidator<std::vector<int>> i;
Russell Taylor
committed
std::vector<int> ivec;
TS_ASSERT(ivec.empty())
TS_ASSERT_EQUALS(i.isValid(ivec),
"A value must be entered for this parameter")
Russell Taylor
committed
ivec.push_back(1);
TS_ASSERT_EQUALS(i.isValid(ivec), "")
Russell Taylor
committed
MandatoryValidator<std::vector<double>> d;
Russell Taylor
committed
std::vector<double> dvec;
TS_ASSERT(dvec.empty())
TS_ASSERT_EQUALS(d.isValid(dvec),
"A value must be entered for this parameter")
Russell Taylor
committed
dvec.push_back(1.1);
TS_ASSERT_EQUALS(d.isValid(dvec), "")
Russell Taylor
committed
MandatoryValidator<std::vector<std::string>> s;
Russell Taylor
committed
std::vector<std::string> svec;
TS_ASSERT(svec.empty())
TS_ASSERT_EQUALS(s.isValid(svec),
"A value must be entered for this parameter")
TS_ASSERT_EQUALS(s.isValid(svec), "")
Gigg, Martyn Anthony
committed
MandatoryValidator<int> validate_int;
TS_ASSERT_EQUALS(validate_int.isValid(5), "");
TS_ASSERT_EQUALS(validate_int.isValid(-10000), "");
Gigg, Martyn Anthony
committed
MandatoryValidator<double> validate_dbl;
TS_ASSERT_EQUALS(validate_dbl.isValid(5.0), "");
TS_ASSERT_EQUALS(validate_dbl.isValid(-250.0), "");
}
void testMandatoryValidatorOptionalBool() {
MandatoryValidator<OptionalBool> validator;
OptionalBool defaultValue;
TS_ASSERT(!validator.isValid(defaultValue).empty());
OptionalBool notDefaultIsTrue(OptionalBool::True);
TS_ASSERT(validator.isValid(notDefaultIsTrue).empty());
OptionalBool notDefaultIsFalse(OptionalBool::False);
TS_ASSERT(validator.isValid(notDefaultIsFalse).empty());
}