blob: 25d7ffe67df013e4f20a42c5ac7d459f21eae499 [file] [log] [blame]
Jon Hjelle67e83d62016-01-06 12:05:22 -08001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
Jon Hjelle67e83d62016-01-06 12:05:22 -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 Hjelle67e83d62016-01-06 12:05:22 -08009 */
10
11#import <Foundation/Foundation.h>
12
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "rtc_base/gunit.h"
Jon Hjelle67e83d62016-01-06 12:05:22 -080014
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020015#import "api/peerconnection/RTCSessionDescription+Private.h"
16#import "api/peerconnection/RTCSessionDescription.h"
17#import "helpers/NSString+StdString.h"
Jon Hjelle67e83d62016-01-06 12:05:22 -080018
19@interface RTCSessionDescriptionTest : NSObject
20- (void)testSessionDescriptionConversion;
21- (void)testInitFromNativeSessionDescription;
22@end
23
24@implementation RTCSessionDescriptionTest
25
26/**
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020027 * Test conversion of an Objective-C RTC_OBJC_TYPE(RTCSessionDescription) to a native
Jon Hjelle67e83d62016-01-06 12:05:22 -080028 * SessionDescriptionInterface (based on the types and SDP strings being equal).
29 */
30- (void)testSessionDescriptionConversion {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020031 RTC_OBJC_TYPE(RTCSessionDescription) *description =
32 [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithType:RTCSdpTypeAnswer sdp:[self sdp]];
Jon Hjelle67e83d62016-01-06 12:05:22 -080033
Byoungchan Lee33728152021-08-04 20:54:45 +090034 std::unique_ptr<webrtc::SessionDescriptionInterface> nativeDescription =
Jon Hjelle67e83d62016-01-06 12:05:22 -080035 description.nativeDescription;
36
37 EXPECT_EQ(RTCSdpTypeAnswer,
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020038 [RTC_OBJC_TYPE(RTCSessionDescription) typeForStdString:nativeDescription->type()]);
Jon Hjelle67e83d62016-01-06 12:05:22 -080039
40 std::string sdp;
41 nativeDescription->ToString(&sdp);
42 EXPECT_EQ([self sdp].stdString, sdp);
43}
44
45- (void)testInitFromNativeSessionDescription {
46 webrtc::SessionDescriptionInterface *nativeDescription;
47
48 nativeDescription = webrtc::CreateSessionDescription(
49 webrtc::SessionDescriptionInterface::kAnswer,
50 [self sdp].stdString,
51 nullptr);
52
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020053 RTC_OBJC_TYPE(RTCSessionDescription) *description =
54 [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:nativeDescription];
Jon Hjelle67e83d62016-01-06 12:05:22 -080055 EXPECT_EQ(webrtc::SessionDescriptionInterface::kAnswer,
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020056 [RTC_OBJC_TYPE(RTCSessionDescription) stdStringForType:description.type]);
Jon Hjelle67e83d62016-01-06 12:05:22 -080057 EXPECT_TRUE([[self sdp] isEqualToString:description.sdp]);
58}
59
60- (NSString *)sdp {
Elad Alonfadb1812019-05-24 13:40:02 +020061 return @"v=0\r\n"
62 "o=- 5319989746393411314 2 IN IP4 127.0.0.1\r\n"
63 "s=-\r\n"
64 "t=0 0\r\n"
65 "a=group:BUNDLE audio video\r\n"
66 "a=msid-semantic: WMS ARDAMS\r\n"
67 "m=audio 9 UDP/TLS/RTP/SAVPF 111 103 9 0 8 126\r\n"
68 "c=IN IP4 0.0.0.0\r\n"
69 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
70 "a=ice-ufrag:f3o+0HG7l9nwIWFY\r\n"
71 "a=ice-pwd:VDctmJNCptR2TB7+meDpw7w5\r\n"
72 "a=fingerprint:sha-256 A9:D5:8D:A8:69:22:39:60:92:AD:94:1A:22:2D:5E:"
73 "A5:4A:A9:18:C2:35:5D:46:5E:59:BD:1C:AF:38:9F:E6:E1\r\n"
74 "a=setup:active\r\n"
75 "a=mid:audio\r\n"
76 "a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\n"
77 "a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/"
78 "abs-send-time\r\n"
79 "a=sendrecv\r\n"
80 "a=rtcp-mux\r\n"
81 "a=rtpmap:111 opus/48000/2\r\n"
82 "a=fmtp:111 minptime=10;useinbandfec=1\r\n"
83 "a=rtpmap:103 ISAC/16000\r\n"
84 "a=rtpmap:9 G722/8000\r\n"
85 "a=rtpmap:0 PCMU/8000\r\n"
86 "a=rtpmap:8 PCMA/8000\r\n"
87 "a=rtpmap:126 telephone-event/8000\r\n"
88 "a=maxptime:60\r\n"
89 "a=ssrc:1504474588 cname:V+FdIC5AJpxLhdYQ\r\n"
90 "a=ssrc:1504474588 msid:ARDAMS ARDAMSa0\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +000091 "a=ssrc:1504474588 mslabel:ARDAMS\r\n"
92 "a=ssrc:1504474588 label:ARDAMSa0\r\n"
Elad Alonfadb1812019-05-24 13:40:02 +020093 "m=video 9 UDP/TLS/RTP/SAVPF 100 116 117 96\r\n"
94 "c=IN IP4 0.0.0.0\r\n"
95 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
96 "a=ice-ufrag:f3o+0HG7l9nwIWFY\r\n"
97 "a=ice-pwd:VDctmJNCptR2TB7+meDpw7w5\r\n"
98 "a=fingerprint:sha-256 A9:D5:8D:A8:69:22:39:60:92:AD:94:1A:22:2D:5E:"
99 "A5:4A:A9:18:C2:35:5D:46:5E:59:BD:1C:AF:38:9F:E6:E1\r\n"
100 "a=setup:active\r\n"
101 "a=mid:video\r\n"
102 "a=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\n"
103 "a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/"
104 "abs-send-time\r\n"
105 "a=extmap:4 urn:3gpp:video-orientation\r\n"
106 "a=sendrecv\r\n"
107 "a=rtcp-mux\r\n"
108 "a=rtpmap:100 VP8/90000\r\n"
109 "a=rtcp-fb:100 ccm fir\r\n"
110 "a=rtcp-fb:100 goog-lntf\r\n"
111 "a=rtcp-fb:100 nack\r\n"
112 "a=rtcp-fb:100 nack pli\r\n"
113 "a=rtcp-fb:100 goog-remb\r\n"
114 "a=rtpmap:116 red/90000\r\n"
115 "a=rtpmap:117 ulpfec/90000\r\n"
116 "a=rtpmap:96 rtx/90000\r\n"
117 "a=fmtp:96 apt=100\r\n"
118 "a=ssrc-group:FID 498297514 1644357692\r\n"
119 "a=ssrc:498297514 cname:V+FdIC5AJpxLhdYQ\r\n"
120 "a=ssrc:498297514 msid:ARDAMS ARDAMSv0\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000121 "a=ssrc:498297514 mslabel:ARDAMS\r\n"
122 "a=ssrc:498297514 label:ARDAMSv0\r\n"
Elad Alonfadb1812019-05-24 13:40:02 +0200123 "a=ssrc:1644357692 cname:V+FdIC5AJpxLhdYQ\r\n"
Artem Titovf0a34f22020-03-16 17:52:04 +0000124 "a=ssrc:1644357692 msid:ARDAMS ARDAMSv0\r\n"
125 "a=ssrc:1644357692 mslabel:ARDAMS\r\n"
126 "a=ssrc:1644357692 label:ARDAMSv0\r\n";
Jon Hjelle67e83d62016-01-06 12:05:22 -0800127}
128
129@end
130
131TEST(RTCSessionDescriptionTest, SessionDescriptionConversionTest) {
132 @autoreleasepool {
133 RTCSessionDescriptionTest *test = [[RTCSessionDescriptionTest alloc] init];
134 [test testSessionDescriptionConversion];
135 }
136}
137
Jon Hjelle67e83d62016-01-06 12:05:22 -0800138TEST(RTCSessionDescriptionTest, InitFromSessionDescriptionTest) {
139 @autoreleasepool {
140 RTCSessionDescriptionTest *test = [[RTCSessionDescriptionTest alloc] init];
141 [test testInitFromNativeSessionDescription];
142 }
143}