OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 // TODO(nona): Add more tests. | |
5 | |
6 #include "chromeos/ime/candidate_window.h" | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "base/logging.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 namespace chromeos { | |
16 namespace input_method { | |
17 | |
18 TEST(CandidateWindow, IsEqualTest) { | |
19 CandidateWindow cw1; | |
20 CandidateWindow cw2; | |
21 | |
22 const char kSampleString1[] = "Sample 1"; | |
23 const char kSampleString2[] = "Sample 2"; | |
24 | |
25 EXPECT_TRUE(cw1.IsEqual(cw2)); | |
26 EXPECT_TRUE(cw2.IsEqual(cw1)); | |
27 | |
28 cw1.set_page_size(1); | |
29 cw2.set_page_size(2); | |
30 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
31 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
32 cw2.set_page_size(1); | |
33 | |
34 cw1.set_cursor_position(1); | |
35 cw2.set_cursor_position(2); | |
36 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
37 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
38 cw2.set_cursor_position(1); | |
39 | |
40 cw1.set_is_cursor_visible(true); | |
41 cw2.set_is_cursor_visible(false); | |
42 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
43 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
44 cw2.set_is_cursor_visible(true); | |
45 | |
46 cw1.set_orientation(CandidateWindow::HORIZONTAL); | |
47 cw2.set_orientation(CandidateWindow::VERTICAL); | |
48 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
49 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
50 cw2.set_orientation(CandidateWindow::HORIZONTAL); | |
51 | |
52 cw1.set_show_window_at_composition(true); | |
53 cw2.set_show_window_at_composition(false); | |
54 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
55 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
56 cw2.set_show_window_at_composition(true); | |
57 | |
58 // Check equality for candidates member variable. | |
59 CandidateWindow::Entry entry1; | |
60 CandidateWindow::Entry entry2; | |
61 | |
62 cw1.mutable_candidates()->push_back(entry1); | |
63 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
64 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
65 cw2.mutable_candidates()->push_back(entry2); | |
66 EXPECT_TRUE(cw1.IsEqual(cw2)); | |
67 EXPECT_TRUE(cw2.IsEqual(cw1)); | |
68 | |
69 entry1.value = kSampleString1; | |
70 entry2.value = kSampleString2; | |
71 cw1.mutable_candidates()->push_back(entry1); | |
72 cw2.mutable_candidates()->push_back(entry2); | |
73 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
74 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
75 cw1.mutable_candidates()->clear(); | |
76 cw2.mutable_candidates()->clear(); | |
77 | |
78 entry1.label = kSampleString1; | |
79 entry2.label = kSampleString2; | |
80 cw1.mutable_candidates()->push_back(entry1); | |
81 cw2.mutable_candidates()->push_back(entry2); | |
82 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
83 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
84 cw1.mutable_candidates()->clear(); | |
85 cw2.mutable_candidates()->clear(); | |
86 | |
87 entry1.annotation = kSampleString1; | |
88 entry2.annotation = kSampleString2; | |
89 cw1.mutable_candidates()->push_back(entry1); | |
90 cw2.mutable_candidates()->push_back(entry2); | |
91 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
92 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
93 cw1.mutable_candidates()->clear(); | |
94 cw2.mutable_candidates()->clear(); | |
95 | |
96 entry1.description_title = kSampleString1; | |
97 entry2.description_title = kSampleString2; | |
98 cw1.mutable_candidates()->push_back(entry1); | |
99 cw2.mutable_candidates()->push_back(entry2); | |
100 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
101 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
102 cw1.mutable_candidates()->clear(); | |
103 cw2.mutable_candidates()->clear(); | |
104 | |
105 entry1.description_body = kSampleString1; | |
106 entry2.description_body = kSampleString2; | |
107 cw1.mutable_candidates()->push_back(entry1); | |
108 cw2.mutable_candidates()->push_back(entry2); | |
109 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
110 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
111 cw1.mutable_candidates()->clear(); | |
112 cw2.mutable_candidates()->clear(); | |
113 } | |
114 | |
115 TEST(CandidateWindow, CopyFromTest) { | |
116 CandidateWindow cw1; | |
117 CandidateWindow cw2; | |
118 | |
119 const char kSampleString[] = "Sample"; | |
120 | |
121 cw1.set_page_size(1); | |
122 cw1.set_cursor_position(2); | |
123 cw1.set_is_cursor_visible(false); | |
124 cw1.set_orientation(CandidateWindow::HORIZONTAL); | |
125 cw1.set_show_window_at_composition(false); | |
126 | |
127 CandidateWindow::Entry entry; | |
128 entry.value = kSampleString; | |
129 entry.label = kSampleString; | |
130 entry.annotation = kSampleString; | |
131 entry.description_title = kSampleString; | |
132 entry.description_body = kSampleString; | |
133 cw1.mutable_candidates()->push_back(entry); | |
134 | |
135 cw2.CopyFrom(cw1); | |
136 EXPECT_TRUE(cw1.IsEqual(cw2)); | |
137 } | |
138 | |
139 } // namespace input_method | |
140 } // namespace chromeos | |
OLD | NEW |