/
ListValidatorTest.h
83 lines (70 loc) · 2.27 KB
/
ListValidatorTest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef LISTVALIDATORTEST_H_
#define LISTVALIDATORTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidKernel/ListValidator.h"
using namespace Mantid::Kernel;
class ListValidatorTest : public CxxTest::TestSuite
{
public:
void testEmptyConstructor()
{
StringListValidator v;
TS_ASSERT( v.allowedValues().empty() )
}
void testVectorConstructor()
{
std::vector<std::string> vec;
vec.push_back("one");
vec.push_back("two");
vec.push_back("three");
StringListValidator v(vec);
TS_ASSERT_EQUALS( v.allowedValues().size(), 3 )
}
void testIsValid()
{
StringListValidator v;
TS_ASSERT_EQUALS( v.isValid(""), "Select a value" )
TS_ASSERT_EQUALS( v.isValid("b"),
"The value \"b\" is not in the list of allowed values")
v.addAllowedValue("a");
TS_ASSERT_EQUALS( v.isValid(""),
"Select a value" )
TS_ASSERT_EQUALS( v.isValid("a"), "" )
TS_ASSERT_EQUALS( v.isValid("b"),
"The value \"b\" is not in the list of allowed values")
TS_ASSERT_EQUALS( v.isValid("A"),
"The value \"A\" is not in the list of allowed values")
}
void testAllowedValues()
{
StringListValidator v;
v.addAllowedValue("one");
v.addAllowedValue("two");
std::vector<std::string> s;
TS_ASSERT_THROWS_NOTHING( s = v.allowedValues() )
TS_ASSERT_EQUALS( s.size(), 2 )
TS_ASSERT( std::find( s.begin(), s.end(), "one") != s.end() )
TS_ASSERT( std::find( s.begin(), s.end(), "two") != s.end() )
TS_ASSERT( std::find( s.begin(), s.end(), "three") == s.end() )
}
void testAddAllowedValue()
{
StringListValidator v;
TS_ASSERT( v.allowedValues().empty() )
TS_ASSERT_THROWS_NOTHING( v.addAllowedValue("x") )
TS_ASSERT_EQUALS( v.allowedValues().size(), 1 )
TS_ASSERT_EQUALS( v.isValid("x"), "" )
// Try adding again just to make sure the instruction is ignored, but doesn't throw
TS_ASSERT_THROWS_NOTHING( v.addAllowedValue("x") )
TS_ASSERT_EQUALS( v.allowedValues().size(), 1 )
TS_ASSERT_EQUALS( v.isValid("x"), "" )
}
void testClone()
{
IValidator_sptr v(new StringListValidator);
IValidator_sptr vv = v->clone();
TS_ASSERT_DIFFERS( v, vv );
TS_ASSERT( boost::dynamic_pointer_cast<StringListValidator>(vv) );
}
};
#endif /*LISTVALIDATORTEST_H_*/