Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #import <Foundation/Foundation.h> |
Byoungchan Lee | c8a6fb2 | 2022-05-13 19:59:49 +0900 | [diff] [blame] | 12 | #import <XCTest/XCTest.h> |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 13 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "rtc_base/gunit.h" |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 17 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 18 | #import "api/peerconnection/RTCIceCandidate+Private.h" |
| 19 | #import "api/peerconnection/RTCIceCandidate.h" |
Artem Titov | 63ee39d | 2022-05-13 14:46:42 +0000 | [diff] [blame^] | 20 | #import "helpers/NSString+StdString.h" |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 21 | |
Byoungchan Lee | c8a6fb2 | 2022-05-13 19:59:49 +0900 | [diff] [blame] | 22 | @interface RTCIceCandidateTest : XCTestCase |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 32 | RTC_OBJC_TYPE(RTCIceCandidate) *candidate = |
| 33 | [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithSdp:sdp sdpMLineIndex:0 sdpMid:@"audio"]; |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 34 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 35 | std::unique_ptr<webrtc::IceCandidateInterface> nativeCandidate = |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 52 | RTC_OBJC_TYPE(RTCIceCandidate) *iceCandidate = |
| 53 | [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:nativeCandidate]; |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 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 |