Skip to content
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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions MobileVLCKit.xcodeproj/project.pbxproj
Expand Up @@ -179,6 +179,8 @@
8D826AE1203F3CC500536EF7 /* VLCRendererDiscoverer.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 8D2CE647203DCC48004BB7F6 /* VLCRendererDiscoverer.h */; };
8D826AE2203F3CC500536EF7 /* VLCRendererItem.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 8D2CE64E203EEA47004BB7F6 /* VLCRendererItem.h */; };
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
CA7BC89120F4419E00C86820 /* XCTestHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA7BC88720F4418000C86820 /* XCTestHelper.swift */; };
CA7BC89520F441B500C86820 /* XCTestHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA7BC88720F4418000C86820 /* XCTestHelper.swift */; };
CAA03D0C20C8DCDB001764DA /* libTVVLCKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D1329591BA304D900BE647E /* libTVVLCKit.a */; };
CAA03D1720C8DE4D001764DA /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CAA03D1620C8DE4D001764DA /* libbz2.tbd */; };
CAA03D1920C8DE51001764DA /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CAA03D1820C8DE51001764DA /* libz.tbd */; };
Expand All @@ -192,6 +194,8 @@
CAA9F00420D254AC00CDBB2C /* VLCTimeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAA9F00120D254A600CDBB2C /* VLCTimeTest.swift */; };
CABF4D4120D8DBA900FCCE29 /* VLCMediaTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABF4D4020D8DBA900FCCE29 /* VLCMediaTest.swift */; };
CABF4D4220D8DBA900FCCE29 /* VLCMediaTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABF4D4020D8DBA900FCCE29 /* VLCMediaTest.swift */; };
CABCBAE220EB0B080040E2F5 /* VLCAudioTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABCBADD20EB0B080040E2F5 /* VLCAudioTest.swift */; };
CABCBAE320EB0B080040E2F5 /* VLCAudioTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABCBADD20EB0B080040E2F5 /* VLCAudioTest.swift */; };
CABF4D4520D8DCDD00FCCE29 /* libMobileVLCKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D2AAC07E0554694100DB518D /* libMobileVLCKit.a */; };
CABF4D4620D8DD1B00FCCE29 /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D797FC31DF41F9100AD93ED /* libc++.tbd */; };
CABF4D4720D8DD2000FCCE29 /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D24C2B51EC0A3390047E700 /* libbz2.tbd */; };
Expand Down Expand Up @@ -422,6 +426,7 @@
CA0301CB20ADFD2500452BB8 /* MobileVLCKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MobileVLCKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
CA0301CF20ADFD2500452BB8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CA08590420F7184A00B3AB69 /* macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = macros.h; path = Headers/Internal/macros.h; sourceTree = "<group>"; };
CA7BC88720F4418000C86820 /* XCTestHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCTestHelper.swift; sourceTree = "<group>"; };
CA978D1E20B89F4B00F7E768 /* MobileVLCKitTests-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MobileVLCKitTests-Bridging-Header.h"; sourceTree = "<group>"; };
CAA03D0720C8DCDA001764DA /* TVVLCKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TVVLCKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
CAA03D1620C8DE4D001764DA /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS11.4.sdk/usr/lib/libbz2.tbd; sourceTree = DEVELOPER_DIR; };
Expand All @@ -436,6 +441,7 @@
CAA9EFFF20D2549300CDBB2C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CAA9F00120D254A600CDBB2C /* VLCTimeTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VLCTimeTest.swift; sourceTree = "<group>"; };
CABF4D4020D8DBA900FCCE29 /* VLCMediaTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VLCMediaTest.swift; sourceTree = "<group>"; };
CABCBADD20EB0B080040E2F5 /* VLCAudioTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VLCAudioTest.swift; sourceTree = "<group>"; };
D2AAC07E0554694100DB518D /* libMobileVLCKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMobileVLCKit.a; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -786,9 +792,18 @@
path = MobileVLCKitTests;
sourceTree = "<group>";
};
CA7BC88520F4418000C86820 /* Helper */ = {
isa = PBXGroup;
children = (
CA7BC88720F4418000C86820 /* XCTestHelper.swift */,
);
path = Helper;
sourceTree = "<group>";
};
CAA9EFFC20D2546000CDBB2C /* Tests */ = {
isa = PBXGroup;
children = (
CA7BC88520F4418000C86820 /* Helper */,
CAA9F00020D254A600CDBB2C /* Sources */,
CAA9EFFD20D2549300CDBB2C /* TVVLCKitTests */,
CA0301CC20ADFD2500452BB8 /* MobileVLCKitTests */,
Expand All @@ -808,6 +823,7 @@
CAA9F00020D254A600CDBB2C /* Sources */ = {
isa = PBXGroup;
children = (
CABCBADD20EB0B080040E2F5 /* VLCAudioTest.swift */,
CAA9F00120D254A600CDBB2C /* VLCTimeTest.swift */,
CABF4D4020D8DBA900FCCE29 /* VLCMediaTest.swift */,
);
Expand Down Expand Up @@ -1171,7 +1187,9 @@
buildActionMask = 2147483647;
files = (
CABF4D4120D8DBA900FCCE29 /* VLCMediaTest.swift in Sources */,
CA7BC89120F4419E00C86820 /* XCTestHelper.swift in Sources */,
CAA9F00320D254AB00CDBB2C /* VLCTimeTest.swift in Sources */,
CABCBAE220EB0B080040E2F5 /* VLCAudioTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -1180,7 +1198,9 @@
buildActionMask = 2147483647;
files = (
CABF4D4220D8DBA900FCCE29 /* VLCMediaTest.swift in Sources */,
CA7BC89520F441B500C86820 /* XCTestHelper.swift in Sources */,
CAA9F00420D254AC00CDBB2C /* VLCTimeTest.swift in Sources */,
CABCBAE320EB0B080040E2F5 /* VLCAudioTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 1 addition & 5 deletions Sources/VLCAudio.m
Expand Up @@ -122,17 +122,13 @@ - (void)volumeUp
int tempVolume = [self volume] + VOLUME_STEP;
if (tempVolume > VOLUME_MAX)
tempVolume = VOLUME_MAX;
else if (tempVolume < VOLUME_MIN)
Copy link
Contributor Author

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

tempVolume = VOLUME_MIN;
[self setVolume: tempVolume];
}

- (void)volumeDown
{
int tempVolume = [self volume] - VOLUME_STEP;
if (tempVolume > VOLUME_MAX)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This predicate will never execute as setVolume performs this check already

tempVolume = VOLUME_MAX;
else if (tempVolume < VOLUME_MIN)
if (tempVolume < VOLUME_MIN)
tempVolume = VOLUME_MIN;
[self setVolume: tempVolume];
}
Expand Down
38 changes: 38 additions & 0 deletions Tests/Helper/XCTestHelper.swift
@@ -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()
Copy link
Member

Choose a reason for hiding this comment

The 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
106 changes: 106 additions & 0 deletions Tests/Sources/VLCAudioTest.swift
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The 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)
}
}
}
16 changes: 16 additions & 0 deletions VLCKit.xcodeproj/project.pbxproj
Expand Up @@ -87,6 +87,8 @@
7DEBDAD9203C561D000A7D2F /* vlc.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = CCEC5B7E114D9BE800D34AAB /* vlc.h */; };
CA23EBC120BDF02700C0D635 /* VLCKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DC28D7F20194117002D05C4 /* VLCKit.framework */; };
CA23EBCC20BDF07700C0D635 /* VLCTimeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA23EBCB20BDF07700C0D635 /* VLCTimeTest.swift */; };
CA766ED620E9E53E009B3F3F /* VLCAudioTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA766ED520E9E53E009B3F3F /* VLCAudioTest.swift */; };
CA7BC8B720F4424100C86820 /* XCTestHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA7BC8B020F4424100C86820 /* XCTestHelper.swift */; };
CABF4D5420D8E31700FCCE29 /* VLCMediaTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABF4D5320D8E31700FCCE29 /* VLCMediaTest.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -191,6 +193,8 @@
CA23EBC020BDF02700C0D635 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CA23EBCA20BDF07700C0D635 /* VLCKitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "VLCKitTests-Bridging-Header.h"; sourceTree = "<group>"; };
CA23EBCB20BDF07700C0D635 /* VLCTimeTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VLCTimeTest.swift; sourceTree = "<group>"; };
CA766ED520E9E53E009B3F3F /* VLCAudioTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VLCAudioTest.swift; sourceTree = "<group>"; };
CA7BC8B020F4424100C86820 /* XCTestHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCTestHelper.swift; sourceTree = "<group>"; };
CABF4D5320D8E31700FCCE29 /* VLCMediaTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VLCMediaTest.swift; sourceTree = "<group>"; };
CCEC5B73114D9BE800D34AAB /* deprecated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = deprecated.h; path = libvlc/vlc/include/vlc/deprecated.h; sourceTree = SOURCE_ROOT; };
CCEC5B74114D9BE800D34AAB /* libvlc_events.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = libvlc_events.h; path = libvlc/vlc/include/vlc/libvlc_events.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -435,6 +439,7 @@
CA0B184920BDEFB0001CA52B /* Tests */ = {
isa = PBXGroup;
children = (
CA7BC8AE20F4424100C86820 /* Helper */,
CA23EBC720BDF03400C0D635 /* Sources */,
CA23EBBD20BDF02700C0D635 /* VLCKitTests */,
);
Expand All @@ -454,11 +459,20 @@
isa = PBXGroup;
children = (
CABF4D5320D8E31700FCCE29 /* VLCMediaTest.swift */,
CA766ED520E9E53E009B3F3F /* VLCAudioTest.swift */,
CA23EBCB20BDF07700C0D635 /* VLCTimeTest.swift */,
);
path = Sources;
sourceTree = "<group>";
};
CA7BC8AE20F4424100C86820 /* Helper */ = {
isa = PBXGroup;
children = (
CA7BC8B020F4424100C86820 /* XCTestHelper.swift */,
);
path = Helper;
sourceTree = "<group>";
};
CCEC5B6C114D9BD300D34AAB /* libvlc */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -717,6 +731,8 @@
files = (
CABF4D5420D8E31700FCCE29 /* VLCMediaTest.swift in Sources */,
CA23EBCC20BDF07700C0D635 /* VLCTimeTest.swift in Sources */,
CA766ED620E9E53E009B3F3F /* VLCAudioTest.swift in Sources */,
CA7BC8B720F4424100C86820 /* XCTestHelper.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down