blob: 4d5e450fffb892122861a69099a2129144c80307 [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
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020017#import "api/peerconnection/RTCMediaConstraints+Private.h"
18#import "api/peerconnection/RTCMediaConstraints.h"
19#import "helpers/NSString+StdString.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
Niels Möllerdac03d92019-02-13 08:52:27 +010037 webrtc::MediaConstraints::Constraints nativeMandatory = nativeConstraints->GetMandatory();
hjon6f5ca082016-01-07 09:29:29 -080038 [self expectConstraints:mandatory inNativeConstraints:nativeMandatory];
39
Niels Möllerdac03d92019-02-13 08:52:27 +010040 webrtc::MediaConstraints::Constraints nativeOptional = nativeConstraints->GetOptional();
hjon6f5ca082016-01-07 09:29:29 -080041 [self expectConstraints:optional inNativeConstraints:nativeOptional];
42}
43
44- (void)expectConstraints:(NSDictionary *)constraints
Niels Möllerdac03d92019-02-13 08:52:27 +010045 inNativeConstraints:(webrtc::MediaConstraints::Constraints)nativeConstraints {
hjon6f5ca082016-01-07 09:29:29 -080046 EXPECT_EQ(constraints.count, nativeConstraints.size());
47
48 for (NSString *key in constraints) {
hjon6b039952016-02-25 12:32:58 -080049 NSString *value = [constraints objectForKey:key];
hjon6f5ca082016-01-07 09:29:29 -080050
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
60TEST(RTCMediaConstraintsTest, MediaConstraintsTest) {
61 @autoreleasepool {
62 RTCMediaConstraintsTest *test = [[RTCMediaConstraintsTest alloc] init];
63 [test testMediaConstraints];
64 }
65}