1/* 2 * Copyright 2016 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 <OCMock/OCMock.h> 13#import <XCTest/XCTest.h> 14 15#import <WebRTC/RTCMediaConstraints.h> 16 17#import "ARDSettingsModel+Private.h" 18#import "ARDSettingsStore.h" 19 20 21@interface ARDSettingsModelTests : XCTestCase { 22 ARDSettingsModel *_model; 23} 24@end 25 26@implementation ARDSettingsModelTests 27 28- (id)setupMockStore { 29 id storeMock = [OCMockObject mockForClass:[ARDSettingsStore class]]; 30 31 id partialMock = [OCMockObject partialMockForObject:_model]; 32 [[[partialMock stub] andReturn:storeMock] settingsStore]; 33 [[[partialMock stub] andReturn:@[ @"640x480", @"960x540", @"1280x720" ]] 34 availableVideoResolutions]; 35 36 return storeMock; 37} 38 39- (void)setUp { 40 _model = [[ARDSettingsModel alloc] init]; 41} 42 43- (void)testRetrievingSetting { 44 id storeMock = [self setupMockStore]; 45 [[[storeMock expect] andReturn:@"640x480"] videoResolution]; 46 NSString *string = [_model currentVideoResolutionSettingFromStore]; 47 48 XCTAssertEqualObjects(string, @"640x480"); 49} 50 51- (void)testStoringInvalidConstraintReturnsNo { 52 id storeMock = [self setupMockStore]; 53 [([[storeMock stub] andReturn:@"960x480"])videoResolution]; 54 XCTAssertFalse([_model storeVideoResolutionSetting:@"960x480"]); 55} 56 57- (void)testWidthConstraintFromStore { 58 id storeMock = [self setupMockStore]; 59 [([[storeMock stub] andReturn:@"1270x480"])videoResolution]; 60 int width = [_model currentVideoResolutionWidthFromStore]; 61 62 XCTAssertEqual(width, 1270); 63} 64 65- (void)testHeightConstraintFromStore { 66 id storeMock = [self setupMockStore]; 67 [([[storeMock stub] andReturn:@"960x540"])videoResolution]; 68 int height = [_model currentVideoResolutionHeightFromStore]; 69 70 XCTAssertEqual(height, 540); 71} 72 73- (void)testConstraintComponentIsNilWhenInvalidConstraintString { 74 id storeMock = [self setupMockStore]; 75 [([[storeMock stub] andReturn:@"invalid"])videoResolution]; 76 int width = [_model currentVideoResolutionWidthFromStore]; 77 78 XCTAssertEqual(width, 0); 79} 80 81- (void)testStoringAudioSetting { 82 id storeMock = [self setupMockStore]; 83 [[storeMock expect] setAudioOnly:YES]; 84 85 [_model storeAudioOnlySetting:YES]; 86 [storeMock verify]; 87} 88 89- (void)testReturningDefaultCallOption { 90 id storeMock = [self setupMockStore]; 91 [[[storeMock stub] andReturnValue:@YES] useManualAudioConfig]; 92 93 XCTAssertTrue([_model currentUseManualAudioConfigSettingFromStore]); 94} 95 96@end 97