-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstartline_test.go
53 lines (50 loc) · 2.24 KB
/
startline_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2011, Shelby Ramsey. All rights reserved.
// Use of this code is governed by a BSD license that can be
// found in the LICENSE.txt file.
package sipparser
// Imports from the go standard library
import (
"testing"
)
func TestStartLine(t *testing.T) {
str := "SIP/2.0 487 Request Cancelled"
s := &StartLine{Val: str}
s.run()
if s.Type != SIP_RESPONSE {
t.Errorf("[TestStartLine] Error parsing startline: SIP/2.0 487 Request Cancelled. s.Type should be \"RESPONSE\".")
}
if s.Resp != "487" {
t.Errorf("[TestStartLine] Error parsing startline: SIP/2.0 487 Request Cancelled. s.Resp should be \"487\".")
}
if s.RespText != "Request Cancelled" {
t.Errorf("[TestStartLine] Error parsing startline: SIP/2.0 487 Request Cancelled. s.RespText should be \"Request Cancelled\".")
}
str = "dlskmgkfmdg ldf,l,"
s = ParseStartLine(str)
if s.Error == nil {
t.Errorf("[TestStartLine] Error parsing startline. s.Error should not be nil for string: \"dlskmgkfmdg ldf,l,\".")
}
str = "INVITE sip:[email protected];user=phone SIP/2.0"
s = ParseStartLine(str)
if s.Error != nil {
t.Errorf("[TestStartLine] Got error when parsing startline: \"INVITE sip:[email protected];user=phone SIP/2.0\". Received err: " + s.Error.Error())
}
if s.Type != SIP_REQUEST {
t.Errorf("[TestStartLine] Got error when parsing startline: \"INVITE sip:[email protected];user=phone SIP/2.0\". s.Type should be \"Request\".")
}
if s.Method != SIP_METHOD_INVITE {
t.Errorf("[TestStartLine] Got error when parsing startline: \"INVITE sip:[email protected];user=phone SIP/2.0\". s.Method should be \"INVITE\".")
}
if s.Proto != "SIP" {
t.Errorf("[TestStartLine] Got error when startline: \"INVITE sip:[email protected];user=phone SIP/2.0\". s.Proto should be \"SIP\". Received: " + s.Proto)
}
if s.Version != "2.0" {
t.Errorf("[TestStartLine] Got error when parsing startline: \"INVITE sip:[email protected];user=phone SIP/2.0\". s.Version should be \"2.0\". Received: " + s.Version)
}
// throwing this in to make sure we don't toss an index error
str = "INVITE [email protected] SIP/"
s = ParseStartLine(str)
if s.Error == nil {
t.Errorf("[TestStartLine] Should have a no version err when parsing request line: \"INVITE [email protected] SIP/\".")
}
}