diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-06-24 11:52:40 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-06-24 20:08:22 +0200 |
commit | 56f86debceee818709a5a329cea4e509d6cc8f76 (patch) | |
tree | d90c0a71b7cdbd4a76e18dd43001a419f94a1fa9 | |
parent | 03348c1e8d7a309cbd8ec01a1c1003cd79a60684 (diff) |
callagent: Add testcase for the allocation FSM of an endpoint
Verify the legal transitions and the non-legal ones (exceptions
are thrown in that case).
-rw-r--r-- | callagent/MGCPEndpoint.st | 2 | ||||
-rw-r--r-- | callagent/Tests.st | 46 | ||||
-rw-r--r-- | package.xml | 1 |
3 files changed, 48 insertions, 1 deletions
diff --git a/callagent/MGCPEndpoint.st b/callagent/MGCPEndpoint.st index 4a0920e..53de003 100644 --- a/callagent/MGCPEndpoint.st +++ b/callagent/MGCPEndpoint.st @@ -91,7 +91,7 @@ Object subclass: MGCPEndpoint [ free [ <category: 'allocation'> self requireState: self class stateUsed. - state := self class stateUsed. + state := self class stateUnused. ] tryBlock [ diff --git a/callagent/Tests.st b/callagent/Tests.st index 0854453..db76558 100644 --- a/callagent/Tests.st +++ b/callagent/Tests.st @@ -185,3 +185,49 @@ TestCase subclass: MGCPTransactionTest [ self dropAgent stop. ] ] + +TestCase subclass: MGCPEndpointAllocTest [ + testStateTransition [ + | trunk endp | + + trunk := MGCPVirtualTrunk createWithDest: '127.0.0.1' numberPorts: 32. + endp := trunk endpointAt: 1. + + "Initial..." + self assert: endp isUnused. + + "Reserve..." + endp reserve. + self assert: endp isReserved. + self should: [endp reserve] raise: Error. + self should: [endp free] raise: Error. + self should: [endp unblock] raise: Error. + self deny: endp tryBlock. + + "Move to used..." + endp used. + self assert: endp isUsed. + self should: [endp reserve] raise: Error. + self should: [endp used] raise: Error. + self should: [endp unblock] raise: Error. + self deny: endp tryBlock. + + "Move to free..." + endp free. + self assert: endp isUnused. + self should: [endp used] raise: Error. + self should: [endp unblock] raise: Error. + self assert: endp tryBlock. + + "Now try to block it..." + self assert: endp isBlocked. + self should: [endp reserve] raise: Error. + self should: [endp free] raise: Error. + self should: [endp used] raise: Error. + self deny: endp tryBlock. + + "Now unblock and restore" + endp unblock. + self assert: endp isUnused. + ] +] diff --git a/package.xml b/package.xml index 82826bb..0ebcfa1 100644 --- a/package.xml +++ b/package.xml @@ -16,6 +16,7 @@ <test> <sunit>Osmo.MGCPGrammarTest</sunit> <sunit>Osmo.MGCPCommandTest</sunit> + <sunit>Osmo.MGCPEndpointAllocTest</sunit> <sunit>Osmo.MGCPTransactionTest</sunit> <filein>grammar/MGCPGrammarTest.st</filein> <filein>callagent/Tests.st</filein> |