diff --git a/.swiftlint.yml b/.swiftlint.yml index c3b611bf8..601e04651 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -13,7 +13,6 @@ analyzer_rules: excluded: - Carthage - Pods - - Tests - Vendor - .build opt_in_rules: diff --git a/Tests/CMAudioSampleBufferFactory.swift b/Tests/CMAudioSampleBufferFactory.swift index cdd249c9b..896ca249c 100644 --- a/Tests/CMAudioSampleBufferFactory.swift +++ b/Tests/CMAudioSampleBufferFactory.swift @@ -14,7 +14,7 @@ enum CMAudioSampleBufferFactory { mBitsPerChannel: 16, mReserved: 0 ) - var formatDescription: CMAudioFormatDescription? = nil + var formatDescription: CMAudioFormatDescription? var status: OSStatus = noErr var blockBuffer: CMBlockBuffer? let blockSize = numSamples * Int(asbd.mBytesPerPacket) diff --git a/Tests/CMVideoSampleBufferFactory.swift b/Tests/CMVideoSampleBufferFactory.swift index 4be591f7e..bd2008ea9 100644 --- a/Tests/CMVideoSampleBufferFactory.swift +++ b/Tests/CMVideoSampleBufferFactory.swift @@ -1,5 +1,5 @@ -import Foundation import AVFoundation +import Foundation enum CMVideoSampleBufferFactory { static func makeSampleBuffer(width: Int, height: Int) -> CMSampleBuffer? { diff --git a/Tests/Codec/AudioCodecTests.swift b/Tests/Codec/AudioCodecTests.swift index 1a2f198d0..89bf06629 100644 --- a/Tests/Codec/AudioCodecTests.swift +++ b/Tests/Codec/AudioCodecTests.swift @@ -1,6 +1,6 @@ +import AVFoundation import Foundation import Testing -import AVFoundation @testable import HaishinKit @@ -94,4 +94,3 @@ import AVFoundation } } } - diff --git a/Tests/Extension/CMSampleBuffer+ExtensionTests.swift b/Tests/Extension/CMSampleBuffer+ExtensionTests.swift index 26694db9c..2839f7d4a 100644 --- a/Tests/Extension/CMSampleBuffer+ExtensionTests.swift +++ b/Tests/Extension/CMSampleBuffer+ExtensionTests.swift @@ -1,6 +1,6 @@ +import CoreMedia import Foundation import Testing -import CoreMedia @testable import HaishinKit diff --git a/Tests/Extension/ExpressibleByIntegerLiteral+ExtensionTests.swift b/Tests/Extension/ExpressibleByIntegerLiteral+ExtensionTests.swift index df5184861..8bb5bcc43 100644 --- a/Tests/Extension/ExpressibleByIntegerLiteral+ExtensionTests.swift +++ b/Tests/Extension/ExpressibleByIntegerLiteral+ExtensionTests.swift @@ -15,11 +15,11 @@ import Testing #expect(UInt32(32).bigEndian.data == Data([0, 0, 0, 32])) #expect(UInt32.max.bigEndian.data == Data([255, 255, 255, 255])) } - + @Test func int64() { #expect(Int64.min.bigEndian.data == Data([128, 0, 0, 0, 0, 0, 0, 0])) #expect(Int64(32).bigEndian.data == Data([0, 0, 0, 0, 0, 0, 0, 32])) - #expect(Int64.max.bigEndian.data == Data([127,255,255, 255, 255, 255, 255, 255])) + #expect(Int64.max.bigEndian.data == Data([127, 255, 255, 255, 255, 255, 255, 255])) } @Test func uInt64() { diff --git a/Tests/HKStream/HKStreamRecorderTests.swift b/Tests/HKStream/HKStreamRecorderTests.swift index 1fd7d4425..9c1f9afb7 100644 --- a/Tests/HKStream/HKStreamRecorderTests.swift +++ b/Tests/HKStream/HKStreamRecorderTests.swift @@ -4,15 +4,15 @@ import Testing @testable import HaishinKit @Suite struct HKStreamRecorderTests { - @Test func startRunning_nil() async { + @Test func startRunning_nil() async throws { let recorder = HKStreamRecorder() - try! await recorder.startRecording(nil) + try await recorder.startRecording(nil) let moviesDirectory = await recorder.moviesDirectory // $moviesDirectory/B644F60F-0959-4F54-9D14-7F9949E02AD8.mp4 #expect(((await recorder.outputURL?.path.contains(moviesDirectory.path())) != nil)) } - @Test func startRunning_fileName() async { + @Test func startRunning_fileName() async throws { let recorder = HKStreamRecorder() try? await recorder.startRecording(URL(string: "dir/sample.mp4")) let moviesDirectory = await recorder.moviesDirectory diff --git a/Tests/ISO/ADTSHeaderTests.swift b/Tests/ISO/ADTSHeaderTests.swift index 16909a221..5554603a4 100644 --- a/Tests/ISO/ADTSHeaderTests.swift +++ b/Tests/ISO/ADTSHeaderTests.swift @@ -6,6 +6,6 @@ import Testing @Suite struct ADTSHeaderTests { @Test func bytes() { let data = Data([255, 241, 77, 128, 112, 127, 252, 1]) - let _ = ADTSHeader(data: data) + _ = ADTSHeader(data: data) } } diff --git a/Tests/ISO/AVCDecoderConfigurationRecordTests.swift b/Tests/ISO/AVCDecoderConfigurationRecordTests.swift index 6b230e7f0..d85fee243 100644 --- a/Tests/ISO/AVCDecoderConfigurationRecordTests.swift +++ b/Tests/ISO/AVCDecoderConfigurationRecordTests.swift @@ -1,5 +1,5 @@ -import Foundation import AVFoundation +import Foundation import Testing @testable import HaishinKit diff --git a/Tests/ISO/ESSpecificDataTests.swift b/Tests/ISO/ESSpecificDataTests.swift index a80ad1f2b..dc9bf05ad 100644 --- a/Tests/ISO/ESSpecificDataTests.swift +++ b/Tests/ISO/ESSpecificDataTests.swift @@ -1,5 +1,5 @@ -import Foundation import CoreMedia +import Foundation import Testing @testable import HaishinKit diff --git a/Tests/ISO/HEVCDecoderConfigurationRecordTests.swift b/Tests/ISO/HEVCDecoderConfigurationRecordTests.swift index 9eb74b713..ffcff1bb8 100644 --- a/Tests/ISO/HEVCDecoderConfigurationRecordTests.swift +++ b/Tests/ISO/HEVCDecoderConfigurationRecordTests.swift @@ -1,5 +1,5 @@ -import Foundation import AVFoundation +import Foundation import Testing @testable import HaishinKit diff --git a/Tests/ISO/NALUnitReaderTests.swift b/Tests/ISO/NALUnitReaderTests.swift index 0e55eb9f1..ec410f354 100644 --- a/Tests/ISO/NALUnitReaderTests.swift +++ b/Tests/ISO/NALUnitReaderTests.swift @@ -1,5 +1,5 @@ -import Foundation import CoreMedia +import Foundation import Testing @testable import HaishinKit diff --git a/Tests/ISO/PacketizedElementaryStreamTests.swift b/Tests/ISO/PacketizedElementaryStreamTests.swift index f3461cda0..83d084d57 100644 --- a/Tests/ISO/PacketizedElementaryStreamTests.swift +++ b/Tests/ISO/PacketizedElementaryStreamTests.swift @@ -1,5 +1,5 @@ -import Foundation import CoreMedia +import Foundation import Testing @testable import HaishinKit diff --git a/Tests/ISO/TSProgramTests.swift b/Tests/ISO/TSProgramTests.swift index 50f316d53..0a8deb97c 100644 --- a/Tests/ISO/TSProgramTests.swift +++ b/Tests/ISO/TSProgramTests.swift @@ -4,7 +4,6 @@ import Testing @testable import HaishinKit @Suite struct TSProgramTests { - static let dataForPAT: Data = .init([0, 0, 176, 13, 0, 1, 193, 0, 0, 0, 1, 240, 0, 42, 177, 4, 178]) static let dataForPMT: Data = .init([0, 2, 176, 29, 0, 1, 193, 0, 0, 225, 0, 240, 0, 27, 225, 0, 240, 0, 15, 225, 1, 240, 6, 10, 4, 117, 110, 100, 0, 8, 125, 232, 119]) diff --git a/Tests/ISO/TSReaderTests.swift b/Tests/ISO/TSReaderTests.swift index 7a7ad3043..b43a5e7f7 100644 --- a/Tests/ISO/TSReaderTests.swift +++ b/Tests/ISO/TSReaderTests.swift @@ -1,81 +1,81 @@ +import AVFAudio import Foundation -import Testing import Logboard -import AVFAudio +import Testing @testable import HaishinKit /* -final class TSReaderTests: XCTestCase { - func testTSFileRead() { - let bundle = Bundle(for: type(of: self)) - let url = URL(fileURLWithPath: bundle.path(forResource: "SampleVideo_360x240_5mb_2ch", ofType: "ts")!) - do { - let readerDelegate = TSReaderTestsResult() - let fileHandle = try FileHandle(forReadingFrom: url) - let reader = TSReader() - reader.delegate = readerDelegate - _ = reader.read(fileHandle.readDataToEndOfFile()) - } catch { - } - } + final class TSReaderTests: XCTestCase { + func testTSFileRead() { + let bundle = Bundle(for: type(of: self)) + let url = URL(fileURLWithPath: bundle.path(forResource: "SampleVideo_360x240_5mb_2ch", ofType: "ts")!) + do { + let readerDelegate = TSReaderTestsResult() + let fileHandle = try FileHandle(forReadingFrom: url) + let reader = TSReader() + reader.delegate = readerDelegate + _ = reader.read(fileHandle.readDataToEndOfFile()) + } catch { + } + } + + func testTSFileRead_changeResolution() { + let bundle = Bundle(for: type(of: self)) + let url = URL(fileURLWithPath: bundle.path(forResource: "change_video_resolution", ofType: "ts")!) + do { + let readerDelegate = TSReaderTestsResult() + let fileHandle = try FileHandle(forReadingFrom: url) + let reader = TSReader() + reader.delegate = readerDelegate + _ = reader.read(fileHandle.readDataToEndOfFile()) + XCTAssertEqual(readerDelegate.videoFormats[0].dimensions.width, 640) + XCTAssertEqual(readerDelegate.videoFormats[0].dimensions.height, 360) + XCTAssertEqual(readerDelegate.videoFormats[1].dimensions.width, 1280) + XCTAssertEqual(readerDelegate.videoFormats[1].dimensions.height, 720) + XCTAssertEqual(readerDelegate.videoFormats[2].dimensions.width, 1920) + XCTAssertEqual(readerDelegate.videoFormats[2].dimensions.height, 1080) + } catch { + } + } + } - func testTSFileRead_changeResolution() { - let bundle = Bundle(for: type(of: self)) - let url = URL(fileURLWithPath: bundle.path(forResource: "change_video_resolution", ofType: "ts")!) - do { - let readerDelegate = TSReaderTestsResult() - let fileHandle = try FileHandle(forReadingFrom: url) - let reader = TSReader() - reader.delegate = readerDelegate - _ = reader.read(fileHandle.readDataToEndOfFile()) - XCTAssertEqual(readerDelegate.videoFormats[0].dimensions.width, 640) - XCTAssertEqual(readerDelegate.videoFormats[0].dimensions.height, 360) - XCTAssertEqual(readerDelegate.videoFormats[1].dimensions.width, 1280) - XCTAssertEqual(readerDelegate.videoFormats[1].dimensions.height, 720) - XCTAssertEqual(readerDelegate.videoFormats[2].dimensions.width, 1920) - XCTAssertEqual(readerDelegate.videoFormats[2].dimensions.height, 1080) - } catch { - } - } -} + private final class TSReaderTestsResult: TSReaderDelegate, AudioCodecDelegate { + private var audioCodec: HaishinKit.AudioCodec = .init(lockQueue: DispatchQueue(label: "TSReaderAudioCodec")) -private final class TSReaderTestsResult: TSReaderDelegate, AudioCodecDelegate { - private var audioCodec: HaishinKit.AudioCodec = .init(lockQueue: DispatchQueue(label: "TSReaderAudioCodec")) - - var videoFormats: [CMFormatDescription] = [] + var videoFormats: [CMFormatDescription] = [] - init() { - audioCodec.delegate = self - audioCodec.settings.format = .pcm - audioCodec.startRunning() - } + init() { + audioCodec.delegate = self + audioCodec.settings.format = .pcm + audioCodec.startRunning() + } - func reader(_ reader: TSReader, id: UInt16, didRead formatDescription: CMFormatDescription) { - switch formatDescription.mediaType { - case .video: - videoFormats.append(formatDescription) - default: - break - } - } + func reader(_ reader: TSReader, id: UInt16, didRead formatDescription: CMFormatDescription) { + switch formatDescription.mediaType { + case .video: + videoFormats.append(formatDescription) + default: + break + } + } - func reader(_ reader: TSReader, id: UInt16, didRead sampleBuffer: CMSampleBuffer) { - if sampleBuffer.formatDescription?.mediaType == .audio { - audioCodec.append(sampleBuffer) - } - } + func reader(_ reader: TSReader, id: UInt16, didRead sampleBuffer: CMSampleBuffer) { + if sampleBuffer.formatDescription?.mediaType == .audio { + audioCodec.append(sampleBuffer) + } + } - func audioCodec(_ codec: HaishinKit.AudioCodec, didOutput outputFormat: AVAudioFormat?) { - } + func audioCodec(_ codec: HaishinKit.AudioCodec, didOutput outputFormat: AVAudioFormat?) { + } - func audioCodec(_ codec: HaishinKit.AudioCodec, errorOccurred error: HaishinKit.IOAudioUnitError) { - // XCTFail() - } + func audioCodec(_ codec: HaishinKit.AudioCodec, errorOccurred error: HaishinKit.IOAudioUnitError) { + // XCTFail() + } - func audioCodec(_ codec: HaishinKit.AudioCodec, didOutput audioBuffer: AVAudioBuffer, when: AVAudioTime) { - } -} + func audioCodec(_ codec: HaishinKit.AudioCodec, didOutput audioBuffer: AVAudioBuffer, when: AVAudioTime) { + } + } -*/ + */ diff --git a/Tests/Mixer/AudioMixerByMultiTrackTests.swift b/Tests/Mixer/AudioMixerByMultiTrackTests.swift index 3f0507f69..878a229d4 100644 --- a/Tests/Mixer/AudioMixerByMultiTrackTests.swift +++ b/Tests/Mixer/AudioMixerByMultiTrackTests.swift @@ -1,5 +1,5 @@ -import Foundation import AVFoundation +import Foundation import Testing @testable import HaishinKit diff --git a/Tests/Mixer/AudioMixerBySingleTrackTests.swift b/Tests/Mixer/AudioMixerBySingleTrackTests.swift index 1bef9e519..27bfec776 100644 --- a/Tests/Mixer/AudioMixerBySingleTrackTests.swift +++ b/Tests/Mixer/AudioMixerBySingleTrackTests.swift @@ -1,5 +1,5 @@ -import Foundation import AVFoundation +import Foundation import Testing @testable import HaishinKit @@ -110,4 +110,3 @@ import Testing #expect(inputFormats[0]?.sampleRate == 48000) } } - diff --git a/Tests/Mixer/AudioMixerTrackTests.swift b/Tests/Mixer/AudioMixerTrackTests.swift index 6c736e980..dcdac195d 100644 --- a/Tests/Mixer/AudioMixerTrackTests.swift +++ b/Tests/Mixer/AudioMixerTrackTests.swift @@ -1,59 +1,58 @@ -import Foundation import AVFoundation +import Foundation import Testing @testable import HaishinKit @Suite struct AudioMixerTrackTests { /* - @Test func pKeep16000() { - let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 16000, channels: 1, interleaved: true)! - let track = AudioMixerTrack(id: 0, outputFormat: format) - track.delegate = self - track.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) - #expect(track.outputFormat.sampleRate == 16000) - track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) - #expect(track.outputFormat.sampleRate == 16000) - } + @Test func pKeep16000() { + let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 16000, channels: 1, interleaved: true)! + let track = AudioMixerTrack(id: 0, outputFormat: format) + track.delegate = self + track.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) + #expect(track.outputFormat.sampleRate == 16000) + track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) + #expect(track.outputFormat.sampleRate == 16000) + } - @Test func pKeep44100() { - let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 44100, channels: 1, interleaved: true)! - let resampler = AudioMixerTrack(id: 0, outputFormat: format) - resampler.delegate = self - resampler.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) - #expect(resampler.outputFormat.sampleRate == 44100) - resampler.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) - #expect(resampler.outputFormat.sampleRate == 44100) - resampler.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) - #expect(resampler.outputFormat.sampleRate == 44100) - resampler.append(CMAudioSampleBufferFactory.makeSinWave(16000, numSamples: 1024 * 20, channels: 1)!) - #expect(resampler.outputFormat.sampleRate == 44100) - } + @Test func pKeep44100() { + let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 44100, channels: 1, interleaved: true)! + let resampler = AudioMixerTrack(id: 0, outputFormat: format) + resampler.delegate = self + resampler.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) + #expect(resampler.outputFormat.sampleRate == 44100) + resampler.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) + #expect(resampler.outputFormat.sampleRate == 44100) + resampler.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) + #expect(resampler.outputFormat.sampleRate == 44100) + resampler.append(CMAudioSampleBufferFactory.makeSinWave(16000, numSamples: 1024 * 20, channels: 1)!) + #expect(resampler.outputFormat.sampleRate == 44100) + } - @Test func pKeep48000() { - let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 48000, channels: 1, interleaved: true)! - let track = AudioMixerTrack(id: 0, outputFormat: format) - track.delegate = self - track.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) - track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024 * 2, channels: 1)!) - } + @Test func pKeep48000() { + let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 48000, channels: 1, interleaved: true)! + let track = AudioMixerTrack(id: 0, outputFormat: format) + track.delegate = self + track.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) + track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024 * 2, channels: 1)!) + } - @Test func pPassthrough48000_44100() { - let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 44000, channels: 1, interleaved: true)! - let resampler = AudioMixerTrack(id: 0, outputFormat: format) - resampler.delegate = self - resampler.append(CMAudioSampleBufferFactory.makeSinWave(44000, numSamples: 1024, channels: 1)!) - resampler.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) - } + @Test func pPassthrough48000_44100() { + let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 44000, channels: 1, interleaved: true)! + let resampler = AudioMixerTrack(id: 0, outputFormat: format) + resampler.delegate = self + resampler.append(CMAudioSampleBufferFactory.makeSinWave(44000, numSamples: 1024, channels: 1)!) + resampler.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) + } - @Test func pPassthrough16000_48000() { - let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 48000, channels: 1, interleaved: true)! - let track = AudioMixerTrack(id: 0, outputFormat: format) - track.delegate = self - track.append(CMAudioSampleBufferFactory.makeSinWave(16000, numSamples: 1024, channels: 1)!) - #expect(track.outputFormat.sampleRate == 48000) - track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) - } + @Test func pPassthrough16000_48000() { + let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 48000, channels: 1, interleaved: true)! + let track = AudioMixerTrack(id: 0, outputFormat: format) + track.delegate = self + track.append(CMAudioSampleBufferFactory.makeSinWave(16000, numSamples: 1024, channels: 1)!) + #expect(track.outputFormat.sampleRate == 48000) + track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) + } */ } - diff --git a/Tests/Mixer/AudioRingBufferTests.swift b/Tests/Mixer/AudioRingBufferTests.swift index 748dd3534..bc4cad51a 100644 --- a/Tests/Mixer/AudioRingBufferTests.swift +++ b/Tests/Mixer/AudioRingBufferTests.swift @@ -1,27 +1,27 @@ +import AVFoundation import Foundation import Testing -import AVFoundation @testable import HaishinKit @Suite struct AudioRingBufferTests { - @Test func monoAppendSampleBuffer_920() { - appendSampleBuffer(920, channels: 1) + @Test func monoAppendSampleBuffer_920() throws { + try appendSampleBuffer(920, channels: 1) } - @Test func monoAppendSampleBuffer_1024() { - appendSampleBuffer(1024, channels: 1) + @Test func monoAppendSampleBuffer_1024() throws { + try appendSampleBuffer(1024, channels: 1) } - @Test func stereoAppendSampleBuffer_920() { - appendSampleBuffer(920, channels: 2) + @Test func stereoAppendSampleBuffer_920() throws { + try appendSampleBuffer(920, channels: 2) } - @Test func stereoAppendSampleBuffer_1024() { - appendSampleBuffer(1024, channels: 2) + @Test func stereoAppendSampleBuffer_1024() throws { + try appendSampleBuffer(1024, channels: 2) } - private func appendSampleBuffer(_ numSamples: Int, channels: UInt32) { + private func appendSampleBuffer(_ numSamples: Int, channels: UInt32) throws { var asbd = AudioStreamBasicDescription( mSampleRate: 44100, mFormatID: kAudioFormatLinearPCM, @@ -46,7 +46,7 @@ import AVFoundation buffer?.append(sinWave) readBuffer.int16ChannelData?[0].update(repeating: 0, count: numSamples) _ = buffer?.render(UInt32(numSamples), ioData: readBuffer.mutableAudioBufferList) - #expect(try! sinWave.dataBuffer?.dataBytes().bytes == Data(bytes: bufferList[0].mData!, count: numSamples * Int(channels) * 2).bytes) + #expect(try sinWave.dataBuffer?.dataBytes().bytes == Data(bytes: bufferList[0].mData!, count: numSamples * Int(channels) * 2).bytes) } } } diff --git a/Tests/Mixer/MediaMixerTests.swift b/Tests/Mixer/MediaMixerTests.swift index a3c95251d..f0aa97d85 100644 --- a/Tests/Mixer/MediaMixerTests.swift +++ b/Tests/Mixer/MediaMixerTests.swift @@ -5,15 +5,15 @@ import Testing @Suite struct MediaMixerTests { /* - func testRelease() { - weak var weakIOMixer: IOMixer? - _ = { - let mixer = IOMixer() - mixer.audioIO.settings.bitRate = 100000 - mixer.videoIO.settings.bitRate = 100000 - weakIOMixer = mixer - }() - XCTAssertNil(weakIOMixer) - } + func testRelease() { + weak var weakIOMixer: IOMixer? + _ = { + let mixer = IOMixer() + mixer.audioIO.settings.bitRate = 100000 + mixer.videoIO.settings.bitRate = 100000 + weakIOMixer = mixer + }() + XCTAssertNil(weakIOMixer) + } */ } diff --git a/Tests/Mixer/MediaRecorderTests.swift b/Tests/Mixer/MediaRecorderTests.swift index 50a91c725..9901f8201 100644 --- a/Tests/Mixer/MediaRecorderTests.swift +++ b/Tests/Mixer/MediaRecorderTests.swift @@ -1,62 +1,62 @@ +import AVFoundation +import CoreMedia import Foundation import Testing -import CoreMedia -import AVFoundation @testable import HaishinKit /* -final class IOStreamRecorderTests: XCTestCase, IOStreamRecorderDelegate { - func testRecorder2channel() { - let recorder = IOStreamRecorder() - recorder.delegate = self - recorder.settings = [.audio: [ - AVFormatIDKey: Int(kAudioFormatMPEG4AAC), - AVSampleRateKey: 0, - AVNumberOfChannelsKey: 0 - ]] - recorder.startRunning() - sleep(1) - var presentationTimeStamp: CMTime = .zero - for _ in 0...100 { - guard let sampleBuffer = CMAudioSampleBufferFactory.makeSilence(44100, numSamples: 1024, channels: 2, presentaionTimeStamp: presentationTimeStamp) else { - return - } - presentationTimeStamp = CMTimeAdd(presentationTimeStamp, sampleBuffer.duration) - recorder.append(sampleBuffer) - } - recorder.stopRunning() - sleep(1) - } + final class IOStreamRecorderTests: XCTestCase, IOStreamRecorderDelegate { + func testRecorder2channel() { + let recorder = IOStreamRecorder() + recorder.delegate = self + recorder.settings = [.audio: [ + AVFormatIDKey: Int(kAudioFormatMPEG4AAC), + AVSampleRateKey: 0, + AVNumberOfChannelsKey: 0 + ]] + recorder.startRunning() + sleep(1) + var presentationTimeStamp: CMTime = .zero + for _ in 0...100 { + guard let sampleBuffer = CMAudioSampleBufferFactory.makeSilence(44100, numSamples: 1024, channels: 2, presentaionTimeStamp: presentationTimeStamp) else { + return + } + presentationTimeStamp = CMTimeAdd(presentationTimeStamp, sampleBuffer.duration) + recorder.append(sampleBuffer) + } + recorder.stopRunning() + sleep(1) + } - func testRecorder4channel() { - let recorder = IOStreamRecorder() - recorder.delegate = self - recorder.settings = [.audio: [ - AVFormatIDKey: Int(kAudioFormatMPEG4AAC), - AVSampleRateKey: 0, - AVNumberOfChannelsKey: 0 - ]] - recorder.startRunning() - sleep(1) - var presentationTimeStamp: CMTime = .zero - for _ in 0...100 { - guard let sampleBuffer = CMAudioSampleBufferFactory.makeSilence(44100, numSamples: 1024, channels: 4, presentaionTimeStamp: presentationTimeStamp) else { - return - } - presentationTimeStamp = CMTimeAdd(presentationTimeStamp, sampleBuffer.duration) - recorder.append(sampleBuffer) - } - recorder.stopRunning() - sleep(1) - } + func testRecorder4channel() { + let recorder = IOStreamRecorder() + recorder.delegate = self + recorder.settings = [.audio: [ + AVFormatIDKey: Int(kAudioFormatMPEG4AAC), + AVSampleRateKey: 0, + AVNumberOfChannelsKey: 0 + ]] + recorder.startRunning() + sleep(1) + var presentationTimeStamp: CMTime = .zero + for _ in 0...100 { + guard let sampleBuffer = CMAudioSampleBufferFactory.makeSilence(44100, numSamples: 1024, channels: 4, presentaionTimeStamp: presentationTimeStamp) else { + return + } + presentationTimeStamp = CMTimeAdd(presentationTimeStamp, sampleBuffer.duration) + recorder.append(sampleBuffer) + } + recorder.stopRunning() + sleep(1) + } - func recorder(_ recorder: HaishinKit.IOStreamRecorder, errorOccured error: IOStreamRecorder.Error) { - // print("recorder:errorOccured", error) - } + func recorder(_ recorder: HaishinKit.IOStreamRecorder, errorOccured error: IOStreamRecorder.Error) { + // print("recorder:errorOccured", error) + } - func recorder(_ recorder: HaishinKit.IOStreamRecorder, finishWriting writer: AVAssetWriter) { - // print("recorder:finishWriting") - } -} -*/ + func recorder(_ recorder: HaishinKit.IOStreamRecorder, finishWriting writer: AVAssetWriter) { + // print("recorder:finishWriting") + } + } + */ diff --git a/Tests/RTMP/AMF0SerializerTests.swift b/Tests/RTMP/AMF0SerializerTests.swift index 4557351f9..5f1392aa2 100644 --- a/Tests/RTMP/AMF0SerializerTests.swift +++ b/Tests/RTMP/AMF0SerializerTests.swift @@ -4,7 +4,6 @@ import Testing @testable import HaishinKit @Suite struct AMF0SerializerTests { - static let connectionChunk: AMFObject = [ "tcUrl": "rtmp://localhost:1935/live", "flashVer": "FMLE/3.0 (compatible; FMSc/1.0)", @@ -20,11 +19,11 @@ import Testing "objectEncoding": Double(0) ] - @Test func connectionChunk() { + @Test func connectionChunk() throws { var amf: any AMFSerializer = AMF0Serializer() amf.serialize(AMF0SerializerTests.connectionChunk) amf.position = 0 - let result: AMFObject = try! amf.deserialize() + let result: AMFObject = try amf.deserialize() for key in AMF0SerializerTests.connectionChunk.keys { let value: Any? = result[key]! as Any? switch key { @@ -58,14 +57,14 @@ import Testing } } - @Test func aSArray() { + @Test func asarray() throws { var array = AMFArray() array["hello"] = "world" array["world"] = "hello" var amf: any AMFSerializer = AMF0Serializer() amf.serialize(array) amf.position = 0 - let result: AMFArray = try! amf.deserialize() + let result: AMFArray = try amf.deserialize() #expect(array["hello"] as? String == result["hello"] as? String) #expect(array["world"] as? String == result["world"] as? String) } diff --git a/Tests/RTMP/AMFFoundationTests.swift b/Tests/RTMP/AMFFoundationTests.swift index a77335a2e..15ae10bdf 100644 --- a/Tests/RTMP/AMFFoundationTests.swift +++ b/Tests/RTMP/AMFFoundationTests.swift @@ -4,7 +4,6 @@ import Testing @testable import HaishinKit @Suite struct AMFFoundationTests { - static let hello: String = "hello" @Test func aSArray() { diff --git a/Tests/RTMP/FLVVideoFourCCTests.swift b/Tests/RTMP/FLVVideoFourCCTests.swift index f1f98c593..3acf6db19 100644 --- a/Tests/RTMP/FLVVideoFourCCTests.swift +++ b/Tests/RTMP/FLVVideoFourCCTests.swift @@ -1,6 +1,6 @@ +import AVFoundation import Foundation import Testing -import AVFoundation @testable import HaishinKit @@ -19,4 +19,3 @@ import AVFoundation return result } } - diff --git a/Tests/RTMP/RTMPConnectionTests.swift b/Tests/RTMP/RTMPConnectionTests.swift index fe6d307e9..ae632a1aa 100644 --- a/Tests/RTMP/RTMPConnectionTests.swift +++ b/Tests/RTMP/RTMPConnectionTests.swift @@ -5,23 +5,23 @@ import Testing @Suite struct RTMPConnectionTests { /* - func publish() { - let connection = RTMPConnection() - let stream = RTMPStream(connection: connection) - connection.connect("rtmp://localhost:1935/live") - stream.publish("live") - sleep(10000) - } + func publish() { + let connection = RTMPConnection() + let stream = RTMPStream(connection: connection) + connection.connect("rtmp://localhost:1935/live") + stream.publish("live") + sleep(10000) + } - func testReleaseWhenClose() { - weak var weakConnection: RTMPConnection? - _ = { - let connection = RTMPConnection() - connection.connect("rtmp://localhost:1935/live") - connection.close() - weakConnection = connection - }() - XCTAssertNil(weakConnection) - } + func testReleaseWhenClose() { + weak var weakConnection: RTMPConnection? + _ = { + let connection = RTMPConnection() + connection.connect("rtmp://localhost:1935/live") + connection.close() + weakConnection = connection + }() + XCTAssertNil(weakConnection) + } */ } diff --git a/Tests/RTMP/RTMPTimestampTests.swift b/Tests/RTMP/RTMPTimestampTests.swift index 570f1d2c0..c98eb2f5e 100644 --- a/Tests/RTMP/RTMPTimestampTests.swift +++ b/Tests/RTMP/RTMPTimestampTests.swift @@ -1,10 +1,10 @@ -import Foundation -import Testing import AVFoundation +import Foundation @testable import HaishinKit +import Testing @Suite struct RTMPTimestampTests { - @Test func updateCMTime() { + @Test func updateCMTime() throws { let times: [CMTime] = [ CMTime(value: 286340171565869, timescale: 1000000000), CMTime(value: 286340204889958, timescale: 1000000000), @@ -12,32 +12,32 @@ import AVFoundation CMTime(value: 286340271560111, timescale: 1000000000), CMTime(value: 286340304906325, timescale: 1000000000), CMTime(value: 286340338232723, timescale: 1000000000), - CMTime(value: 286340338232723, timescale: 1000000000), + CMTime(value: 286340338232723, timescale: 1000000000) ] var timestamp = RTMPTimestamp() - #expect(try! timestamp.update(times[0]) == 0) - #expect(try! timestamp.update(times[1]) == 33) - #expect(try! timestamp.update(times[2]) == 33) - #expect(try! timestamp.update(times[3]) == 33) - #expect(try! timestamp.update(times[4]) == 34) - #expect(try! timestamp.update(times[5]) == 33) + #expect(try timestamp.update(times[0]) == 0) + #expect(try timestamp.update(times[1]) == 33) + #expect(try timestamp.update(times[2]) == 33) + #expect(try timestamp.update(times[3]) == 33) + #expect(try timestamp.update(times[4]) == 34) + #expect(try timestamp.update(times[5]) == 33) } - @Test func updateAVAudioTime() { + @Test func updateAVAudioTime() throws { let times: [AVAudioTime] = [ .init(hostTime: 6901294874500, sampleTime: 13802589749, atRate: 48000), .init(hostTime: 6901295386500, sampleTime: 13802590773, atRate: 48000), .init(hostTime: 6901295898500, sampleTime: 13802591797, atRate: 48000), .init(hostTime: 6901296410500, sampleTime: 13802592821, atRate: 48000), .init(hostTime: 6901296922500, sampleTime: 13802593845, atRate: 48000), - .init(hostTime: 6901297434500, sampleTime: 13802594869, atRate: 48000), + .init(hostTime: 6901297434500, sampleTime: 13802594869, atRate: 48000) ] var timestamp = RTMPTimestamp() - #expect(try! timestamp.update(times[0]) == 0) - #expect(try! timestamp.update(times[1]) == 21) - #expect(try! timestamp.update(times[2]) == 21) - #expect(try! timestamp.update(times[3]) == 22) - #expect(try! timestamp.update(times[4]) == 21) - #expect(try! timestamp.update(times[5]) == 21) + #expect(try timestamp.update(times[0]) == 0) + #expect(try timestamp.update(times[1]) == 21) + #expect(try timestamp.update(times[2]) == 21) + #expect(try timestamp.update(times[3]) == 22) + #expect(try timestamp.update(times[4]) == 21) + #expect(try timestamp.update(times[5]) == 21) } } diff --git a/Tests/Screen/ScreenObjectContainerTests.swift b/Tests/Screen/ScreenObjectContainerTests.swift index 04881cedf..e689f7e63 100644 --- a/Tests/Screen/ScreenObjectContainerTests.swift +++ b/Tests/Screen/ScreenObjectContainerTests.swift @@ -1,6 +1,6 @@ +import AVFoundation import Foundation import Testing -import AVFoundation @testable import HaishinKit @@ -8,21 +8,21 @@ import AVFoundation @Test func lookUpVideoTrackScreenObject() { Task { @ScreenActor in let container1 = ScreenObjectContainer() - + let videoTrack1 = VideoTrackScreenObject() let videoTrack2 = VideoTrackScreenObject() - + try? container1.addChild(videoTrack1) try? container1.addChild(videoTrack2) - + let videoTracks1 = container1.getScreenObjects() as [VideoTrackScreenObject] #expect(videoTracks1.count == 2) - + let container2 = ScreenObjectContainer() let videoTrack3 = VideoTrackScreenObject() try? container2.addChild(videoTrack3) try? container1.addChild(container2) - + let videoTracks2 = container1.getScreenObjects() as [VideoTrackScreenObject] #expect(videoTracks2.count == 3) } diff --git a/Tests/Screen/ScreenObjectTests.swift b/Tests/Screen/ScreenObjectTests.swift index f390a7bfd..d73337bcc 100644 --- a/Tests/Screen/ScreenObjectTests.swift +++ b/Tests/Screen/ScreenObjectTests.swift @@ -1,103 +1,103 @@ +import AVFoundation import Foundation import Testing -import AVFoundation @testable import HaishinKit /* -@Suite struct ScreenObjectTests { - @Test func screenHorizontalAlignmentRect() { - Task { @ScreenActor in - let screen = Screen() - - let object1 = ScreenObject() - object1.size = .init(width: 100, height: 100) - object1.horizontalAlignment = .left - - let object2 = ScreenObject() - object2.size = .init(width: 100, height: 100) - object2.horizontalAlignment = .center - - let object3 = ScreenObject() - object3.size = .init(width: 100, height: 100) - object3.horizontalAlignment = .right - - try? screen.addChild(object1) - try? screen.addChild(object2) - try? screen.addChild(object3) - - if let sampleBuffer = CMVideoSampleBufferFactory.makeSampleBuffer(width: 1600, height: 900) { - // _ = screen.render(sampleBuffer) - } - #expect(object1.bounds == .init(origin: .zero, size: object1.size)) - #expect(object2.bounds == .init(x: 750, y: 0, width: 100, height: 100)) - #expect(object3.bounds == .init(x: 1500, y: 0, width: 100, height: 100)) - } - } - - @Test func screenVerticalAlignmentRect() { - Task { @ScreenActor in - let screen = Screen() - - let object0 = ScreenObject() - object0.size = .zero - object0.verticalAlignment = .top - - let object1 = ScreenObject() - object1.size = .init(width: 100, height: 100) - object1.verticalAlignment = .top - - let object2 = ScreenObject() - object2.size = .init(width: 100, height: 100) - object2.verticalAlignment = .middle - - let object3 = ScreenObject() - object3.size = .init(width: 100, height: 100) - object3.verticalAlignment = .bottom - - try? screen.addChild(object0) - try? screen.addChild(object1) - try? screen.addChild(object2) - try? screen.addChild(object3) - - if let sampleBuffer = CMVideoSampleBufferFactory.makeSampleBuffer(width: 1600, height: 900) { - // _ = screen.render(sampleBuffer) - } - #expect(object0.bounds == .init(x: 0, y: 0, width: 1600, height: 900)) - #expect(object1.bounds == .init(x: 0, y: 0, width: object1.size.width, height: object1.size.height)) - #expect(object2.bounds == .init(x: 0, y: 400, width: 100, height: 100)) - #expect(object3.bounds == .init(x: 0, y: 800, width: 100, height: 100)) - } - } - - @Test func screenWithContainerTests() { - Task { @ScreenActor in - let screen = Screen() - - let container = ScreenObjectContainer() - container.size = .init(width: 200, height: 100) - container.layoutMargin = .init(top: 16, left: 16, bottom: 0, right: 0) - - let object0 = ScreenObject() - object0.size = .zero - object0.verticalAlignment = .top - - let object1 = ScreenObject() - object1.size = .init(width: 100, height: 100) - object1.layoutMargin = .init(top: 16, left: 16, bottom: 0, right: 0) - object1.verticalAlignment = .top - - try? container.addChild(object0) - try? container.addChild(object1) - try? screen.addChild(container) - - if let sampleBuffer = CMVideoSampleBufferFactory.makeSampleBuffer(width: 1600, height: 900) { - // _ = screen.render(sampleBuffer) - } - - #expect(object0.bounds == .init(x: 16, y: 16, width: 200, height: 100)) - #expect(object1.bounds == .init(x: 32, y: 32, width: 100, height: 100)) - } - } -} -*/ + @Suite struct ScreenObjectTests { + @Test func screenHorizontalAlignmentRect() { + Task { @ScreenActor in + let screen = Screen() + + let object1 = ScreenObject() + object1.size = .init(width: 100, height: 100) + object1.horizontalAlignment = .left + + let object2 = ScreenObject() + object2.size = .init(width: 100, height: 100) + object2.horizontalAlignment = .center + + let object3 = ScreenObject() + object3.size = .init(width: 100, height: 100) + object3.horizontalAlignment = .right + + try? screen.addChild(object1) + try? screen.addChild(object2) + try? screen.addChild(object3) + + if let sampleBuffer = CMVideoSampleBufferFactory.makeSampleBuffer(width: 1600, height: 900) { + // _ = screen.render(sampleBuffer) + } + #expect(object1.bounds == .init(origin: .zero, size: object1.size)) + #expect(object2.bounds == .init(x: 750, y: 0, width: 100, height: 100)) + #expect(object3.bounds == .init(x: 1500, y: 0, width: 100, height: 100)) + } + } + + @Test func screenVerticalAlignmentRect() { + Task { @ScreenActor in + let screen = Screen() + + let object0 = ScreenObject() + object0.size = .zero + object0.verticalAlignment = .top + + let object1 = ScreenObject() + object1.size = .init(width: 100, height: 100) + object1.verticalAlignment = .top + + let object2 = ScreenObject() + object2.size = .init(width: 100, height: 100) + object2.verticalAlignment = .middle + + let object3 = ScreenObject() + object3.size = .init(width: 100, height: 100) + object3.verticalAlignment = .bottom + + try? screen.addChild(object0) + try? screen.addChild(object1) + try? screen.addChild(object2) + try? screen.addChild(object3) + + if let sampleBuffer = CMVideoSampleBufferFactory.makeSampleBuffer(width: 1600, height: 900) { + // _ = screen.render(sampleBuffer) + } + #expect(object0.bounds == .init(x: 0, y: 0, width: 1600, height: 900)) + #expect(object1.bounds == .init(x: 0, y: 0, width: object1.size.width, height: object1.size.height)) + #expect(object2.bounds == .init(x: 0, y: 400, width: 100, height: 100)) + #expect(object3.bounds == .init(x: 0, y: 800, width: 100, height: 100)) + } + } + + @Test func screenWithContainerTests() { + Task { @ScreenActor in + let screen = Screen() + + let container = ScreenObjectContainer() + container.size = .init(width: 200, height: 100) + container.layoutMargin = .init(top: 16, left: 16, bottom: 0, right: 0) + + let object0 = ScreenObject() + object0.size = .zero + object0.verticalAlignment = .top + + let object1 = ScreenObject() + object1.size = .init(width: 100, height: 100) + object1.layoutMargin = .init(top: 16, left: 16, bottom: 0, right: 0) + object1.verticalAlignment = .top + + try? container.addChild(object0) + try? container.addChild(object1) + try? screen.addChild(container) + + if let sampleBuffer = CMVideoSampleBufferFactory.makeSampleBuffer(width: 1600, height: 900) { + // _ = screen.render(sampleBuffer) + } + + #expect(object0.bounds == .init(x: 16, y: 16, width: 200, height: 100)) + #expect(object1.bounds == .init(x: 32, y: 32, width: 100, height: 100)) + } + } + } + */ diff --git a/Tests/Screen/VideoTrackScreenObjectTests.swift b/Tests/Screen/VideoTrackScreenObjectTests.swift index 5f6c4f464..d1afb6c10 100644 --- a/Tests/Screen/VideoTrackScreenObjectTests.swift +++ b/Tests/Screen/VideoTrackScreenObjectTests.swift @@ -1,43 +1,43 @@ +import AVFoundation import Foundation import Testing -import AVFoundation @testable import HaishinKit @Suite struct VideoTrackObjectContainerTests { /* - func testHorizontalAlignmentBounds() { - let screen = Screen() - - let object1 = VideoTrackScreenObject() - object1.videoGravity = .resizeAspect - object1.size = .init(width: 160, height: 90) - object1.enqueue(CMVideoSampleBufferFactory.makeSampleBuffer(width: 900, height: 1600)!) - object1.horizontalAlignment = .left - - let object2 = VideoTrackScreenObject() - object2.videoGravity = .resizeAspect - object2.size = .init(width: 160, height: 90) - object2.enqueue(CMVideoSampleBufferFactory.makeSampleBuffer(width: 900, height: 1600)!) - object2.horizontalAlignment = .center - - let object3 = VideoTrackScreenObject() - object3.videoGravity = .resizeAspect - object3.size = .init(width: 160, height: 90) - object3.enqueue(CMVideoSampleBufferFactory.makeSampleBuffer(width: 900, height: 1600)!) - object3.horizontalAlignment = .right - - try? screen.addChild(object1) - try? screen.addChild(object2) - try? screen.addChild(object3) - - if let sampleBuffer = CMVideoSampleBufferFactory.makeSampleBuffer(width: 1600, height: 900) { - _ = screen.render(sampleBuffer) - } - - XCTAssertEqual(object1.bounds, .init(x: 0, y: 0, width: 50.625, height: 90)) - XCTAssertEqual(object2.bounds, .init(x: 774.6875, y: 0, width: 50.625, height: 90)) - XCTAssertEqual(object3.bounds, .init(x: 1549.375, y: 0, width: 50.625, height: 90)) - } - */ + func testHorizontalAlignmentBounds() { + let screen = Screen() + + let object1 = VideoTrackScreenObject() + object1.videoGravity = .resizeAspect + object1.size = .init(width: 160, height: 90) + object1.enqueue(CMVideoSampleBufferFactory.makeSampleBuffer(width: 900, height: 1600)!) + object1.horizontalAlignment = .left + + let object2 = VideoTrackScreenObject() + object2.videoGravity = .resizeAspect + object2.size = .init(width: 160, height: 90) + object2.enqueue(CMVideoSampleBufferFactory.makeSampleBuffer(width: 900, height: 1600)!) + object2.horizontalAlignment = .center + + let object3 = VideoTrackScreenObject() + object3.videoGravity = .resizeAspect + object3.size = .init(width: 160, height: 90) + object3.enqueue(CMVideoSampleBufferFactory.makeSampleBuffer(width: 900, height: 1600)!) + object3.horizontalAlignment = .right + + try? screen.addChild(object1) + try? screen.addChild(object2) + try? screen.addChild(object3) + + if let sampleBuffer = CMVideoSampleBufferFactory.makeSampleBuffer(width: 1600, height: 900) { + _ = screen.render(sampleBuffer) + } + + XCTAssertEqual(object1.bounds, .init(x: 0, y: 0, width: 50.625, height: 90)) + XCTAssertEqual(object2.bounds, .init(x: 774.6875, y: 0, width: 50.625, height: 90)) + XCTAssertEqual(object3.bounds, .init(x: 1549.375, y: 0, width: 50.625, height: 90)) + } + */ } diff --git a/Tests/Util/ByteArrayTests.swift b/Tests/Util/ByteArrayTests.swift index f87088bde..2c02973fe 100644 --- a/Tests/Util/ByteArrayTests.swift +++ b/Tests/Util/ByteArrayTests.swift @@ -4,104 +4,103 @@ import Testing @testable import HaishinKit @Suite struct ByteArrayTests { - - @Test func int8() { + @Test func int8() throws { let bytes = ByteArray() bytes.writeInt8(Int8.min) bytes.writeInt8(0) bytes.writeInt8(Int8.max) #expect(bytes.position == ByteArray.sizeOfInt8 * 3) bytes.position = 0 - #expect(try! bytes.readInt8() == Int8.min) - #expect(try! bytes.readInt8() == 0 ) - #expect(try! bytes.readInt8() == Int8.max) + #expect(try bytes.readInt8() == Int8.min) + #expect(try bytes.readInt8() == 0 ) + #expect(try bytes.readInt8() == Int8.max) } - @Test func uInt8() { + @Test func uint8() throws { let bytes = ByteArray() bytes.writeUInt8(UInt8.min) bytes.writeUInt8(0) bytes.writeUInt8(UInt8.max) #expect(bytes.position == ByteArray.sizeOfInt8 * 3) bytes.position = 0 - #expect(try! bytes.readUInt8() == UInt8.min) - #expect(try! bytes.readUInt8() == 0) - #expect(try! bytes.readUInt8() == UInt8.max) + #expect(try bytes.readUInt8() == UInt8.min) + #expect(try bytes.readUInt8() == 0) + #expect(try bytes.readUInt8() == UInt8.max) } - @Test func int16() { + @Test func int16() throws { let bytes = ByteArray() bytes.writeInt16(Int16.min) bytes.writeInt16(0) bytes.writeInt16(Int16.max) print(bytes) bytes.position = 0 - #expect(try! bytes.readInt16() == Int16.min) - #expect(try! bytes.readInt16() == 0) - #expect(try! bytes.readInt16() == Int16.max) + #expect(try bytes.readInt16() == Int16.min) + #expect(try bytes.readInt16() == 0) + #expect(try bytes.readInt16() == Int16.max) } - @Test func uInt16() { + @Test func uint16() throws { let bytes = ByteArray() bytes.writeUInt16(UInt16.min) bytes.writeUInt16(0) bytes.writeUInt16(UInt16.max) bytes.position = 0 - #expect(try! bytes.readUInt16() == UInt16.min) - #expect(try! bytes.readUInt16() == 0) - #expect(try! bytes.readUInt16() == UInt16.max) + #expect(try bytes.readUInt16() == UInt16.min) + #expect(try bytes.readUInt16() == 0) + #expect(try bytes.readUInt16() == UInt16.max) } - @Test func uInt24() { + @Test func uint24() throws { let bytes = ByteArray() bytes.writeUInt24(0xFFFFFF) bytes.position = 0 - #expect(try! bytes.readUInt24() == 0xFFFFFF) + #expect(try bytes.readUInt24() == 0xFFFFFF) } - @Test func uInt32() { + @Test func uint32() throws { let bytes = ByteArray() bytes.writeUInt32(UInt32.min) bytes.writeUInt32(0) bytes.writeUInt32(UInt32.max) bytes.position = 0 - #expect(try! bytes.readUInt32() == UInt32.min) - #expect(try! bytes.readUInt32() == 0) - #expect(try! bytes.readUInt32() == UInt32.max) + #expect(try bytes.readUInt32() == UInt32.min) + #expect(try bytes.readUInt32() == 0) + #expect(try bytes.readUInt32() == UInt32.max) } - @Test func int32() { + @Test func int32() throws { let bytes = ByteArray() bytes.writeInt32(Int32.min) bytes.writeInt32(0) bytes.writeInt32(Int32.max) bytes.position = 0 - #expect(try! bytes.readInt32() == Int32.min) - #expect(try! bytes.readInt32() == 0) - #expect(try! bytes.readInt32() == Int32.max) + #expect(try bytes.readInt32() == Int32.min) + #expect(try bytes.readInt32() == 0) + #expect(try bytes.readInt32() == Int32.max) } - @Test func float() { + @Test func float() throws { let bytes = ByteArray() bytes.writeFloat(Float.infinity) #expect(bytes.position == ByteArray.sizeOfFloat) bytes.position = 0 - #expect(try! bytes.readFloat() == Float.infinity) + #expect(try bytes.readFloat() == Float.infinity) } - @Test func double() { + @Test func double() throws { let bytes = ByteArray() bytes.writeDouble(.pi) #expect(bytes.position == ByteArray.sizeOfDouble) bytes.position = 0 - #expect(try! bytes.readDouble() == Double.pi) + #expect(try bytes.readDouble() == Double.pi) bytes.clear() bytes.writeDouble(Double.infinity) bytes.position = 0 - #expect(try! bytes.readDouble() == Double.infinity) + #expect(try bytes.readDouble() == Double.infinity) } - @Test func uTF8() { + @Test func utf8() throws { let bytes = ByteArray() do { try bytes.writeUTF8("hello world!!") @@ -111,7 +110,7 @@ import Testing let length: Int = bytes.position bytes.position = 0 - #expect(try! bytes.readUTF8() == "hello world!!") + #expect(try bytes.readUTF8() == "hello world!!") bytes.position = 0 var raiseError = false diff --git a/Tests/Util/MD5Tests.swift b/Tests/Util/MD5Tests.swift index d97c7b91f..c9a111c60 100755 --- a/Tests/Util/MD5Tests.swift +++ b/Tests/Util/MD5Tests.swift @@ -4,11 +4,10 @@ import Testing @testable import HaishinKit @Suite struct MD5Tests { - func hex(_ data: Data) -> String { var hash = "" for i in 0..