blob: ce9f2c35218b5215b6bc5421acccee857b2aa3e2 [file] [log] [blame]
Per K4ac37182023-11-15 09:43:321/*
2 * Copyright 2023 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "rtc_base/async_packet_socket.h"
12
Per K2fafcec2024-02-22 06:42:4213#include "rtc_base/socket_address.h"
Per K4ac37182023-11-15 09:43:3214#include "rtc_base/third_party/sigslot/sigslot.h"
15#include "test/gmock.h"
16#include "test/gtest.h"
17
18namespace rtc {
19namespace {
20
21using ::testing::MockFunction;
22
23class MockAsyncPacketSocket : public rtc::AsyncPacketSocket {
24 public:
25 ~MockAsyncPacketSocket() = default;
26
27 MOCK_METHOD(SocketAddress, GetLocalAddress, (), (const, override));
28 MOCK_METHOD(SocketAddress, GetRemoteAddress, (), (const, override));
29 MOCK_METHOD(int,
30 Send,
31 (const void* pv, size_t cb, const rtc::PacketOptions& options),
32 (override));
33
34 MOCK_METHOD(int,
35 SendTo,
36 (const void* pv,
37 size_t cb,
38 const SocketAddress& addr,
39 const rtc::PacketOptions& options),
40 (override));
41 MOCK_METHOD(int, Close, (), (override));
42 MOCK_METHOD(State, GetState, (), (const, override));
43 MOCK_METHOD(int,
44 GetOption,
45 (rtc::Socket::Option opt, int* value),
46 (override));
47 MOCK_METHOD(int, SetOption, (rtc::Socket::Option opt, int value), (override));
48 MOCK_METHOD(int, GetError, (), (const, override));
49 MOCK_METHOD(void, SetError, (int error), (override));
50
Per K2fafcec2024-02-22 06:42:4251 using AsyncPacketSocket::NotifyPacketReceived;
Per K4ac37182023-11-15 09:43:3252};
53
54TEST(AsyncPacketSocket, RegisteredCallbackReceivePacketsFromNotify) {
55 MockAsyncPacketSocket mock_socket;
56 MockFunction<void(AsyncPacketSocket*, const rtc::ReceivedPacket&)>
57 received_packet;
58
59 EXPECT_CALL(received_packet, Call);
60 mock_socket.RegisterReceivedPacketCallback(received_packet.AsStdFunction());
Per K2fafcec2024-02-22 06:42:4261 mock_socket.NotifyPacketReceived(ReceivedPacket({}, SocketAddress()));
Per K4ac37182023-11-15 09:43:3262}
63
Per K4ac37182023-11-15 09:43:3264} // namespace
65} // namespace rtc