blob: 5f9026c29de4ef1bf1af6b249e14472ed7922965 [file] [log] [blame]
hjon6f5ca082016-01-07 09:29:29 -08001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
hjon6f5ca082016-01-07 09:29:29 -08003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
hjon6f5ca082016-01-07 09:29:29 -08009 */
10
11#import <Foundation/Foundation.h>
12
kwibergbfefb032016-05-01 14:53:46 -070013#include <memory>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/gunit.h"
hjon6f5ca082016-01-07 09:29:29 -080016
tkchin9eeb6242016-04-27 01:54:20 -070017#import "NSString+StdString.h"
18#import "RTCMediaConstraints+Private.h"
19#import "WebRTC/RTCMediaConstraints.h"
hjon6f5ca082016-01-07 09:29:29 -080020
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];
kwibergbfefb032016-05-01 14:53:46 -070034 std::unique_ptr<webrtc::MediaConstraints> nativeConstraints =
hjon6f5ca082016-01-07 09:29:29 -080035 [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) {
hjon6b039952016-02-25 12:32:58 -080052 NSString *value = [constraints objectForKey:key];
hjon6f5ca082016-01-07 09:29:29 -080053
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
63TEST(RTCMediaConstraintsTest, MediaConstraintsTest) {
64 @autoreleasepool {
65 RTCMediaConstraintsTest *test = [[RTCMediaConstraintsTest alloc] init];
66 [test testMediaConstraints];
67 }
68}