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

Unified Diff: chromeos/dbus/ibus/ibus_object_unittest.cc

Issue 10384141: Extends IBusObject. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Change my mind to add IBusText handling into IBusObject. Created 8 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« chromeos/dbus/ibus/ibus_object.h ('K') | « chromeos/dbus/ibus/ibus_object.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/ibus/ibus_object_unittest.cc
diff --git a/chromeos/dbus/ibus/ibus_object_unittest.cc b/chromeos/dbus/ibus/ibus_object_unittest.cc
index b4cd2bbdbed25dd21d6dd258a42e58395d7dbae1..c12fac68ca1f88fda7ab2e896b345f543e83e36f 100644
--- a/chromeos/dbus/ibus/ibus_object_unittest.cc
+++ b/chromeos/dbus/ibus/ibus_object_unittest.cc
@@ -22,12 +22,16 @@ TEST(IBusObjectTest, WriteReadTest) {
const char kSampleText1[] = "Sample Text 1";
const char kSampleText2[] = "Sample Text 2";
const uint32 kSampleUint32 = 12345UL;
+ const int32 kSampleInt32 = 54321;
+ const bool kSampleBool = false;
const uint32 kSampleArrayOfUint32Count = 10UL;
// Create ibus object.
- IBusObjectWriter ibus_object_writer(kSampleTypeName1, "suauv", &writer);
+ IBusObjectWriter ibus_object_writer(kSampleTypeName1, "suibauv", &writer);
ibus_object_writer.AppendString(kSampleText1);
ibus_object_writer.AppendUint32(kSampleUint32);
+ ibus_object_writer.AppendInt32(kSampleInt32);
+ ibus_object_writer.AppendBool(kSampleBool);
dbus::MessageWriter array_writer(NULL);
ibus_object_writer.OpenArray("u", &array_writer);
for (uint32 i = 0; i < kSampleArrayOfUint32Count; ++i)
@@ -50,7 +54,15 @@ TEST(IBusObjectTest, WriteReadTest) {
uint32 expected_uint32;
ASSERT_TRUE(ibus_object_reader.PopUint32(&expected_uint32));
EXPECT_EQ(kSampleUint32, expected_uint32);
- // Check the third value which is array of uint32.
+ // Check the third int value.
+ int32 expected_int32;
satorux1 2012/05/18 01:23:36 initialize this with 0. Please fix other uninitial
Seigo Nonaka 2012/05/18 01:41:52 Done.
+ ASSERT_TRUE(ibus_object_reader.PopInt32(&expected_int32));
+ EXPECT_EQ(kSampleInt32, expected_int32);
+ // Check the fourth boolean value.
+ bool expected_bool;
+ ASSERT_TRUE(ibus_object_reader.PopBool(&expected_bool));
+ EXPECT_EQ(kSampleBool, expected_bool);
+ // Check the fifth value which is array of uint32.
dbus::MessageReader array_reader(NULL);
ASSERT_TRUE(ibus_object_reader.PopArray(&array_reader));
for (uint32 i = 0; i < kSampleArrayOfUint32Count; ++i) {
@@ -58,7 +70,7 @@ TEST(IBusObjectTest, WriteReadTest) {
ASSERT_TRUE(array_reader.PopUint32(&expected_uint32));
EXPECT_EQ(i, expected_uint32);
}
- // Check the fourth value which is IBusObject.
+ // Check the sixth value which is IBusObject.
IBusObjectReader ibus_nested_object_reader(kSampleTypeName2, NULL);
ibus_object_reader.PopIBusObject(&ibus_nested_object_reader);
std::string expected_text2;
@@ -87,4 +99,48 @@ TEST(IBusObjectTest, EmptyEntryTest) {
EXPECT_FALSE(ibus_object_reader.HasMoreData());
}
+TEST(IBusObjctTest, WriteWithGetContentsWriterTest) {
+ const char kSampleTypeName[] = "IBusObject Name";
+ const char kSampleText[] = "Sample Text 1";
+ scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
+
+ // Write string by writer given by GetContentsWriter.
+ dbus::MessageWriter writer(message.get());
+ IBusObjectWriter ibus_object_writer(kSampleTypeName, "s", &writer);
+ dbus::MessageWriter* contents_writer = ibus_object_writer.GetContentsWriter();
+ ASSERT_TRUE(contents_writer);
+ contents_writer->AppendString(kSampleText);
+ ibus_object_writer.CloseAll();
+
+ // Read by IBusObjectReader to make sure string exists in same field.
+ dbus::MessageReader reader(message.get());
+ IBusObjectReader ibus_object_reader(kSampleTypeName, &reader);
+ ASSERT_TRUE(ibus_object_reader.Init());
+ std::string actual_value;
+ ASSERT_TRUE(ibus_object_reader.PopString(&actual_value));
+ EXPECT_EQ(kSampleText, actual_value);
+}
+
+TEST(IBusObjctTest, ReadWithGetContentsReaderTest) {
+ const char kSampleTypeName[] = "IBusObject Name";
+ const char kSampleText[] = "Sample Text 1";
+ scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
+
+ // Write string by IBusObject.
+ dbus::MessageWriter writer(message.get());
+ IBusObjectWriter ibus_object_writer(kSampleTypeName, "s", &writer);
+ ibus_object_writer.AppendString(kSampleText);
+ ibus_object_writer.CloseAll();
+
+ // Read string by reader given by GetContentsReader.
+ dbus::MessageReader reader(message.get());
+ IBusObjectReader ibus_object_reader(kSampleTypeName, &reader);
+ ASSERT_TRUE(ibus_object_reader.Init());
+ dbus::MessageReader* contents_reader = ibus_object_reader.GetContentsReader();
+ ASSERT_TRUE(contents_reader);
+ std::string actual_value;
+ ASSERT_TRUE(contents_reader->PopString(&actual_value));
+ EXPECT_EQ(kSampleText, actual_value);
+}
+
} // namespace chromeos
« chromeos/dbus/ibus/ibus_object.h ('K') | « chromeos/dbus/ibus/ibus_object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698