Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / chromeos / dbus / ibus / ibus_component_unittest.cc
blob2bed5517ce100a65f900222b1bc34421d5dcca2d
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"
6 #include <string>
8 #include "base/memory/scoped_ptr.h"
9 #include "dbus/message.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace chromeos {
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";
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 std::string kEngineLayout1 = "us::eng";
25 const IBusComponent::EngineDescription engine_desc1(kEngineId1,
26 kEngineDisplayName1,
27 kEngineDescription1,
28 kEngineLanguageCode1,
29 kEngineAuthor1,
30 kEngineLayout1);
32 const std::string kEngineId2 = "Engine Id 2";
33 const std::string kEngineDisplayName2 = "Engine Display Name 2";
34 const std::string kEngineDescription2 = "Engine Description 2";
35 const std::string kEngineLanguageCode2 = "ja";
36 const std::string kEngineAuthor2 = "Engine Author 2";
37 const std::string kEngineLayout2 = "ja::jp";
38 const IBusComponent::EngineDescription engine_desc2(kEngineId2,
39 kEngineDisplayName2,
40 kEngineDescription2,
41 kEngineLanguageCode2,
42 kEngineAuthor2,
43 kEngineLayout2);
45 // Create a IBusComponent.
46 IBusComponent ibus_component;
47 ibus_component.set_name(kName);
48 ibus_component.set_description(kDescription);
49 ibus_component.set_author(kAuthor);
50 ibus_component.mutable_engine_description()->push_back(engine_desc1);
51 ibus_component.mutable_engine_description()->push_back(engine_desc2);
53 // Write a IBusComponent.
54 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
55 dbus::MessageWriter writer(response.get());
56 AppendIBusComponent(ibus_component, &writer);
58 // Read a IBusComponent.
59 IBusComponent target_component;
60 dbus::MessageReader reader(response.get());
61 PopIBusComponent(&reader, &target_component);
63 // Check a result.
64 EXPECT_EQ(kName, target_component.name());
65 EXPECT_EQ(kDescription, target_component.description());
66 EXPECT_EQ(kAuthor, target_component.author());
68 const std::vector<IBusComponent::EngineDescription>& engine_descriptions =
69 ibus_component.engine_description();
70 EXPECT_EQ(kEngineId1, engine_descriptions[0].engine_id);
71 EXPECT_EQ(kEngineDisplayName1, engine_descriptions[0].display_name);
72 EXPECT_EQ(kEngineDescription1, engine_descriptions[0].description);
73 EXPECT_EQ(kEngineLanguageCode1, engine_descriptions[0].language_code);
74 EXPECT_EQ(kEngineAuthor1, engine_descriptions[0].author);
75 EXPECT_EQ(kEngineLayout1, engine_descriptions[0].layout);
77 EXPECT_EQ(kEngineId2, engine_descriptions[1].engine_id);
78 EXPECT_EQ(kEngineDisplayName2, engine_descriptions[1].display_name);
79 EXPECT_EQ(kEngineDescription2, engine_descriptions[1].description);
80 EXPECT_EQ(kEngineLanguageCode2, engine_descriptions[1].language_code);
81 EXPECT_EQ(kEngineAuthor2, engine_descriptions[1].author);
82 EXPECT_EQ(kEngineLayout2, engine_descriptions[1].layout);
85 } // namespace chromeos