Make FakeHardware the default for all unit tests.
Previously, unit tests by default ran with a MockSystemState
that used the Hardware class instead of the FakeHardware mock.
This changes to make all tests use the FakeHardware mock
unconditionally.
BUG=None
TEST=unit tests
Change-Id: I9d70aec0d59c5913968e4d37f1d4a2a28e854920
Reviewed-on: https://chromium-review.googlesource.com/174915
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Richard Barnette <jrbarnette@chromium.org>
diff --git a/SConstruct b/SConstruct
index 485e35e..bc71c75 100644
--- a/SConstruct
+++ b/SConstruct
@@ -308,7 +308,6 @@
extent_mapper_unittest.cc
extent_ranges_unittest.cc
extent_writer_unittest.cc
- fake_hardware.cc
file_writer_unittest.cc
filesystem_copier_action_unittest.cc
filesystem_iterator_unittest.cc
diff --git a/fake_hardware.cc b/fake_hardware.cc
deleted file mode 100644
index feb6ec6..0000000
--- a/fake_hardware.cc
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "update_engine/fake_hardware.h"
-
-using std::string;
-
-namespace chromeos_update_engine {
-
-} // namespace chromeos_update_engine
diff --git a/fake_hardware.h b/fake_hardware.h
index 6394b25..6d3b926 100644
--- a/fake_hardware.h
+++ b/fake_hardware.h
@@ -7,16 +7,13 @@
#include "update_engine/hardware_interface.h"
-#include "base/basictypes.h"
-
-#include <map>
-
namespace chromeos_update_engine {
// Implements a fake hardware interface used for testing.
class FakeHardware : public HardwareInterface {
public:
- FakeHardware() {}
+ FakeHardware()
+ : boot_device_("/dev/sdz5") {}
// HardwareInterface methods.
virtual const std::string BootDevice() { return boot_device_; }
diff --git a/mock_system_state.h b/mock_system_state.h
index de0caef..e18c403 100644
--- a/mock_system_state.h
+++ b/mock_system_state.h
@@ -15,7 +15,7 @@
#include "update_engine/mock_p2p_manager.h"
#include "update_engine/mock_payload_state.h"
#include "update_engine/clock.h"
-#include "update_engine/hardware.h"
+#include "update_engine/fake_hardware.h"
#include "update_engine/prefs_mock.h"
#include "update_engine/system_state.h"
@@ -97,6 +97,10 @@
hardware_ = hardware;
}
+ inline FakeHardware* get_fake_hardware() {
+ return &default_hardware_;
+ }
+
inline void set_prefs(PrefsInterface* prefs) {
prefs_ = prefs;
}
@@ -142,7 +146,7 @@
// These are the other object we own.
Clock default_clock_;
- Hardware default_hardware_;
+ FakeHardware default_hardware_;
OmahaRequestParams default_request_params_;
// These are pointers to objects which caller can override.
diff --git a/payload_state_unittest.cc b/payload_state_unittest.cc
index ec79950..4efce28 100644
--- a/payload_state_unittest.cc
+++ b/payload_state_unittest.cc
@@ -1353,7 +1353,6 @@
}
TEST(PayloadStateTest, RebootAfterUpdateFailedMetric) {
- FakeHardware fake_hardware;
MockSystemState mock_system_state;
OmahaResponse response;
PayloadState payload_state;
@@ -1366,8 +1365,8 @@
prefs.Init(FilePath(temp_dir));
mock_system_state.set_prefs(&prefs);
- fake_hardware.SetBootDevice("/dev/sda3");
- mock_system_state.set_hardware(&fake_hardware);
+ FakeHardware* fake_hardware = mock_system_state.get_fake_hardware();
+ fake_hardware->SetBootDevice("/dev/sda3");
EXPECT_TRUE(payload_state.Initialize(&mock_system_state));
SetupPayloadStateWith2Urls("Hash3141", true, &payload_state, &response);
@@ -1404,7 +1403,6 @@
}
TEST(PayloadStateTest, RebootAfterUpdateSucceed) {
- FakeHardware fake_hardware;
MockSystemState mock_system_state;
OmahaResponse response;
PayloadState payload_state;
@@ -1417,8 +1415,8 @@
prefs.Init(FilePath(temp_dir));
mock_system_state.set_prefs(&prefs);
- fake_hardware.SetBootDevice("/dev/sda3");
- mock_system_state.set_hardware(&fake_hardware);
+ FakeHardware* fake_hardware = mock_system_state.get_fake_hardware();
+ fake_hardware->SetBootDevice("/dev/sda3");
EXPECT_TRUE(payload_state.Initialize(&mock_system_state));
SetupPayloadStateWith2Urls("Hash3141", true, &payload_state, &response);
@@ -1429,7 +1427,7 @@
payload_state.ExpectRebootInNewVersion("Version:12345678");
// Change the BootDevice to a different one, no metric should be sent.
- fake_hardware.SetBootDevice("/dev/sda5");
+ fake_hardware->SetBootDevice("/dev/sda5");
EXPECT_CALL(*mock_system_state.mock_metrics_lib(), SendToUMA(
"Installer.RebootToNewPartitionAttempt", _, _, _, _))
@@ -1438,7 +1436,7 @@
// A second reboot in eiher partition should not send a metric.
payload_state.ReportFailedBootIfNeeded();
- fake_hardware.SetBootDevice("/dev/sda3");
+ fake_hardware->SetBootDevice("/dev/sda3");
payload_state.ReportFailedBootIfNeeded();
EXPECT_TRUE(utils::RecursiveUnlinkDir(temp_dir));