| RoomModel room.basic.etunit { |
| |
| import room.basic.service.timing.* from "../TimingService.room" |
| import room.basic.types.* from "../Types.room" |
| |
| /** |
| * Creates an etUnit test suite. Test cases can be added by creating instances of ActorClass <i>TestSuiteActor</i>. |
| * <p> |
| * <i>getTestSuiteName()</i> and <i>getTestSuiteFileName()</i> return actor instances name by default. |
| * </p> |
| */ |
| abstract ActorClass TestSuiteActor { |
| Structure { } |
| Behavior { |
| ctor { |
| "etUnit_open(\"log\", getTestSuiteFileName());" |
| "etUnit_openTestSuite(getTestSuiteName());" |
| } |
| dtor { |
| "etUnit_closeTestSuite();" |
| "etUnit_close();" |
| } |
| Operation getTestSuiteName() : charPtr { |
| "return self->constData->instName;" |
| } |
| Operation getTestSuiteFileName() : charPtr { |
| "return self->constData->instName;" |
| } |
| |
| } |
| } |
| |
| abstract async ActorClass TestCaseActor { |
| Structure { |
| SAP tcLifecycle : PTestLifecycle |
| SAP tcTimer : PTimer |
| Attribute tcTimeoutIgnore : boolean |
| Attribute tcCaseId : int32 |
| } |
| Behavior { |
| Operation getTestCaseName() : charPtr { |
| "return self->constData->instName;" |
| } |
| Operation startTimeout(time: uint32){ |
| "tcTimeoutIgnore = ET_FALSE;" |
| "tcTimer.startTimeout(time);" |
| } |
| Operation invalidateTimeout(){ |
| "tcTimeoutIgnore = ET_TRUE;" |
| } |
| StateMachine { |
| Transition init: initial -> tpEnter of testing { |
| action { |
| "invalidateTimeout();" |
| "tcLifecycle.registerTestCase();" |
| "tcCaseId = etUnit_openTestCase(getTestCaseName());" |
| } |
| } |
| Transition trFinish: tpFinish of testing -> finish |
| Transition trTimeout: testing -> timeout { |
| triggers { |
| <timeout: tcTimer guard { |
| "!tcTimeoutIgnore" |
| }> |
| } |
| action { |
| "invalidateTimeout();" |
| } |
| } |
| State testing { |
| subgraph { |
| EntryPoint tpEnter |
| ExitPoint tpFinish |
| } |
| } |
| State timeout { |
| entry { |
| "EXPECT_FALSE(tcCaseId, \"timeout\", ET_TRUE);" |
| "etUnit_closeTestCase(tcCaseId);" |
| "tcLifecycle.finishedTestCase(tcCaseId);" |
| } |
| } |
| State finish { |
| entry { |
| "etUnit_closeTestCase(tcCaseId);" |
| "tcLifecycle.finishedTestCase(tcCaseId);" |
| } |
| } |
| } |
| } |
| } |
| |
| ActorClass TestLifecycleActor { |
| Interface { |
| SPP fct: PTestLifecycle |
| } |
| Structure { |
| ServiceImplementation of fct |
| SAP timer : PTimer |
| Attribute entireTestTimeout : int32 = "5000" |
| Attribute tcCount : int32 = "0" |
| } |
| Behavior { |
| StateMachine { |
| Transition init: initial -> idle { |
| action { |
| "timer.startTimeout(entireTestTimeout);" |
| } |
| } |
| Transition tr0: idle -> idle { |
| triggers { |
| <registerTestCase: fct> |
| } |
| action { |
| "tcCount++;" |
| } |
| } |
| Transition tr1: idle -> cp cp0 { |
| triggers { |
| <finishedTestCase: fct> |
| } |
| action { |
| "tcCount--;" |
| } |
| } |
| Transition tr2: idle -> terminate { |
| triggers { |
| <timeout: timer> |
| } |
| } |
| Transition tr3: cp cp0 -> idle |
| Transition tr4: cp cp0 -> terminate { |
| cond { |
| "tcCount==0" |
| } |
| } |
| Transition tr5: cp cp0 -> error { |
| cond { |
| "tcCount < 0" |
| } |
| } |
| ChoicePoint cp0 |
| State idle |
| State terminate { |
| entry { |
| "etUnit_testFinished(-1);" |
| } |
| } |
| State error |
| } |
| } |
| } |
| |
| ProtocolClass PTestLifecycle { |
| incoming { |
| Message registerTestCase() |
| Message finishedTestCase() |
| } |
| } |
| |
| } |