blob: 69f9844b9813820b9ff63cb8f4b02a1b7efcc1d8 [file] [log] [blame]
Paul Stewartcf199de2012-08-16 07:50:41 -07001// Copyright (c) 2012 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/ethernet_service.h"
6
7#include <gmock/gmock.h>
8#include <gtest/gtest.h>
9
10#include "shill/mock_ethernet.h"
11#include "shill/property_store_unittest.h"
12#include "shill/refptr_types.h"
13
14using ::testing::NiceMock;
15
16namespace shill {
17
18class EthernetServiceTest : public PropertyStoreTest {
19 public:
20 EthernetServiceTest()
21 : ethernet_(
22 new NiceMock<MockEthernet>(control_interface(),
23 dispatcher(),
24 metrics(),
25 manager(),
26 "ethernet",
27 fake_mac,
28 0)),
29 service_(
30 new EthernetService(control_interface(),
31 dispatcher(),
32 metrics(),
33 manager(),
34 ethernet_)) {}
35 virtual ~EthernetServiceTest() {}
36
37 protected:
38 static const char fake_mac[];
39
40 bool GetAutoConnect() {
41 return service_->GetAutoConnect(NULL);
42 }
43
44 void SetAutoConnect(const bool connect, Error *error) {
45 return service_->SetAutoConnect(connect, error);
46 }
47
48 scoped_refptr<MockEthernet> ethernet_;
49 EthernetServiceRefPtr service_;
50};
51
52// static
53const char EthernetServiceTest::fake_mac[] = "AaBBcCDDeeFF";
54
55TEST_F(EthernetServiceTest, AutoConnect) {
56 EXPECT_TRUE(service_->IsAutoConnectByDefault());
57 EXPECT_TRUE(GetAutoConnect());
58 {
59 Error error;
60 SetAutoConnect(false, &error);
61 EXPECT_FALSE(error.IsSuccess());
62 }
63 EXPECT_TRUE(GetAutoConnect());
64 {
65 Error error;
66 SetAutoConnect(true, &error);
67 EXPECT_TRUE(error.IsSuccess());
68 }
69 EXPECT_TRUE(GetAutoConnect());
70}
71
Christopher Wiley2f1bbf02012-10-25 15:31:13 -070072TEST_F(EthernetServiceTest, ConnectDisconnectDelegation) {
73 EXPECT_CALL(*ethernet_, ConnectTo(service_.get()));
74 service_->AutoConnect();
75 EXPECT_CALL(*ethernet_, DisconnectFrom(service_.get()));
76 Error error;
77 service_->Disconnect(&error);
78}
79
Paul Stewartcf199de2012-08-16 07:50:41 -070080} // namespace shill