Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium OS 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 <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
| 6 #include <gdk/gdk.h> | 6 #include <gdk/gdk.h> |
| 7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <X11/extensions/XTest.h> | 9 #include <X11/extensions/XTest.h> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "metrics/metrics_library_mock.h" | 12 #include "metrics/metrics_library_mock.h" |
| 13 #include "power_manager/mock_backlight.h" | 13 #include "power_manager/mock_backlight.h" |
| 14 #include "power_manager/mock_video_detector.h" | 14 #include "power_manager/mock_video_detector.h" |
| 15 #include "power_manager/mock_monitor_reconfigure.h" | |
|
Daniel Erat
2011/04/14 19:18:46
nit: move before mock_video_detector.h
marcheu
2011/04/14 19:54:57
Done.
| |
| 15 #include "power_manager/power_constants.h" | 16 #include "power_manager/power_constants.h" |
| 16 #include "power_manager/powerd.h" | 17 #include "power_manager/powerd.h" |
| 17 | 18 |
| 18 namespace power_manager { | 19 namespace power_manager { |
| 19 | 20 |
| 20 using ::testing::_; | 21 using ::testing::_; |
| 21 using ::testing::DoAll; | 22 using ::testing::DoAll; |
| 22 using ::testing::InSequence; | 23 using ::testing::InSequence; |
| 23 using ::testing::NotNull; | 24 using ::testing::NotNull; |
| 24 using ::testing::Return; | 25 using ::testing::Return; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 41 static const int64 kUnpluggedSuspend = kPluggedSuspend; | 42 static const int64 kUnpluggedSuspend = kPluggedSuspend; |
| 42 | 43 |
| 43 bool CheckMetricInterval(time_t now, time_t last, time_t interval); | 44 bool CheckMetricInterval(time_t now, time_t last, time_t interval); |
| 44 | 45 |
| 45 class DaemonTest : public Test { | 46 class DaemonTest : public Test { |
| 46 public: | 47 public: |
| 47 DaemonTest() | 48 DaemonTest() |
| 48 : prefs_(FilePath("."), FilePath(".")), | 49 : prefs_(FilePath("."), FilePath(".")), |
| 49 backlight_ctl_(&backlight_, &prefs_), | 50 backlight_ctl_(&backlight_, &prefs_), |
| 50 daemon_(&backlight_ctl_, &prefs_, &metrics_lib_, &video_detector_, | 51 daemon_(&backlight_ctl_, &prefs_, &metrics_lib_, &video_detector_, |
| 51 FilePath(".")) {} | 52 &monitor_reconfigure_, FilePath(".")) {} |
| 52 | 53 |
| 53 virtual void SetUp() { | 54 virtual void SetUp() { |
| 54 // Tests initialization done by the daemon's constructor. | 55 // Tests initialization done by the daemon's constructor. |
| 55 EXPECT_EQ(0, daemon_.battery_discharge_rate_metric_last_); | 56 EXPECT_EQ(0, daemon_.battery_discharge_rate_metric_last_); |
| 56 EXPECT_EQ(0, daemon_.battery_remaining_charge_metric_last_); | 57 EXPECT_EQ(0, daemon_.battery_remaining_charge_metric_last_); |
| 57 EXPECT_EQ(0, daemon_.battery_time_to_empty_metric_last_); | 58 EXPECT_EQ(0, daemon_.battery_time_to_empty_metric_last_); |
| 58 EXPECT_CALL(backlight_, GetBrightness(NotNull(), NotNull())) | 59 EXPECT_CALL(backlight_, GetBrightness(NotNull(), NotNull())) |
| 59 .WillOnce(DoAll(SetArgumentPointee<0>(kDefaultBrightness), | 60 .WillOnce(DoAll(SetArgumentPointee<0>(kDefaultBrightness), |
| 60 SetArgumentPointee<1>(kMaxBrightness), | 61 SetArgumentPointee<1>(kMaxBrightness), |
| 61 Return(true))); | 62 Return(true))); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 Daemon::kMetricBatteryTimeToEmptyBuckets); | 112 Daemon::kMetricBatteryTimeToEmptyBuckets); |
| 112 } | 113 } |
| 113 | 114 |
| 114 // Resets all fields of |info| to 0. | 115 // Resets all fields of |info| to 0. |
| 115 void ResetPowerStatus(chromeos::PowerStatus& status) { | 116 void ResetPowerStatus(chromeos::PowerStatus& status) { |
| 116 memset(&status, 0, sizeof(chromeos::PowerStatus)); | 117 memset(&status, 0, sizeof(chromeos::PowerStatus)); |
| 117 } | 118 } |
| 118 | 119 |
| 119 StrictMock<MockBacklight> backlight_; | 120 StrictMock<MockBacklight> backlight_; |
| 120 StrictMock<MockVideoDetector> video_detector_; | 121 StrictMock<MockVideoDetector> video_detector_; |
| 122 StrictMock<MockMonitorReconfigureMain> monitor_reconfigure_; | |
| 121 PowerPrefs prefs_; | 123 PowerPrefs prefs_; |
| 122 chromeos::PowerStatus status_; | 124 chromeos::PowerStatus status_; |
| 123 BacklightController backlight_ctl_; | 125 BacklightController backlight_ctl_; |
| 124 | 126 |
| 125 // StrictMock turns all unexpected calls into hard failures. | 127 // StrictMock turns all unexpected calls into hard failures. |
| 126 StrictMock<MetricsLibraryMock> metrics_lib_; | 128 StrictMock<MetricsLibraryMock> metrics_lib_; |
| 127 Daemon daemon_; | 129 Daemon daemon_; |
| 128 }; | 130 }; |
| 129 | 131 |
| 130 TEST_F(DaemonTest, CheckMetricInterval) { | 132 TEST_F(DaemonTest, CheckMetricInterval) { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 EXPECT_CALL(backlight_, GetBrightness(NotNull(), NotNull())) | 353 EXPECT_CALL(backlight_, GetBrightness(NotNull(), NotNull())) |
| 352 .WillOnce(DoAll(SetArgumentPointee<0>(kDefaultBrightness), | 354 .WillOnce(DoAll(SetArgumentPointee<0>(kDefaultBrightness), |
| 353 SetArgumentPointee<1>(kMaxBrightness), | 355 SetArgumentPointee<1>(kMaxBrightness), |
| 354 Return(true))); | 356 Return(true))); |
| 355 ExpectEnumMetric("Power.BacklightLevelOnAC", | 357 ExpectEnumMetric("Power.BacklightLevelOnAC", |
| 356 kDefaultBrightness, kMaxBrightness); | 358 kDefaultBrightness, kMaxBrightness); |
| 357 daemon_.GenerateBacklightLevelMetricThunk(&daemon_); | 359 daemon_.GenerateBacklightLevelMetricThunk(&daemon_); |
| 358 } | 360 } |
| 359 | 361 |
| 360 } // namespace power_manager | 362 } // namespace power_manager |
| OLD | NEW |