25 #ifndef WPROPERTYVARIABLE_TEST_H
26 #define WPROPERTYVARIABLE_TEST_H
31 #include <cxxtest/TestSuite.h>
33 #include "../WPropertyVariable.h"
34 #include "../constraints/WPropertyConstraintMax.h"
35 #include "../constraints/WPropertyConstraintMin.h"
36 #include "../exceptions/WPropertyNameMalformed.h"
37 #include "../exceptions/WPropertyNotUnique.h"
38 #include "../exceptions/WPropertyUnknown.h"
77 std::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 std::shared_ptr< WPropertyVariable< bool > > p;
111 std::shared_ptr< WPropertyVariable< int > > p =
121 std::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() );
167 clone->removeConstraint( PC_MIN );
174 p->removeConstraint( PC_MIN );
187 std::shared_ptr< WPropertyVariable< int > > p =
197 TS_ASSERT( p->set( 123 ) );
198 TS_ASSERT( p->get() == 123 );
199 TS_ASSERT( p->accept( 12345 ) );
202 cmin = p->setMin( 10 );
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 std::shared_ptr< WPropertyVariable< int > > p =
278 p->addConstraint( cmin );
279 TS_ASSERT( p->m_constraints->getReadTicket()->get().size() == 1 );
287 TS_ASSERT( p->countConstraint( PC_MIN ) == 1 );
288 TS_ASSERT( p->countConstraint( PC_MAX ) == 0 );
292 TS_ASSERT( !p->getFirstConstraint( PC_MAX ) );
304 TS_ASSERT_THROWS_NOTHING( p->replaceConstraint( cmax, PC_MAX ) );
311 p->replaceConstraint( cmax2, PC_MAX );
320 p->removeConstraint( PC_NOTEMPTY );
325 TS_ASSERT( p->countConstraint( PC_MAX ) == 1 );
326 p->removeConstraint( PC_MAX );
327 TS_ASSERT( p->countConstraint( PC_MAX ) == 0 );
332 TS_ASSERT( p->countConstraint( PC_MIN ) == 1 );
333 p->removeConstraint( cmin );
334 TS_ASSERT( p->countConstraint( PC_MIN ) == 0 );
static void disableBacktrace()
Function disables backtraces.
This class allows constraining properties using a maximum value and the corresponding <= operator.
This class allows constraining properties using a minimum value and the corresponding >= operator.
bool m_testTemporary2
A temporary holder for some value.
void testClone()
Tests the cloning functionality.
void testInstantiation(void)
Test instantiation, also test name and description and type (from WPropertyBase)
void testMinMaxWithSetAndAccept()
Test min/max functionality, including tests for set(), accept() and ensureValidity.
bool m_testTemporary1
A temporary holder for some value.
void setTemporary1()
Helper function which simply sets the value above to true.
void testNameConvention(void)
Tests that only properties with proper names can be created.
void setTemporary2()
Helper function which simply sets the value above to true.
void testConstraintManagement(void)
Tests constraint management.
A named property class with a concrete type.
PropertyConstraintMax setMax(const T &max)
Set a maximum constraint.
std::shared_ptr< WPropertyConstraintMin< T > > PropertyConstraintMin
Alias for min constraints.
std::shared_ptr< WPropertyConstraintMax< T > > PropertyConstraintMax
Alias for max constraints.
PropertyConstraintMax getMax()
Gets the current maximum constraint value.
std::shared_ptr< PropertyConstraint > getFirstConstraint(PROPERTYCONSTRAINT_TYPE type)
Method searching the first appearance of a constrained with the specified type.