mgcp: Be able to serialize a MGCPResponse again and add a test
The parameters are stored in a dictionary so the order might be able to change. This should be aligned with the MGCP command so that one is using a list for the parameters.
This commit is contained in:
parent
948264560f
commit
afb53fc0d0
|
@ -17,16 +17,21 @@
|
|||
"
|
||||
|
||||
Object subclass: MGCPResponse [
|
||||
| code transaction params sdp |
|
||||
| code transaction params sdp responseString |
|
||||
|
||||
<category: 'OsmoMGCP-Response'>
|
||||
<comment: 'I provide a nicer way to look at responses'>
|
||||
|
||||
MGCPResponse class >> fromDict: aDict [
|
||||
| responseString |
|
||||
<category: 'creation'>
|
||||
|
||||
responseString := aDict first at: 5.
|
||||
responseString ifNotNil: [responseString := responseString second].
|
||||
^ self new
|
||||
initialize;
|
||||
responseCode: aDict first first;
|
||||
responseString: responseString;
|
||||
transaction: aDict first third;
|
||||
addParamsFromDict: aDict second;
|
||||
addSDPFromDict: aDict third;
|
||||
|
@ -58,6 +63,15 @@ Object subclass: MGCPResponse [
|
|||
code := aCode asInteger
|
||||
]
|
||||
|
||||
responseString: aString [
|
||||
<category: 'creation'>
|
||||
responseString := aString
|
||||
]
|
||||
|
||||
responseString [
|
||||
^responseString
|
||||
]
|
||||
|
||||
transaction: aTrans [
|
||||
<category: 'creation'>
|
||||
self transactionId: aTrans
|
||||
|
@ -104,4 +118,30 @@ Object subclass: MGCPResponse [
|
|||
^ params at: aKey ifAbsent: aBlock.
|
||||
]
|
||||
|
||||
asDatagram [
|
||||
^String streamContents: [:stream |
|
||||
stream
|
||||
nextPutAll: code displayString;
|
||||
nextPutAll: ' ';
|
||||
nextPutAll: transaction displayString.
|
||||
|
||||
responseString ifNotNil: [
|
||||
stream
|
||||
nextPutAll: ' ';
|
||||
nextPutAll: responseString].
|
||||
|
||||
stream cr; nl.
|
||||
|
||||
params associationsDo: [:assoc |
|
||||
stream
|
||||
nextPutAll: assoc key;
|
||||
nextPutAll: ': ';
|
||||
nextPutAll: assoc value;
|
||||
cr; nl].
|
||||
|
||||
sdp ifNotNil: [
|
||||
stream
|
||||
cr; nl;
|
||||
nextPutAll: sdp]]
|
||||
]
|
||||
]
|
||||
|
|
|
@ -393,7 +393,7 @@ PP.PPCompositeParserTest subclass: MGCPParserTest [
|
|||
]
|
||||
|
||||
testRespParse [
|
||||
| nl res sdp |
|
||||
| nl res sdp inp |
|
||||
nl := Character cr asString, Character nl asString.
|
||||
|
||||
sdp := 'v=0', nl,
|
||||
|
@ -409,16 +409,18 @@ PP.PPCompositeParserTest subclass: MGCPParserTest [
|
|||
'a=T38FaxVersion:0', nl,
|
||||
'a=T38MaxBitRate:14400', nl.
|
||||
|
||||
res := self parse: '200 32323 OK', nl,
|
||||
inp := '200 32323 OK', nl,
|
||||
'I: 233434', nl,
|
||||
nl,
|
||||
sdp.
|
||||
res := self parse: inp.
|
||||
|
||||
self assert: res code = 200.
|
||||
self assert: res isSuccess.
|
||||
self assert: res transactionId = '32323'.
|
||||
self assert: res sdp = sdp.
|
||||
self assert: (res parameterAt: 'I' ifAbsent: []) = '233434'.
|
||||
self assert: res asDatagram equals: inp.
|
||||
]
|
||||
|
||||
testFailureResp [
|
||||
|
|
Reference in New Issue