OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // TODO(nona): Add more tests. | 4 // TODO(nona): Add more tests. |
5 | 5 |
6 #include "chromeos/dbus/ibus/ibus_lookup_table.h" | 6 #include "chromeos/dbus/ibus/ibus_lookup_table.h" |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 TEST(IBusLookupTable, WriteReadTest) { | 23 TEST(IBusLookupTable, WriteReadTest) { |
24 const char kSampleText1[] = "Sample Text 1"; | 24 const char kSampleText1[] = "Sample Text 1"; |
25 const char kSampleText2[] = "Sample Text 2"; | 25 const char kSampleText2[] = "Sample Text 2"; |
26 const char kSampleLabel1[] = "Sample Label 1"; | 26 const char kSampleLabel1[] = "Sample Label 1"; |
27 const char kSampleLabel2[] = "Sample Label 2"; | 27 const char kSampleLabel2[] = "Sample Label 2"; |
28 const uint32 kPageSize = 11; | 28 const uint32 kPageSize = 11; |
29 const uint32 kCursorPosition = 12; | 29 const uint32 kCursorPosition = 12; |
30 const bool kIsCursorVisible = true; | 30 const bool kIsCursorVisible = true; |
31 const IBusLookupTable::Orientation kOrientation = | 31 const IBusLookupTable::Orientation kOrientation = |
32 IBusLookupTable::IBUS_LOOKUP_TABLE_ORIENTATION_VERTICAL; | 32 IBusLookupTable::VERTICAL; |
33 | 33 |
34 // Create IBusLookupTable. | 34 // Create IBusLookupTable. |
35 IBusLookupTable lookup_table; | 35 IBusLookupTable lookup_table; |
36 lookup_table.set_page_size(kPageSize); | 36 lookup_table.set_page_size(kPageSize); |
37 lookup_table.set_cursor_position(kCursorPosition); | 37 lookup_table.set_cursor_position(kCursorPosition); |
38 lookup_table.set_is_cursor_visible(kIsCursorVisible); | 38 lookup_table.set_is_cursor_visible(kIsCursorVisible); |
39 lookup_table.set_orientation(kOrientation); | 39 lookup_table.set_orientation(kOrientation); |
40 std::vector<IBusLookupTable::Entry>* candidates = | 40 std::vector<IBusLookupTable::Entry>* candidates = |
41 lookup_table.mutable_candidates(); | 41 lookup_table.mutable_candidates(); |
42 IBusLookupTable::Entry entry1; | 42 IBusLookupTable::Entry entry1; |
(...skipping 28 matching lines...) Expand all Loading... |
71 EXPECT_EQ(kSampleLabel2, target_lookup_table.candidates().at(1).label); | 71 EXPECT_EQ(kSampleLabel2, target_lookup_table.candidates().at(1).label); |
72 } | 72 } |
73 | 73 |
74 TEST(IBusLookupTable, WriteReadWithoutLableTest) { | 74 TEST(IBusLookupTable, WriteReadWithoutLableTest) { |
75 const char kSampleText1[] = "Sample Text 1"; | 75 const char kSampleText1[] = "Sample Text 1"; |
76 const char kSampleText2[] = "Sample Text 2"; | 76 const char kSampleText2[] = "Sample Text 2"; |
77 const uint32 kPageSize = 11; | 77 const uint32 kPageSize = 11; |
78 const uint32 kCursorPosition = 12; | 78 const uint32 kCursorPosition = 12; |
79 const bool kIsCursorVisible = true; | 79 const bool kIsCursorVisible = true; |
80 const IBusLookupTable::Orientation kOrientation = | 80 const IBusLookupTable::Orientation kOrientation = |
81 IBusLookupTable::IBUS_LOOKUP_TABLE_ORIENTATION_VERTICAL; | 81 IBusLookupTable::VERTICAL; |
82 | 82 |
83 // Create IBusLookupTable. | 83 // Create IBusLookupTable. |
84 IBusLookupTable lookup_table; | 84 IBusLookupTable lookup_table; |
85 lookup_table.set_page_size(kPageSize); | 85 lookup_table.set_page_size(kPageSize); |
86 lookup_table.set_cursor_position(kCursorPosition); | 86 lookup_table.set_cursor_position(kCursorPosition); |
87 lookup_table.set_is_cursor_visible(kIsCursorVisible); | 87 lookup_table.set_is_cursor_visible(kIsCursorVisible); |
88 lookup_table.set_orientation(kOrientation); | 88 lookup_table.set_orientation(kOrientation); |
89 std::vector<IBusLookupTable::Entry>* candidates = | 89 std::vector<IBusLookupTable::Entry>* candidates = |
90 lookup_table.mutable_candidates(); | 90 lookup_table.mutable_candidates(); |
91 IBusLookupTable::Entry entry1; | 91 IBusLookupTable::Entry entry1; |
(...skipping 30 matching lines...) Expand all Loading... |
122 // IBusObjectWriter does not support attachment field handling, so manually | 122 // IBusObjectWriter does not support attachment field handling, so manually |
123 // create IBusLookupTable with mozc.candidates attachment. | 123 // create IBusLookupTable with mozc.candidates attachment. |
124 const char kSampleText1[] = "Sample Text 1"; | 124 const char kSampleText1[] = "Sample Text 1"; |
125 const char kSampleText2[] = "Sample Text 2"; | 125 const char kSampleText2[] = "Sample Text 2"; |
126 const char kSampleLabel1[] = "Sample Label 1"; | 126 const char kSampleLabel1[] = "Sample Label 1"; |
127 const char kSampleLabel2[] = "Sample Label 2"; | 127 const char kSampleLabel2[] = "Sample Label 2"; |
128 const uint32 kPageSize = 11; | 128 const uint32 kPageSize = 11; |
129 const uint32 kCursorPosition = 12; | 129 const uint32 kCursorPosition = 12; |
130 const bool kIsCursorVisible = true; | 130 const bool kIsCursorVisible = true; |
131 const IBusLookupTable::Orientation kOrientation = | 131 const IBusLookupTable::Orientation kOrientation = |
132 IBusLookupTable::IBUS_LOOKUP_TABLE_ORIENTATION_VERTICAL; | 132 IBusLookupTable::VERTICAL; |
133 const bool kShowWindowAtComposition = false; | 133 const bool kShowWindowAtComposition = false; |
134 | 134 |
135 // Create IBusLookupTable. | 135 // Create IBusLookupTable. |
136 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 136 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
137 dbus::MessageWriter writer(response.get()); | 137 dbus::MessageWriter writer(response.get()); |
138 dbus::MessageWriter top_variant_writer(NULL); | 138 dbus::MessageWriter top_variant_writer(NULL); |
139 writer.OpenVariant("(sa{sv}uubbiavav)", &top_variant_writer); | 139 writer.OpenVariant("(sa{sv}uubbiavav)", &top_variant_writer); |
140 dbus::MessageWriter contents_writer(NULL); | 140 dbus::MessageWriter contents_writer(NULL); |
141 top_variant_writer.OpenStruct(&contents_writer); | 141 top_variant_writer.OpenStruct(&contents_writer); |
142 contents_writer.AppendString("IBusLookupTable"); | 142 contents_writer.AppendString("IBusLookupTable"); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 EXPECT_EQ(kOrientation, target_lookup_table.orientation()); | 194 EXPECT_EQ(kOrientation, target_lookup_table.orientation()); |
195 ASSERT_EQ(2UL, target_lookup_table.candidates().size()); | 195 ASSERT_EQ(2UL, target_lookup_table.candidates().size()); |
196 EXPECT_EQ(kSampleText1, target_lookup_table.candidates().at(0).value); | 196 EXPECT_EQ(kSampleText1, target_lookup_table.candidates().at(0).value); |
197 EXPECT_EQ(kSampleText2, target_lookup_table.candidates().at(1).value); | 197 EXPECT_EQ(kSampleText2, target_lookup_table.candidates().at(1).value); |
198 EXPECT_EQ(kSampleLabel1, target_lookup_table.candidates().at(0).label); | 198 EXPECT_EQ(kSampleLabel1, target_lookup_table.candidates().at(0).label); |
199 EXPECT_EQ(kSampleLabel2, target_lookup_table.candidates().at(1).label); | 199 EXPECT_EQ(kSampleLabel2, target_lookup_table.candidates().at(1).label); |
200 EXPECT_EQ(kShowWindowAtComposition, | 200 EXPECT_EQ(kShowWindowAtComposition, |
201 target_lookup_table.show_window_at_composition()); | 201 target_lookup_table.show_window_at_composition()); |
202 } | 202 } |
203 | 203 |
| 204 TEST(IBusLookupTable, IsEqualTest) { |
| 205 IBusLookupTable table1; |
| 206 IBusLookupTable table2; |
| 207 |
| 208 const char kSampleString1[] = "Sample 1"; |
| 209 const char kSampleString2[] = "Sample 2"; |
| 210 |
| 211 EXPECT_TRUE(table1.IsEqual(table2)); |
| 212 EXPECT_TRUE(table2.IsEqual(table1)); |
| 213 |
| 214 table1.set_page_size(1); |
| 215 table2.set_page_size(2); |
| 216 EXPECT_FALSE(table1.IsEqual(table2)); |
| 217 EXPECT_FALSE(table2.IsEqual(table1)); |
| 218 table2.set_page_size(1); |
| 219 |
| 220 table1.set_cursor_position(1); |
| 221 table2.set_cursor_position(2); |
| 222 EXPECT_FALSE(table1.IsEqual(table2)); |
| 223 EXPECT_FALSE(table2.IsEqual(table1)); |
| 224 table2.set_cursor_position(1); |
| 225 |
| 226 table1.set_is_cursor_visible(true); |
| 227 table2.set_is_cursor_visible(false); |
| 228 EXPECT_FALSE(table1.IsEqual(table2)); |
| 229 EXPECT_FALSE(table2.IsEqual(table1)); |
| 230 table2.set_is_cursor_visible(true); |
| 231 |
| 232 table1.set_orientation(IBusLookupTable::HORIZONTAL); |
| 233 table2.set_orientation(IBusLookupTable::VERTICAL); |
| 234 EXPECT_FALSE(table1.IsEqual(table2)); |
| 235 EXPECT_FALSE(table2.IsEqual(table1)); |
| 236 table2.set_orientation(IBusLookupTable::HORIZONTAL); |
| 237 |
| 238 table1.set_show_window_at_composition(true); |
| 239 table2.set_show_window_at_composition(false); |
| 240 EXPECT_FALSE(table1.IsEqual(table2)); |
| 241 EXPECT_FALSE(table2.IsEqual(table1)); |
| 242 table2.set_show_window_at_composition(true); |
| 243 |
| 244 // Check equality for candidates member variable. |
| 245 IBusLookupTable::Entry entry1; |
| 246 IBusLookupTable::Entry entry2; |
| 247 |
| 248 table1.mutable_candidates()->push_back(entry1); |
| 249 EXPECT_FALSE(table1.IsEqual(table2)); |
| 250 EXPECT_FALSE(table2.IsEqual(table1)); |
| 251 table2.mutable_candidates()->push_back(entry2); |
| 252 EXPECT_TRUE(table1.IsEqual(table2)); |
| 253 EXPECT_TRUE(table2.IsEqual(table1)); |
| 254 |
| 255 entry1.value = kSampleString1; |
| 256 entry2.value = kSampleString2; |
| 257 table1.mutable_candidates()->push_back(entry1); |
| 258 table2.mutable_candidates()->push_back(entry2); |
| 259 EXPECT_FALSE(table1.IsEqual(table2)); |
| 260 EXPECT_FALSE(table2.IsEqual(table1)); |
| 261 table1.mutable_candidates()->clear(); |
| 262 table2.mutable_candidates()->clear(); |
| 263 |
| 264 entry1.label = kSampleString1; |
| 265 entry2.label = kSampleString2; |
| 266 table1.mutable_candidates()->push_back(entry1); |
| 267 table2.mutable_candidates()->push_back(entry2); |
| 268 EXPECT_FALSE(table1.IsEqual(table2)); |
| 269 EXPECT_FALSE(table2.IsEqual(table1)); |
| 270 table1.mutable_candidates()->clear(); |
| 271 table2.mutable_candidates()->clear(); |
| 272 |
| 273 entry1.annotation = kSampleString1; |
| 274 entry2.annotation = kSampleString2; |
| 275 table1.mutable_candidates()->push_back(entry1); |
| 276 table2.mutable_candidates()->push_back(entry2); |
| 277 EXPECT_FALSE(table1.IsEqual(table2)); |
| 278 EXPECT_FALSE(table2.IsEqual(table1)); |
| 279 table1.mutable_candidates()->clear(); |
| 280 table2.mutable_candidates()->clear(); |
| 281 |
| 282 entry1.description_title = kSampleString1; |
| 283 entry2.description_title = kSampleString2; |
| 284 table1.mutable_candidates()->push_back(entry1); |
| 285 table2.mutable_candidates()->push_back(entry2); |
| 286 EXPECT_FALSE(table1.IsEqual(table2)); |
| 287 EXPECT_FALSE(table2.IsEqual(table1)); |
| 288 table1.mutable_candidates()->clear(); |
| 289 table2.mutable_candidates()->clear(); |
| 290 |
| 291 entry1.description_body = kSampleString1; |
| 292 entry2.description_body = kSampleString2; |
| 293 table1.mutable_candidates()->push_back(entry1); |
| 294 table2.mutable_candidates()->push_back(entry2); |
| 295 EXPECT_FALSE(table1.IsEqual(table2)); |
| 296 EXPECT_FALSE(table2.IsEqual(table1)); |
| 297 table1.mutable_candidates()->clear(); |
| 298 table2.mutable_candidates()->clear(); |
| 299 } |
| 300 |
| 301 TEST(IBusLookupTable, CopyFromTest) { |
| 302 IBusLookupTable table1; |
| 303 IBusLookupTable table2; |
| 304 |
| 305 const char kSampleString[] = "Sample"; |
| 306 |
| 307 table1.set_page_size(1); |
| 308 table1.set_cursor_position(2); |
| 309 table1.set_is_cursor_visible(false); |
| 310 table1.set_orientation(IBusLookupTable::HORIZONTAL); |
| 311 table1.set_show_window_at_composition(false); |
| 312 |
| 313 IBusLookupTable::Entry entry; |
| 314 entry.value = kSampleString; |
| 315 entry.label = kSampleString; |
| 316 entry.annotation = kSampleString; |
| 317 entry.description_title = kSampleString; |
| 318 entry.description_body = kSampleString; |
| 319 table1.mutable_candidates()->push_back(entry); |
| 320 |
| 321 table2.CopyFrom(table1); |
| 322 EXPECT_TRUE(table1.IsEqual(table2)); |
| 323 } |
204 } // namespace ibus | 324 } // namespace ibus |
205 } // namespace chromeos | 325 } // namespace chromeos |
OLD | NEW |