25 #ifndef WPROPERTYVARIABLE_TEST_H
26 #define WPROPERTYVARIABLE_TEST_H
30 #include <cxxtest/TestSuite.h>
32 #include "../WPropertyVariable.h"
33 #include "../constraints/WPropertyConstraintMin.h"
34 #include "../constraints/WPropertyConstraintMax.h"
36 #include "../exceptions/WPropertyNotUnique.h"
37 #include "../exceptions/WPropertyUnknown.h"
38 #include "../exceptions/WPropertyNameMalformed.h"
61 m_testTemporary1 =
true;
69 m_testTemporary2 =
true;
77 boost::shared_ptr< WPropertyVariable< bool > > p;
81 TS_ASSERT( p->getName() ==
"hey" );
82 TS_ASSERT( p->getDescription() ==
"you" );
83 TS_ASSERT( p->getType() == PV_BOOL );
85 TS_ASSERT_THROWS_NOTHING( p.reset() );
95 boost::shared_ptr< WPropertyVariable< bool > > p;
111 boost::shared_ptr< WPropertyVariable< int > > p =
121 boost::shared_ptr< WPropertyVariable< int > > clone = p->clone()->toPropInt();
125 TS_ASSERT( clone->getType() == PV_INT );
126 TS_ASSERT( clone->getName() == p->getName() );
127 TS_ASSERT( clone->getDescription() == p->getDescription() );
128 TS_ASSERT( clone->getPurpose() == p->getPurpose() );
131 TS_ASSERT( p->get() == clone->get() );
134 TS_ASSERT( p->getContraintsChangedCondition() != clone->getContraintsChangedCondition() );
135 TS_ASSERT( p->getUpdateCondition() != clone->getUpdateCondition() );
138 TS_ASSERT( p->getMin() != clone->getMin() );
139 TS_ASSERT( p->getMax() != clone->getMax() );
141 TS_ASSERT( p->getMin()->getMin() == clone->getMin()->getMin() );
143 TS_ASSERT( p->getMax()->getMax() == clone->getMax()->getMax() );
151 m_testTemporary1 =
false;
152 m_testTemporary2 =
false;
154 TS_ASSERT( !m_testTemporary1 );
155 TS_ASSERT( m_testTemporary2 );
158 m_testTemporary1 =
false;
159 m_testTemporary2 =
false;
161 TS_ASSERT( m_testTemporary1 );
162 TS_ASSERT( !m_testTemporary2 );
165 m_testTemporary1 =
false;
166 m_testTemporary2 =
false;
167 clone->removeConstraint( PC_MIN );
168 TS_ASSERT( !m_testTemporary1 );
169 TS_ASSERT( m_testTemporary2 );
172 m_testTemporary1 =
false;
173 m_testTemporary2 =
false;
174 p->removeConstraint( PC_MIN );
175 TS_ASSERT( m_testTemporary1 );
176 TS_ASSERT( !m_testTemporary2 );
187 boost::shared_ptr< WPropertyVariable< int > > p =
197 TS_ASSERT( p->set( 123 ) );
198 TS_ASSERT( p->get() == 123 );
199 TS_ASSERT( p->accept( 12345 ) );
208 TS_ASSERT( cmin == p->getMin() );
209 TS_ASSERT( cmax == p->
getMax() );
212 TS_ASSERT( p->set( 10 ) );
213 TS_ASSERT( p->get() == 10 );
216 TS_ASSERT( !p->set( 9 ) );
217 TS_ASSERT( p->get() == 10 );
218 TS_ASSERT( !p->set( 16 ) );
219 TS_ASSERT( p->get() == 10 );
224 p->m_constraints->getReadTicket()->get().size();
227 TS_ASSERT( p->set( 9 ) );
228 TS_ASSERT( p->get() == 9 );
229 TS_ASSERT( p->set( 16 ) );
230 TS_ASSERT( p->get() == 16 );
236 TS_ASSERT( p->ensureValidity( 10 ) );
237 TS_ASSERT( p->get() == 16 );
240 TS_ASSERT( p->isValid() );
242 TS_ASSERT( !p->isValid() );
243 TS_ASSERT( p->get() == 16 );
246 TS_ASSERT( p->ensureValidity( 18 ) );
247 TS_ASSERT( p->get() == 18 );
248 TS_ASSERT( p->isValid() );
252 TS_ASSERT( !p->ensureValidity( 16 ) );
253 TS_ASSERT( !p->isValid() );
254 TS_ASSERT( p->get() == 18 );
265 boost::shared_ptr< WPropertyVariable< int > > p =
275 m_testTemporary1 =
false;
278 p->addConstraint( cmin );
279 TS_ASSERT( p->m_constraints->getReadTicket()->get().size() == 1 );
280 TS_ASSERT( m_testTemporary1 );
286 m_testTemporary1 =
false;
287 TS_ASSERT( p->countConstraint( PC_MIN ) == 1 );
288 TS_ASSERT( p->countConstraint( PC_MAX ) == 0 );
292 TS_ASSERT( !p->getFirstConstraint( PC_MAX ) );
293 TS_ASSERT( !m_testTemporary1 );
299 m_testTemporary1 =
false;
304 TS_ASSERT_THROWS_NOTHING( p->replaceConstraint( cmax, PC_MAX ) );
305 TS_ASSERT( m_testTemporary1 );
308 m_testTemporary1 =
false;
311 p->replaceConstraint( cmax2, PC_MAX );
312 TS_ASSERT( m_testTemporary1 );
319 m_testTemporary1 =
false;
320 p->removeConstraint( PC_NOTEMPTY );
321 TS_ASSERT( !m_testTemporary1 );
324 m_testTemporary1 =
false;
325 TS_ASSERT( p->countConstraint( PC_MAX ) == 1 );
326 p->removeConstraint( PC_MAX );
327 TS_ASSERT( p->countConstraint( PC_MAX ) == 0 );
328 TS_ASSERT( m_testTemporary1 );
331 m_testTemporary1 =
false;
332 TS_ASSERT( p->countConstraint( PC_MIN ) == 1 );
333 p->removeConstraint( cmin );
334 TS_ASSERT( p->countConstraint( PC_MIN ) == 0 );
335 TS_ASSERT( m_testTemporary1 );
339 #endif // WPROPERTYVARIABLE_TEST_H
This class allows constraining properties using a maximum value and the corresponding <= operator...
static void disableBacktrace()
Function disables backtraces.
bool m_testTemporary1
A temporary holder for some value.
PropertyConstraintMax getMax()
Gets the current maximum constraint value.
A named property class with a concrete type.
boost::shared_ptr< WPropertyConstraintMax< T > > PropertyConstraintMax
Alias for max constraints.
void testConstraintManagement(void)
Tests constraint management.
void testNameConvention(void)
Tests that only properties with proper names can be created.
void testClone()
Tests the cloning functionality.
boost::shared_ptr< PropertyConstraint > getFirstConstraint(PROPERTYCONSTRAINT_TYPE type)
Method searching the first appearance of a constrained with the specified type.
void setTemporary2()
Helper function which simply sets the value above to true.
PropertyConstraintMax setMax(const T &max)
Set a maximum constraint.
void testMinMaxWithSetAndAccept()
Test min/max functionality, including tests for set(), accept() and ensureValidity.
PropertyConstraintMin setMin(const T &min)
Set a minimum constraint.
bool m_testTemporary2
A temporary holder for some value.
void setTemporary1()
Helper function which simply sets the value above to true.
This class allows constraining properties using a minimum value and the corresponding >= operator...
boost::shared_ptr< WPropertyConstraintMin< T > > PropertyConstraintMin
Alias for min constraints.
void testInstantiation(void)
Test instantiation, also test name and description and type (from WPropertyBase)