diff options
author | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-18 18:31:44 +0000 |
---|---|---|
committer | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-18 18:31:44 +0000 |
commit | 9cb7cacccfd34117fd3b4f9f82d33a705b6b1aa8 (patch) | |
tree | 70b29f60b6d499d19c901c1598bd01e446e69d16 /chromeos | |
parent | a846872bc284d476f57c9c7794fc16eeaf9177f7 (diff) | |
download | chromium_src-9cb7cacccfd34117fd3b4f9f82d33a705b6b1aa8.zip chromium_src-9cb7cacccfd34117fd3b4f9f82d33a705b6b1aa8.tar.gz chromium_src-9cb7cacccfd34117fd3b4f9f82d33a705b6b1aa8.tar.bz2 |
Extends IBusText I/O function.
Introduce AppendStringAsIBusText/PopStringFromIBusText utility functions to
handle string as IBusText, because there are many cases to handle IBusText as
simple string.
BUG=None
TEST=chromeos-unittests,unit_tests,ui_unittests
Review URL: https://chromiumcodereview.appspot.com/10332228
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137911 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r-- | chromeos/dbus/ibus/ibus_text.cc | 16 | ||||
-rw-r--r-- | chromeos/dbus/ibus/ibus_text.h | 10 | ||||
-rw-r--r-- | chromeos/dbus/ibus/ibus_text_unittest.cc | 32 |
3 files changed, 58 insertions, 0 deletions
diff --git a/chromeos/dbus/ibus/ibus_text.cc b/chromeos/dbus/ibus/ibus_text.cc index b2eae15..8f0044d 100644 --- a/chromeos/dbus/ibus/ibus_text.cc +++ b/chromeos/dbus/ibus/ibus_text.cc @@ -93,6 +93,13 @@ void AppendIBusText(const IBusText& ibus_text, dbus::MessageWriter* writer) { ibus_text_writer.CloseAll(); } +void CHROMEOS_EXPORT AppendStringAsIBusText(const std::string& text, + dbus::MessageWriter* writer) { + IBusText ibus_text; + ibus_text.set_text(text); + AppendIBusText(ibus_text, writer); +} + bool PopIBusText(dbus::MessageReader* reader, IBusText* ibus_text) { IBusObjectReader ibus_text_reader("IBusText", reader); if (!ibus_text_reader.Init()) @@ -153,6 +160,15 @@ bool PopIBusText(dbus::MessageReader* reader, IBusText* ibus_text) { return true; } +bool CHROMEOS_EXPORT PopStringFromIBusText(dbus::MessageReader* reader, + std::string* text) { + IBusText ibus_text; + if(!PopIBusText(reader, &ibus_text)) + return false; + *text = ibus_text.text(); + return true; +} + /////////////////////////////////////////////////////////////////////////////// // IBusText IBusText::IBusText() diff --git a/chromeos/dbus/ibus/ibus_text.h b/chromeos/dbus/ibus/ibus_text.h index 6010b12..c05baeb 100644 --- a/chromeos/dbus/ibus/ibus_text.h +++ b/chromeos/dbus/ibus/ibus_text.h @@ -82,10 +82,20 @@ class IBusText; // Returns false if an error occures. bool CHROMEOS_EXPORT PopIBusText(dbus::MessageReader* reader, IBusText* ibus_text); +// Pops a IBusText from |reader| and stores it's text field into text. Use +// PopIBusText instead in the case of using any attribute entries in IBusText. +// Returns true on success. +bool CHROMEOS_EXPORT PopStringFromIBusText(dbus::MessageReader* reader, + std::string* text); // Appends a IBusText to |writer|. void CHROMEOS_EXPORT AppendIBusText(const IBusText& ibus_text, dbus::MessageWriter* writer); +// Appends a string to |writer| as IBusText without any attributes. Use +// AppendIBusText instead in the case of using any attribute entries. +void CHROMEOS_EXPORT AppendStringAsIBusText(const std::string& text, + dbus::MessageWriter* writer); + // Handles IBusText object which is used in dbus communication with ibus-daemon. // The IBusAttribute has four uint32 variables and the IBusAttributes represents // three type of decoration based on it's values. diff --git a/chromeos/dbus/ibus/ibus_text_unittest.cc b/chromeos/dbus/ibus/ibus_text_unittest.cc index cc1afbf..744eb78 100644 --- a/chromeos/dbus/ibus/ibus_text_unittest.cc +++ b/chromeos/dbus/ibus/ibus_text_unittest.cc @@ -58,5 +58,37 @@ TEST(IBusTextTest, WriteReadTest) { EXPECT_EQ(1U, expected_text.selection_attributes().size()); } +TEST(IBusTextTest, StringAsIBusTextTest) { + const char kSampleText[] = "Sample Text"; + + // Write to Response object. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + dbus::MessageWriter writer(response.get()); + AppendStringAsIBusText(kSampleText, &writer); + + // Read from Response object. + dbus::MessageReader reader(response.get()); + IBusText ibus_text; + ASSERT_TRUE(PopIBusText(&reader, &ibus_text)); + EXPECT_EQ(kSampleText, ibus_text.text()); + EXPECT_TRUE(ibus_text.underline_attributes().empty()); + EXPECT_TRUE(ibus_text.selection_attributes().empty()); +} + +TEST(IBusTextTest, PopStringFromIBusTextTest) { + const char kSampleText[] = "Sample Text"; + + // Write to Response object. + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + dbus::MessageWriter writer(response.get()); + AppendStringAsIBusText(kSampleText, &writer); + + // Read from Response object. + dbus::MessageReader reader(response.get()); + std::string result; + ASSERT_TRUE(PopStringFromIBusText(&reader, &result)); + EXPECT_EQ(kSampleText, result); +} + } // namespace ibus } // namespace chromeos |