blob: 26ab09ea5dbc7e524ce2a6b2636723a54589db98 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:261/*
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 Olssona4d87372019-07-05 17:08:3311#include "rtc_base/async_udp_socket.h"
12
Per Kjellander906deaf2024-10-31 14:10:1913#include <cstdint>
jbauch555604a2016-04-26 10:13:2214#include <memory>
henrike@webrtc.orgf0488722014-05-13 18:00:2615
Per Kjellander906deaf2024-10-31 14:10:1916#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 Anton10542f22019-01-11 17:11:0020#include "rtc_base/virtual_socket_server.h"
Per Kjellander906deaf2024-10-31 14:10:1921#include "test/gtest.h"
henrike@webrtc.orgf0488722014-05-13 18:00:2622
23namespace rtc {
24
Per Kjellander906deaf2024-10-31 14:10:1925static const SocketAddress kAddr("22.22.22.22", 0);
henrike@webrtc.orgf0488722014-05-13 18:00:2626
Per Kjellander906deaf2024-10-31 14:10:1927TEST(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.orgf0488722014-05-13 18:00:2632
Per Kjellander906deaf2024-10-31 14:10:1933 int ect = 0;
34 socket->GetOption(Socket::OPT_SEND_ECN, &ect);
35 ASSERT_EQ(ect, 0);
henrike@webrtc.orgf0488722014-05-13 18:00:2636
Per Kjellander906deaf2024-10-31 14:10:1937 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.orgf0488722014-05-13 18:00:2653}
54
55} // namespace rtc