25 #ifndef WPROPERTIES_TEST_H
26 #define WPROPERTIES_TEST_H
30 #include <cxxtest/TestSuite.h>
32 #include "../WProperties.h"
33 #include "../exceptions/WPropertyNotUnique.h"
34 #include "../exceptions/WPropertyUnknown.h"
35 #include "../exceptions/WPropertyNameMalformed.h"
74 boost::shared_ptr< WProperties > p;
75 TS_ASSERT_THROWS_NOTHING( p = boost::shared_ptr< WProperties >(
new WProperties(
"hey",
"you" ) ) );
78 TS_ASSERT( p->getName() ==
"hey" );
79 TS_ASSERT( p->getDescription() ==
"you" );
80 TS_ASSERT( p->getType() == PV_GROUP );
82 TS_ASSERT_THROWS_NOTHING( p.reset() );
92 boost::shared_ptr< WProperties > p(
new WProperties(
"hey",
"you" ) );
95 boost::shared_ptr< WPropertyBase > p1 = p->addProperty(
"1",
"test1",
true );
96 boost::shared_ptr< WPropertyBase > p2 = p->addProperty(
"2",
"test2", 1 );
97 boost::shared_ptr< WPropertyBase > p3 = p->addProperty(
"3",
"test3", 1.0 );
104 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 3 );
107 TS_ASSERT( p1->getType() == PV_BOOL );
108 TS_ASSERT( p2->getType() == PV_INT );
109 TS_ASSERT( p3->getType() == PV_DOUBLE );
122 boost::shared_ptr< WProperties > p(
new WProperties(
"hey",
"you" ) );
125 boost::shared_ptr< WPropertyBase > p1 = p->addProperty(
"1",
"test1",
true );
126 boost::shared_ptr< WPropertyBase > p2 = p->addProperty(
"2",
"test2", 1 );
127 boost::shared_ptr< WPropertyBase > p3 = p->addProperty(
"3",
"test3", 1.0 );
130 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 3 );
133 TS_ASSERT_THROWS_NOTHING( p->clear() );
134 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 0 );
137 TS_ASSERT_THROWS_NOTHING( p->clear() );
147 boost::shared_ptr< WProperties > p(
new WProperties(
"hey",
"you" ) );
150 boost::shared_ptr< WPropertyBase > p1 = p->addProperty(
"1",
"test1",
true );
151 boost::shared_ptr< WPropertyBase > p2 = p->addProperty(
"2",
"test2", 1 );
152 boost::shared_ptr< WPropertyBase > p3 = p->addProperty(
"3",
"test3", 1.0 );
155 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 3 );
158 TS_ASSERT_THROWS_NOTHING( p->removeProperty( p2 ) );
159 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 2 );
162 TS_ASSERT_THROWS_NOTHING( p->removeProperty( p2 ) );
163 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 2 );
174 boost::shared_ptr< WProperties > t(
new WProperties(
"hey",
"you" ) );
177 WPropBool tp1 = t->addProperty(
"p1",
"",
true );
178 WPropInt tp2 = t->addProperty(
"p2",
"", 1 );
179 WPropGroup tg1 = t->addPropertyGroup(
"g1",
"" );
180 WPropDouble tp3 = tg1->addProperty(
"p3",
"", 1.0 );
181 WPropDouble tp4 = t->addProperty(
"p4",
"", 10.0 );
184 boost::shared_ptr< WProperties > s(
new WProperties(
"hey",
"you" ) );
187 WPropBool sp1 = s->addProperty(
"p1",
"",
false );
188 WPropInt sp2 = s->addProperty(
"p2__",
"", 10 );
189 WPropGroup sg1 = s->addPropertyGroup(
"g1",
"" );
190 WPropDouble sp3 = sg1->addProperty(
"p3",
"", 2.0 );
191 WPropInt sp4 = s->addProperty(
"p4",
"", 2 );
198 TS_ASSERT( tp1->get() == sp1->get() );
200 TS_ASSERT( tp2->get() == 1 );
202 TS_ASSERT( tp3->get() == sp3->get() );
204 TS_ASSERT( tp4->get() == 10.0 );
214 boost::shared_ptr< WProperties > p(
new WProperties(
"hey",
"you" ) );
217 boost::shared_ptr< WPropertyBase > p1 = p->addProperty(
"1",
"test1",
true );
218 boost::shared_ptr< WPropertyBase > p2 = p->addProperty(
"2",
"test2", 1 );
219 boost::shared_ptr< WPropertyBase > p3 = p->addProperty(
"3",
"test3", 1.0 );
225 TS_ASSERT( p->existsProperty(
"1" ) );
226 TS_ASSERT( !p->existsProperty(
"shouldNotBeInTheList" ) );
232 boost::shared_ptr< WPropertyBase > someProp;
233 TS_ASSERT_THROWS_NOTHING( someProp = p->findProperty(
"1" ) );
235 TS_ASSERT( someProp );
238 TS_ASSERT_THROWS_NOTHING( someProp = p->findProperty(
"shouldNotBeInTheList" ) );
240 TS_ASSERT( !someProp );
248 TS_ASSERT_THROWS_NOTHING( someProp = p->getProperty(
"1" ) );
249 TS_ASSERT( someProp );
252 TS_ASSERT_THROWS( someProp = p->getProperty(
"shouldNotBeInTheList" ),
WPropertyUnknown );
260 boost::shared_ptr< WProperties > p(
new WProperties(
"hey",
"you" ) );
261 boost::shared_ptr< WProperties > psub = p->addPropertyGroup(
"heySub",
"you" );
264 boost::shared_ptr< WPropertyBase > p1 = p->addProperty(
"1",
"test1",
true );
265 boost::shared_ptr< WPropertyBase > p2 = p->addProperty(
"2",
"test2", 1 );
266 boost::shared_ptr< WPropertyBase > p3 = psub->addProperty(
"3",
"test3", 1.0 );
267 boost::shared_ptr< WPropertyBase > p4 = psub->addProperty(
"4",
"test4", std::string(
"hello" ) );
276 TS_ASSERT( !p->existsProperty(
"3" ) );
277 TS_ASSERT( !p->existsProperty(
"4" ) );
278 TS_ASSERT( psub->existsProperty(
"3" ) );
279 TS_ASSERT( psub->existsProperty(
"4" ) );
280 TS_ASSERT( !psub->existsProperty(
"1" ) );
281 TS_ASSERT( !psub->existsProperty(
"2" ) );
284 TS_ASSERT( p->existsProperty(
"heySub/3" ) );
285 TS_ASSERT( !p->existsProperty(
"heySub/1" ) );
291 TS_ASSERT( p3 == p->findProperty(
"heySub/3" ) );
292 TS_ASSERT( p4 == p->findProperty(
"heySub/4" ) );
295 TS_ASSERT( boost::shared_ptr< WPropertyBase >() == p->findProperty(
"heySub/1" ) );
300 TS_ASSERT_THROWS_NOTHING( p->getProperty(
"heySub/3" ) );
301 TS_ASSERT_THROWS_NOTHING( p->getProperty(
"heySub/4" ) );
315 boost::shared_ptr< WProperties > orig(
new WProperties(
"hey",
"you" ) );
316 boost::shared_ptr< WProperties > clone = orig->clone()->toPropGroup();
319 TS_ASSERT( clone.get() );
320 TS_ASSERT( orig != clone );
326 TS_ASSERT( orig->getUpdateCondition() != clone->getUpdateCondition() );
329 clone->addProperty(
"1",
"test1", 1.0 );
330 TS_ASSERT( clone->m_properties.getReadTicket()->get().size() == 1 );
331 TS_ASSERT( orig->m_properties.getReadTicket()->get().size() == 0 );
341 clone->addProperty(
"2",
"test2",
false );
344 TS_ASSERT( m_testTemporary1 ==
false );
348 m_testTemporary1 =
false;
350 orig->addProperty(
"1",
"test1",
false );
353 TS_ASSERT( m_testTemporary1 ==
true );
359 boost::shared_ptr< WProperties > cloneClone = clone->clone()->toPropGroup();
362 TS_ASSERT( clone->m_properties.getReadTicket()->get().size() == 2 );
363 TS_ASSERT( cloneClone->m_properties.getReadTicket()->get().size() == 2 );
371 boost::shared_ptr< WPropertyBase > p = cloneClone->findProperty( ( *iter )->getName() );
373 TS_ASSERT( p != ( *iter ) );
378 #endif // WPROPERTIES_TEST_H
static void disableBacktrace()
Function disables backtraces.
void testAdd(void)
Test the add features, also tests the type of properties added.
void testGetAndExistsAndFindRecursive(void)
Test the recursive search mechanism.
void testClone()
Tests the cloning functionality.
WPropertyGroupBase::PropertyConstIterator PropertyConstIterator
The const iterator type of the container.
void testGetAndExistsAndFind(void)
Test the features to find and get properties.
void testRemove(void)
Test the removeProperty() method.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
void setTemporary1()
Helper function which simply sets the value above to true.
void setTemporary2()
Helper function which simply sets the value above to true.
Indicates that a given property is not unique in a group of properties.
void testClear(void)
Test the clear() method.
bool m_testTemporary2
A temporary holder for some value.
void testInstantiation(void)
Test instantiation, also test name and description and type (from WPropertyBase)
bool m_testTemporary1
A temporary holder for some value.
void testRecursiveSetByProperty(void)
Tests whether the properties children can be set by the WProperties::set call using a other WProperti...
boost::shared_ptr< WSharedObjectTicketRead< PropertyContainerType > > ReadTicket
Type for read tickets.
Indicates invalid element access of a container.