OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/dbus_client_bundle.h" | 5 #include "chromeos/dbus/dbus_client_bundle.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "chromeos/dbus/dbus_client_types.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace chromeos { | 10 namespace chromeos { |
| 11 namespace { |
11 | 12 |
12 TEST(DBusClientBundleTest, UnstubFlagParser) { | 13 // Makes mask operations more readable. |
13 EXPECT_EQ(0, DBusClientBundle::ParseUnstubList("foo")); | 14 DBusClientTypeMask AsClientTypeMask(DBusClientType type) { |
| 15 return static_cast<DBusClientTypeMask>(type); |
| 16 } |
14 | 17 |
15 EXPECT_EQ(DBusClientBundle::BLUETOOTH, | 18 } // namespace |
16 DBusClientBundle::ParseUnstubList("BLUETOOTH")); | |
17 | 19 |
18 EXPECT_EQ(DBusClientBundle::BLUETOOTH, | 20 // Tests that real and fake clients can be created. |
19 DBusClientBundle::ParseUnstubList("bluetooth")); | 21 TEST(DBusClientBundleTest, CreateClientBundle) { |
| 22 const DBusClientTypeMask real_clients = |
| 23 AsClientTypeMask(DBusClientType::CRAS) | |
| 24 AsClientTypeMask(DBusClientType::CROS_DISKS); |
| 25 DBusClientBundle bundle(real_clients); |
20 | 26 |
21 EXPECT_EQ( | 27 // Real clients are real. |
22 DBusClientBundle::CRAS | | 28 EXPECT_TRUE(bundle.cras_audio_client()); |
23 DBusClientBundle::CROS_DISKS | | 29 EXPECT_TRUE(bundle.cros_disks_client()); |
24 DBusClientBundle::DEBUG_DAEMON | | 30 EXPECT_TRUE(bundle.IsUsingReal(DBusClientType::CRAS)); |
25 DBusClientBundle::SHILL, | 31 EXPECT_TRUE(bundle.IsUsingReal(DBusClientType::CROS_DISKS)); |
26 DBusClientBundle::ParseUnstubList( | |
27 "Cras,Cros_Disks,debug_daemon,Shill")); | |
28 | 32 |
29 EXPECT_EQ( | 33 // Fake clients are fake. |
30 DBusClientBundle::CRAS | | 34 EXPECT_TRUE(bundle.permission_broker_client()); |
31 DBusClientBundle::CROS_DISKS | | 35 EXPECT_TRUE(bundle.power_manager_client()); |
32 DBusClientBundle::DEBUG_DAEMON | | 36 EXPECT_FALSE(bundle.IsUsingReal(DBusClientType::PERMISSION_BROKER)); |
33 DBusClientBundle::SHILL, | 37 EXPECT_FALSE(bundle.IsUsingReal(DBusClientType::POWER_MANAGER)); |
34 DBusClientBundle::ParseUnstubList( | 38 } |
35 "foo,Cras,Cros_Disks,debug_daemon,Shill")); | 39 |
| 40 TEST(DBusClientBundleTest, RealClientsFlagParser) { |
| 41 EXPECT_EQ(AsClientTypeMask(DBusClientType::NONE), |
| 42 ParseDBusRealClientsList("foo")); |
| 43 |
| 44 EXPECT_EQ(AsClientTypeMask(DBusClientType::BLUETOOTH), |
| 45 ParseDBusRealClientsList("BLUETOOTH")); |
| 46 |
| 47 EXPECT_EQ(AsClientTypeMask(DBusClientType::BLUETOOTH), |
| 48 ParseDBusRealClientsList("bluetooth")); |
| 49 |
| 50 EXPECT_EQ(AsClientTypeMask(DBusClientType::CRAS) | |
| 51 AsClientTypeMask(DBusClientType::CROS_DISKS) | |
| 52 AsClientTypeMask(DBusClientType::DEBUG_DAEMON) | |
| 53 AsClientTypeMask(DBusClientType::SHILL), |
| 54 ParseDBusRealClientsList("Cras,Cros_Disks,debug_daemon,Shill")); |
| 55 |
| 56 EXPECT_EQ(AsClientTypeMask(DBusClientType::CRAS) | |
| 57 AsClientTypeMask(DBusClientType::CROS_DISKS) | |
| 58 AsClientTypeMask(DBusClientType::DEBUG_DAEMON) | |
| 59 AsClientTypeMask(DBusClientType::SHILL), |
| 60 ParseDBusRealClientsList("foo,Cras,Cros_Disks,debug_daemon,Shill")); |
36 } | 61 } |
37 | 62 |
38 } // namespace chromeos | 63 } // namespace chromeos |
OLD | NEW |