Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Side by Side Diff: chromeos/dbus/ibus/ibus_text_unittest.cc

Issue 11361210: Extends IBusObject to handle attachment field. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix include order Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/ibus/ibus_text.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_text.h" 6 #include "chromeos/dbus/ibus/ibus_text.h"
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "chromeos/dbus/ibus/ibus_object.h" 13 #include "chromeos/dbus/ibus/ibus_object.h"
14 #include "dbus/message.h" 14 #include "dbus/message.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace chromeos { 18 namespace chromeos {
19 // TODO(nona): Remove ibus namespace after complete libibus removal. 19 // TODO(nona): Remove ibus namespace after complete libibus removal.
20 namespace ibus { 20 namespace ibus {
21 21
22 TEST(IBusTextTest, WriteReadTest) { 22 TEST(IBusTextTest, WriteReadTest) {
23 const char kSampleText[] = "Sample Text"; 23 const char kSampleText[] = "Sample Text";
24 const char kAnnotation[] = "Annotation";
25 const char kDescription[] = "Description";
24 const IBusText::UnderlineAttribute kSampleUnderlineAttribute1 = { 26 const IBusText::UnderlineAttribute kSampleUnderlineAttribute1 = {
25 IBusText::IBUS_TEXT_UNDERLINE_SINGLE, 10, 20}; 27 IBusText::IBUS_TEXT_UNDERLINE_SINGLE, 10, 20};
26 28
27 const IBusText::UnderlineAttribute kSampleUnderlineAttribute2 = { 29 const IBusText::UnderlineAttribute kSampleUnderlineAttribute2 = {
28 IBusText::IBUS_TEXT_UNDERLINE_DOUBLE, 11, 21}; 30 IBusText::IBUS_TEXT_UNDERLINE_DOUBLE, 11, 21};
29 31
30 const IBusText::UnderlineAttribute kSampleUnderlineAttribute3 = { 32 const IBusText::UnderlineAttribute kSampleUnderlineAttribute3 = {
31 IBusText::IBUS_TEXT_UNDERLINE_ERROR, 12, 22}; 33 IBusText::IBUS_TEXT_UNDERLINE_ERROR, 12, 22};
32 34
33 const IBusText::SelectionAttribute kSampleSelectionAttribute = {30, 40}; 35 const IBusText::SelectionAttribute kSampleSelectionAttribute = {30, 40};
34 36
35 // Make IBusText 37 // Make IBusText
36 IBusText text; 38 IBusText text;
37 text.set_text(kSampleText); 39 text.set_text(kSampleText);
40 text.set_annotation(kAnnotation);
41 text.set_description(kDescription);
38 std::vector<IBusText::UnderlineAttribute>* underline_attributes = 42 std::vector<IBusText::UnderlineAttribute>* underline_attributes =
39 text.mutable_underline_attributes(); 43 text.mutable_underline_attributes();
40 underline_attributes->push_back(kSampleUnderlineAttribute1); 44 underline_attributes->push_back(kSampleUnderlineAttribute1);
41 underline_attributes->push_back(kSampleUnderlineAttribute2); 45 underline_attributes->push_back(kSampleUnderlineAttribute2);
42 underline_attributes->push_back(kSampleUnderlineAttribute3); 46 underline_attributes->push_back(kSampleUnderlineAttribute3);
43 std::vector<IBusText::SelectionAttribute>* selection_attributes = 47 std::vector<IBusText::SelectionAttribute>* selection_attributes =
44 text.mutable_selection_attributes(); 48 text.mutable_selection_attributes();
45 selection_attributes->push_back(kSampleSelectionAttribute); 49 selection_attributes->push_back(kSampleSelectionAttribute);
46 50
47 // Write to Response object. 51 // Write to Response object.
48 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 52 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
49 dbus::MessageWriter writer(response.get()); 53 dbus::MessageWriter writer(response.get());
50 AppendIBusText(text, &writer); 54 AppendIBusText(text, &writer);
51 55
52 // Read from Response object. 56 // Read from Response object.
53 dbus::MessageReader reader(response.get()); 57 dbus::MessageReader reader(response.get());
54 IBusText expected_text; 58 IBusText expected_text;
55 ASSERT_TRUE(PopIBusText(&reader, &expected_text)); 59 ASSERT_TRUE(PopIBusText(&reader, &expected_text));
56 EXPECT_EQ(expected_text.text(), kSampleText); 60 EXPECT_EQ(kSampleText, expected_text.text());
61 EXPECT_EQ(kAnnotation, expected_text.annotation());
62 EXPECT_EQ(kDescription, expected_text.description());
57 EXPECT_EQ(3U, expected_text.underline_attributes().size()); 63 EXPECT_EQ(3U, expected_text.underline_attributes().size());
58 EXPECT_EQ(1U, expected_text.selection_attributes().size()); 64 EXPECT_EQ(1U, expected_text.selection_attributes().size());
59 } 65 }
60 66
61 TEST(IBusTextTest, StringAsIBusTextTest) { 67 TEST(IBusTextTest, StringAsIBusTextTest) {
62 const char kSampleText[] = "Sample Text"; 68 const char kSampleText[] = "Sample Text";
63 69
64 // Write to Response object. 70 // Write to Response object.
65 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 71 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
66 dbus::MessageWriter writer(response.get()); 72 dbus::MessageWriter writer(response.get());
(...skipping 16 matching lines...) Expand all
83 dbus::MessageWriter writer(response.get()); 89 dbus::MessageWriter writer(response.get());
84 AppendStringAsIBusText(kSampleText, &writer); 90 AppendStringAsIBusText(kSampleText, &writer);
85 91
86 // Read from Response object. 92 // Read from Response object.
87 dbus::MessageReader reader(response.get()); 93 dbus::MessageReader reader(response.get());
88 std::string result; 94 std::string result;
89 ASSERT_TRUE(PopStringFromIBusText(&reader, &result)); 95 ASSERT_TRUE(PopStringFromIBusText(&reader, &result));
90 EXPECT_EQ(kSampleText, result); 96 EXPECT_EQ(kSampleText, result);
91 } 97 }
92 98
93 TEST(IBusTextTest, ReadAnnotationFieldTest) {
94 const char kSampleText[] = "Sample Text";
95 const char kSampleAnnotationText[] = "Sample Annotation";
96
97 // Create IBusLookupTable.
98 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
99 dbus::MessageWriter writer(response.get());
100 dbus::MessageWriter top_variant_writer(NULL);
101 writer.OpenVariant("(sa{sv}sv)", &top_variant_writer);
102 dbus::MessageWriter contents_writer(NULL);
103 top_variant_writer.OpenStruct(&contents_writer);
104 contents_writer.AppendString("IBusText");
105
106 // Write attachment field.
107 dbus::MessageWriter attachment_array_writer(NULL);
108 contents_writer.OpenArray("{sv}", &attachment_array_writer);
109 dbus::MessageWriter entry_writer(NULL);
110 attachment_array_writer.OpenDictEntry(&entry_writer);
111 entry_writer.AppendString("annotation");
112 dbus::MessageWriter variant_writer(NULL);
113 entry_writer.OpenVariant("v", &variant_writer);
114 dbus::MessageWriter sub_variant_writer(NULL);
115 variant_writer.OpenVariant("s", &sub_variant_writer);
116 sub_variant_writer.AppendString(kSampleAnnotationText);
117
118 // Close attachment field container.
119 variant_writer.CloseContainer(&sub_variant_writer);
120 entry_writer.CloseContainer(&variant_writer);
121 attachment_array_writer.CloseContainer(&entry_writer);
122 contents_writer.CloseContainer(&attachment_array_writer);
123
124 // Write IBusText contents.
125 contents_writer.AppendString(kSampleText);
126 IBusObjectWriter ibus_attr_list_writer("IBusAttrList", "av",
127 &contents_writer);
128 dbus::MessageWriter attribute_array_writer(NULL);
129 ibus_attr_list_writer.OpenArray("v", &attribute_array_writer);
130 ibus_attr_list_writer.CloseContainer(&attribute_array_writer);
131 ibus_attr_list_writer.CloseAll();
132
133 // Close all containers.
134 top_variant_writer.CloseContainer(&contents_writer);
135 writer.CloseContainer(&top_variant_writer);
136
137 // Read IBusText.
138 IBusText ibus_text;
139 dbus::MessageReader reader(response.get());
140 PopIBusText(&reader, &ibus_text);
141
142 // Check values.
143 EXPECT_EQ(kSampleText, ibus_text.text());
144 EXPECT_EQ(kSampleAnnotationText, ibus_text.annotation());
145 }
146
147 TEST(IBusTextTest, ReadDescriptionFieldTest) {
148 const char kSampleText[] = "Sample Text";
149 const char kSampleDescriptionText[] = "Sample Description";
150
151 // Create IBusLookupTable.
152 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
153 dbus::MessageWriter writer(response.get());
154 dbus::MessageWriter top_variant_writer(NULL);
155 writer.OpenVariant("(sa{sv}sv)", &top_variant_writer);
156 dbus::MessageWriter contents_writer(NULL);
157 top_variant_writer.OpenStruct(&contents_writer);
158 contents_writer.AppendString("IBusText");
159
160 // Write attachment field.
161 dbus::MessageWriter attachment_array_writer(NULL);
162 contents_writer.OpenArray("{sv}", &attachment_array_writer);
163 dbus::MessageWriter entry_writer(NULL);
164 attachment_array_writer.OpenDictEntry(&entry_writer);
165 entry_writer.AppendString("description");
166 dbus::MessageWriter variant_writer(NULL);
167 entry_writer.OpenVariant("v", &variant_writer);
168 dbus::MessageWriter sub_variant_writer(NULL);
169 variant_writer.OpenVariant("s", &sub_variant_writer);
170 sub_variant_writer.AppendString(kSampleDescriptionText);
171
172 // Close attachment field container.
173 variant_writer.CloseContainer(&sub_variant_writer);
174 entry_writer.CloseContainer(&variant_writer);
175 attachment_array_writer.CloseContainer(&entry_writer);
176 contents_writer.CloseContainer(&attachment_array_writer);
177
178 // Write IBusText contents.
179 contents_writer.AppendString(kSampleText);
180 IBusObjectWriter ibus_attr_list_writer("IBusAttrList", "av",
181 &contents_writer);
182 dbus::MessageWriter attribute_array_writer(NULL);
183 ibus_attr_list_writer.OpenArray("v", &attribute_array_writer);
184 ibus_attr_list_writer.CloseContainer(&attribute_array_writer);
185 ibus_attr_list_writer.CloseAll();
186
187 // Close all containers.
188 top_variant_writer.CloseContainer(&contents_writer);
189 writer.CloseContainer(&top_variant_writer);
190
191 // Read IBusText.
192 IBusText ibus_text;
193 dbus::MessageReader reader(response.get());
194 PopIBusText(&reader, &ibus_text);
195
196 // Check values.
197 EXPECT_EQ(kSampleText, ibus_text.text());
198 EXPECT_EQ(kSampleDescriptionText, ibus_text.description());
199 }
200
201 } // namespace ibus 99 } // namespace ibus
202 } // namespace chromeos 100 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/ibus/ibus_text.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698