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