chromium/third_party/blink/renderer/platform/peerconnection/webrtc_connection_matchers.h

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

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_WEBRTC_CONNECTION_MATCHERS_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_WEBRTC_CONNECTION_MATCHERS_H_

#include <iterator>
#include <ostream>
#include <vector>

#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "testing/gmock/include/gmock/gmock.h"

#include "third_party/webrtc/api/rtc_error.h"
#include "third_party/webrtc/p2p/base/connection.h"
#include "third_party/webrtc/p2p/base/ice_controller_interface.h"
#include "third_party/webrtc/p2p/base/ice_switch_reason.h"

#include "third_party/webrtc_overrides/p2p/base/ice_switch_proposal.h"

namespace cricket {

// Pretty prints a connection object for tests.
inline void PrintTo(const Connection* conn, std::ostream* os) {}

// Pretty prints an optional connection object for tests.
inline void PrintTo(std::optional<const Connection*> conn, std::ostream* os) {}

// Pretty prints a ping result for tests.
inline void PrintTo(const IceControllerInterface::PingResult& result,
                    std::ostream* os) {}

// Pretty prints an ICE switch reason for tests.
inline void PrintTo(const IceSwitchReason reason, std::ostream* os) {}

// Pretty prints an ICE recheck event for tests.
inline void PrintTo(const IceRecheckEvent& event, std::ostream* os) {}

// Pretty prints a switch result for tests.
inline void PrintTo(const IceControllerInterface::SwitchResult& result,
                    std::ostream* os) {}

}  // namespace cricket

namespace webrtc {

// Pretty prints an RTCError for tests.
inline void PrintTo(const RTCErrorType error, std::ostream* os) {}

}  // namespace webrtc

namespace blink {

namespace {

ExplainMatchResult;
Optional;
PrintToString;
UnorderedPointwise;

}  // unnamed namespace

// Tests the equality of a blink::IceConnection and a cricket::Connection.
MATCHER_P(ConnectionEq,
          /* const blink::IceConnection& arg, */
          /* const cricket::Connection* */ conn,
          base::StrCat({}

// Tests the equality of two optionals containing a blink::IceConnection and a
// cricket::Connection each.
MATCHER_P(ConnectionOptionalsEq,
          /* const std::optional<blink::IceConnection> arg, */
          /* const std::optional<cricket::Connection*> */ conn,
          "") {}

// Helper to test the equality of a (blink::IceConnection, cricket::Connection)
// tuple using ConnectionEq for use with container matchers.
MATCHER(CricketBlinkConnectionTupleEq,
        /* std::tuple<const blink::IceConnection&, const cricket::Connection*>
           arg, */
        "") {}

// Tests the equality of two sequences containing blink::IceConnection and
// cricket::Connection objects each, ignoring null cricket::Connections and
// ordering.
MATCHER_P(ConnectionSequenceEq,
          /* std::vector<blink::IceConnection> arg, */
          /* std::vector<const cricket::Connection*> */ connections,
          "") {}

// Tests the equality of a blink::IcePingProposal and a cricket::PingResult.
MATCHER_P2(PingProposalEq,
           /* const blink::IcePingProposal& arg, */
           /* const cricket::IceControllerInterface::PingResult& */ result,
           /* bool */ reply_expected,
           base::StrCat({}

// Tests the equality of a blink::IceRecheckEvent and a
// cricket::IceRecheckEvent.
MATCHER_P(RecheckEventEq,
          /* const blink::IceRecheckEvent& arg, */
          /* const cricket::IceRecheckEvent& */ event,
          base::StrCat({}

// Tests the equality of a blink::IceSwitchProposal and a cricket::SwitchResult.
MATCHER_P3(SwitchProposalEq,
           /* const blink::IceSwitchProposal& arg, */
           /* const cricket::IceSwitchReason */ reason,
           /* const cricket::IceControllerInterface::SwitchResult& */ result,
           /* bool */ reply_expected,
           base::StrCat({}

// Tests the equality of a blink::IceOruneProposal and a collection of
// cricket::Connections selected for pruning.
MATCHER_P2(PruneProposalEq,
           /* const blink::IcePruneProposal& arg, */
           /* std::vector<const cricket::Connection*> */ connections,
           /* bool */ reply_expected,
           base::StrCat({}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_WEBRTC_CONNECTION_MATCHERS_H_