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 pathplacemark_test.go
167 lines (157 loc) · 4.11 KB
/
placemark_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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package kml
import (
"encoding/xml"
"testing"
)
func Test_XmlUnmarshal_Placemark_1(t *testing.T) {
raw := `
<Placemark>
<name>Taipei 101</name>
<Style>
<IconStyle>
<color>12452450</color>
<scale>0.1</scale>
<Icon>
<href>http://i-am.url.com</href>
</Icon>
</IconStyle>
<LabelStyle>
<Scale>0</Scale>
</LabelStyle>
</Style>
<Point>
<coordinates>1.0,-1.0,+0.35</coordinates>
<altitudeMode>relativeToGround</altitudeMode>
</Point>
</Placemark>
`
var v Placemark
xml.Unmarshal([]byte(raw), &v)
expect := Placemark{
XMLName: xml.Name{Space: "", Local: "Placemark"},
Name: "Taipei 101",
Style: Style{
XMLName: xml.Name{Space: "", Local: "Style"},
IconStyle: IconStyle{
XMLName: xml.Name{Space: "", Local: "IconStyle"},
Scale: 0.1,
KMLColor: "12452450",
IconHref: "http://i-am.url.com"},
LabelStyleScale: 0.0},
Point: Point{XMLName: xml.Name{Space: "", Local: "Point"},
CoordData: "1.0,-1.0,+0.35",
Mode: "relativeToGround"}}
/*
if v != expect {
t.Errorf("Unmarshal Placemark , raw data: %s\n, Expect %#v\n, Result %#v", raw, expect, v)
} else {
t.Log("Test_XmlUnmarshal_Placemark_1 PASS")
}
*/
t.Logf("\n%+v \n\n%+v", expect, v)
}
func Test_XmlUnmarshal_Placemark_2(t *testing.T) {
raw := `
<Placemark>
<name>Taipei 101</name>
<Style>
<IconStyle>
<color>12452450</color>
<scale>0.1</scale>
<Icon>
<href>http://i-am.url.com</href>
</Icon>
</IconStyle>
<LabelStyle>
<Scale>0</Scale>
</LabelStyle>
</Style>
<ExtendedData>
<Data name="SNR">
<value>-30 dbm</value>
</Data>
</ExtendedData>
<Point>
<coordinates>1.0,-1.0,+0.35</coordinates>
<altitudeMode>relativeToGround</altitudeMode>
</Point>
</Placemark>
`
var v Placemark
xml.Unmarshal([]byte(raw), &v)
expect := Placemark{
XMLName: xml.Name{Space: "", Local: "Placemark"},
Name: "Taipei 101",
Style: Style{
XMLName: xml.Name{Space: "", Local: "Style"},
IconStyle: IconStyle{
XMLName: xml.Name{Space: "", Local: "IconStyle"},
Scale: 0.1,
KMLColor: "12452450",
IconHref: "http://i-am.url.com"},
LabelStyleScale: 0.0},
Point: Point{XMLName: xml.Name{Space: "", Local: "Point"},
CoordData: "1.0,-1.0,+0.35",
Mode: "relativeToGround"}}
// Add ExtData XMLName (optional)
expect.ExtData.XMLName.Local = "ExtendedData"
arr := &expect.ExtData.Data
//Add DataType contents
//Add DataType XMLName (optional)
*arr = append(*arr, DataType{XMLName: xml.Name{Local: "Data"}, Name: "SNR", Value: "-30 dbm"})
//Human check
t.Logf("\n%+v \n\n%+v", expect, v)
}
func Test_XmlMarshal_Placemark_1(t *testing.T) {
raw := `
<Placemark>
<name>Taipei 101</name>
<Style>
<IconStyle>
<color>12452450</color>
<scale>0.1</scale>
<Icon>
<href>http://i-am.url.com</href>
</Icon>
</IconStyle>
<LabelStyle>
<Scale>0</Scale>
</LabelStyle>
</Style>
<ExtendedData>
<Data name="SNR">
<value>-30 dbm</value>
</Data>
</ExtendedData>
<Point>
<coordinates>1.0,-1.0,+0.35</coordinates>
<altitudeMode>relativeToGround</altitudeMode>
</Point>
</Placemark>
`
var v Placemark
xml.Unmarshal([]byte(raw), &v)
expect := Placemark{
XMLName: xml.Name{Space: "", Local: "Placemark"},
Name: "Taipei 101",
Style: Style{
XMLName: xml.Name{Space: "", Local: "Style"},
IconStyle: IconStyle{
XMLName: xml.Name{Space: "", Local: "IconStyle"},
Scale: 0.1,
KMLColor: "12452450",
IconHref: "http://i-am.url.com"},
LabelStyleScale: 0.0},
Point: Point{XMLName: xml.Name{Space: "", Local: "Point"},
CoordData: "1.0,-1.0,+0.35",
Mode: "relativeToGround"}}
// Add ExtData XMLName (optional)
expect.ExtData.XMLName.Local = "ExtendedData"
arr := &expect.ExtData.Data
//Add DataType contents
//Add DataType XMLName (optional)
*arr = append(*arr, DataType{XMLName: xml.Name{Local: "Data"}, Name: "SNR", Value: "-30 dbm"})
data, _ := xml.Marshal(expect)
//Human check
t.Logf("\n%+v \n\n%+v", expect, string(data))
}