| 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 "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace chromeos { | |
| 16 TEST(IBusLookupTable, IsEqualTest) { | |
| 17 IBusLookupTable table1; | |
| 18 IBusLookupTable table2; | |
| 19 | |
| 20 const char kSampleString1[] = "Sample 1"; | |
| 21 const char kSampleString2[] = "Sample 2"; | |
| 22 | |
| 23 EXPECT_TRUE(table1.IsEqual(table2)); | |
| 24 EXPECT_TRUE(table2.IsEqual(table1)); | |
| 25 | |
| 26 table1.set_page_size(1); | |
| 27 table2.set_page_size(2); | |
| 28 EXPECT_FALSE(table1.IsEqual(table2)); | |
| 29 EXPECT_FALSE(table2.IsEqual(table1)); | |
| 30 table2.set_page_size(1); | |
| 31 | |
| 32 table1.set_cursor_position(1); | |
| 33 table2.set_cursor_position(2); | |
| 34 EXPECT_FALSE(table1.IsEqual(table2)); | |
| 35 EXPECT_FALSE(table2.IsEqual(table1)); | |
| 36 table2.set_cursor_position(1); | |
| 37 | |
| 38 table1.set_is_cursor_visible(true); | |
| 39 table2.set_is_cursor_visible(false); | |
| 40 EXPECT_FALSE(table1.IsEqual(table2)); | |
| 41 EXPECT_FALSE(table2.IsEqual(table1)); | |
| 42 table2.set_is_cursor_visible(true); | |
| 43 | |
| 44 table1.set_orientation(IBusLookupTable::HORIZONTAL); | |
| 45 table2.set_orientation(IBusLookupTable::VERTICAL); | |
| 46 EXPECT_FALSE(table1.IsEqual(table2)); | |
| 47 EXPECT_FALSE(table2.IsEqual(table1)); | |
| 48 table2.set_orientation(IBusLookupTable::HORIZONTAL); | |
| 49 | |
| 50 table1.set_show_window_at_composition(true); | |
| 51 table2.set_show_window_at_composition(false); | |
| 52 EXPECT_FALSE(table1.IsEqual(table2)); | |
| 53 EXPECT_FALSE(table2.IsEqual(table1)); | |
| 54 table2.set_show_window_at_composition(true); | |
| 55 | |
| 56 // Check equality for candidates member variable. | |
| 57 IBusLookupTable::Entry entry1; | |
| 58 IBusLookupTable::Entry entry2; | |
| 59 | |
| 60 table1.mutable_candidates()->push_back(entry1); | |
| 61 EXPECT_FALSE(table1.IsEqual(table2)); | |
| 62 EXPECT_FALSE(table2.IsEqual(table1)); | |
| 63 table2.mutable_candidates()->push_back(entry2); | |
| 64 EXPECT_TRUE(table1.IsEqual(table2)); | |
| 65 EXPECT_TRUE(table2.IsEqual(table1)); | |
| 66 | |
| 67 entry1.value = kSampleString1; | |
| 68 entry2.value = kSampleString2; | |
| 69 table1.mutable_candidates()->push_back(entry1); | |
| 70 table2.mutable_candidates()->push_back(entry2); | |
| 71 EXPECT_FALSE(table1.IsEqual(table2)); | |
| 72 EXPECT_FALSE(table2.IsEqual(table1)); | |
| 73 table1.mutable_candidates()->clear(); | |
| 74 table2.mutable_candidates()->clear(); | |
| 75 | |
| 76 entry1.label = kSampleString1; | |
| 77 entry2.label = kSampleString2; | |
| 78 table1.mutable_candidates()->push_back(entry1); | |
| 79 table2.mutable_candidates()->push_back(entry2); | |
| 80 EXPECT_FALSE(table1.IsEqual(table2)); | |
| 81 EXPECT_FALSE(table2.IsEqual(table1)); | |
| 82 table1.mutable_candidates()->clear(); | |
| 83 table2.mutable_candidates()->clear(); | |
| 84 | |
| 85 entry1.annotation = kSampleString1; | |
| 86 entry2.annotation = kSampleString2; | |
| 87 table1.mutable_candidates()->push_back(entry1); | |
| 88 table2.mutable_candidates()->push_back(entry2); | |
| 89 EXPECT_FALSE(table1.IsEqual(table2)); | |
| 90 EXPECT_FALSE(table2.IsEqual(table1)); | |
| 91 table1.mutable_candidates()->clear(); | |
| 92 table2.mutable_candidates()->clear(); | |
| 93 | |
| 94 entry1.description_title = kSampleString1; | |
| 95 entry2.description_title = kSampleString2; | |
| 96 table1.mutable_candidates()->push_back(entry1); | |
| 97 table2.mutable_candidates()->push_back(entry2); | |
| 98 EXPECT_FALSE(table1.IsEqual(table2)); | |
| 99 EXPECT_FALSE(table2.IsEqual(table1)); | |
| 100 table1.mutable_candidates()->clear(); | |
| 101 table2.mutable_candidates()->clear(); | |
| 102 | |
| 103 entry1.description_body = kSampleString1; | |
| 104 entry2.description_body = kSampleString2; | |
| 105 table1.mutable_candidates()->push_back(entry1); | |
| 106 table2.mutable_candidates()->push_back(entry2); | |
| 107 EXPECT_FALSE(table1.IsEqual(table2)); | |
| 108 EXPECT_FALSE(table2.IsEqual(table1)); | |
| 109 table1.mutable_candidates()->clear(); | |
| 110 table2.mutable_candidates()->clear(); | |
| 111 } | |
| 112 | |
| 113 TEST(IBusLookupTable, CopyFromTest) { | |
| 114 IBusLookupTable table1; | |
| 115 IBusLookupTable table2; | |
| 116 | |
| 117 const char kSampleString[] = "Sample"; | |
| 118 | |
| 119 table1.set_page_size(1); | |
| 120 table1.set_cursor_position(2); | |
| 121 table1.set_is_cursor_visible(false); | |
| 122 table1.set_orientation(IBusLookupTable::HORIZONTAL); | |
| 123 table1.set_show_window_at_composition(false); | |
| 124 | |
| 125 IBusLookupTable::Entry entry; | |
| 126 entry.value = kSampleString; | |
| 127 entry.label = kSampleString; | |
| 128 entry.annotation = kSampleString; | |
| 129 entry.description_title = kSampleString; | |
| 130 entry.description_body = kSampleString; | |
| 131 table1.mutable_candidates()->push_back(entry); | |
| 132 | |
| 133 table2.CopyFrom(table1); | |
| 134 EXPECT_TRUE(table1.IsEqual(table2)); | |
| 135 } | |
| 136 } // namespace chromeos | |
| OLD | NEW |