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
/
folder_test.go
67 lines (64 loc) · 1.49 KB
/
folder_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
package kml
import (
"encoding/xml"
"testing"
)
func Test_XmlMarshal_Folder_1(t *testing.T) {
f := &Folder{
XMLName: xml.Name{Local: "Folder"},
Name: "New expt",
}
p := 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: "",
},
}
f.Placemarks = append(f.Placemarks, p)
t.Log(f)
}
func Test_XmlUnmarshal_Folder_1(t *testing.T) {
raw := `
<Folder>
<name>New expt</name>
<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>
</Folder>
`
var f Folder
err := xml.Unmarshal([]byte(raw), &f)
if err != nil {
t.Error("UnMarshal Folder failed")
} else if f.Name != "New expt" ||
len(f.Placemarks) != 1 ||
f.Placemarks[0].Point.CoordData != "1.0,-1.0,+0.35" {
t.Errorf("UnMarshal Folder failed. inner error \n%v", f)
}
}