OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 "ui/base/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 ui { | |
16 | |
17 TEST(CandidateWindow, IsEqualTest) { | |
18 CandidateWindow cw1; | |
19 CandidateWindow cw2; | |
20 | |
21 const char kSampleString1[] = "Sample 1"; | |
22 const char kSampleString2[] = "Sample 2"; | |
23 | |
24 EXPECT_TRUE(cw1.IsEqual(cw2)); | |
25 EXPECT_TRUE(cw2.IsEqual(cw1)); | |
26 | |
27 cw1.set_page_size(1); | |
28 cw2.set_page_size(2); | |
29 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
30 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
31 cw2.set_page_size(1); | |
32 | |
33 cw1.set_cursor_position(1); | |
34 cw2.set_cursor_position(2); | |
35 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
36 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
37 cw2.set_cursor_position(1); | |
38 | |
39 cw1.set_is_cursor_visible(true); | |
40 cw2.set_is_cursor_visible(false); | |
41 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
42 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
43 cw2.set_is_cursor_visible(true); | |
44 | |
45 cw1.set_orientation(CandidateWindow::HORIZONTAL); | |
46 cw2.set_orientation(CandidateWindow::VERTICAL); | |
47 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
48 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
49 cw2.set_orientation(CandidateWindow::HORIZONTAL); | |
50 | |
51 cw1.set_show_window_at_composition(true); | |
52 cw2.set_show_window_at_composition(false); | |
53 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
54 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
55 cw2.set_show_window_at_composition(true); | |
56 | |
57 // Check equality for candidates member variable. | |
58 CandidateWindow::Entry entry1; | |
59 CandidateWindow::Entry entry2; | |
60 | |
61 cw1.mutable_candidates()->push_back(entry1); | |
62 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
63 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
64 cw2.mutable_candidates()->push_back(entry2); | |
65 EXPECT_TRUE(cw1.IsEqual(cw2)); | |
66 EXPECT_TRUE(cw2.IsEqual(cw1)); | |
67 | |
68 entry1.value = kSampleString1; | |
69 entry2.value = kSampleString2; | |
70 cw1.mutable_candidates()->push_back(entry1); | |
71 cw2.mutable_candidates()->push_back(entry2); | |
72 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
73 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
74 cw1.mutable_candidates()->clear(); | |
75 cw2.mutable_candidates()->clear(); | |
76 | |
77 entry1.label = kSampleString1; | |
78 entry2.label = kSampleString2; | |
79 cw1.mutable_candidates()->push_back(entry1); | |
80 cw2.mutable_candidates()->push_back(entry2); | |
81 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
82 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
83 cw1.mutable_candidates()->clear(); | |
84 cw2.mutable_candidates()->clear(); | |
85 | |
86 entry1.annotation = kSampleString1; | |
87 entry2.annotation = kSampleString2; | |
88 cw1.mutable_candidates()->push_back(entry1); | |
89 cw2.mutable_candidates()->push_back(entry2); | |
90 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
91 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
92 cw1.mutable_candidates()->clear(); | |
93 cw2.mutable_candidates()->clear(); | |
94 | |
95 entry1.description_title = kSampleString1; | |
96 entry2.description_title = kSampleString2; | |
97 cw1.mutable_candidates()->push_back(entry1); | |
98 cw2.mutable_candidates()->push_back(entry2); | |
99 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
100 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
101 cw1.mutable_candidates()->clear(); | |
102 cw2.mutable_candidates()->clear(); | |
103 | |
104 entry1.description_body = kSampleString1; | |
105 entry2.description_body = kSampleString2; | |
106 cw1.mutable_candidates()->push_back(entry1); | |
107 cw2.mutable_candidates()->push_back(entry2); | |
108 EXPECT_FALSE(cw1.IsEqual(cw2)); | |
109 EXPECT_FALSE(cw2.IsEqual(cw1)); | |
110 cw1.mutable_candidates()->clear(); | |
111 cw2.mutable_candidates()->clear(); | |
112 } | |
113 | |
114 TEST(CandidateWindow, CopyFromTest) { | |
115 CandidateWindow cw1; | |
116 CandidateWindow cw2; | |
117 | |
118 const char kSampleString[] = "Sample"; | |
119 | |
120 cw1.set_page_size(1); | |
121 cw1.set_cursor_position(2); | |
122 cw1.set_is_cursor_visible(false); | |
123 cw1.set_orientation(CandidateWindow::HORIZONTAL); | |
124 cw1.set_show_window_at_composition(false); | |
125 | |
126 CandidateWindow::Entry entry; | |
127 entry.value = kSampleString; | |
128 entry.label = kSampleString; | |
129 entry.annotation = kSampleString; | |
130 entry.description_title = kSampleString; | |
131 entry.description_body = kSampleString; | |
132 cw1.mutable_candidates()->push_back(entry); | |
133 | |
134 cw2.CopyFrom(cw1); | |
135 EXPECT_TRUE(cw1.IsEqual(cw2)); | |
136 } | |
137 | |
138 } // namespace ui | |
OLD | NEW |