blob: 8fa5effd8a14b52c84e3db58859a478be25b326f [file] [log] [blame]
Paul Stewart59a8cba2015-01-09 15:48:19 -08001// Copyright 2015 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 "shill/upstart/upstart.h"
6
7
8#include <gmock/gmock.h>
9#include <gtest/gtest.h>
10
11#include "shill/proxy_factory.h"
12#include "shill/upstart/mock_upstart_proxy.h"
13#include "shill/upstart/upstart_proxy_interface.h"
14
15using testing::_;
16using testing::Test;
17
18namespace shill {
19
20namespace {
21
22class FakeProxyFactory : public ProxyFactory {
23 public:
24 FakeProxyFactory()
25 : upstart_proxy_raw_(new MockUpstartProxy),
26 upstart_proxy_(upstart_proxy_raw_) {}
27
28 UpstartProxyInterface *CreateUpstartProxy() override {
29 CHECK(upstart_proxy_);
30 // Passes ownership.
31 return upstart_proxy_.release();
32 }
33
34 // Can not guarantee that the returned object is alive.
35 MockUpstartProxy *upstart_proxy() const {
36 return upstart_proxy_raw_;
37 }
38
39 private:
40 MockUpstartProxy *const upstart_proxy_raw_;
41 std::unique_ptr<MockUpstartProxy> upstart_proxy_;
42};
43
44} // namespace
45
46class UpstartTest : public Test {
47 public:
48 UpstartTest()
49 : upstart_(&factory_),
50 upstart_proxy_(factory_.upstart_proxy()) {}
51
52 protected:
53 FakeProxyFactory factory_;
54 Upstart upstart_;
55 MockUpstartProxy *const upstart_proxy_;
56};
57
58TEST_F(UpstartTest, NotifyDisconnected) {
59 EXPECT_CALL(*upstart_proxy_, EmitEvent("shill-disconnected", _, false));
60 upstart_.NotifyDisconnected();
61}
62
63} // namespace shill