New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests: VLCAudio #24
Tests: VLCAudio #24
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,17 +122,13 @@ - (void)volumeUp | |
int tempVolume = [self volume] + VOLUME_STEP; | ||
if (tempVolume > VOLUME_MAX) | ||
tempVolume = VOLUME_MAX; | ||
else if (tempVolume < VOLUME_MIN) | ||
tempVolume = VOLUME_MIN; | ||
[self setVolume: tempVolume]; | ||
} | ||
|
||
- (void)volumeDown | ||
{ | ||
int tempVolume = [self volume] - VOLUME_STEP; | ||
if (tempVolume > VOLUME_MAX) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This predicate will never execute as |
||
tempVolume = VOLUME_MAX; | ||
else if (tempVolume < VOLUME_MIN) | ||
if (tempVolume < VOLUME_MIN) | ||
tempVolume = VOLUME_MIN; | ||
[self setVolume: tempVolume]; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/***************************************************************************** | ||
* XCTestHelper.swift | ||
***************************************************************************** | ||
* Copyright (C) 2018 Mike JS. Choi | ||
* Copyright (C) 2018 VLC authors and VideoLAN | ||
* $Id$ | ||
* | ||
* Authors: Mike JS. Choi <mkchoi212 # icloud.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2.1 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. | ||
*****************************************************************************/ | ||
|
||
|
||
import XCTest | ||
|
||
struct UnexpectedNilError: Error {} | ||
|
||
func XCTAssertNotNilAndUnwrap<T>(_ variable: T?, message: String = "Unexpected nil variable", file: StaticString = #file, line: UInt = #line) throws -> T { | ||
guard let variable = variable else { | ||
XCTFail(message, file: file, line: line) | ||
throw UnexpectedNilError() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to throw here since this is just a test ? |
||
} | ||
return variable | ||
} | ||
|
||
let STANDARD_TIME_OUT = 5.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/***************************************************************************** | ||
* VLCAudioTest.swift | ||
***************************************************************************** | ||
* Copyright (C) 2018 Mike JS. Choi | ||
* Copyright (C) 2018 VLC authors and VideoLAN | ||
* $Id$ | ||
* | ||
* Authors: Mike JS. Choi <mkchoi212 # icloud.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2.1 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. | ||
*****************************************************************************/ | ||
|
||
import XCTest | ||
|
||
class VLCAudioTest: XCTestCase { | ||
|
||
let step = 6 | ||
let min: Int32 = 0 | ||
let max: Int32 = 200 | ||
|
||
func testPassThrough() throws { | ||
let player = VLCMediaPlayer() | ||
let audio = try XCTAssertNotNilAndUnwrap(player.audio) | ||
|
||
XCTAssertFalse(audio.passthrough) | ||
|
||
audio.passthrough = true | ||
XCTAssertTrue(audio.passthrough) | ||
|
||
audio.passthrough = false | ||
XCTAssertFalse(audio.passthrough) | ||
} | ||
|
||
func testVolumeDown() throws { | ||
let player = VLCMediaPlayer() | ||
let audio = try XCTAssertNotNilAndUnwrap(player.audio) | ||
|
||
audio.volume = max | ||
XCTAssertEqual(audio.volume, max) | ||
|
||
let tests: [(repeatCount: Int, expected: Int32)] = [ | ||
(10, 140), | ||
(5, 110), | ||
(0, 110), | ||
(15, 20), | ||
(100, min) | ||
] | ||
|
||
for (repeatCount, expected) in tests { | ||
(0..<repeatCount).forEach { _ in audio.volumeDown() } | ||
XCTAssertEqual(audio.volume, expected) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just see this now but I think it might make sense to split setting volume and volumedown. Because right now you rely on audio.volume = Int32(9000) to cap and work so that the next tests succeed. They should be independent. |
||
} | ||
} | ||
|
||
func testVolumeUp() throws { | ||
let player = VLCMediaPlayer() | ||
let audio = try XCTAssertNotNilAndUnwrap(player.audio) | ||
|
||
audio.volume = min | ||
XCTAssertEqual(audio.volume, 0) | ||
|
||
let tests: [(repeatCount: Int, expected: Int32)] = [ | ||
(5, 30), | ||
(10, 90), | ||
(10, 150), | ||
(0, 150), | ||
(100, max) | ||
] | ||
|
||
for (repeatCount, expected) in tests { | ||
(0..<repeatCount).forEach { _ in audio.volumeUp() } | ||
XCTAssertEqual(audio.volume, expected) | ||
} | ||
} | ||
|
||
func testSetVolume() throws { | ||
let player = VLCMediaPlayer() | ||
let audio = try XCTAssertNotNilAndUnwrap(player.audio) | ||
|
||
let tests: [(target: Int32, expected: Int32)] = [ | ||
(min, min), | ||
(min - 100, min), | ||
(50, 50), | ||
(100, 100), | ||
(max, max), | ||
(max + 100, max) | ||
] | ||
|
||
for (target, expected) in tests { | ||
audio.volume = target | ||
XCTAssertEqual(audio.volume, expected) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This predicate is also impossible as
setVolume
already checks this