// // PlayerTests.swift // // Copyright 2026 Brendan Szymanski // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 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 General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // SPDX-License-Identifier: GPL-3.0-or-later // // // NOTE: Requires Testing or XCTest framework which is not available in the // current CLI-only Swift 6.4 beta toolchain. These tests compile and run // inside Xcode or with a full macOS SDK that includes the Testing framework. // See WidgetTests.swift for the same constraint. // import Foundation @testable import LuminateCore // MARK: - PlayerState Tests func testPlayerStateHashable() { let url = URL(string: "https://example.com/stream")! let a = PlayerState( itemId: "item1", mediaSourceId: "ms1", playSessionId: "ps1", streamURL: url, serverBase: "https://example.com" ) let b = PlayerState( itemId: "item1", mediaSourceId: "ms1", playSessionId: "ps1", streamURL: url, serverBase: "https://example.com" ) assert(a == b, "Equal instances should be equal") assert(a.hashValue == b.hashValue, "Equal instances should have equal hashes") let c = PlayerState( itemId: "item2", mediaSourceId: "ms1", playSessionId: "ps1", streamURL: url, serverBase: "https://example.com" ) assert(a != c, "Different instances should not be equal") } // MARK: - Tick Conversion Tests func testTickConversion() { let seconds: Double = 65.5 let ticks = Int64(seconds * 10_000_000) assert(ticks == 655_000_000, "65.5s should be 655,000,000 ticks") let back = Double(ticks) / 10_000_000 assert(abs(back - seconds) < 0.001, "Round-trip should match within tolerance") } // MARK: - Time Formatting Tests func testTimeFormatting() { let formatTime: (Double) -> String = { seconds in guard seconds.isFinite, seconds >= 0 else { return "0:00" } let h = Int(seconds) / 3600 let m = (Int(seconds) / 60) % 60 let s = Int(seconds) % 60 if h > 0 { return String(format: "%d:%02d:%02d", h, m, s) } return String(format: "%d:%02d", m, s) } assert(formatTime(0) == "0:00") assert(formatTime(65) == "1:05") assert(formatTime(3661) == "1:01:01") assert(formatTime(-1) == "0:00") assert(formatTime(Double.infinity) == "0:00") }