• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2015 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include "shill/upstart/upstart.h"
18 
19 
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
22 
23 #include "shill/mock_control.h"
24 #include "shill/upstart/mock_upstart_proxy.h"
25 #include "shill/upstart/upstart_proxy_interface.h"
26 
27 using testing::_;
28 using testing::Test;
29 
30 namespace shill {
31 
32 namespace {
33 
34 class FakeControl : public MockControl {
35  public:
FakeControl()36   FakeControl()
37       : upstart_proxy_raw_(new MockUpstartProxy),
38         upstart_proxy_(upstart_proxy_raw_) {}
39 
CreateUpstartProxy()40   UpstartProxyInterface* CreateUpstartProxy() override {
41     CHECK(upstart_proxy_);
42     // Passes ownership.
43     return upstart_proxy_.release();
44   }
45 
46   // Can not guarantee that the returned object is alive.
upstart_proxy() const47   MockUpstartProxy* upstart_proxy() const {
48     return upstart_proxy_raw_;
49   }
50 
51  private:
52   MockUpstartProxy* const upstart_proxy_raw_;
53   std::unique_ptr<MockUpstartProxy> upstart_proxy_;
54 };
55 
56 }  // namespace
57 
58 class UpstartTest : public Test {
59  public:
UpstartTest()60   UpstartTest()
61       : upstart_(&control_),
62         upstart_proxy_(control_.upstart_proxy()) {}
63 
64  protected:
65   FakeControl control_;
66   Upstart upstart_;
67   MockUpstartProxy* const upstart_proxy_;
68 };
69 
TEST_F(UpstartTest,NotifyDisconnected)70 TEST_F(UpstartTest, NotifyDisconnected) {
71   EXPECT_CALL(*upstart_proxy_, EmitEvent("shill-disconnected", _, false));
72   upstart_.NotifyDisconnected();
73 }
74 
TEST_F(UpstartTest,NotifyConnected)75 TEST_F(UpstartTest, NotifyConnected) {
76   EXPECT_CALL(*upstart_proxy_, EmitEvent("shill-connected", _, false));
77   upstart_.NotifyConnected();
78 }
79 
80 }  // namespace shill
81