2016-11-02 02:56:09 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2016 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
#import <OCMock/OCMock.h>
|
2016-11-09 06:26:18 -08:00
|
|
|
#import "ARDSettingsModel+Private.h"
|
|
|
|
|
#import "ARDSettingsStore.h"
|
2016-11-02 02:56:09 -07:00
|
|
|
#import "WebRTC/RTCMediaConstraints.h"
|
|
|
|
|
#include "webrtc/base/gunit.h"
|
|
|
|
|
|
|
|
|
|
|
2016-11-09 06:26:18 -08:00
|
|
|
@interface ARDSettingsModelTests : NSObject {
|
|
|
|
|
ARDSettingsModel *_model;
|
2016-11-02 02:56:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)testStoringInavlidConstraintReturnsNo;
|
|
|
|
|
- (void)testDefaultMediaFromStore;
|
|
|
|
|
- (void)testWidthConstraintFromStore;
|
|
|
|
|
- (void)testHeightConstraintFromStore;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2016-11-09 06:26:18 -08:00
|
|
|
@implementation ARDSettingsModelTests
|
2016-11-02 02:56:09 -07:00
|
|
|
|
|
|
|
|
- (instancetype)init {
|
|
|
|
|
self = [super init];
|
|
|
|
|
if (self) {
|
2016-11-09 06:26:18 -08:00
|
|
|
_model = [[ARDSettingsModel alloc] init];
|
2016-11-02 02:56:09 -07:00
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id)setupMockStoreWithMediaConstraintString:(NSString *)constraintString {
|
2016-11-09 06:26:18 -08:00
|
|
|
id storeMock = [OCMockObject mockForClass:[ARDSettingsStore class]];
|
2016-11-17 00:43:43 -08:00
|
|
|
[([[storeMock stub] andReturn:constraintString]) videoResolutionConstraints];
|
2016-11-02 02:56:09 -07:00
|
|
|
|
|
|
|
|
id partialMock = [OCMockObject partialMockForObject:_model];
|
|
|
|
|
[[[partialMock stub] andReturn:storeMock] settingsStore];
|
|
|
|
|
|
|
|
|
|
return storeMock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)testDefaultMediaFromStore {
|
|
|
|
|
// given
|
|
|
|
|
id storeMock = [self setupMockStoreWithMediaConstraintString:nil];
|
|
|
|
|
|
2016-11-17 00:43:43 -08:00
|
|
|
[[storeMock expect] setVideoResolutionConstraints:@"640x480"];
|
2016-11-02 02:56:09 -07:00
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
NSString *string = [_model currentVideoResoultionConstraintFromStore];
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
EXPECT_TRUE([string isEqualToString:@"640x480"]);
|
|
|
|
|
[storeMock verify];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)testStoringInavlidConstraintReturnsNo {
|
|
|
|
|
// given
|
|
|
|
|
id storeMock = [self setupMockStoreWithMediaConstraintString:@"960x480"];
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
BOOL result = [_model storeVideoResoultionConstraint:@"960x480"];
|
|
|
|
|
|
|
|
|
|
// then
|
2016-11-15 00:41:26 -08:00
|
|
|
EXPECT_FALSE(result);
|
2016-11-02 02:56:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)testWidthConstraintFromStore {
|
|
|
|
|
// given
|
|
|
|
|
[self setupMockStoreWithMediaConstraintString:@"1270x480"];
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
NSString *width = [_model currentVideoResolutionWidthFromStore];
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
EXPECT_TRUE([width isEqualToString:@"1270"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)testHeightConstraintFromStore {
|
|
|
|
|
// given
|
|
|
|
|
[self setupMockStoreWithMediaConstraintString:@"960x540"];
|
|
|
|
|
// when
|
|
|
|
|
NSString *height = [_model currentVideoResolutionHeightFromStore];
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
EXPECT_TRUE([height isEqualToString:@"540"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)testConstraintComponentIsNilWhenInvalidConstraintString {
|
|
|
|
|
// given
|
|
|
|
|
[self setupMockStoreWithMediaConstraintString:@"invalid"];
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
NSString *width = [_model currentVideoResolutionWidthFromStore];
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
EXPECT_TRUE(width == nil);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)testConstraintsDictionaryIsNilWhenInvalidConstraintString {
|
|
|
|
|
// given
|
|
|
|
|
[self setupMockStoreWithMediaConstraintString:@"invalid"];
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
NSDictionary *constraintsDictionary = [_model currentMediaConstraintFromStoreAsRTCDictionary];
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
EXPECT_TRUE(constraintsDictionary == nil);
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
2016-11-09 06:26:18 -08:00
|
|
|
class ARDSettingsModelTest : public ::testing::Test {
|
2016-11-02 02:56:09 -07:00
|
|
|
protected:
|
2016-11-09 06:26:18 -08:00
|
|
|
ARDSettingsModelTests *test;
|
|
|
|
|
ARDSettingsModelTest() { test = [[ARDSettingsModelTests alloc] init]; }
|
2016-11-02 02:56:09 -07:00
|
|
|
};
|
|
|
|
|
|
2016-11-09 06:26:18 -08:00
|
|
|
TEST_F(ARDSettingsModelTest, DefaultMediaFromStore) {
|
2016-11-02 02:56:09 -07:00
|
|
|
@autoreleasepool {
|
|
|
|
|
[test testDefaultMediaFromStore];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-09 06:26:18 -08:00
|
|
|
TEST_F(ARDSettingsModelTest, StoringInvalidConstraintsReturnsNo) {
|
2016-11-02 02:56:09 -07:00
|
|
|
@autoreleasepool {
|
|
|
|
|
[test testStoringInavlidConstraintReturnsNo];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-09 06:26:18 -08:00
|
|
|
TEST_F(ARDSettingsModelTest, WidthConstraintFromStore) {
|
2016-11-02 02:56:09 -07:00
|
|
|
@autoreleasepool {
|
|
|
|
|
[test testWidthConstraintFromStore];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-09 06:26:18 -08:00
|
|
|
TEST_F(ARDSettingsModelTest, HeightConstraintFromStore) {
|
2016-11-02 02:56:09 -07:00
|
|
|
@autoreleasepool {
|
|
|
|
|
[test testHeightConstraintFromStore];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-09 06:26:18 -08:00
|
|
|
TEST_F(ARDSettingsModelTest, ConstratintIsNil) {
|
2016-11-02 02:56:09 -07:00
|
|
|
@autoreleasepool {
|
|
|
|
|
[test testConstraintComponentIsNilWhenInvalidConstraintString];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-09 06:26:18 -08:00
|
|
|
TEST_F(ARDSettingsModelTest, DictionaryIsNil) {
|
2016-11-02 02:56:09 -07:00
|
|
|
@autoreleasepool {
|
|
|
|
|
[test testConstraintsDictionaryIsNilWhenInvalidConstraintString];
|
|
|
|
|
}
|
|
|
|
|
}
|