chromium/services/network/p2p/socket_test_utils.h

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#ifndef SERVICES_NETWORK_P2P_SOCKET_TEST_UTILS_H_
#define SERVICES_NETWORK_P2P_SOCKET_TEST_UTILS_H_

#include <stdint.h>

#include <list>
#include <memory>
#include <string>
#include <tuple>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/net_errors.h"
#include "net/base/network_interfaces.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/stream_socket.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/p2p/socket.h"
#include "services/network/public/cpp/p2p_param_traits.h"
#include "services/network/public/mojom/p2p.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace network {

const char kTestLocalIpAddress[] =;
const char kTestIpAddress1[] =;
const uint16_t kTestPort1 =;
const char kTestIpAddress2[] =;
const uint16_t kTestPort2 =;

class FakeP2PSocketDelegate : public P2PSocket::Delegate {};

class FakeSocket : public net::StreamSocket {};

class FakeSocketClient : public mojom::P2PSocketClient {};

class FakeNetworkNotificationClient
    : public mojom::P2PNetworkNotificationClient {};

void CreateRandomPacket(std::vector<uint8_t>* packet);
void CreateStunRequest(std::vector<uint8_t>* packet);
void CreateStunResponse(std::vector<uint8_t>* packet);
void CreateStunError(std::vector<uint8_t>* packet);

net::IPEndPoint ParseAddress(const std::string& ip_str, uint16_t port);

MATCHER_P(MatchMessage, type, "") {}

MATCHER_P2(MatchSendPacketMetrics, rtc_packet_id, test_start_time, "") {}

// Creates a GMock matcher that matches `base::span` to `std::vector`.
MATCHER_P(SpanEq, expected, "") {}

}  // namespace network

#endif  // SERVICES_NETWORK_P2P_SOCKET_TEST_UTILS_H_