Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 1 | // Copyright 2019 The Chromium OS 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 "dev-install/dev_install.h" |
| 6 | |
| 7 | #include <gmock/gmock.h> |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | using ::testing::_; |
| 11 | using ::testing::Return; |
| 12 | |
| 13 | namespace dev_install { |
| 14 | |
| 15 | namespace { |
| 16 | |
| 17 | class DevInstallMock : public DevInstall { |
| 18 | public: |
| 19 | MOCK_METHOD1(Exec, int(const std::vector<const char*>&)); |
Mike Frysinger | ee5af6e | 2019-02-23 23:47:03 -0500 | [diff] [blame] | 20 | MOCK_CONST_METHOD0(IsDevMode, bool()); |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 21 | }; |
| 22 | |
| 23 | class DevInstallTest : public ::testing::Test { |
Mike Frysinger | ee5af6e | 2019-02-23 23:47:03 -0500 | [diff] [blame] | 24 | public: |
| 25 | void SetUp() override { |
| 26 | // Set the default to dev mode enabled. Most tests want that. |
| 27 | ON_CALL(dev_install_, IsDevMode()).WillByDefault(Return(true)); |
| 28 | } |
| 29 | |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 30 | protected: |
| 31 | DevInstallMock dev_install_; |
| 32 | }; |
| 33 | |
| 34 | } // namespace |
| 35 | |
| 36 | // Check default run through. |
| 37 | TEST_F(DevInstallTest, Run) { |
| 38 | EXPECT_CALL(dev_install_, Exec(_)).WillOnce(Return(1234)); |
| 39 | EXPECT_EQ(1234, dev_install_.Run()); |
| 40 | } |
| 41 | |
Mike Frysinger | ee5af6e | 2019-02-23 23:47:03 -0500 | [diff] [blame] | 42 | // Systems not in dev mode should abort. |
| 43 | TEST_F(DevInstallTest, NonDevMode) { |
| 44 | EXPECT_CALL(dev_install_, IsDevMode()).WillOnce(Return(false)); |
| 45 | EXPECT_CALL(dev_install_, Exec(_)).Times(0); |
| 46 | EXPECT_EQ(2, dev_install_.Run()); |
| 47 | } |
| 48 | |
Mike Frysinger | 1dad097 | 2019-02-23 18:36:37 -0500 | [diff] [blame] | 49 | } // namespace dev_install |