Newer
Older
#ifndef PROPERTYMANAGERTEST_H_
#define PROPERTYMANAGERTEST_H_
#include <cxxtest/TestSuite.h>
#include "../inc/PropertyManager.h"
#include "../inc/PropertyWithValue.h"
#include <iostream>
using namespace Mantid::Kernel;
class PropertyManagerTest : public CxxTest::TestSuite
{
public:
PropertyManagerTest()
{
Property *p = new PropertyWithValue<int>("aProp",1);
manager.declareProperty(p);
}
void testConstructor()
{
PropertyManager mgr;
std::vector<Property*> props = mgr.getProperties();
TS_ASSERT( props.empty() )
}
void testdeclareProperty_pointer()
{
PropertyManager mgr;
Property *p = new PropertyWithValue<double>("myProp", 9.99);
TS_ASSERT_THROWS_NOTHING( mgr.declareProperty(p) )
TS_ASSERT( mgr.existsProperty(p->name()) )
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
TS_ASSERT( ! mgr.getPropertyValue("myProp").compare("9.99") )
TS_ASSERT_THROWS( mgr.declareProperty(p), Exception::ExistsError )
}
void testdeclareProperty_int()
{
PropertyManager mgr;
TS_ASSERT_THROWS_NOTHING( mgr.declareProperty("myProp", 1, "hello") )
TS_ASSERT( ! mgr.getPropertyValue("myProp").compare("1") )
Property *p = mgr.getProperty("myProp");
TS_ASSERT( ! p->documentation().compare("hello") )
TS_ASSERT_THROWS( mgr.declareProperty("MYPROP", 5), Exception::ExistsError )
}
void testdeclareProperty_double()
{
PropertyManager mgr;
TS_ASSERT_THROWS_NOTHING( mgr.declareProperty("myProp", 9.99, "hello") )
TS_ASSERT( ! mgr.getPropertyValue("myProp").compare("9.99") )
Property *p = mgr.getProperty("myProp");
TS_ASSERT( ! p->documentation().compare("hello") )
TS_ASSERT_THROWS( mgr.declareProperty("MYPROP", 5), Exception::ExistsError )
}
void testdeclareProperty_string()
{
PropertyManager mgr;
TS_ASSERT_THROWS_NOTHING( mgr.declareProperty("myProp", "theValue", "hello") )
TS_ASSERT( ! mgr.getPropertyValue("myProp").compare("theValue") )
Property *p = mgr.getProperty("myProp");
TS_ASSERT( ! p->documentation().compare("hello") )
TS_ASSERT_THROWS( mgr.declareProperty("MYPROP", 5), Exception::ExistsError )
}
void testSetProperty()
{
manager.setProperty("APROP","10");
TS_ASSERT( ! manager.getPropertyValue("aProp").compare("10") )
manager.setProperty("aProp","1");
TS_ASSERT_THROWS( manager.setProperty("fhfjsdf","0"), Exception::NotFoundError )
}
void testExistsProperty()
{
Property *p = new PropertyWithValue<int>("sjfudh",0);
TS_ASSERT( ! manager.existsProperty(p->name()) )
Property *pp = new PropertyWithValue<double>("APROP",9.99);
// Note that although the name of the property is the same, the type is different - yet it passes
TS_ASSERT( manager.existsProperty(pp->name()) )
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
}
void testGetPropertyValue()
{
TS_ASSERT( ! manager.getPropertyValue("APROP").compare("1") )
TS_ASSERT_THROWS( manager.getPropertyValue("sdfshdu"), Exception::NotFoundError )
}
void testGetProperty()
{
Property *p = manager.getProperty("APROP");
TS_ASSERT( p )
TS_ASSERT( ! p->name().compare("aProp") )
TS_ASSERT( ! p->value().compare("1") )
TS_ASSERT( ! p->documentation().compare("") )
TS_ASSERT( typeid(int) == *p->type_info() )
TS_ASSERT_THROWS( manager.getProperty("werhui"), Exception::NotFoundError )
}
void testGetProperties()
{
std::vector<Property*> props = manager.getProperties();
TS_ASSERT( props.size() == 1 )
Property *p = props[0];
TS_ASSERT( ! p->name().compare("aProp") )
TS_ASSERT( ! p->value().compare("1") )
}
private:
PropertyManager manager;
};
#endif /*PROPERTYMANAGERTEST_H_*/