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.
6 #include "chromeos/ime/candidate_window.h"
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"
16 namespace input_method {
18 TEST(CandidateWindow, IsEqualTest) {
22 const char kSampleString1[] = "Sample 1";
23 const char kSampleString2[] = "Sample 2";
25 EXPECT_TRUE(cw1.IsEqual(cw2));
26 EXPECT_TRUE(cw2.IsEqual(cw1));
30 EXPECT_FALSE(cw1.IsEqual(cw2));
31 EXPECT_FALSE(cw2.IsEqual(cw1));
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);
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);
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);
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);
58 // Check equality for candidates member variable.
59 CandidateWindow::Entry entry1;
60 CandidateWindow::Entry entry2;
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));
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();
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();
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();
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();
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();
115 TEST(CandidateWindow, CopyFromTest) {
119 const char kSampleString[] = "Sample";
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);
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);
136 EXPECT_TRUE(cw1.IsEqual(cw2));
139 } // namespace input_method
140 } // namespace chromeos