VLCLibraryTest.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*****************************************************************************
  2. * VLCLibraryTest.swift
  3. *****************************************************************************
  4. * Copyright (C) 2018 VLC authors and VideoLAN
  5. * $Id$
  6. *
  7. * Authors: Mike JS. Choi <mkchoi212 # icloud.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this program; if not, write to the Free Software Foundation,
  21. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22. *****************************************************************************/
  23. import XCTest
  24. class VLCLibraryTest: XCTestCase {
  25. let paramKey = "VLCParams"
  26. override func setUp() {
  27. super.setUp()
  28. UserDefaults.standard.removeObject(forKey: paramKey)
  29. }
  30. func testSharedLibrary() {
  31. XCTAssertNotNil(VLCLibrary.shared())
  32. XCTAssertNotNil(VLCLibrary.shared().instance)
  33. }
  34. func testInitWithOptions() throws {
  35. let customLibrary1 = try XCTAssertNotNilAndUnwrap(VLCLibrary(options: ["--verbose=1", "--avi-index=1"]))
  36. assertDefaultParameters()
  37. XCTAssertNotNil(customLibrary1.instance)
  38. UserDefaults.standard.removeObject(forKey: paramKey)
  39. let customLibrary2 = try XCTAssertNotNilAndUnwrap(VLCLibrary(options: []))
  40. assertDefaultParameters()
  41. XCTAssertNotNil(customLibrary2.instance)
  42. }
  43. func testInit() {
  44. let library = VLCLibrary()
  45. XCTAssertNotNil(library.instance)
  46. assertDefaultParameters()
  47. }
  48. func testDebugLoggingLevel() throws {
  49. let library = try XCTAssertNotNilAndUnwrap(VLCLibrary.shared())
  50. XCTAssertEqual(library.debugLoggingLevel, 0)
  51. let tests: [(input: Int32, expected: Int32)] = [
  52. (0, 0),
  53. (3, 3),
  54. (4, 4),
  55. (100, 0),
  56. (-10, 0)
  57. ]
  58. for (input, expected) in tests {
  59. library.debugLoggingLevel = input
  60. XCTAssertEqual(library.debugLoggingLevel, expected)
  61. }
  62. }
  63. func testDebugLogging() throws {
  64. let library = try XCTAssertNotNilAndUnwrap(VLCLibrary.shared())
  65. XCTAssertFalse(library.debugLogging)
  66. library.debugLogging = true
  67. XCTAssertTrue(library.debugLogging)
  68. library.debugLogging = false
  69. XCTAssertFalse(library.debugLogging)
  70. }
  71. func testLibraryDescription() throws {
  72. let library = try XCTAssertNotNilAndUnwrap(VLCLibrary.shared())
  73. let warn: (String) -> (String) = { desirable in
  74. return "Should hold a string of form \"\(desirable)\""
  75. }
  76. XCTAssertFalse(library.version.isEmpty, warn("3.0.4 Vetinari"))
  77. XCTAssertFalse(library.compiler.isEmpty, warn("InstalledDir: /Applications/Xcode.app/..."))
  78. XCTAssertFalse(library.changeset.isEmpty, warn("3.0.3-1-108-g7039639e6b"))
  79. }
  80. }
  81. extension VLCLibraryTest {
  82. func assertDefaultParameters() {
  83. let expected = [
  84. "--play-and-pause",
  85. "--no-color",
  86. "--no-video-title-show",
  87. "--verbose=4",
  88. "--no-sout-keep",
  89. "--vout=macosx",
  90. "--text-renderer=freetype",
  91. "--extraintf=macosx_dialog_provider",
  92. "--audio-resampler=soxr"
  93. ]
  94. let defaultParams = UserDefaults.standard.object(forKey: paramKey)
  95. #if os(macOS)
  96. XCTAssertEqual(defaultParams as? [String], expected)
  97. #else
  98. XCTAssertNil(defaultParams)
  99. #endif
  100. }
  101. }