25 #ifndef WPROPERTIES_TEST_H
26 #define WPROPERTIES_TEST_H
31 #include <cxxtest/TestSuite.h>
33 #include "../WProperties.h"
34 #include "../exceptions/WPropertyNameMalformed.h"
35 #include "../exceptions/WPropertyNotUnique.h"
36 #include "../exceptions/WPropertyUnknown.h"
75 std::shared_ptr< WProperties > p;
76 TS_ASSERT_THROWS_NOTHING( p = std::shared_ptr< WProperties >(
new WProperties(
"hey",
"you" ) ) );
79 TS_ASSERT( p->getName() ==
"hey" );
80 TS_ASSERT( p->getDescription() ==
"you" );
81 TS_ASSERT( p->getType() == PV_GROUP );
83 TS_ASSERT_THROWS_NOTHING( p.reset() );
93 std::shared_ptr< WProperties > p(
new WProperties(
"hey",
"you" ) );
96 std::shared_ptr< WPropertyBase > p1 = p->addProperty(
"1",
"test1",
true );
97 std::shared_ptr< WPropertyBase > p2 = p->addProperty(
"2",
"test2", 1 );
98 std::shared_ptr< WPropertyBase > p3 = p->addProperty(
"3",
"test3", 1.0 );
105 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 3 );
108 TS_ASSERT( p1->getType() == PV_BOOL );
109 TS_ASSERT( p2->getType() == PV_INT );
110 TS_ASSERT( p3->getType() == PV_DOUBLE );
123 std::shared_ptr< WProperties > p(
new WProperties(
"hey",
"you" ) );
126 std::shared_ptr< WPropertyBase > p1 = p->addProperty(
"1",
"test1",
true );
127 std::shared_ptr< WPropertyBase > p2 = p->addProperty(
"2",
"test2", 1 );
128 std::shared_ptr< WPropertyBase > p3 = p->addProperty(
"3",
"test3", 1.0 );
131 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 3 );
134 TS_ASSERT_THROWS_NOTHING( p->clear() );
135 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 0 );
138 TS_ASSERT_THROWS_NOTHING( p->clear() );
148 std::shared_ptr< WProperties > p(
new WProperties(
"hey",
"you" ) );
151 std::shared_ptr< WPropertyBase > p1 = p->addProperty(
"1",
"test1",
true );
152 std::shared_ptr< WPropertyBase > p2 = p->addProperty(
"2",
"test2", 1 );
153 std::shared_ptr< WPropertyBase > p3 = p->addProperty(
"3",
"test3", 1.0 );
156 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 3 );
159 TS_ASSERT_THROWS_NOTHING( p->removeProperty( p2 ) );
160 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 2 );
163 TS_ASSERT_THROWS_NOTHING( p->removeProperty( p2 ) );
164 TS_ASSERT( p->m_properties.getReadTicket()->get().size() == 2 );
175 std::shared_ptr< WProperties > t(
new WProperties(
"hey",
"you" ) );
178 WPropBool tp1 = t->addProperty(
"p1",
"",
true );
179 WPropInt tp2 = t->addProperty(
"p2",
"", 1 );
180 WPropGroup tg1 = t->addPropertyGroup(
"g1",
"" );
181 WPropDouble tp3 = tg1->addProperty(
"p3",
"", 1.0 );
182 WPropDouble tp4 = t->addProperty(
"p4",
"", 10.0 );
185 std::shared_ptr< WProperties > s(
new WProperties(
"hey",
"you" ) );
188 WPropBool sp1 = s->addProperty(
"p1",
"",
false );
189 WPropInt sp2 = s->addProperty(
"p2__",
"", 10 );
190 WPropGroup sg1 = s->addPropertyGroup(
"g1",
"" );
191 WPropDouble sp3 = sg1->addProperty(
"p3",
"", 2.0 );
192 WPropInt sp4 = s->addProperty(
"p4",
"", 2 );
199 TS_ASSERT( tp1->get() == sp1->get() );
201 TS_ASSERT( tp2->get() == 1 );
203 TS_ASSERT( tp3->get() == sp3->get() );
205 TS_ASSERT( tp4->get() == 10.0 );
215 std::shared_ptr< WProperties > p(
new WProperties(
"hey",
"you" ) );
218 std::shared_ptr< WPropertyBase > p1 = p->addProperty(
"1",
"test1",
true );
219 std::shared_ptr< WPropertyBase > p2 = p->addProperty(
"2",
"test2", 1 );
220 std::shared_ptr< WPropertyBase > p3 = p->addProperty(
"3",
"test3", 1.0 );
226 TS_ASSERT( p->existsProperty(
"1" ) );
227 TS_ASSERT( !p->existsProperty(
"shouldNotBeInTheList" ) );
233 std::shared_ptr< WPropertyBase > someProp;
234 TS_ASSERT_THROWS_NOTHING( someProp = p->findProperty(
"1" ) );
236 TS_ASSERT( someProp );
239 TS_ASSERT_THROWS_NOTHING( someProp = p->findProperty(
"shouldNotBeInTheList" ) );
241 TS_ASSERT( !someProp );
249 TS_ASSERT_THROWS_NOTHING( someProp = p->getProperty(
"1" ) );
250 TS_ASSERT( someProp );
253 TS_ASSERT_THROWS( someProp = p->getProperty(
"shouldNotBeInTheList" ),
const WPropertyUnknown& );
261 std::shared_ptr< WProperties > p(
new WProperties(
"hey",
"you" ) );
262 std::shared_ptr< WProperties > psub = p->addPropertyGroup(
"heySub",
"you" );
265 std::shared_ptr< WPropertyBase > p1 = p->addProperty(
"1",
"test1",
true );
266 std::shared_ptr< WPropertyBase > p2 = p->addProperty(
"2",
"test2", 1 );
267 std::shared_ptr< WPropertyBase > p3 = psub->addProperty(
"3",
"test3", 1.0 );
268 std::shared_ptr< WPropertyBase > p4 = psub->addProperty(
"4",
"test4", std::string(
"hello" ) );
271 TS_ASSERT_THROWS( p->addProperty(
"heySub",
"test1",
true ),
const WPropertyNotUnique& );
277 TS_ASSERT( !p->existsProperty(
"3" ) );
278 TS_ASSERT( !p->existsProperty(
"4" ) );
279 TS_ASSERT( psub->existsProperty(
"3" ) );
280 TS_ASSERT( psub->existsProperty(
"4" ) );
281 TS_ASSERT( !psub->existsProperty(
"1" ) );
282 TS_ASSERT( !psub->existsProperty(
"2" ) );
285 TS_ASSERT( p->existsProperty(
"heySub/3" ) );
286 TS_ASSERT( !p->existsProperty(
"heySub/1" ) );
292 TS_ASSERT( p3 == p->findProperty(
"heySub/3" ) );
293 TS_ASSERT( p4 == p->findProperty(
"heySub/4" ) );
296 TS_ASSERT( std::shared_ptr< WPropertyBase >() == p->findProperty(
"heySub/1" ) );
301 TS_ASSERT_THROWS_NOTHING( p->getProperty(
"heySub/3" ) );
302 TS_ASSERT_THROWS_NOTHING( p->getProperty(
"heySub/4" ) );
316 std::shared_ptr< WProperties > orig(
new WProperties(
"hey",
"you" ) );
317 std::shared_ptr< WProperties > clone = orig->clone()->toPropGroup();
320 TS_ASSERT( clone.get() );
321 TS_ASSERT( orig != clone );
327 TS_ASSERT( orig->getUpdateCondition() != clone->getUpdateCondition() );
330 clone->addProperty(
"1",
"test1", 1.0 );
331 TS_ASSERT( clone->m_properties.getReadTicket()->get().size() == 1 );
332 TS_ASSERT( orig->m_properties.getReadTicket()->get().size() == 0 );
342 clone->addProperty(
"2",
"test2",
false );
351 orig->addProperty(
"1",
"test1",
false );
360 std::shared_ptr< WProperties > cloneClone = clone->clone()->toPropGroup();
363 TS_ASSERT( clone->m_properties.getReadTicket()->get().size() == 2 );
364 TS_ASSERT( cloneClone->m_properties.getReadTicket()->get().size() == 2 );
372 std::shared_ptr< WPropertyBase > p = cloneClone->findProperty( ( *iter )->getName() );
374 TS_ASSERT( p != ( *iter ) );
static void disableBacktrace()
Function disables backtraces.
void setTemporary2()
Helper function which simply sets the value above to true.
bool m_testTemporary2
A temporary holder for some value.
void testClone()
Tests the cloning functionality.
void testClear(void)
Test the clear() method.
void testRecursiveSetByProperty(void)
Tests whether the properties children can be set by the WProperties::set call using a other WProperti...
void testRemove(void)
Test the removeProperty() method.
bool m_testTemporary1
A temporary holder for some value.
void testGetAndExistsAndFindRecursive(void)
Test the recursive search mechanism.
void setTemporary1()
Helper function which simply sets the value above to true.
void testInstantiation(void)
Test instantiation, also test name and description and type (from WPropertyBase)
void testGetAndExistsAndFind(void)
Test the features to find and get properties.
void testAdd(void)
Test the add features, also tests the type of properties added.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
WPropertyGroupBase::PropertyConstIterator PropertyConstIterator
The const iterator type of the container.
Indicates that a given property is not unique in a group of properties.
Indicates invalid element access of a container.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.