~phablet-team/aethercast/fix-for-microsoft-dongle

« back to all changes in this revision

Viewing changes to tests/w11tng/netlinklistener_tests.cpp

  • Committer: Tarmac
  • Author(s): Simon Fels
  • Date: 2016-03-04 14:14:09 UTC
  • mfrom: (119.4.12 ac-networking-fixes)
  • Revision ID: tarmac-20160304141409-xe8khdgb43nha1fn
Multiple changes for Networking support:

* Add a DisconnectAll dbus method to allow the UI to easily disconnect
  any connected device. Just for the purpose of a demo.
* Return proper errors when scanning fails.
* Enable miracast mode for the WiFi driver if available.
* Set GO intent by default to 7. Should be higher if we're a sink.
* Print frequencies consider for GO negotiation
* Several minor fixes
* Enable unit tests again.

Approved by PS Jenkins bot, Thomas Voß.

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 <asm/types.h>
22
 
#include <linux/netlink.h>
23
 
#include <linux/rtnetlink.h>
24
 
#include <sys/socket.h>
25
 
 
26
 
#include <common/glibhelpers.h>
27
 
#include <common/virtualnetwork.h>
28
 
 
29
 
#include <mcs/networkutils.h>
30
 
 
31
 
#include <w11tng/netlinklistener.h>
32
 
 
33
 
namespace {
34
 
class MockNetlinkListenerDelegate : public w11tng::NetlinkListener::Delegate {
35
 
public:
36
 
    MOCK_METHOD2(OnInterfaceAddressChanged, void(const std::string &, const std::string &));
37
 
};
38
 
class NetlinkListener : public ::testing::TestWithParam<bool> {
39
 
};
40
 
}
41
 
 
42
 
TEST_P(NetlinkListener, NotifiesIpAddressChanges) {
43
 
    auto delegate = std::make_shared<MockNetlinkListenerDelegate>();
44
 
 
45
 
    mcs::testing::VirtualNetwork veth;
46
 
 
47
 
    auto listener = w11tng::NetlinkListener::Create(delegate);
48
 
    if (GetParam())
49
 
        listener->SetInterfaceFilter(veth.Endpoint1());
50
 
 
51
 
    std::string expected_address = "192.168.7.1";
52
 
 
53
 
    // We can't really influence the number of times this is
54
 
    // called as the events come in multiple times (for whatever
55
 
    // reason) so we require it to happen at least once.
56
 
    EXPECT_CALL(*delegate, OnInterfaceAddressChanged(veth.Endpoint1(), expected_address))
57
 
            .Times(::testing::AtLeast(1));
58
 
 
59
 
    auto interface_index = mcs::NetworkUtils::RetrieveInterfaceIndex(veth.Endpoint1().c_str());
60
 
    mcs::NetworkUtils::ModifyInterfaceAddress(RTM_NEWADDR, NLM_F_REPLACE | NLM_F_ACK,
61
 
                                              interface_index, AF_INET, expected_address.c_str(),
62
 
                                              nullptr, 24, "255.255.255.0");
63
 
 
64
 
    mcs::testing::RunMainLoop(std::chrono::seconds{2});
65
 
}
66
 
 
67
 
INSTANTIATE_TEST_CASE_P(InterfaceAddressChanges, NetlinkListener, ::testing::Values(false, true));