1*d9f75844SAndroid Build Coastguard Worker/* 2*d9f75844SAndroid Build Coastguard Worker * Copyright 2015 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker#import <Foundation/Foundation.h> 12*d9f75844SAndroid Build Coastguard Worker#import <XCTest/XCTest.h> 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker#include <memory> 15*d9f75844SAndroid Build Coastguard Worker 16*d9f75844SAndroid Build Coastguard Worker#include "rtc_base/gunit.h" 17*d9f75844SAndroid Build Coastguard Worker 18*d9f75844SAndroid Build Coastguard Worker#import "api/peerconnection/RTCMediaConstraints+Private.h" 19*d9f75844SAndroid Build Coastguard Worker#import "api/peerconnection/RTCMediaConstraints.h" 20*d9f75844SAndroid Build Coastguard Worker#import "helpers/NSString+StdString.h" 21*d9f75844SAndroid Build Coastguard Worker 22*d9f75844SAndroid Build Coastguard Worker@interface RTCMediaConstraintsTests : XCTestCase 23*d9f75844SAndroid Build Coastguard Worker@end 24*d9f75844SAndroid Build Coastguard Worker 25*d9f75844SAndroid Build Coastguard Worker@implementation RTCMediaConstraintsTests 26*d9f75844SAndroid Build Coastguard Worker 27*d9f75844SAndroid Build Coastguard Worker- (void)testMediaConstraints { 28*d9f75844SAndroid Build Coastguard Worker NSDictionary *mandatory = @{@"key1": @"value1", @"key2": @"value2"}; 29*d9f75844SAndroid Build Coastguard Worker NSDictionary *optional = @{@"key3": @"value3", @"key4": @"value4"}; 30*d9f75844SAndroid Build Coastguard Worker 31*d9f75844SAndroid Build Coastguard Worker RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = 32*d9f75844SAndroid Build Coastguard Worker [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:mandatory 33*d9f75844SAndroid Build Coastguard Worker optionalConstraints:optional]; 34*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<webrtc::MediaConstraints> nativeConstraints = 35*d9f75844SAndroid Build Coastguard Worker [constraints nativeConstraints]; 36*d9f75844SAndroid Build Coastguard Worker 37*d9f75844SAndroid Build Coastguard Worker webrtc::MediaConstraints::Constraints nativeMandatory = nativeConstraints->GetMandatory(); 38*d9f75844SAndroid Build Coastguard Worker [self expectConstraints:mandatory inNativeConstraints:nativeMandatory]; 39*d9f75844SAndroid Build Coastguard Worker 40*d9f75844SAndroid Build Coastguard Worker webrtc::MediaConstraints::Constraints nativeOptional = nativeConstraints->GetOptional(); 41*d9f75844SAndroid Build Coastguard Worker [self expectConstraints:optional inNativeConstraints:nativeOptional]; 42*d9f75844SAndroid Build Coastguard Worker} 43*d9f75844SAndroid Build Coastguard Worker 44*d9f75844SAndroid Build Coastguard Worker- (void)expectConstraints:(NSDictionary *)constraints 45*d9f75844SAndroid Build Coastguard Worker inNativeConstraints:(webrtc::MediaConstraints::Constraints)nativeConstraints { 46*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(constraints.count, nativeConstraints.size()); 47*d9f75844SAndroid Build Coastguard Worker 48*d9f75844SAndroid Build Coastguard Worker for (NSString *key in constraints) { 49*d9f75844SAndroid Build Coastguard Worker NSString *value = [constraints objectForKey:key]; 50*d9f75844SAndroid Build Coastguard Worker 51*d9f75844SAndroid Build Coastguard Worker std::string nativeValue; 52*d9f75844SAndroid Build Coastguard Worker bool found = nativeConstraints.FindFirst(key.stdString, &nativeValue); 53*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(found); 54*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(value.stdString, nativeValue); 55*d9f75844SAndroid Build Coastguard Worker } 56*d9f75844SAndroid Build Coastguard Worker} 57*d9f75844SAndroid Build Coastguard Worker 58*d9f75844SAndroid Build Coastguard Worker@end 59