forked from futurehomeno/fimpgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
address_test.go
101 lines (94 loc) · 2.75 KB
/
address_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package fimpgo
import "testing"
func TestNewAddressFromStringDevice(t *testing.T) {
addrString := "pt:j1/mt:evt/rt:dev/rn:zw/ad:1/sv:sensor_presence/ad:16"
adr, err := NewAddressFromString(addrString)
if err != nil {
t.Error(err)
}
if adr.PayloadType != "j1" {
t.Error("Wrong payload type")
}
if adr.MsgType != MsgTypeEvt {
t.Error("Wrong message type")
}
if adr.ResourceType != ResourceTypeDevice {
t.Error("Wrong resource type")
}
if adr.ResourceName != "zw" {
t.Error("Wrong resource name type")
}
if adr.ResourceAddress != "1" {
t.Error("Wrong resource address")
}
if adr.ServiceName != "sensor_presence" {
t.Error("Wrong payload type")
}
if adr.ServiceAddress != "16" {
t.Error("Wrong service address")
}
}
func TestNewAddressFromStringAdapter(t *testing.T) {
addrString := "pt:j1/mt:evt/rt:ad/rn:zw/ad:1"
adr, err := NewAddressFromString(addrString)
if err != nil {
t.Error(err)
}
if adr.PayloadType != "j1" {
t.Error("Wrong payload type")
}
if adr.MsgType != MsgTypeEvt {
t.Error("Wrong message type")
}
if adr.ResourceType != ResourceTypeAdapter {
t.Error("Wrong resource type")
}
if adr.ResourceName != "zw" {
t.Error("Wrong resource name type")
}
if adr.ResourceAddress != "1" {
t.Error("Wrong resource address")
}
}
func TestNewAddressFromStringAdapterGlobalPrefix(t *testing.T) {
addrString := "BDNF123/pt:j1/mt:evt/rt:ad/rn:zw/ad:1"
adr, err := NewAddressFromString(addrString)
if err != nil {
t.Error(err)
}
if adr.GlobalPrefix != "BDNF123" {
t.Error("Wrong global prefix type")
}
if adr.PayloadType != "j1" {
t.Error("Wrong payload type")
}
if adr.MsgType != MsgTypeEvt {
t.Error("Wrong message type")
}
if adr.ResourceType != ResourceTypeAdapter {
t.Error("Wrong resource type")
}
if adr.ResourceName != "zw" {
t.Error("Wrong resource name type")
}
if adr.ResourceAddress != "1" {
t.Error("Wrong resource address")
}
t.Log("Global prefix = ", adr.GlobalPrefix)
}
func TestAddress_Serialize(t *testing.T) {
adr := Address{MsgType: MsgTypeEvt, ResourceType: ResourceTypeDevice, ResourceName: "zw", ResourceAddress: "1", ServiceName: "sensor_presence", ServiceAddress: "16"}
adrStr := adr.Serialize()
if adrStr != "pt:j1/mt:evt/rt:dev/rn:zw/ad:1/sv:sensor_presence/ad:16" {
t.Error("Serialization is incorrect . Result is - ", adrStr)
}
t.Log(adrStr)
}
func TestAddress_SerializeWithGlobalPrefix(t *testing.T) {
adr := Address{MsgType: MsgTypeEvt, ResourceType: ResourceTypeDevice, ResourceName: "zw", ResourceAddress: "1", ServiceName: "sensor_presence", ServiceAddress: "16", GlobalPrefix: "BDNF123"}
adrStr := adr.Serialize()
if adrStr != "BDNF123/pt:j1/mt:evt/rt:dev/rn:zw/ad:1/sv:sensor_presence/ad:16" {
t.Error("Serialization is incorrect . Result is - ", adrStr)
}
t.Log(adrStr)
}