" (C) 2011 by Holger Hans Peter Freyther All Rights Reserved This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . " PackageLoader fileInPackage: 'PetitParserTests'. PP.PPCompositeParserTest subclass: SIPParserTest [ parserClass [ ^ SIPParser ] testResponseData [ ^ (WriteStream on: (String new)) nextPutAll: 'SIP/2.0 480 Temporarily Unavailable'; cr; nl; nextPutAll: 'Via: SIP/2.0/UDP 172.16.254.34;branch=z9hG4bKMzQ4NTQzNDgxNCwyNDE1Nw__'; cr; nl; nextPutAll: 'From: ;tag=MzQ4NTQ0MTg2NzIyNDEwNjkyNjY_'; cr; nl; nextPutAll: 'To: ;tag=42eBv22Fj314N;abc=def;kbc;ajk'; cr; nl; nextPutAll: 'Call-ID: MzY3NzE3ODgyNw__@xiaoyu'; cr; nl; nextPutAll: 'CSeq: 1 INVITE'; cr; nl; nextPutAll: 'User-Agent: FreeSWITCH-mod_sofia/1.0.head-git-dff41af 2011-04-20 14-11-24 +0200'; cr; nl; nextPutAll: 'Accept: application/sdp'; cr; nl; nextPutAll: 'Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, UPDATE, INFO, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE'; cr; nl; nextPutAll: 'Supported: timer, precondition, path, replaces'; cr; nl; nextPutAll: 'Allow-Events: talk, hold, presence, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer'; cr; nl; nextPutAll: 'Reason: Q.850;cause=96;text="MANDATORY_IE_MISSING"'; cr; nl; nextPutAll: 'Content-Length: 0'; cr; nl; nextPutAll: 'Remote-Party-ID: "9198" ;party=calling;privacy=off;screen=no'; cr; nl; cr;nl; contents. ] testResponse [ | res | res := self parse: self testResponseData. self assert: res asDatagram = self testResponseData. self assert: (res parameter: 'Via') branch = 'z9hG4bKMzQ4NTQzNDgxNCwyNDE1Nw__'. self assert: (res parameter: 'CSeq') number = 1. self assert: (res parameter: 'CSeq') method = 'INVITE'. self assert: (res parameter: 'To') tag = '42eBv22Fj314N'. self assert: (res parameter: 'To') address = 'sip:9198@172.16.1.72'. self assert: ((res parameter: 'To') valueAt: 'abc') = 'def'. self assert: ((res parameter: 'To') valueAt: 'kbc') = nil. self assert: ((res parameter: 'To') valueAt: 'ajk') = nil. self should: [((res parameter: 'To') valueAt: 'foo')] raise: SystemExceptions.NotFound. self assert: (res parameter: 'From') tag = 'MzQ4NTQ0MTg2NzIyNDEwNjkyNjY_'. self assert: (res parameter: 'From') address = 'sip:1000@on-waves.com'. ] testSIPDialog [ | dialog | dialog := SIPDialog fromMessage: (self parse: self testResponseData). self assert: dialog to = 'sip:9198@172.16.1.72'; assert: dialog to_tag = '42eBv22Fj314N'; assert: dialog from = 'sip:1000@on-waves.com'; assert: dialog from_tag = 'MzQ4NTQ0MTg2NzIyNDEwNjkyNjY_'; assert: dialog callId = 'MzY3NzE3ODgyNw__@xiaoyu'; assert: dialog cseq = 1. ] testDialogCompatible [ | initial_dialog dialog1 dialog2 | initial_dialog := (SIPDialog fromUser: 'sip:1000@on-waves.com' host: '0.0.0.0' port: 5060) fromTag: 'MzQ4NTQ0MTg2NzIyNDEwNjkyNjY_'; callId: 'MzY3NzE3ODgyNw__@xiaoyu'; yourself. self assert: initial_dialog isUnconfirmed. self deny: initial_dialog isConfirmed. dialog1 := initial_dialog newFromRequest: (self parse: self testResponseData). self deny: initial_dialog == dialog1. self assert: dialog1 isConfirmed. dialog2 := dialog1 newFromRequest: (self parse: self testResponseData). self assert: dialog1 == dialog2. self assert: dialog2 isConfirmed. ] ]