17 #include <QTest> |
17 #include <QTest> |
18 |
18 |
19 #include "unittest_cxestatemachine.h" |
19 #include "unittest_cxestatemachine.h" |
20 #include "cxestate.h" |
20 #include "cxestate.h" |
21 #include "cxestatemachineunit.h" |
21 #include "cxestatemachineunit.h" |
22 #include "cxeerrormappingsymbian.h" // CxeErrorHandlingSymbian |
|
23 |
22 |
24 // ----------------------------------- |
23 // ----------------------------------- |
25 // CxsStateMachine |
24 // CxsStateMachine |
26 // ----------------------------------- |
25 // ----------------------------------- |
27 UnitTestCxeStateMachine::UnitTestCxeStateMachine() |
26 UnitTestCxeStateMachine::UnitTestCxeStateMachine() |
28 : mStateMachine(NULL), mStartState(NULL), mMiddleState(NULL), mEndState(NULL), mIsolatedState(NULL) |
27 : mStateMachine(NULL), |
29 { |
28 mStartState(NULL), |
|
29 mMiddleState(NULL), |
|
30 mEndState(NULL), |
|
31 mIsolatedState(NULL) |
|
32 { |
|
33 qRegisterMetaType<CxeError::Id>("CxeError::Id"); |
30 } |
34 } |
31 |
35 |
32 UnitTestCxeStateMachine::~UnitTestCxeStateMachine() |
36 UnitTestCxeStateMachine::~UnitTestCxeStateMachine() |
33 { |
37 { |
34 } |
38 } |
104 mStateMachine->mHandleStateChangedCounter = 0; |
108 mStateMachine->mHandleStateChangedCounter = 0; |
105 |
109 |
106 // set state, when initial state is not set -> NOK |
110 // set state, when initial state is not set -> NOK |
107 // check that handleStateChange is not called |
111 // check that handleStateChange is not called |
108 // current state is undefined |
112 // current state is undefined |
109 QVERIFY(!mStateMachine->setState(StartId, 2)); |
113 QVERIFY(!mStateMachine->setState(StartId)); |
110 QCOMPARE(mStateMachine->mHandleStateChangedCounter, 0); |
114 QCOMPARE(mStateMachine->mHandleStateChangedCounter, 0); |
111 QCOMPARE(mStateMachine->stateId(), 0); |
115 QCOMPARE(mStateMachine->stateId(), 0); // 0 - undefined state |
112 |
116 |
113 // set start state as initial state, change to another state (allowed change) -> OK |
117 // set start state as initial state, change to another state (allowed change) -> OK |
114 // (there should be a call to state change, check the error code) |
118 // (there should be a call to state change, check the error code) |
115 mStateMachine->setInitialState(StartId); |
119 mStateMachine->setInitialState(StartId); |
116 QVERIFY(mStateMachine->setState(MiddleId, 0)); |
120 QVERIFY(mStateMachine->setState(MiddleId, CxeError::None)); |
117 QCOMPARE(mStateMachine->mHandleStateChangedCounter, 1); |
121 QCOMPARE(mStateMachine->mHandleStateChangedCounter, 1); |
118 QVERIFY(mStateMachine->mStateChangeStateId == MiddleId); |
122 QVERIFY(mStateMachine->mStateChangeStateId == MiddleId); |
119 QVERIFY(mStateMachine->mStateChangeErrorId == CxeErrorHandlingSymbian::map(0)); |
123 QCOMPARE(mStateMachine->mStateChangeErrorId, CxeError::None); |
120 QVERIFY(mStateMachine->stateId() == MiddleId); |
124 QVERIFY(mStateMachine->stateId() == MiddleId); |
121 |
125 |
122 // set another state (allowed change) -> OK |
126 // set another state (allowed change) -> OK |
123 // check the error code is correct one (return value is mapped error value) |
127 // check the error code is correct one |
124 QVERIFY(mStateMachine->setState(EndId, -1)); |
128 QVERIFY(mStateMachine->setState(EndId, CxeError::NotFound)); |
125 QCOMPARE(mStateMachine->mHandleStateChangedCounter, 2); |
129 QCOMPARE(mStateMachine->mHandleStateChangedCounter, 2); |
126 QVERIFY(mStateMachine->mStateChangeStateId == EndId); |
130 QVERIFY(mStateMachine->mStateChangeStateId == EndId); |
127 QVERIFY(mStateMachine->mStateChangeErrorId == CxeErrorHandlingSymbian::map(-1)); |
131 QCOMPARE(mStateMachine->mStateChangeErrorId, CxeError::NotFound); |
128 QVERIFY(mStateMachine->stateId() == EndId); |
132 QVERIFY(mStateMachine->stateId() == EndId); |
129 |
133 |
130 // reset the counter for handleStateChanged slot |
134 // reset the counter for handleStateChanged slot |
131 mStateMachine->mHandleStateChangedCounter = 0; |
135 mStateMachine->mHandleStateChangedCounter = 0; |
132 |
136 |
133 // set same state again -> OK |
137 // set same state again -> OK |
134 // but state change should not be called |
138 // but state change should not be called |
135 QVERIFY(mStateMachine->setState(EndId, 0)); |
139 QVERIFY(mStateMachine->setState(EndId, CxeError::None)); |
136 QCOMPARE(mStateMachine->mHandleStateChangedCounter, 0); |
140 QCOMPARE(mStateMachine->mHandleStateChangedCounter, 0); |
137 |
141 |
138 // setstate to a state that does not exists -> NOK |
142 // setstate to a state that does not exists -> NOK |
139 // state has not changed |
143 // state has not changed |
140 QVERIFY(mStateMachine->stateId() == EndId); |
144 QVERIFY(mStateMachine->stateId() == EndId); |