1 // Copyright 2008, Google Inc. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
5 //
6 // 1. Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // 2. Redistributions in binary form must reproduce the above copyright notice,
9 // this list of conditions and the following disclaimer in the documentation
10 // and/or other materials provided with the distribution.
11 // 3. Neither the name of Google Inc. nor the names of its contributors may be
12 // used to endorse or promote products derived from this software without
13 // specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26 #include "kml/dom/liststyle.h"
27 #include "kml/dom/kml_factory.h"
28 #include "kml/dom/kml_ptr.h"
29 #include "kml/dom/kmldom.h"
30 #include "gtest/gtest.h"
31
32 using kmlbase::Color32;
33
34 namespace kmldom {
35
36 class ItemIconTest : public testing::Test {
37 protected:
SetUp()38 virtual void SetUp() {
39 itemicon_ = KmlFactory::GetFactory()->CreateItemIcon();
40 }
41
42 ItemIconPtr itemicon_;
43 };
44
TEST_F(ItemIconTest,TestType)45 TEST_F(ItemIconTest, TestType) {
46 ASSERT_TRUE(itemicon_->IsA(Type_ItemIcon));
47 ASSERT_TRUE(itemicon_->IsA(Type_Object));
48 }
49
50 // Verify proper defaults:
TEST_F(ItemIconTest,TestDefaults)51 TEST_F(ItemIconTest, TestDefaults) {
52 ASSERT_FALSE(itemicon_->has_state());
53 ASSERT_EQ(static_cast<size_t>(1), itemicon_->get_state_array_size());
54 ASSERT_EQ(ITEMICONSTATE_OPEN, itemicon_->get_state_array_at(0));
55 ASSERT_FALSE(itemicon_->has_href());
56 ASSERT_EQ(string(""), itemicon_->get_href());
57 }
58
59 // Verify setting default makes has_xxx() true:
TEST_F(ItemIconTest,TestSetToDefaultValues)60 TEST_F(ItemIconTest, TestSetToDefaultValues) {
61 itemicon_->add_state(itemicon_->get_state_array_at(0));
62 ASSERT_TRUE(itemicon_->has_state());
63 itemicon_->set_href(itemicon_->get_href());
64 ASSERT_TRUE(itemicon_->has_href());
65 }
66
67 // Verify set, get, has, clear:
TEST_F(ItemIconTest,TestSetGetHasClear)68 TEST_F(ItemIconTest, TestSetGetHasClear) {
69 // Non-default values:
70 ItemIconStateEnum state = ITEMICONSTATE_ERROR;
71 string href("http://example.com/foo.jpg");
72
73 // Set all fields:
74 itemicon_->clear_state();
75 itemicon_->add_state(state);
76 itemicon_->set_href(href);
77
78 // Verify getter and has_xxx():
79 ASSERT_TRUE(itemicon_->has_state());
80 ASSERT_EQ(state, itemicon_->get_state_array_at(0));
81 ASSERT_TRUE(itemicon_->has_href());
82 ASSERT_EQ(href, itemicon_->get_href());
83
84 // Clear all fields:
85 itemicon_->clear_state();
86 itemicon_->clear_href();
87 }
88
TEST_F(ItemIconTest,TestStateArrays)89 TEST_F(ItemIconTest, TestStateArrays) {
90 ItemIconStateEnum iis_open= ITEMICONSTATE_OPEN;
91 ItemIconStateEnum iis_error = ITEMICONSTATE_ERROR;
92 ItemIconStateEnum iis_fetching0 = ITEMICONSTATE_FETCHING0;
93
94 // Verify the default constructed state.
95 ASSERT_FALSE(itemicon_->has_state());
96 ASSERT_EQ(static_cast<size_t>(1), itemicon_->get_state_array_size());
97 ASSERT_EQ(iis_open, itemicon_->get_state_array_at(0));
98
99 // Clear <state> array.
100 itemicon_->clear_state();
101 ASSERT_FALSE(itemicon_->has_state());
102 ASSERT_EQ(static_cast<size_t>(0), itemicon_->get_state_array_size());
103
104 // Add an explict error enum.
105 itemicon_->add_state(iis_error);
106 ASSERT_TRUE(itemicon_->has_state());
107 ASSERT_EQ(static_cast<size_t>(1), itemicon_->get_state_array_size());
108 ASSERT_EQ(iis_error, itemicon_->get_state_array_at(0));
109
110 // Add a fetching0 to the open.
111 itemicon_->add_state(iis_fetching0);
112 ASSERT_TRUE(itemicon_->has_state());
113 ASSERT_EQ(static_cast<size_t>(2), itemicon_->get_state_array_size());
114 ASSERT_EQ(iis_error, itemicon_->get_state_array_at(0));
115 ASSERT_EQ(iis_fetching0, itemicon_->get_state_array_at(1));
116 }
117
118 class ListStyleTest : public testing::Test {
119 protected:
SetUp()120 virtual void SetUp() {
121 liststyle_ = KmlFactory::GetFactory()->CreateListStyle();
122 }
123
124 ListStylePtr liststyle_;
125 };
126
TEST_F(ListStyleTest,TestType)127 TEST_F(ListStyleTest, TestType) {
128 ASSERT_TRUE(liststyle_->IsA(Type_ListStyle));
129 ASSERT_EQ(Type_ListStyle, liststyle_->Type());
130 ASSERT_TRUE(liststyle_->IsA(Type_SubStyle));
131 }
132
TEST_F(ListStyleTest,TestLists)133 TEST_F(ListStyleTest, TestLists) {
134 ASSERT_EQ(static_cast<size_t>(0), liststyle_->get_itemicon_array_size());
135 liststyle_->add_itemicon(KmlFactory::GetFactory()->CreateItemIcon());
136 liststyle_->add_itemicon(KmlFactory::GetFactory()->CreateItemIcon());
137 ASSERT_EQ(static_cast<size_t>(2), liststyle_->get_itemicon_array_size());
138 ASSERT_EQ(Type_ItemIcon, liststyle_->get_itemicon_array_at(0)->Type());
139 ASSERT_EQ(Type_ItemIcon, liststyle_->get_itemicon_array_at(1)->Type());
140 }
141
142 // Verify proper defaults:
TEST_F(ListStyleTest,TestDefaults)143 TEST_F(ListStyleTest, TestDefaults) {
144 ASSERT_FALSE(liststyle_->has_listitemtype());
145 ASSERT_EQ(LISTITEMTYPE_CHECK, liststyle_->get_listitemtype());
146 ASSERT_FALSE(liststyle_->has_bgcolor());
147 ASSERT_TRUE(Color32(0xffffffff) == liststyle_->get_bgcolor());
148 ASSERT_EQ(2, liststyle_->get_maxsnippetlines());
149 }
150
151 // Verify setting default makes has_xxx() true:
TEST_F(ListStyleTest,TestSetToDefaultValues)152 TEST_F(ListStyleTest, TestSetToDefaultValues) {
153 liststyle_->set_listitemtype(liststyle_->get_listitemtype());
154 ASSERT_TRUE(liststyle_->has_listitemtype());
155 liststyle_->set_bgcolor(liststyle_->get_bgcolor());
156 ASSERT_TRUE(liststyle_->has_bgcolor());
157 liststyle_->set_maxsnippetlines(liststyle_->get_maxsnippetlines());
158 ASSERT_TRUE(liststyle_->has_maxsnippetlines());
159 }
160
161 // Verify set, get, has, clear:
TEST_F(ListStyleTest,TestSetGetHasClear)162 TEST_F(ListStyleTest, TestSetGetHasClear) {
163 // Non-default values:
164 ListItemTypeEnum listitemtype = LISTITEMTYPE_CHECKHIDECHILDREN;
165 Color32 bgcolor(Color32(0x00112233));
166 int maxsnippetlines(3);
167
168 // Set all fields:
169 liststyle_->set_listitemtype(listitemtype);
170 liststyle_->set_bgcolor(bgcolor);
171 liststyle_->set_maxsnippetlines(maxsnippetlines);
172
173 // Verify getter and has_xxx():
174 ASSERT_TRUE(liststyle_->has_listitemtype());
175 ASSERT_EQ(listitemtype, liststyle_->get_listitemtype());
176 ASSERT_TRUE(liststyle_->has_bgcolor());
177 ASSERT_TRUE(bgcolor == liststyle_->get_bgcolor());
178 ASSERT_TRUE(liststyle_->has_maxsnippetlines());
179 ASSERT_EQ(maxsnippetlines, liststyle_->get_maxsnippetlines());
180
181 // Clear all fields:
182 liststyle_->clear_listitemtype();
183 liststyle_->clear_bgcolor();
184 liststyle_->clear_maxsnippetlines();
185 }
186
187 } // end namespace kmldom
188