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
/
style_test.go
121 lines (110 loc) · 2.57 KB
/
style_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
package kml
import (
"encoding/xml"
"testing"
)
func Test_XmlUnmarshal_IconStyle_1(t *testing.T) {
raw := `
<IconStyle>
<color>12452450</color>
<scale>0.1</scale>
<Icon>
<href>http://i-am.url.com</href>
</Icon>
<LabelStyle>
<Scale>0</Scale>
</LabelStyle>
</IconStyle>
`
s := IconStyle{
XMLName: xml.Name{Space: "", Local: "IconStyle"},
Scale: 0.1,
KMLColor: "12452450",
IconHref: "http://i-am.url.com"}
var unmarshal IconStyle
xml.Unmarshal([]byte(raw), &unmarshal)
if s != unmarshal {
t.Errorf("Unmarshal Point, raw data: %s, Expect %#v\n, Result %#v", raw, s, unmarshal)
} else {
t.Log("Test_XmlUnmarshal_IconStyle_1 PASS")
}
}
func Test_XmlMarshal_IconStyle_1(t *testing.T) {
s := IconStyle{
XMLName: xml.Name{Space: "", Local: "IconStyle"},
Scale: 0.1,
KMLColor: "12452450",
IconHref: "http://i-am.url.com"}
d, err := xml.Marshal(&s)
if err != nil {
t.Error("Marshal Style-IconStyle failed")
} else {
t.Logf("%s", string(d))
}
}
func Test_XmlUnmarshal_Style_1(t *testing.T) {
raw := `
<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>
`
s := 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}
var unmarshal Style
xml.Unmarshal([]byte(raw), &unmarshal)
if s != unmarshal {
t.Errorf("Unmarshal Point , raw data: %s\n, Expect %#v\n, Result %#v", raw, s, unmarshal)
} else {
t.Log("Test_XmlUnmarshal_Style_1 PASS")
}
}
func Test_XmlMarshal_Style_1(t *testing.T) {
s := 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}
d, err := xml.Marshal(&s)
if err != nil {
t.Error("Marshal Style failed")
} else {
t.Logf("%s", string(d))
}
}
func Test_Style_Color_ToRgba(t *testing.T) {
i := IconStyle{
XMLName: xml.Name{Local: "IconStyle"},
KMLColor: "1234aced",
Scale: 0.1,
IconHref: "http://any.url.com",
}
expect := "edac3412"
if expect != ToRgba(i.KMLColor) {
t.Error("Color : ToRgba() failed")
}
}
func Test_Style_Color_SetRgba(t *testing.T) {
rgba := "aabb1122"
KMLColor := "2211bbaa"
if ToKmlColor(rgba) != KMLColor {
t.Error("Color ToKmlColor failed")
}
}