From 56f86debceee818709a5a329cea4e509d6cc8f76 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 24 Jun 2011 11:52:40 +0200 Subject: [PATCH] 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). --- callagent/MGCPEndpoint.st | 2 +- callagent/Tests.st | 46 +++++++++++++++++++++++++++++++++++++++ package.xml | 1 + 3 files changed, 48 insertions(+), 1 deletion(-) 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 [ 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 @@ Osmo.MGCPGrammarTest Osmo.MGCPCommandTest + Osmo.MGCPEndpointAllocTest Osmo.MGCPTransactionTest grammar/MGCPGrammarTest.st callagent/Tests.st