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> |
| 12 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 13 | #include <memory> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 15 | #include "rtc_base/gunit.h" |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 16 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 17 | #import "NSString+StdString.h" |
| 18 | #import "RTCIceCandidate+Private.h" |
| 19 | #import "WebRTC/RTCIceCandidate.h" |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 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 | RTCIceCandidate *candidate = [[RTCIceCandidate alloc] initWithSdp:sdp |
| 34 | sdpMLineIndex:0 |
| 35 | sdpMid:@"audio"]; |
| 36 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 37 | std::unique_ptr<webrtc::IceCandidateInterface> nativeCandidate = |
Jon Hjelle | 29d5e57 | 2016-01-06 11:49:11 -0800 | [diff] [blame] | 38 | candidate.nativeCandidate; |
| 39 | EXPECT_EQ("audio", nativeCandidate->sdp_mid()); |
| 40 | EXPECT_EQ(0, nativeCandidate->sdp_mline_index()); |
| 41 | |
| 42 | std::string sdpString; |
| 43 | nativeCandidate->ToString(&sdpString); |
| 44 | EXPECT_EQ(sdp.stdString, sdpString); |
| 45 | } |
| 46 | |
| 47 | - (void)testInitFromNativeCandidate { |
| 48 | std::string sdp("candidate:4025901590 1 udp 2122265343 " |
| 49 | "fdff:2642:12a6:fe38:c001:beda:fcf9:51aa " |
| 50 | "59052 typ host generation 0"); |
| 51 | webrtc::IceCandidateInterface *nativeCandidate = |
| 52 | webrtc::CreateIceCandidate("audio", 0, sdp, nullptr); |
| 53 | |
| 54 | RTCIceCandidate *iceCandidate = |
| 55 | [[RTCIceCandidate alloc] initWithNativeCandidate:nativeCandidate]; |
| 56 | EXPECT_TRUE([@"audio" isEqualToString:iceCandidate.sdpMid]); |
| 57 | EXPECT_EQ(0, iceCandidate.sdpMLineIndex); |
| 58 | |
| 59 | EXPECT_EQ(sdp, iceCandidate.sdp.stdString); |
| 60 | } |
| 61 | |
| 62 | @end |
| 63 | |
| 64 | TEST(RTCIceCandidateTest, CandidateTest) { |
| 65 | @autoreleasepool { |
| 66 | RTCIceCandidateTest *test = [[RTCIceCandidateTest alloc] init]; |
| 67 | [test testCandidate]; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | TEST(RTCIceCandidateTest, InitFromCandidateTest) { |
| 72 | @autoreleasepool { |
| 73 | RTCIceCandidateTest *test = [[RTCIceCandidateTest alloc] init]; |
| 74 | [test testInitFromNativeCandidate]; |
| 75 | } |
| 76 | } |