blob: 576411985d68ac5cedcec1fcfeac9f9c61b336ae [file] [log] [blame]
Jon Hjelle29d5e572016-01-06 11:49:11 -08001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
Jon Hjelle29d5e572016-01-06 11:49:11 -08003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
Jon Hjelle29d5e572016-01-06 11:49:11 -08009 */
10
11#import <Foundation/Foundation.h>
Byoungchan Leec8a6fb22022-05-13 19:59:49 +090012#import <XCTest/XCTest.h>
Jon Hjelle29d5e572016-01-06 11:49:11 -080013
kwibergbfefb032016-05-01 14:53:46 -070014#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "rtc_base/gunit.h"
Jon Hjelle29d5e572016-01-06 11:49:11 -080017
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020018#import "api/peerconnection/RTCIceCandidate+Private.h"
19#import "api/peerconnection/RTCIceCandidate.h"
Artem Titov63ee39d2022-05-13 14:46:42 +000020#import "helpers/NSString+StdString.h"
Jon Hjelle29d5e572016-01-06 11:49:11 -080021
Byoungchan Leec8a6fb22022-05-13 19:59:49 +090022@interface RTCIceCandidateTest : XCTestCase
Jon Hjelle29d5e572016-01-06 11:49:11 -080023@end
24
25@implementation RTCIceCandidateTest
26
27- (void)testCandidate {
28 NSString *sdp = @"candidate:4025901590 1 udp 2122265343 "
29 "fdff:2642:12a6:fe38:c001:beda:fcf9:51aa "
30 "59052 typ host generation 0";
31
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020032 RTC_OBJC_TYPE(RTCIceCandidate) *candidate =
33 [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithSdp:sdp sdpMLineIndex:0 sdpMid:@"audio"];
Jon Hjelle29d5e572016-01-06 11:49:11 -080034
kwibergbfefb032016-05-01 14:53:46 -070035 std::unique_ptr<webrtc::IceCandidateInterface> nativeCandidate =
Jon Hjelle29d5e572016-01-06 11:49:11 -080036 candidate.nativeCandidate;
37 EXPECT_EQ("audio", nativeCandidate->sdp_mid());
38 EXPECT_EQ(0, nativeCandidate->sdp_mline_index());
39
40 std::string sdpString;
41 nativeCandidate->ToString(&sdpString);
42 EXPECT_EQ(sdp.stdString, sdpString);
43}
44
45- (void)testInitFromNativeCandidate {
46 std::string sdp("candidate:4025901590 1 udp 2122265343 "
47 "fdff:2642:12a6:fe38:c001:beda:fcf9:51aa "
48 "59052 typ host generation 0");
49 webrtc::IceCandidateInterface *nativeCandidate =
50 webrtc::CreateIceCandidate("audio", 0, sdp, nullptr);
51
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020052 RTC_OBJC_TYPE(RTCIceCandidate) *iceCandidate =
53 [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:nativeCandidate];
Jon Hjelle29d5e572016-01-06 11:49:11 -080054 EXPECT_TRUE([@"audio" isEqualToString:iceCandidate.sdpMid]);
55 EXPECT_EQ(0, iceCandidate.sdpMLineIndex);
56
57 EXPECT_EQ(sdp, iceCandidate.sdp.stdString);
58}
59
60@end