blob: 13f8db292751b7480f2c37857aa54e217fc19bbd [file] [log] [blame]
Alex Deymo2de23f52014-02-26 14:30:13 -08001// 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 Arnoldbeb39e92014-03-11 11:34:50 -07005// TODO(garnold) Remove once shill DBus constants not needed.
6#include <chromeos/dbus/service_constants.h>
Alex Deymo2de23f52014-02-26 14:30:13 -08007#include <gtest/gtest.h>
8
Gilad Arnold5ef9c482014-03-03 13:51:02 -08009#include "update_engine/fake_clock.h"
10#include "update_engine/mock_dbus_wrapper.h"
Alex Deymo2de23f52014-02-26 14:30:13 -080011#include "update_engine/policy_manager/real_state.h"
12#include "update_engine/policy_manager/pmtest_utils.h"
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070013// TODO(garnold) Remove once we stop mocking DBus.
14#include "update_engine/test_utils.h"
Alex Deymo2de23f52014-02-26 14:30:13 -080015
Gilad Arnold5ef9c482014-03-03 13:51:02 -080016using chromeos_update_engine::FakeClock;
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070017using chromeos_update_engine::GValueNewString;
18using chromeos_update_engine::GValueFree;
Gilad Arnold5ef9c482014-03-03 13:51:02 -080019using chromeos_update_engine::MockDBusWrapper;
20using testing::_;
21using testing::NiceMock;
22using testing::Return;
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070023using testing::SetArgPointee;
Gilad Arnold5ef9c482014-03-03 13:51:02 -080024
25namespace {
26
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070027// TODO(garnold) This whole section gets removed once we mock the shill provider
28// itself in tests.
29
30// Fake dbus-glib objects.
Gilad Arnold5ef9c482014-03-03 13:51:02 -080031DBusGConnection* const kFakeConnection = reinterpret_cast<DBusGConnection*>(1);
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070032DBusGProxy* const kFakeManagerProxy = reinterpret_cast<DBusGProxy*>(2);
Gilad Arnold5ef9c482014-03-03 13:51:02 -080033
34} // namespace
35
Alex Deymo2de23f52014-02-26 14:30:13 -080036namespace chromeos_policy_manager {
37
38TEST(PmRealStateTest, InitTest) {
Gilad Arnold5ef9c482014-03-03 13:51:02 -080039 NiceMock<MockDBusWrapper> mock_dbus;
40 FakeClock fake_clock;
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070041
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 Arnold5ef9c482014-03-03 13:51:02 -080060 RealState state(&mock_dbus, &fake_clock);
Alex Deymo2de23f52014-02-26 14:30:13 -080061 EXPECT_TRUE(state.Init());
Gilad Arnoldbeb39e92014-03-11 11:34:50 -070062
63 // TODO(garnold) Remove this, too.
64 g_hash_table_unref(properties);
65
Alex Deymo2de23f52014-02-26 14:30:13 -080066 // Check that the providers are being initialized.
67 PMTEST_ASSERT_NOT_NULL(state.random_provider());
Alex Deymo540d9422014-02-27 11:17:31 -080068 PMTEST_EXPECT_NOT_NULL(state.random_provider()->var_seed());
Alex Deymo2de23f52014-02-26 14:30:13 -080069}
70
71} // namespace chromeos_policy_manager