Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 1 | // Copyright (c) 2014 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 | |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame^] | 5 | // TODO(garnold) Remove once shill DBus constants not needed. |
| 6 | #include <chromeos/dbus/service_constants.h> |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 7 | #include <gtest/gtest.h> |
| 8 | |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 9 | #include "update_engine/fake_clock.h" |
| 10 | #include "update_engine/mock_dbus_wrapper.h" |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 11 | #include "update_engine/policy_manager/real_state.h" |
| 12 | #include "update_engine/policy_manager/pmtest_utils.h" |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame^] | 13 | // TODO(garnold) Remove once we stop mocking DBus. |
| 14 | #include "update_engine/test_utils.h" |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 15 | |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 16 | using chromeos_update_engine::FakeClock; |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame^] | 17 | using chromeos_update_engine::GValueNewString; |
| 18 | using chromeos_update_engine::GValueFree; |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 19 | using chromeos_update_engine::MockDBusWrapper; |
| 20 | using testing::_; |
| 21 | using testing::NiceMock; |
| 22 | using testing::Return; |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame^] | 23 | using testing::SetArgPointee; |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 24 | |
| 25 | namespace { |
| 26 | |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame^] | 27 | // TODO(garnold) This whole section gets removed once we mock the shill provider |
| 28 | // itself in tests. |
| 29 | |
| 30 | // Fake dbus-glib objects. |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 31 | DBusGConnection* const kFakeConnection = reinterpret_cast<DBusGConnection*>(1); |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame^] | 32 | DBusGProxy* const kFakeManagerProxy = reinterpret_cast<DBusGProxy*>(2); |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 33 | |
| 34 | } // namespace |
| 35 | |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 36 | namespace chromeos_policy_manager { |
| 37 | |
| 38 | TEST(PmRealStateTest, InitTest) { |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 39 | NiceMock<MockDBusWrapper> mock_dbus; |
| 40 | FakeClock fake_clock; |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame^] | 41 | |
| 42 | // TODO(garnold) Replace this low-level DBus injection with a high-level |
| 43 | // mock shill provider. |
| 44 | EXPECT_CALL(mock_dbus, BusGet(_, _)) |
| 45 | .WillOnce(Return(kFakeConnection)); |
| 46 | EXPECT_CALL(mock_dbus, ProxyNewForName(_, _, _, _)) |
| 47 | .WillOnce(Return(kFakeManagerProxy)); |
| 48 | EXPECT_CALL(mock_dbus, ProxyAddSignal_2(_, _, _, _)) |
| 49 | .WillOnce(Return()); |
| 50 | EXPECT_CALL(mock_dbus, ProxyConnectSignal(_, _, _, _, _)) |
| 51 | .WillOnce(Return()); |
| 52 | auto properties = g_hash_table_new_full(g_str_hash, g_str_equal, free, |
| 53 | GValueFree); |
| 54 | g_hash_table_insert(properties, strdup(shill::kDefaultServiceProperty), |
| 55 | GValueNewString("/")); |
| 56 | EXPECT_CALL(mock_dbus, ProxyCall_0_1(_, _, _, _)) |
| 57 | .WillOnce(DoAll(SetArgPointee<3>(g_hash_table_ref(properties)), |
| 58 | Return(true))); |
| 59 | |
Gilad Arnold | 5ef9c48 | 2014-03-03 13:51:02 -0800 | [diff] [blame] | 60 | RealState state(&mock_dbus, &fake_clock); |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 61 | EXPECT_TRUE(state.Init()); |
Gilad Arnold | beb39e9 | 2014-03-11 11:34:50 -0700 | [diff] [blame^] | 62 | |
| 63 | // TODO(garnold) Remove this, too. |
| 64 | g_hash_table_unref(properties); |
| 65 | |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 66 | // Check that the providers are being initialized. |
| 67 | PMTEST_ASSERT_NOT_NULL(state.random_provider()); |
Alex Deymo | 540d942 | 2014-02-27 11:17:31 -0800 | [diff] [blame] | 68 | PMTEST_EXPECT_NOT_NULL(state.random_provider()->var_seed()); |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | } // namespace chromeos_policy_manager |