OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 // TODO(nona): Add more tests. |
| 5 |
| 6 #include "chromeos/dbus/ibus/ibus_lookup_table.h" |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chromeos/dbus/ibus/ibus_object.h" |
| 14 #include "dbus/message.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 namespace chromeos { |
| 19 // TODO(nona): Remove ibus namespace after complete libibus removale. |
| 20 namespace ibus { |
| 21 |
| 22 TEST(IBusLookupTable, WriteReadTest) { |
| 23 const char kSampleText1[] = "Sample Text 1"; |
| 24 const char kSampleText2[] = "Sample Text 2"; |
| 25 const char kSampleLabel1[] = "Sample Label 1"; |
| 26 const char kSampleLabel2[] = "Sample Label 2"; |
| 27 const uint32 kPageSize = 11; |
| 28 const uint32 kCursorPosition = 12; |
| 29 const bool kIsCursorVisible = true; |
| 30 const IBusLookupTable::Orientation kOrientation = |
| 31 IBusLookupTable::IBUS_LOOKUP_TABLE_ORIENTATION_VERTICAL; |
| 32 |
| 33 // Create IBusLookupTable. |
| 34 IBusLookupTable lookup_table; |
| 35 lookup_table.set_page_size(kPageSize); |
| 36 lookup_table.set_cursor_position(kCursorPosition); |
| 37 lookup_table.set_is_cursor_visible(kIsCursorVisible); |
| 38 lookup_table.set_orientation(kOrientation); |
| 39 std::vector<IBusLookupTable::Entry>* candidates = |
| 40 lookup_table.mutable_candidates(); |
| 41 IBusLookupTable::Entry entry1; |
| 42 entry1.value = kSampleText1; |
| 43 entry1.label = kSampleLabel1; |
| 44 candidates->push_back(entry1); |
| 45 |
| 46 IBusLookupTable::Entry entry2; |
| 47 entry2.value = kSampleText2; |
| 48 entry2.label = kSampleLabel2; |
| 49 candidates->push_back(entry2); |
| 50 |
| 51 // Write IBusLookupTable. |
| 52 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 53 dbus::MessageWriter writer(response.get()); |
| 54 AppendIBusLookupTable(lookup_table, &writer); |
| 55 |
| 56 // Read IBusLookupTable. |
| 57 IBusLookupTable target_lookup_table; |
| 58 dbus::MessageReader reader(response.get()); |
| 59 PopIBusLookupTable(&reader, &target_lookup_table); |
| 60 |
| 61 // Check values. |
| 62 EXPECT_EQ(kPageSize, target_lookup_table.page_size()); |
| 63 EXPECT_EQ(kCursorPosition, target_lookup_table.cursor_position()); |
| 64 EXPECT_EQ(kIsCursorVisible, target_lookup_table.is_cursor_visible()); |
| 65 EXPECT_EQ(kOrientation, target_lookup_table.orientation()); |
| 66 ASSERT_EQ(2UL, target_lookup_table.candidates().size()); |
| 67 EXPECT_EQ(kSampleText1, target_lookup_table.candidates().at(0).value); |
| 68 EXPECT_EQ(kSampleText2, target_lookup_table.candidates().at(1).value); |
| 69 EXPECT_EQ(kSampleLabel1, target_lookup_table.candidates().at(0).label); |
| 70 EXPECT_EQ(kSampleLabel2, target_lookup_table.candidates().at(1).label); |
| 71 } |
| 72 |
| 73 TEST(IBusLookupTable, WriteReadWithoutLableTest) { |
| 74 const char kSampleText1[] = "Sample Text 1"; |
| 75 const char kSampleText2[] = "Sample Text 2"; |
| 76 const uint32 kPageSize = 11; |
| 77 const uint32 kCursorPosition = 12; |
| 78 const bool kIsCursorVisible = true; |
| 79 const IBusLookupTable::Orientation kOrientation = |
| 80 IBusLookupTable::IBUS_LOOKUP_TABLE_ORIENTATION_VERTICAL; |
| 81 |
| 82 // Create IBusLookupTable. |
| 83 IBusLookupTable lookup_table; |
| 84 lookup_table.set_page_size(kPageSize); |
| 85 lookup_table.set_cursor_position(kCursorPosition); |
| 86 lookup_table.set_is_cursor_visible(kIsCursorVisible); |
| 87 lookup_table.set_orientation(kOrientation); |
| 88 std::vector<IBusLookupTable::Entry>* candidates = |
| 89 lookup_table.mutable_candidates(); |
| 90 IBusLookupTable::Entry entry1; |
| 91 entry1.value = kSampleText1; |
| 92 candidates->push_back(entry1); |
| 93 |
| 94 IBusLookupTable::Entry entry2; |
| 95 entry2.value = kSampleText2; |
| 96 candidates->push_back(entry2); |
| 97 |
| 98 // Write IBusLookupTable. |
| 99 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 100 dbus::MessageWriter writer(response.get()); |
| 101 AppendIBusLookupTable(lookup_table, &writer); |
| 102 |
| 103 // Read IBusLookupTable. |
| 104 IBusLookupTable target_lookup_table; |
| 105 dbus::MessageReader reader(response.get()); |
| 106 PopIBusLookupTable(&reader, &target_lookup_table); |
| 107 |
| 108 // Check values. |
| 109 EXPECT_EQ(kPageSize, target_lookup_table.page_size()); |
| 110 EXPECT_EQ(kCursorPosition, target_lookup_table.cursor_position()); |
| 111 EXPECT_EQ(kIsCursorVisible, target_lookup_table.is_cursor_visible()); |
| 112 EXPECT_EQ(kOrientation, target_lookup_table.orientation()); |
| 113 ASSERT_EQ(2UL, target_lookup_table.candidates().size()); |
| 114 EXPECT_EQ(kSampleText1, target_lookup_table.candidates().at(0).value); |
| 115 EXPECT_EQ(kSampleText2, target_lookup_table.candidates().at(1).value); |
| 116 EXPECT_TRUE(target_lookup_table.candidates().at(0).label.empty()); |
| 117 EXPECT_TRUE(target_lookup_table.candidates().at(1).label.empty()); |
| 118 } |
| 119 |
| 120 } // namespace ibus |
| 121 } // namespace chromeos |
OLD | NEW |