This repository has been archived by the owner on Dec 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextendedData_test.go
146 lines (131 loc) · 2.92 KB
/
extendedData_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package kml
import (
"encoding/xml"
"testing"
)
const raw = `
<ExtendedData>
<Data name="CGI">
<value>466561000000001</value>
</Data>
<Data name="CELLNAME">
</Data>
<Data name="CELLID">
<value>1</value>
</Data>
<Data name="eNB">
<value>521</value>
</Data>
<Data name="TAC">
<value>10000</value>
</Data>
<Data name="TECHNOLOGY">
<value>4G</value>
</Data>
<Data name="MODE">
<value>LTE</value>
</Data>
<Data name="RSRP">
<value>-80 dBm</value>
</Data>
<Data name="RSRQ">
<value>-7</value>
</Data>
<Data name="LAYER">
<value>1</value>
</Data>
<Data name="PC">
<value>0</value>
</Data>
<Data name="DL_BITRATE">
<value>0 kbps</value>
</Data>
<Data name="UL_BITRATE">
<value>0 kbps</value>
</Data>
<Data name="SNR">
<value>30.0</value>
</Data>
<Data name="LTE RSSI">
<value>-66</value>
</Data>
<Data name="PHONE STATE">
<value>I</value>
</Data>
<Data name="SPEED">
<value>17km/h</value>
</Data>
<Data name="HEIGHT">
<value>185m</value>
</Data>
<Data name="ACCURACY">
<value>5m</value>
</Data>
<Data name="TIME">
<value>2016.07.19_11.46.58</value>
</Data>
</ExtendedData>
`
func Test_XmlUnmarshal_ExtData_1(t *testing.T) {
v := &ExtData{}
err := xml.Unmarshal([]byte(raw), v)
if (v.XMLName == xml.Name{Space: "", Local: ""} || len(v.Data) == 0 || err != nil) {
t.Errorf("UnMarshal ExtendedData failed")
} else if len(v.Data) != 20 {
t.Errorf("UnMarshal ExtendedData failed. Partially lost")
} else {
t.Log("UnMarshal ExtendedData OK")
}
}
func Test_XmlMarshal_ExtData_1(t *testing.T) {
v := ExtData{
XMLName: xml.Name{Local: "ExtendedData"},
}
v.Data = append(v.Data, DataType{Name: "BBA", Value: "-1"})
v.Data = append(v.Data, DataType{Name: "AAB", Value: "hello"})
marshal, err := xml.Marshal(&v)
if err != nil {
t.Error("Marshal ExtData failed")
}
t.Logf("%s", string(marshal))
}
func Test_SetField(t *testing.T) {
v := ExtData{
XMLName: xml.Name{Local: "ExtendedData"},
}
v.Data = append(v.Data, DataType{Name: "BBA", Value: "-1"})
v.Data = append(v.Data, DataType{Name: "AAB", Value: "hello"})
v.SetField("AAB", "world")
found := false
for _, d := range v.Data {
if d.Name == "AAB" &&
d.Value == "world" {
found = true
t.Log("func SetField(kind string) string PASS")
break
}
}
//v.Data is empty
if len(v.Data) == 0 {
t.Error("ExtData error")
}
if !found {
t.Error("Invalid field or SetField() failed")
}
}
func Test_Field(t *testing.T) {
v := ExtData{
XMLName: xml.Name{Local: "ExtendedData"},
}
v.Data = append(v.Data, DataType{Name: "BBA", Value: "-1"})
v.Data = append(v.Data, DataType{Name: "AAB", Value: "hello"})
a1, _ := v.Field("AAB")
a2, _ := v.Field("BBA")
if a1 == "hello" && a2 == "-1" {
t.Log("func Field(kind string) string PASS")
}
}
/*
func Test_XmlMarshal_ExtData(t *testing.T) {
}
*/