xref: /aosp_15_r20/external/webrtc/sdk/objc/unittests/RTCIceCandidateTest.mm (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker/*
2*d9f75844SAndroid Build Coastguard Worker *  Copyright 2015 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker *
4*d9f75844SAndroid Build Coastguard Worker *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker */
10*d9f75844SAndroid Build Coastguard Worker
11*d9f75844SAndroid Build Coastguard Worker#import <Foundation/Foundation.h>
12*d9f75844SAndroid Build Coastguard Worker#import <XCTest/XCTest.h>
13*d9f75844SAndroid Build Coastguard Worker
14*d9f75844SAndroid Build Coastguard Worker#include <memory>
15*d9f75844SAndroid Build Coastguard Worker
16*d9f75844SAndroid Build Coastguard Worker#include "rtc_base/gunit.h"
17*d9f75844SAndroid Build Coastguard Worker
18*d9f75844SAndroid Build Coastguard Worker#import "api/peerconnection/RTCIceCandidate+Private.h"
19*d9f75844SAndroid Build Coastguard Worker#import "api/peerconnection/RTCIceCandidate.h"
20*d9f75844SAndroid Build Coastguard Worker#import "helpers/NSString+StdString.h"
21*d9f75844SAndroid Build Coastguard Worker
22*d9f75844SAndroid Build Coastguard Worker@interface RTCIceCandidateTest : XCTestCase
23*d9f75844SAndroid Build Coastguard Worker@end
24*d9f75844SAndroid Build Coastguard Worker
25*d9f75844SAndroid Build Coastguard Worker@implementation RTCIceCandidateTest
26*d9f75844SAndroid Build Coastguard Worker
27*d9f75844SAndroid Build Coastguard Worker- (void)testCandidate {
28*d9f75844SAndroid Build Coastguard Worker  NSString *sdp = @"candidate:4025901590 1 udp 2122265343 "
29*d9f75844SAndroid Build Coastguard Worker                   "fdff:2642:12a6:fe38:c001:beda:fcf9:51aa "
30*d9f75844SAndroid Build Coastguard Worker                   "59052 typ host generation 0";
31*d9f75844SAndroid Build Coastguard Worker
32*d9f75844SAndroid Build Coastguard Worker  RTC_OBJC_TYPE(RTCIceCandidate) *candidate =
33*d9f75844SAndroid Build Coastguard Worker      [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithSdp:sdp sdpMLineIndex:0 sdpMid:@"audio"];
34*d9f75844SAndroid Build Coastguard Worker
35*d9f75844SAndroid Build Coastguard Worker  std::unique_ptr<webrtc::IceCandidateInterface> nativeCandidate =
36*d9f75844SAndroid Build Coastguard Worker      candidate.nativeCandidate;
37*d9f75844SAndroid Build Coastguard Worker  EXPECT_EQ("audio", nativeCandidate->sdp_mid());
38*d9f75844SAndroid Build Coastguard Worker  EXPECT_EQ(0, nativeCandidate->sdp_mline_index());
39*d9f75844SAndroid Build Coastguard Worker
40*d9f75844SAndroid Build Coastguard Worker  std::string sdpString;
41*d9f75844SAndroid Build Coastguard Worker  nativeCandidate->ToString(&sdpString);
42*d9f75844SAndroid Build Coastguard Worker  EXPECT_EQ(sdp.stdString, sdpString);
43*d9f75844SAndroid Build Coastguard Worker}
44*d9f75844SAndroid Build Coastguard Worker
45*d9f75844SAndroid Build Coastguard Worker- (void)testInitFromNativeCandidate {
46*d9f75844SAndroid Build Coastguard Worker  std::string sdp("candidate:4025901590 1 udp 2122265343 "
47*d9f75844SAndroid Build Coastguard Worker                  "fdff:2642:12a6:fe38:c001:beda:fcf9:51aa "
48*d9f75844SAndroid Build Coastguard Worker                  "59052 typ host generation 0");
49*d9f75844SAndroid Build Coastguard Worker  webrtc::IceCandidateInterface *nativeCandidate =
50*d9f75844SAndroid Build Coastguard Worker      webrtc::CreateIceCandidate("audio", 0, sdp, nullptr);
51*d9f75844SAndroid Build Coastguard Worker
52*d9f75844SAndroid Build Coastguard Worker  RTC_OBJC_TYPE(RTCIceCandidate) *iceCandidate =
53*d9f75844SAndroid Build Coastguard Worker      [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:nativeCandidate];
54*d9f75844SAndroid Build Coastguard Worker  EXPECT_TRUE([@"audio" isEqualToString:iceCandidate.sdpMid]);
55*d9f75844SAndroid Build Coastguard Worker  EXPECT_EQ(0, iceCandidate.sdpMLineIndex);
56*d9f75844SAndroid Build Coastguard Worker
57*d9f75844SAndroid Build Coastguard Worker  EXPECT_EQ(sdp, iceCandidate.sdp.stdString);
58*d9f75844SAndroid Build Coastguard Worker}
59*d9f75844SAndroid Build Coastguard Worker
60*d9f75844SAndroid Build Coastguard Worker@end
61