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/arp_client_test_helper.h"
18
19 #include <gtest/gtest.h>
20
21 using testing::_;
22 using testing::Invoke;
23 using testing::Return;
24
25 namespace shill {
26
ArpClientTestHelper(MockArpClient * client)27 ArpClientTestHelper::ArpClientTestHelper(MockArpClient* client)
28 : client_(client) {}
29
~ArpClientTestHelper()30 ArpClientTestHelper::~ArpClientTestHelper() {}
31
GeneratePacket(uint16_t operation,const IPAddress & local_ip,const ByteString & local_mac,const IPAddress & remote_ip,const ByteString & remote_mac)32 void ArpClientTestHelper::GeneratePacket(uint16_t operation,
33 const IPAddress& local_ip,
34 const ByteString& local_mac,
35 const IPAddress& remote_ip,
36 const ByteString& remote_mac) {
37 packet_.set_operation(operation);
38 packet_.set_local_ip_address(local_ip);
39 packet_.set_local_mac_address(local_mac);
40 packet_.set_remote_ip_address(remote_ip);
41 packet_.set_remote_mac_address(remote_mac);
42
43 EXPECT_CALL(*client_, ReceivePacket(_, _))
44 .WillOnce(Invoke(this, &ArpClientTestHelper::SimulateReceivePacket));
45 }
46
SimulateReceivePacket(ArpPacket * packet,ByteString * sender)47 bool ArpClientTestHelper::SimulateReceivePacket(ArpPacket* packet,
48 ByteString* sender) {
49 packet->set_operation(packet_.operation());
50 packet->set_local_ip_address(packet_.local_ip_address());
51 packet->set_local_mac_address(packet_.local_mac_address());
52 packet->set_remote_ip_address(packet_.remote_ip_address());
53 packet->set_remote_mac_address(packet_.remote_mac_address());
54 return true;
55 }
56
57 } // namespace shill
58