OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 | |
5 #include "chromeos/dbus/fake_power_manager_client.h" | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 namespace chromeos { | |
10 | |
11 class FakePowerManagerClientTest { | |
12 public: | |
13 FakePowerManagerClientTest() { | |
14 // Test the default values that are assign when the | |
15 // FakePowerManagerClient::Init() function is created. | |
afakhry
2015/07/01 16:47:48
Nits:
- "assign" --> "assigned"
- "created" --> "c
mozartalouis
2015/07/01 20:05:23
Done.
| |
16 client().Init(NULL); | |
afakhry
2015/07/01 16:47:48
NULL --> nullptr
mozartalouis
2015/07/01 20:05:23
Done.
| |
17 | |
18 EXPECT_EQ(50, client().props().battery_percent()); | |
afakhry
2015/07/01 16:47:48
Nit: You don't have to use client() here, you're i
mozartalouis
2015/07/01 20:05:23
Done.
| |
19 EXPECT_FALSE(client().props().is_calculating_battery_time()); | |
20 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, | |
21 client().props().battery_state()); | |
22 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED, | |
23 client().props().external_power()); | |
24 } | |
25 | |
26 FakePowerManagerClient& client() { return client_; } | |
27 | |
28 private: | |
29 FakePowerManagerClient client_; | |
30 | |
31 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClientTest); | |
32 }; | |
33 | |
34 TEST_F(FakePowerManagerClientTest, BatteryStateTest) { | |
35 // Test if setting props_.battery_percent to 100 and props_.battery_state to | |
36 // _CHARGING will set props_.battery_state to _FULL. | |
37 client().UpdatePowerProperties( | |
afakhry
2015/07/01 16:47:48
I would make things more readable here by wrapping
mozartalouis
2015/07/01 20:05:23
Done.
| |
38 100, false, power_manager::PowerSupplyProperties_BatteryState_CHARGING, | |
39 power_manager::PowerSupplyProperties_ExternalPower_AC); | |
40 | |
41 EXPECT_EQ(100, client().props().battery_percent()); | |
42 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_FULL, | |
43 client().props().battery_state()); | |
44 | |
45 // Test if setting props_.battery_percent less than 100 and | |
46 // props_.battery_state to _FULL will set props_.battery_state to | |
47 // _DISCHARGING. | |
48 client().UpdatePowerProperties( | |
49 80, false, power_manager::PowerSupplyProperties_BatteryState_FULL, | |
50 power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED); | |
51 EXPECT_EQ(80, client().props().battery_percent()); | |
52 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, | |
53 client().props().battery_state()); | |
54 } | |
55 | |
56 TEST_F(FakePowerManagerClientTest, ExternalPowerTest) { | |
57 // Test if setting props_.battery_percent less than 100 and | |
58 // props_.battery_state to _CHARGING while props_.external_power is set to | |
59 // _USB will set props_.external_power to _USB | |
60 client().UpdatePowerProperties( | |
61 80, false, power_manager::PowerSupplyProperties_BatteryState_CHARGING, | |
62 power_manager::PowerSupplyProperties_ExternalPower_USB); | |
63 | |
64 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB, | |
65 client().props().external_power()); | |
66 | |
67 // Test if setting props_.battery_percent less than 100 and | |
68 // props_.battery_state to _DISCHARGING while props_.external_power is set to | |
69 // _USB will set props_.external_power to _USB | |
70 client().UpdatePowerProperties( | |
71 80, false, power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, | |
72 power_manager::PowerSupplyProperties_ExternalPower_USB); | |
73 | |
74 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB, | |
75 client().props().external_power()); | |
76 | |
77 // Test if setting props_.battery_percent less than 100 and | |
78 // props_.battery_state to _CHARGING while props_.external_power is set to | |
79 // _DISCONNECTED will set props_.external_power to _AC | |
80 client().UpdatePowerProperties( | |
81 80, false, power_manager::PowerSupplyProperties_BatteryState_CHARGING, | |
82 power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED); | |
83 | |
84 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_AC, | |
85 client().props().external_power()); | |
86 | |
87 // Test if setting props_.battery_percent less than 100 and | |
88 // props_.battery_state to _CHARGING while props_.external_power is set to | |
89 // _AC will set props_.external_power to _DISCONNECTED | |
90 client().UpdatePowerProperties( | |
91 80, false, power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, | |
92 power_manager::PowerSupplyProperties_ExternalPower_AC); | |
93 | |
94 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED, | |
95 client().props().external_power()); | |
96 } | |
97 | |
98 } // namespace chromeos | |
OLD | NEW |