Per K | 4ac3718 | 2023-11-15 09:43:32 | [diff] [blame] | 1 | /* |
| 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 K | 2fafcec | 2024-02-22 06:42:42 | [diff] [blame] | 13 | #include "rtc_base/socket_address.h" |
Per K | 4ac3718 | 2023-11-15 09:43:32 | [diff] [blame] | 14 | #include "rtc_base/third_party/sigslot/sigslot.h" |
| 15 | #include "test/gmock.h" |
| 16 | #include "test/gtest.h" |
| 17 | |
| 18 | namespace rtc { |
| 19 | namespace { |
| 20 | |
| 21 | using ::testing::MockFunction; |
| 22 | |
| 23 | class 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 K | 2fafcec | 2024-02-22 06:42:42 | [diff] [blame] | 51 | using AsyncPacketSocket::NotifyPacketReceived; |
Per K | 4ac3718 | 2023-11-15 09:43:32 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | TEST(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 K | 2fafcec | 2024-02-22 06:42:42 | [diff] [blame] | 61 | mock_socket.NotifyPacketReceived(ReceivedPacket({}, SocketAddress())); |
Per K | 4ac3718 | 2023-11-15 09:43:32 | [diff] [blame] | 62 | } |
| 63 | |
Per K | 4ac3718 | 2023-11-15 09:43:32 | [diff] [blame] | 64 | } // namespace |
| 65 | } // namespace rtc |