-
Notifications
You must be signed in to change notification settings - Fork 2
/
via_test.go
71 lines (56 loc) · 1.47 KB
/
via_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"testing"
)
func TestParseVia(t *testing.T) {
via, err := ParseVia("SIP/2.0/TLS client.biloxi.example.com:5061;branch=z9hG4bKnashds7;ttl=100,SIP/2.0/UDP client1.biloxi.example.com:5061;branch=z9hG4bKnashdm8;ttl=150")
if err != nil {
t.Fail()
}
if via.Size() != 2 {
t.Fail()
}
viaParam, _ := via.GetParam(0)
if v, err := viaParam.GetParam("branch"); err != nil || v != "z9hG4bKnashds7" {
t.Fail()
}
if viaParam.Host != "client.biloxi.example.com" || viaParam.GetPort() != 5061 {
t.Fail()
}
}
func TestParseVia2(t *testing.T) {
via, err := ParseVia("SIP/2.0/UDP 10.68.103.193:5060;branch=z9hG4bK-343437-6119ae735a31a77df85d22346c030fa7;rport")
if err != nil {
t.Fail()
}
fmt.Println(via)
}
func TestCreateViaParam(t *testing.T) {
viaParam := CreateViaParam("UDP", "client.biloxi.example.com", 0)
branch, _ := CreateBranch()
viaParam.SetBranch(branch)
fmt.Println(viaParam.String())
}
func TestParseVia3(t *testing.T) {
via, err := ParseVia("SIP/2.0/UDP 10.244.2.174:5060;branch=z9hG4bK-343034-8ae1b84c48a3a15106a4bcade0030d29;rport=9999;received=192.168.1.72")
if err != nil {
t.Fail()
}
viaParam, err := via.GetParam(0)
if err != nil {
t.Fail()
}
host, err := viaParam.GetReceived()
if err != nil {
t.Fail()
}
port, err := viaParam.GetRPort()
if err != nil {
port = viaParam.GetPort()
}
if viaParam.HasParam("rport") {
fmt.Println("rport param is supported")
}
fmt.Printf("host=%s, port=%d\n", host, port)
}