1/* 2 * Copyright 2015 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#include <memory> 15 16#include "rtc_base/gunit.h" 17 18#import "api/peerconnection/RTCMediaConstraints+Private.h" 19#import "api/peerconnection/RTCMediaConstraints.h" 20#import "helpers/NSString+StdString.h" 21 22@interface RTCMediaConstraintsTests : XCTestCase 23@end 24 25@implementation RTCMediaConstraintsTests 26 27- (void)testMediaConstraints { 28 NSDictionary *mandatory = @{@"key1": @"value1", @"key2": @"value2"}; 29 NSDictionary *optional = @{@"key3": @"value3", @"key4": @"value4"}; 30 31 RTC_OBJC_TYPE(RTCMediaConstraints) *constraints = 32 [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:mandatory 33 optionalConstraints:optional]; 34 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints = 35 [constraints nativeConstraints]; 36 37 webrtc::MediaConstraints::Constraints nativeMandatory = nativeConstraints->GetMandatory(); 38 [self expectConstraints:mandatory inNativeConstraints:nativeMandatory]; 39 40 webrtc::MediaConstraints::Constraints nativeOptional = nativeConstraints->GetOptional(); 41 [self expectConstraints:optional inNativeConstraints:nativeOptional]; 42} 43 44- (void)expectConstraints:(NSDictionary *)constraints 45 inNativeConstraints:(webrtc::MediaConstraints::Constraints)nativeConstraints { 46 EXPECT_EQ(constraints.count, nativeConstraints.size()); 47 48 for (NSString *key in constraints) { 49 NSString *value = [constraints objectForKey:key]; 50 51 std::string nativeValue; 52 bool found = nativeConstraints.FindFirst(key.stdString, &nativeValue); 53 EXPECT_TRUE(found); 54 EXPECT_EQ(value.stdString, nativeValue); 55 } 56} 57 58@end 59