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

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

Issue 11363033: Extends IBusText to handle mozc's extended field. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments 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"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 dbus::MessageWriter writer(response.get()); 83 dbus::MessageWriter writer(response.get());
84 AppendStringAsIBusText(kSampleText, &writer); 84 AppendStringAsIBusText(kSampleText, &writer);
85 85
86 // Read from Response object. 86 // Read from Response object.
87 dbus::MessageReader reader(response.get()); 87 dbus::MessageReader reader(response.get());
88 std::string result; 88 std::string result;
89 ASSERT_TRUE(PopStringFromIBusText(&reader, &result)); 89 ASSERT_TRUE(PopStringFromIBusText(&reader, &result));
90 EXPECT_EQ(kSampleText, result); 90 EXPECT_EQ(kSampleText, result);
91 } 91 }
92 92
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
93 } // namespace ibus 201 } // namespace ibus
94 } // namespace chromeos 202 } // 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