1/* 2 * Copyright 2015 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 11#import <Foundation/Foundation.h> 12 13#include <memory> 14 15#include "rtc_base/gunit.h" 16 17#import "api/peerconnection/RTCIceCandidate+Private.h" 18#import "api/peerconnection/RTCIceCandidate.h" 19#import "helpers/NSString+StdString.h" 20 21@interface RTCIceCandidateTest : NSObject 22- (void)testCandidate; 23- (void)testInitFromNativeCandidate; 24@end 25 26@implementation RTCIceCandidateTest 27 28- (void)testCandidate { 29 NSString *sdp = @"candidate:4025901590 1 udp 2122265343 " 30 "fdff:2642:12a6:fe38:c001:beda:fcf9:51aa " 31 "59052 typ host generation 0"; 32 33 RTC_OBJC_TYPE(RTCIceCandidate) *candidate = 34 [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithSdp:sdp sdpMLineIndex:0 sdpMid:@"audio"]; 35 36 std::unique_ptr<webrtc::IceCandidateInterface> nativeCandidate = 37 candidate.nativeCandidate; 38 EXPECT_EQ("audio", nativeCandidate->sdp_mid()); 39 EXPECT_EQ(0, nativeCandidate->sdp_mline_index()); 40 41 std::string sdpString; 42 nativeCandidate->ToString(&sdpString); 43 EXPECT_EQ(sdp.stdString, sdpString); 44} 45 46- (void)testInitFromNativeCandidate { 47 std::string sdp("candidate:4025901590 1 udp 2122265343 " 48 "fdff:2642:12a6:fe38:c001:beda:fcf9:51aa " 49 "59052 typ host generation 0"); 50 webrtc::IceCandidateInterface *nativeCandidate = 51 webrtc::CreateIceCandidate("audio", 0, sdp, nullptr); 52 53 RTC_OBJC_TYPE(RTCIceCandidate) *iceCandidate = 54 [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:nativeCandidate]; 55 EXPECT_TRUE([@"audio" isEqualToString:iceCandidate.sdpMid]); 56 EXPECT_EQ(0, iceCandidate.sdpMLineIndex); 57 58 EXPECT_EQ(sdp, iceCandidate.sdp.stdString); 59} 60 61@end 62 63TEST(RTCIceCandidateTest, CandidateTest) { 64 @autoreleasepool { 65 RTCIceCandidateTest *test = [[RTCIceCandidateTest alloc] init]; 66 [test testCandidate]; 67 } 68} 69 70TEST(RTCIceCandidateTest, InitFromCandidateTest) { 71 @autoreleasepool { 72 RTCIceCandidateTest *test = [[RTCIceCandidateTest alloc] init]; 73 [test testInitFromNativeCandidate]; 74 } 75} 76