~morphis/aethercast/enable-arm64-builds

« back to all changes in this revision

Viewing changes to tests/w11tng/dhcp_tests.cpp

  • Committer: Tarmac
  • Author(s): Simon Fels
  • Date: 2016-02-04 06:38:31 UTC
  • mfrom: (119.1.65 trunk)
  • Revision ID: tarmac-20160204063831-b6q9o8ktznevvd8x
Add a network manager implementation to use the DBus interface of wpa-supplicant.

Approved by PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2016 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 */
 
17
 
 
18
#include <gtest/gtest.h>
 
19
#include <gmock/gmock.h>
 
20
 
 
21
#include <boost/filesystem.hpp>
 
22
 
 
23
#include <w11tng/dhcpserver.h>
 
24
#include <w11tng/dhcpclient.h>
 
25
 
 
26
#include <core/posix/process.h>
 
27
 
 
28
#include <common/glibhelpers.h>
 
29
#include <common/virtualnetwork.h>
 
30
 
 
31
namespace {
 
32
class MockDhcpServerDelegate : public w11tng::DhcpServer::Delegate {
 
33
public:
 
34
    MOCK_METHOD2(OnDhcpAddressAssigned, void(const mcs::IpV4Address &, const mcs::IpV4Address&));
 
35
    MOCK_METHOD0(OnDhcpTerminated, void());
 
36
};
 
37
class MockDhcpClientDelegate : public w11tng::DhcpClient::Delegate {
 
38
public:
 
39
    MOCK_METHOD2(OnDhcpAddressAssigned, void(const mcs::IpV4Address &, const mcs::IpV4Address&));
 
40
    MOCK_METHOD0(OnDhcpTerminated, void());
 
41
};
 
42
}
 
43
 
 
44
TEST(Dhcp, AddressAssignment) {
 
45
    mcs::testing::VirtualNetwork veth;
 
46
 
 
47
    boost::filesystem::create_directory("/run/aethercast");
 
48
 
 
49
    auto server_delegate = std::make_shared<MockDhcpServerDelegate>();
 
50
    EXPECT_CALL(*server_delegate, OnDhcpAddressAssigned(mcs::IpV4Address::from_string("192.168.7.1"),
 
51
                                                    mcs::IpV4Address::from_string("192.168.7.5")))
 
52
            .Times(1);
 
53
 
 
54
    auto client_delegate = std::make_shared<MockDhcpClientDelegate>();
 
55
    EXPECT_CALL(*client_delegate, OnDhcpAddressAssigned(mcs::IpV4Address::from_string("192.168.7.5"),
 
56
                                                    mcs::IpV4Address::from_string("192.168.7.1")))
 
57
            .Times(1);
 
58
 
 
59
    auto server = w11tng::DhcpServer::Create(server_delegate, veth.Endpoint1());
 
60
    auto client = w11tng::DhcpClient::Create(client_delegate, veth.Endpoint2());
 
61
 
 
62
    mcs::testing::RunMainLoop(std::chrono::seconds{5});
 
63
 
 
64
    EXPECT_EQ(client->LocalAddress().to_string(), "192.168.7.5");
 
65
    EXPECT_EQ(client->RemoteAddress().to_string(), "192.168.7.1");
 
66
}