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#import <XCTest/XCTest.h> 13 14#include <memory> 15 16#include "rtc_base/gunit.h" 17 18#import "api/peerconnection/RTCIceCandidate+Private.h" 19#import "api/peerconnection/RTCIceCandidate.h" 20#import "helpers/NSString+StdString.h" 21 22@interface RTCIceCandidateTest : XCTestCase 23@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 32 RTC_OBJC_TYPE(RTCIceCandidate) *candidate = 33 [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithSdp:sdp sdpMLineIndex:0 sdpMid:@"audio"]; 34 35 std::unique_ptr<webrtc::IceCandidateInterface> nativeCandidate = 36 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 52 RTC_OBJC_TYPE(RTCIceCandidate) *iceCandidate = 53 [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:nativeCandidate]; 54 EXPECT_TRUE([@"audio" isEqualToString:iceCandidate.sdpMid]); 55 EXPECT_EQ(0, iceCandidate.sdpMLineIndex); 56 57 EXPECT_EQ(sdp, iceCandidate.sdp.stdString); 58} 59 60@end 61