| 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 #include "chromeos/dbus/ibus/ibus_component.h" | |
| 5 | |
| 6 #include <string> | |
| 7 | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "dbus/message.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace chromeos { | |
| 13 | |
| 14 TEST(IBusComponentTest, WriteReadIBusComponentTest) { | |
| 15 const std::string kName = "Component Name"; | |
| 16 const std::string kDescription = "Component Description"; | |
| 17 const std::string kAuthor = "Component Author"; | |
| 18 | |
| 19 const std::string kEngineId1 = "Engine Id 1"; | |
| 20 const std::string kEngineDisplayName1 = "Engine Display Name 1"; | |
| 21 const std::string kEngineDescription1 = "Engine Description 1"; | |
| 22 const std::string kEngineLanguageCode1 = "en"; | |
| 23 const std::string kEngineAuthor1 = "Engine Author 1"; | |
| 24 const IBusComponent::EngineDescription engine_desc1(kEngineId1, | |
| 25 kEngineDisplayName1, | |
| 26 kEngineDescription1, | |
| 27 kEngineLanguageCode1, | |
| 28 kEngineAuthor1); | |
| 29 | |
| 30 const std::string kEngineId2 = "Engine Id 2"; | |
| 31 const std::string kEngineDisplayName2 = "Engine Display Name 2"; | |
| 32 const std::string kEngineDescription2 = "Engine Description 2"; | |
| 33 const std::string kEngineLanguageCode2 = "ja"; | |
| 34 const std::string kEngineAuthor2 = "Engine Author 2"; | |
| 35 const IBusComponent::EngineDescription engine_desc2(kEngineId2, | |
| 36 kEngineDisplayName2, | |
| 37 kEngineDescription2, | |
| 38 kEngineLanguageCode2, | |
| 39 kEngineAuthor2); | |
| 40 | |
| 41 // Create a IBusComponent. | |
| 42 IBusComponent ibus_component; | |
| 43 ibus_component.set_name(kName); | |
| 44 ibus_component.set_description(kDescription); | |
| 45 ibus_component.set_author(kAuthor); | |
| 46 ibus_component.mutable_engine_description()->push_back(engine_desc1); | |
| 47 ibus_component.mutable_engine_description()->push_back(engine_desc2); | |
| 48 | |
| 49 // Write a IBusComponent. | |
| 50 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | |
| 51 dbus::MessageWriter writer(response.get()); | |
| 52 AppendIBusComponent(ibus_component, &writer); | |
| 53 | |
| 54 // Read a IBusComponent. | |
| 55 IBusComponent target_component; | |
| 56 dbus::MessageReader reader(response.get()); | |
| 57 PopIBusComponent(&reader, &target_component); | |
| 58 | |
| 59 // Check a result. | |
| 60 EXPECT_EQ(kName, target_component.name()); | |
| 61 EXPECT_EQ(kDescription, target_component.description()); | |
| 62 EXPECT_EQ(kAuthor, target_component.author()); | |
| 63 | |
| 64 const std::vector<IBusComponent::EngineDescription>& engine_descriptions = | |
| 65 ibus_component.engine_description(); | |
| 66 EXPECT_EQ(kEngineId1, engine_descriptions[0].engine_id); | |
| 67 EXPECT_EQ(kEngineDisplayName1, engine_descriptions[0].display_name); | |
| 68 EXPECT_EQ(kEngineDescription1, engine_descriptions[0].description); | |
| 69 EXPECT_EQ(kEngineLanguageCode1, engine_descriptions[0].language_code); | |
| 70 EXPECT_EQ(kEngineAuthor1, engine_descriptions[0].author); | |
| 71 | |
| 72 EXPECT_EQ(kEngineId2, engine_descriptions[1].engine_id); | |
| 73 EXPECT_EQ(kEngineDisplayName2, engine_descriptions[1].display_name); | |
| 74 EXPECT_EQ(kEngineDescription2, engine_descriptions[1].description); | |
| 75 EXPECT_EQ(kEngineLanguageCode2, engine_descriptions[1].language_code); | |
| 76 EXPECT_EQ(kEngineAuthor2, engine_descriptions[1].author); | |
| 77 } | |
| 78 | |
| 79 } // namespace chromeos | |
| OLD | NEW |