henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 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 | |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 11 | #include "rtc_base/async_udp_socket.h" |
| 12 | |
Per Kjellander | 906deaf | 2024-10-31 14:10:19 | [diff] [blame] | 13 | #include <cstdint> |
jbauch | 555604a | 2016-04-26 10:13:22 | [diff] [blame] | 14 | #include <memory> |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 15 | |
Per Kjellander | 906deaf | 2024-10-31 14:10:19 | [diff] [blame] | 16 | #include "absl/memory/memory.h" |
| 17 | #include "rtc_base/async_packet_socket.h" |
| 18 | #include "rtc_base/socket.h" |
| 19 | #include "rtc_base/socket_address.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 20 | #include "rtc_base/virtual_socket_server.h" |
Per Kjellander | 906deaf | 2024-10-31 14:10:19 | [diff] [blame] | 21 | #include "test/gtest.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 22 | |
| 23 | namespace rtc { |
| 24 | |
Per Kjellander | 906deaf | 2024-10-31 14:10:19 | [diff] [blame] | 25 | static const SocketAddress kAddr("22.22.22.22", 0); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 26 | |
Per Kjellander | 906deaf | 2024-10-31 14:10:19 | [diff] [blame] | 27 | TEST(AsyncUDPSocketTest, SetSocketOptionIfEctChange) { |
| 28 | VirtualSocketServer socket_server; |
| 29 | Socket* socket = socket_server.CreateSocket(kAddr.family(), SOCK_DGRAM); |
| 30 | std::unique_ptr<AsyncUDPSocket> udp__socket = |
| 31 | absl::WrapUnique(AsyncUDPSocket::Create(socket, kAddr)); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 32 | |
Per Kjellander | 906deaf | 2024-10-31 14:10:19 | [diff] [blame] | 33 | int ect = 0; |
| 34 | socket->GetOption(Socket::OPT_SEND_ECN, &ect); |
| 35 | ASSERT_EQ(ect, 0); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 36 | |
Per Kjellander | 906deaf | 2024-10-31 14:10:19 | [diff] [blame] | 37 | uint8_t buffer[] = "hello"; |
| 38 | rtc::PacketOptions packet_options; |
| 39 | packet_options.ecn_1 = false; |
| 40 | udp__socket->SendTo(buffer, 5, kAddr, packet_options); |
| 41 | socket->GetOption(Socket::OPT_SEND_ECN, &ect); |
| 42 | EXPECT_EQ(ect, 0); |
| 43 | |
| 44 | packet_options.ecn_1 = true; |
| 45 | udp__socket->SendTo(buffer, 5, kAddr, packet_options); |
| 46 | socket->GetOption(Socket::OPT_SEND_ECN, &ect); |
| 47 | EXPECT_EQ(ect, 1); |
| 48 | |
| 49 | packet_options.ecn_1 = false; |
| 50 | udp__socket->SendTo(buffer, 5, kAddr, packet_options); |
| 51 | socket->GetOption(Socket::OPT_SEND_ECN, &ect); |
| 52 | EXPECT_EQ(ect, 0); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | } // namespace rtc |