Newer
Older
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
#ifndef PROPERTYWITHVALUETEST_H_
#define PROPERTYWITHVALUETEST_H_
#include <cxxtest/TestSuite.h>
#include "../inc/PropertyWithValue.h"
using namespace Mantid::Kernel;
class PropertyWithValueTest : public CxxTest::TestSuite
{
public:
PropertyWithValueTest()
{
iProp = new PropertyWithValue<int>("intProp", 1);
dProp = new PropertyWithValue<double>("doubleProp", 9.99);
sProp = new PropertyWithValue<std::string>("stringProp", "theValue");
}
void testConstructor()
{
// Test that all the base class member variables are correctly assigned to
TS_ASSERT( ! iProp->name().compare("intProp") )
TS_ASSERT( ! iProp->documentation().compare("") )
TS_ASSERT( typeid( int ) == *iProp->type_info() )
TS_ASSERT( iProp->isDefault() )
TS_ASSERT( ! dProp->name().compare("doubleProp") )
TS_ASSERT( ! dProp->documentation().compare("") )
TS_ASSERT( typeid( double ) == *dProp->type_info() )
TS_ASSERT( dProp->isDefault() )
TS_ASSERT( ! sProp->name().compare("stringProp") )
TS_ASSERT( ! sProp->documentation().compare("") )
TS_ASSERT( typeid( std::string ) == *sProp->type_info() )
TS_ASSERT( sProp->isDefault() )
}
void testValue()
{
TS_ASSERT( ! iProp->value().compare("1") )
TS_ASSERT( ! dProp->value().compare("9.99") )
TS_ASSERT( ! sProp->value().compare("theValue") )
}
void testSetValue()
{
PropertyWithValue<int> i("test", 1);
TS_ASSERT( i.setValue("10") )
TS_ASSERT_EQUALS( i, 10 )
TS_ASSERT( ! i.setValue("9.99") )
TS_ASSERT( ! i.setValue("garbage") )
PropertyWithValue<double> d("test", 5.55);
TS_ASSERT( d.setValue("-9.99") )
TS_ASSERT_EQUALS( d, -9.99 )
TS_ASSERT( d.setValue("0") )
TS_ASSERT_EQUALS( d, 0 )
TS_ASSERT( ! d.setValue("garbage") )
PropertyWithValue<std::string> s("test", "test");
TS_ASSERT( s.setValue("-9.99") )
TS_ASSERT_EQUALS( s.operator()(), "-9.99" )
TS_ASSERT( s.setValue("0") )
TS_ASSERT_EQUALS( s.operator()(), "0" )
TS_ASSERT( s.setValue("it works") )
TS_ASSERT_EQUALS( s.operator()(), "it works" )
}
void testCopyConstructor()
{
PropertyWithValue<int> i = *iProp;
TS_ASSERT( ! i.name().compare("intProp") )
TS_ASSERT( ! i.documentation().compare("") )
TS_ASSERT( typeid( int ) == *i.type_info() )
TS_ASSERT( i.isDefault() )
TS_ASSERT_EQUALS( i, 1 )
Russell Taylor
committed
PropertyWithValue<double> d = *dProp;
TS_ASSERT( ! d.name().compare("doubleProp") )
TS_ASSERT( ! d.documentation().compare("") )
TS_ASSERT( typeid( double ) == *d.type_info() )
TS_ASSERT( d.isDefault() )
TS_ASSERT_EQUALS( d, 9.99 )
PropertyWithValue<std::string> s = *sProp;
TS_ASSERT( ! s.name().compare("stringProp") )
TS_ASSERT( ! s.documentation().compare("") )
TS_ASSERT( typeid( std::string ) == *s.type_info() )
TS_ASSERT( s.isDefault() )
TS_ASSERT_EQUALS( sProp->operator()(), "theValue" )
}
void testCopyAssignmentOperator()
{
Russell Taylor
committed
PropertyWithValue<int> i("Prop1",5);
i = *iProp;
TS_ASSERT( ! i.name().compare("Prop1") )
TS_ASSERT( ! i.documentation().compare("") )
TS_ASSERT( ! i.isDefault() )
TS_ASSERT_EQUALS( i, 1 )
PropertyWithValue<double> d("Prop2",5.5);
d = *dProp;
TS_ASSERT( ! d.name().compare("Prop2") )
TS_ASSERT( ! d.documentation().compare("") )
TS_ASSERT( ! d.isDefault() )
TS_ASSERT_EQUALS( d, 9.99 )
PropertyWithValue<std::string> s("Prop3","test");
s = *sProp;
TS_ASSERT( ! s.name().compare("Prop3") )
TS_ASSERT( ! s.documentation().compare("") )
TS_ASSERT( ! s.isDefault() )
TS_ASSERT_EQUALS( sProp->operator()(), "theValue" )
}
void testAssignmentOperator()
{
Russell Taylor
committed
PropertyWithValue<int> i("Prop1",5);
TS_ASSERT_EQUALS( i = 2, 2 )
PropertyWithValue<double> d("Prop2",5.5);
TS_ASSERT_EQUALS( d = 7.77, 7.77 )
PropertyWithValue<std::string> s("Prop3", "testing");
s = "test";
TS_ASSERT_EQUALS( s.operator()(), "test" )
PropertyWithValue<int> ii("Prop1.1",6);
i = ii = 10;
TS_ASSERT_EQUALS( ii, 10 )
TS_ASSERT_EQUALS( i, 10 )
PropertyWithValue<double> dd("Prop2.2",6.5);
d = dd = 1.111;
TS_ASSERT_EQUALS( dd, 1.111 )
TS_ASSERT_EQUALS( d, 1.111 )
PropertyWithValue<std::string> ss("Prop3", "testing2");
s = ss = "tested";
TS_ASSERT_EQUALS( ss.operator()(), "tested" )
TS_ASSERT_EQUALS( s.operator()(), "tested" )
}
void testOperatorBrackets()
{
TS_ASSERT_EQUALS( iProp->operator()(), 1 )
TS_ASSERT_EQUALS( dProp->operator()(), 9.99 )
TS_ASSERT_EQUALS( sProp->operator()(), "theValue" )
}
void testOperatorNothing()
{
int i = *iProp;
TS_ASSERT_EQUALS( i, 1 )
double d = *dProp;
TS_ASSERT_EQUALS( d, 9.99 )
std::string str(*sProp);
TS_ASSERT( ! str.compare("theValue") )
}
Russell Taylor
committed
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
void testCasting()
{
TS_ASSERT_DIFFERS( dynamic_cast<Property*>(iProp), static_cast<Property*>(0) )
PropertyWithValue<int> i("Prop1",5);
Property *p = dynamic_cast<Property*>(&i);
TS_ASSERT( ! p->name().compare("Prop1") )
TS_ASSERT( ! p->value().compare("5") )
TS_ASSERT( p->setValue("10") )
TS_ASSERT( ! p->value().compare("10") )
TS_ASSERT_EQUALS( i, 10 )
TS_ASSERT_DIFFERS( dynamic_cast<Property*>(dProp), static_cast<Property*>(0) )
PropertyWithValue<double> d("Prop2",5.5);
Property *pp = dynamic_cast<Property*>(&d);
TS_ASSERT( ! pp->name().compare("Prop2") )
TS_ASSERT( ! pp->value().compare("5.5") )
TS_ASSERT( pp->setValue("7.777") )
TS_ASSERT( ! pp->value().compare("7.777") )
TS_ASSERT_EQUALS( d, 7.777 )
TS_ASSERT_DIFFERS( dynamic_cast<Property*>(sProp), static_cast<Property*>(0) )
PropertyWithValue<std::string> s("Prop3", "testing");
Property *ppp = dynamic_cast<Property*>(&s);
TS_ASSERT( ! ppp->name().compare("Prop3") )
TS_ASSERT( ! ppp->value().compare("testing") )
TS_ASSERT( ppp->setValue("newValue") )
TS_ASSERT( ! ppp->value().compare("newValue") )
TS_ASSERT_EQUALS( s.operator()(), "newValue" )
}
private:
PropertyWithValue<int> *iProp;
PropertyWithValue<double> *dProp;
PropertyWithValue<std::string> *sProp;
};
#endif /*PROPERTYWITHVALUETEST_H_*/