VLCAudioTest.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*****************************************************************************
  2. * VLCAudioTest.swift
  3. *****************************************************************************
  4. * Copyright (C) 2018 Mike JS. Choi
  5. * Copyright (C) 2018 VLC authors and VideoLAN
  6. * $Id$
  7. *
  8. * Authors: Mike JS. Choi <mkchoi212 # icloud.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation; either version 2.1 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this program; if not, write to the Free Software Foundation,
  22. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23. *****************************************************************************/
  24. import XCTest
  25. class VLCAudioTest: XCTestCase {
  26. let step = 6
  27. let min: Int32 = 0
  28. let max: Int32 = 200
  29. func testPassThrough() throws {
  30. let player = VLCMediaPlayer()
  31. let audio = try XCTAssertNotNilAndUnwrap(player.audio)
  32. XCTAssertFalse(audio.passthrough)
  33. audio.passthrough = true
  34. XCTAssertTrue(audio.passthrough)
  35. audio.passthrough = false
  36. XCTAssertFalse(audio.passthrough)
  37. }
  38. func testVolumeDown() throws {
  39. let player = VLCMediaPlayer()
  40. let audio = try XCTAssertNotNilAndUnwrap(player.audio)
  41. audio.volume = max
  42. XCTAssertEqual(audio.volume, max)
  43. let tests: [(repeatCount: Int, expected: Int32)] = [
  44. (10, 140),
  45. (5, 110),
  46. (0, 110),
  47. (15, 20),
  48. (100, min)
  49. ]
  50. for (repeatCount, expected) in tests {
  51. (0..<repeatCount).forEach { _ in audio.volumeDown() }
  52. XCTAssertEqual(audio.volume, expected)
  53. }
  54. }
  55. func testVolumeUp() throws {
  56. let player = VLCMediaPlayer()
  57. let audio = try XCTAssertNotNilAndUnwrap(player.audio)
  58. audio.volume = min
  59. XCTAssertEqual(audio.volume, 0)
  60. let tests: [(repeatCount: Int, expected: Int32)] = [
  61. (5, 30),
  62. (10, 90),
  63. (10, 150),
  64. (0, 150),
  65. (100, max)
  66. ]
  67. for (repeatCount, expected) in tests {
  68. (0..<repeatCount).forEach { _ in audio.volumeUp() }
  69. XCTAssertEqual(audio.volume, expected)
  70. }
  71. }
  72. func testSetVolume() throws {
  73. let player = VLCMediaPlayer()
  74. let audio = try XCTAssertNotNilAndUnwrap(player.audio)
  75. let tests: [(target: Int32, expected: Int32)] = [
  76. (min, min),
  77. (min - 100, min),
  78. (50, 50),
  79. (100, 100),
  80. (max, max),
  81. (max + 100, max)
  82. ]
  83. for (target, expected) in tests {
  84. audio.volume = target
  85. XCTAssertEqual(audio.volume, expected)
  86. }
  87. }
  88. }