blob: b94f4047418fa7c2d15ee45c962004a12e84ebdf [file] [log] [blame]
kthelgason4065a572017-02-14 04:58:56 -08001/*
2 * Copyright 2017 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#import "WebRTC/RTCSessionDescription.h"
15
16#import "ARDSDPUtils.h"
17
18@interface ARDSDPUtilsTest : XCTestCase
19@end
20
21@implementation ARDSDPUtilsTest
22
23- (void)testPreferVideoCodecH264 {
kthelgason6644c8b2017-08-28 00:48:18 -070024 NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120 97\r\n"
25 "a=rtpmap:120 H264/90000\r\n"
26 "a=rtpmap:97 H264/90000\r\n");
27 NSString *expectedSdp = @("m=video 9 RTP/SAVPF 120 97 100 116 117 96\r\n"
28 "a=rtpmap:120 H264/90000\r\n"
29 "a=rtpmap:97 H264/90000\r\n");
kthelgason4065a572017-02-14 04:58:56 -080030 [self preferVideoCodec:@"H264" sdp:sdp expected:expectedSdp];
31}
32
33- (void)testPreferVideoCodecVP8 {
kthelgason6644c8b2017-08-28 00:48:18 -070034 NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120 97\r\n"
35 "a=rtpmap:116 VP8/90000\r\n");
36 NSString *expectedSdp = @("m=video 9 RTP/SAVPF 116 100 117 96 120 97\r\n"
37 "a=rtpmap:116 VP8/90000\r\n");
kthelgason4065a572017-02-14 04:58:56 -080038 [self preferVideoCodec:@"VP8" sdp:sdp expected:expectedSdp];
39}
40
41- (void)testNoMLine {
kthelgason6644c8b2017-08-28 00:48:18 -070042 NSString *sdp = @("a=rtpmap:116 VP8/90000\r\n");
kthelgason4065a572017-02-14 04:58:56 -080043 [self preferVideoCodec:@"VP8" sdp:sdp expected:sdp];
44}
45
46- (void)testMissingCodec {
kthelgason6644c8b2017-08-28 00:48:18 -070047 NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120 97\r\n"
48 "a=rtpmap:116 VP8/90000\r\n");
kthelgason4065a572017-02-14 04:58:56 -080049 [self preferVideoCodec:@"foo" sdp:sdp expected:sdp];
50}
51
52#pragma mark - Helpers
53
54- (void)preferVideoCodec:(NSString *)codec
55 sdp:(NSString *)sdp
56 expected:(NSString *)expectedSdp{
57 RTCSessionDescription* desc =
58 [[RTCSessionDescription alloc] initWithType:RTCSdpTypeOffer sdp:sdp];
59 RTCSessionDescription *outputDesc =
60 [ARDSDPUtils descriptionForDescription:desc
61 preferredVideoCodec:codec];
62 XCTAssertTrue([outputDesc.description rangeOfString:expectedSdp].location != NSNotFound);
63}
64@end