kthelgason | 4065a57 | 2017-02-14 04:58:56 -0800 | [diff] [blame] | 1 | /* |
| 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 { |
kthelgason | 6644c8b | 2017-08-28 00:48:18 -0700 | [diff] [blame] | 24 | 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"); |
kthelgason | 4065a57 | 2017-02-14 04:58:56 -0800 | [diff] [blame] | 30 | [self preferVideoCodec:@"H264" sdp:sdp expected:expectedSdp]; |
| 31 | } |
| 32 | |
| 33 | - (void)testPreferVideoCodecVP8 { |
kthelgason | 6644c8b | 2017-08-28 00:48:18 -0700 | [diff] [blame] | 34 | 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"); |
kthelgason | 4065a57 | 2017-02-14 04:58:56 -0800 | [diff] [blame] | 38 | [self preferVideoCodec:@"VP8" sdp:sdp expected:expectedSdp]; |
| 39 | } |
| 40 | |
| 41 | - (void)testNoMLine { |
kthelgason | 6644c8b | 2017-08-28 00:48:18 -0700 | [diff] [blame] | 42 | NSString *sdp = @("a=rtpmap:116 VP8/90000\r\n"); |
kthelgason | 4065a57 | 2017-02-14 04:58:56 -0800 | [diff] [blame] | 43 | [self preferVideoCodec:@"VP8" sdp:sdp expected:sdp]; |
| 44 | } |
| 45 | |
| 46 | - (void)testMissingCodec { |
kthelgason | 6644c8b | 2017-08-28 00:48:18 -0700 | [diff] [blame] | 47 | NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120 97\r\n" |
| 48 | "a=rtpmap:116 VP8/90000\r\n"); |
kthelgason | 4065a57 | 2017-02-14 04:58:56 -0800 | [diff] [blame] | 49 | [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 |