hjon | 6f5ca08 | 2016-01-07 09:29:29 -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. |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -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. |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -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" |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 16 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 17 | #import "NSString+StdString.h" |
| 18 | #import "RTCMediaConstraints+Private.h" |
| 19 | #import "WebRTC/RTCMediaConstraints.h" |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 20 | |
| 21 | @interface RTCMediaConstraintsTest : NSObject |
| 22 | - (void)testMediaConstraints; |
| 23 | @end |
| 24 | |
| 25 | @implementation RTCMediaConstraintsTest |
| 26 | |
| 27 | - (void)testMediaConstraints { |
| 28 | NSDictionary *mandatory = @{@"key1": @"value1", @"key2": @"value2"}; |
| 29 | NSDictionary *optional = @{@"key3": @"value3", @"key4": @"value4"}; |
| 30 | |
| 31 | RTCMediaConstraints *constraints = [[RTCMediaConstraints alloc] |
| 32 | initWithMandatoryConstraints:mandatory |
| 33 | optionalConstraints:optional]; |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 34 | std::unique_ptr<webrtc::MediaConstraints> nativeConstraints = |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 35 | [constraints nativeConstraints]; |
| 36 | |
| 37 | webrtc::MediaConstraintsInterface::Constraints nativeMandatory = |
| 38 | nativeConstraints->GetMandatory(); |
| 39 | [self expectConstraints:mandatory inNativeConstraints:nativeMandatory]; |
| 40 | |
| 41 | webrtc::MediaConstraintsInterface::Constraints nativeOptional = |
| 42 | nativeConstraints->GetOptional(); |
| 43 | [self expectConstraints:optional inNativeConstraints:nativeOptional]; |
| 44 | } |
| 45 | |
| 46 | - (void)expectConstraints:(NSDictionary *)constraints |
| 47 | inNativeConstraints: |
| 48 | (webrtc::MediaConstraintsInterface::Constraints)nativeConstraints { |
| 49 | EXPECT_EQ(constraints.count, nativeConstraints.size()); |
| 50 | |
| 51 | for (NSString *key in constraints) { |
hjon | 6b03995 | 2016-02-25 12:32:58 -0800 | [diff] [blame] | 52 | NSString *value = [constraints objectForKey:key]; |
hjon | 6f5ca08 | 2016-01-07 09:29:29 -0800 | [diff] [blame] | 53 | |
| 54 | std::string nativeValue; |
| 55 | bool found = nativeConstraints.FindFirst(key.stdString, &nativeValue); |
| 56 | EXPECT_TRUE(found); |
| 57 | EXPECT_EQ(value.stdString, nativeValue); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | @end |
| 62 | |
| 63 | TEST(RTCMediaConstraintsTest, MediaConstraintsTest) { |
| 64 | @autoreleasepool { |
| 65 | RTCMediaConstraintsTest *test = [[RTCMediaConstraintsTest alloc] init]; |
| 66 | [test testMediaConstraints]; |
| 67 | } |
| 68 | } |