| OLD | NEW |
| 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_lookup_table.h" | 6 #include "chromeos/dbus/ibus/ibus_lookup_table.h" |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // create IBusLookupTable with mozc.candidates attachment. | 123 // create IBusLookupTable with mozc.candidates attachment. |
| 124 const char kSampleText1[] = "Sample Text 1"; | 124 const char kSampleText1[] = "Sample Text 1"; |
| 125 const char kSampleText2[] = "Sample Text 2"; | 125 const char kSampleText2[] = "Sample Text 2"; |
| 126 const char kSampleLabel1[] = "Sample Label 1"; | 126 const char kSampleLabel1[] = "Sample Label 1"; |
| 127 const char kSampleLabel2[] = "Sample Label 2"; | 127 const char kSampleLabel2[] = "Sample Label 2"; |
| 128 const uint32 kPageSize = 11; | 128 const uint32 kPageSize = 11; |
| 129 const uint32 kCursorPosition = 12; | 129 const uint32 kCursorPosition = 12; |
| 130 const bool kIsCursorVisible = true; | 130 const bool kIsCursorVisible = true; |
| 131 const IBusLookupTable::Orientation kOrientation = | 131 const IBusLookupTable::Orientation kOrientation = |
| 132 IBusLookupTable::IBUS_LOOKUP_TABLE_ORIENTATION_VERTICAL; | 132 IBusLookupTable::IBUS_LOOKUP_TABLE_ORIENTATION_VERTICAL; |
| 133 const uint8 kSampleBuffer[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; | 133 const bool kShowWindowAtComposition = false; |
| 134 const size_t kSampleBufferLength = 6UL; | |
| 135 | 134 |
| 136 // Create IBusLookupTable. | 135 // Create IBusLookupTable. |
| 137 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 136 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 138 dbus::MessageWriter writer(response.get()); | 137 dbus::MessageWriter writer(response.get()); |
| 139 dbus::MessageWriter top_variant_writer(NULL); | 138 dbus::MessageWriter top_variant_writer(NULL); |
| 140 writer.OpenVariant("(sa{sv}uubbiavav)", &top_variant_writer); | 139 writer.OpenVariant("(sa{sv}uubbiavav)", &top_variant_writer); |
| 141 dbus::MessageWriter contents_writer(NULL); | 140 dbus::MessageWriter contents_writer(NULL); |
| 142 top_variant_writer.OpenStruct(&contents_writer); | 141 top_variant_writer.OpenStruct(&contents_writer); |
| 143 contents_writer.AppendString("IBusLookupTable"); | 142 contents_writer.AppendString("IBusLookupTable"); |
| 144 | 143 |
| 145 // Write attachment field. | 144 // Write attachment field. |
| 146 dbus::MessageWriter attachment_array_writer(NULL); | 145 dbus::MessageWriter attachment_array_writer(NULL); |
| 147 contents_writer.OpenArray("{sv}", &attachment_array_writer); | 146 contents_writer.OpenArray("{sv}", &attachment_array_writer); |
| 148 dbus::MessageWriter entry_writer(NULL); | 147 dbus::MessageWriter entry_writer(NULL); |
| 149 attachment_array_writer.OpenDictEntry(&entry_writer); | 148 attachment_array_writer.OpenDictEntry(&entry_writer); |
| 150 entry_writer.AppendString("mozc.candidates"); | 149 entry_writer.AppendString("show_window_at_composition"); |
| 151 dbus::MessageWriter variant_writer(NULL); | 150 dbus::MessageWriter variant_writer(NULL); |
| 152 entry_writer.OpenVariant("v", &variant_writer); | 151 entry_writer.OpenVariant("v", &variant_writer); |
| 153 dbus::MessageWriter sub_variant_writer(NULL); | 152 dbus::MessageWriter sub_variant_writer(NULL); |
| 154 variant_writer.OpenVariant("ay", &sub_variant_writer); | 153 variant_writer.OpenVariant("b", &sub_variant_writer); |
| 155 sub_variant_writer.AppendArrayOfBytes(kSampleBuffer, kSampleBufferLength); | 154 sub_variant_writer.AppendBool(kShowWindowAtComposition); |
| 156 | 155 |
| 157 // Close attachment field container. | 156 // Close attachment field container. |
| 158 variant_writer.CloseContainer(&sub_variant_writer); | 157 variant_writer.CloseContainer(&sub_variant_writer); |
| 159 entry_writer.CloseContainer(&variant_writer); | 158 entry_writer.CloseContainer(&variant_writer); |
| 160 attachment_array_writer.CloseContainer(&entry_writer); | 159 attachment_array_writer.CloseContainer(&entry_writer); |
| 161 contents_writer.CloseContainer(&attachment_array_writer); | 160 contents_writer.CloseContainer(&attachment_array_writer); |
| 162 | 161 |
| 163 // Write IBusLookupTable contents. | 162 // Write IBusLookupTable contents. |
| 164 contents_writer.AppendUint32(kPageSize); | 163 contents_writer.AppendUint32(kPageSize); |
| 165 contents_writer.AppendUint32(kCursorPosition); | 164 contents_writer.AppendUint32(kCursorPosition); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 191 // Check values. | 190 // Check values. |
| 192 EXPECT_EQ(kPageSize, target_lookup_table.page_size()); | 191 EXPECT_EQ(kPageSize, target_lookup_table.page_size()); |
| 193 EXPECT_EQ(kCursorPosition, target_lookup_table.cursor_position()); | 192 EXPECT_EQ(kCursorPosition, target_lookup_table.cursor_position()); |
| 194 EXPECT_EQ(kIsCursorVisible, target_lookup_table.is_cursor_visible()); | 193 EXPECT_EQ(kIsCursorVisible, target_lookup_table.is_cursor_visible()); |
| 195 EXPECT_EQ(kOrientation, target_lookup_table.orientation()); | 194 EXPECT_EQ(kOrientation, target_lookup_table.orientation()); |
| 196 ASSERT_EQ(2UL, target_lookup_table.candidates().size()); | 195 ASSERT_EQ(2UL, target_lookup_table.candidates().size()); |
| 197 EXPECT_EQ(kSampleText1, target_lookup_table.candidates().at(0).value); | 196 EXPECT_EQ(kSampleText1, target_lookup_table.candidates().at(0).value); |
| 198 EXPECT_EQ(kSampleText2, target_lookup_table.candidates().at(1).value); | 197 EXPECT_EQ(kSampleText2, target_lookup_table.candidates().at(1).value); |
| 199 EXPECT_EQ(kSampleLabel1, target_lookup_table.candidates().at(0).label); | 198 EXPECT_EQ(kSampleLabel1, target_lookup_table.candidates().at(0).label); |
| 200 EXPECT_EQ(kSampleLabel2, target_lookup_table.candidates().at(1).label); | 199 EXPECT_EQ(kSampleLabel2, target_lookup_table.candidates().at(1).label); |
| 201 const std::string expected_binary( | 200 EXPECT_EQ(kShowWindowAtComposition, |
| 202 reinterpret_cast<const char*>(kSampleBuffer), kSampleBufferLength); | 201 target_lookup_table.show_window_at_composition()); |
| 203 EXPECT_EQ(expected_binary, | |
| 204 target_lookup_table.serialized_mozc_candidates_data()); | |
| 205 } | 202 } |
| 206 | 203 |
| 207 } // namespace ibus | 204 } // namespace ibus |
| 208 } // namespace chromeos | 205 } // namespace chromeos |
| OLD | NEW |