feat: add PlayMode enum (single=0, loop=1)
This commit is contained in:
10
Sources/DuooomiBleSDK/Models/PlayMode.swift
Normal file
10
Sources/DuooomiBleSDK/Models/PlayMode.swift
Normal file
@@ -0,0 +1,10 @@
|
||||
import Foundation
|
||||
|
||||
/// 播放模式(设备端协议字段 `loop`)。
|
||||
///
|
||||
/// - `single` (0): 单播 —— 设备播完一次后停止
|
||||
/// - `loop` (1): 循环播放 —— 设备循环播放当前内容
|
||||
public enum PlayMode: Int, Codable, Equatable {
|
||||
case single = 0
|
||||
case loop = 1
|
||||
}
|
||||
22
Tests/DuooomiBleSDKTests/PlayModeTests.swift
Normal file
22
Tests/DuooomiBleSDKTests/PlayModeTests.swift
Normal file
@@ -0,0 +1,22 @@
|
||||
import XCTest
|
||||
@testable import DuooomiBleSDK
|
||||
|
||||
final class PlayModeTests: XCTestCase {
|
||||
func testRawValues() {
|
||||
XCTAssertEqual(PlayMode.single.rawValue, 0)
|
||||
XCTAssertEqual(PlayMode.loop.rawValue, 1)
|
||||
}
|
||||
|
||||
func testInitFromRawValue() {
|
||||
XCTAssertEqual(PlayMode(rawValue: 0), .single)
|
||||
XCTAssertEqual(PlayMode(rawValue: 1), .loop)
|
||||
XCTAssertNil(PlayMode(rawValue: 2))
|
||||
}
|
||||
|
||||
func testCodableRoundTrip() throws {
|
||||
let data = try JSONEncoder().encode(PlayMode.loop)
|
||||
XCTAssertEqual(String(data: data, encoding: .utf8), "1")
|
||||
let decoded = try JSONDecoder().decode(PlayMode.self, from: Data("0".utf8))
|
||||
XCTAssertEqual(decoded, .single)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user