Skip to content

Commit

Permalink
Include test cases in SwiftLint
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Nov 8, 2024
1 parent 3563c7f commit 5c1e931
Show file tree
Hide file tree
Showing 31 changed files with 413 additions and 423 deletions.
1 change: 0 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ analyzer_rules:
excluded:
- Carthage
- Pods
- Tests
- Vendor
- .build
opt_in_rules:
Expand Down
2 changes: 1 addition & 1 deletion Tests/CMAudioSampleBufferFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Tests/CMVideoSampleBufferFactory.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import AVFoundation
import Foundation

enum CMVideoSampleBufferFactory {
static func makeSampleBuffer(width: Int, height: Int) -> CMSampleBuffer? {
Expand Down
3 changes: 1 addition & 2 deletions Tests/Codec/AudioCodecTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AVFoundation
import Foundation
import Testing
import AVFoundation

@testable import HaishinKit

Expand Down Expand Up @@ -94,4 +94,3 @@ import AVFoundation
}
}
}

2 changes: 1 addition & 1 deletion Tests/Extension/CMSampleBuffer+ExtensionTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CoreMedia
import Foundation
import Testing
import CoreMedia

@testable import HaishinKit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions Tests/HKStream/HKStreamRecorderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/ISO/ADTSHeaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion Tests/ISO/AVCDecoderConfigurationRecordTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import AVFoundation
import Foundation
import Testing

@testable import HaishinKit
Expand Down
2 changes: 1 addition & 1 deletion Tests/ISO/ESSpecificDataTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import CoreMedia
import Foundation
import Testing

@testable import HaishinKit
Expand Down
2 changes: 1 addition & 1 deletion Tests/ISO/HEVCDecoderConfigurationRecordTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import AVFoundation
import Foundation
import Testing

@testable import HaishinKit
Expand Down
2 changes: 1 addition & 1 deletion Tests/ISO/NALUnitReaderTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import CoreMedia
import Foundation
import Testing

@testable import HaishinKit
Expand Down
2 changes: 1 addition & 1 deletion Tests/ISO/PacketizedElementaryStreamTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import CoreMedia
import Foundation
import Testing

@testable import HaishinKit
Expand Down
1 change: 0 additions & 1 deletion Tests/ISO/TSProgramTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
130 changes: 65 additions & 65 deletions Tests/ISO/TSReaderTests.swift
Original file line number Diff line number Diff line change
@@ -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<TSReaderTestsResult>()
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<TSReaderTestsResult>()
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<TSReaderTestsResult>()
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<TSReaderTestsResult>()
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<TSReaderTestsResult> = .init(lockQueue: DispatchQueue(label: "TSReaderAudioCodec"))

private final class TSReaderTestsResult: TSReaderDelegate, AudioCodecDelegate {
private var audioCodec: HaishinKit.AudioCodec<TSReaderTestsResult> = .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<TSReaderTestsResult>, id: UInt16, didRead formatDescription: CMFormatDescription) {
switch formatDescription.mediaType {
case .video:
videoFormats.append(formatDescription)
default:
break
}
}
func reader(_ reader: TSReader<TSReaderTestsResult>, id: UInt16, didRead formatDescription: CMFormatDescription) {
switch formatDescription.mediaType {
case .video:
videoFormats.append(formatDescription)
default:
break
}
}

func reader(_ reader: TSReader<TSReaderTestsResult>, id: UInt16, didRead sampleBuffer: CMSampleBuffer) {
if sampleBuffer.formatDescription?.mediaType == .audio {
audioCodec.append(sampleBuffer)
}
}
func reader(_ reader: TSReader<TSReaderTestsResult>, id: UInt16, didRead sampleBuffer: CMSampleBuffer) {
if sampleBuffer.formatDescription?.mediaType == .audio {
audioCodec.append(sampleBuffer)
}
}

func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, didOutput outputFormat: AVAudioFormat?) {
}
func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, didOutput outputFormat: AVAudioFormat?) {
}

func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, errorOccurred error: HaishinKit.IOAudioUnitError) {
// XCTFail()
}
func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, errorOccurred error: HaishinKit.IOAudioUnitError) {
// XCTFail()
}

func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, didOutput audioBuffer: AVAudioBuffer, when: AVAudioTime) {
}
}
func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, didOutput audioBuffer: AVAudioBuffer, when: AVAudioTime) {
}
}

*/
*/
2 changes: 1 addition & 1 deletion Tests/Mixer/AudioMixerByMultiTrackTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import AVFoundation
import Foundation
import Testing

@testable import HaishinKit
Expand Down
3 changes: 1 addition & 2 deletions Tests/Mixer/AudioMixerBySingleTrackTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import AVFoundation
import Foundation
import Testing

@testable import HaishinKit
Expand Down Expand Up @@ -110,4 +110,3 @@ import Testing
#expect(inputFormats[0]?.sampleRate == 48000)
}
}

91 changes: 45 additions & 46 deletions Tests/Mixer/AudioMixerTrackTests.swift
Original file line number Diff line number Diff line change
@@ -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<AudioMixerTrackTests>(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<AudioMixerTrackTests>(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<AudioMixerTrackTests>(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<AudioMixerTrackTests>(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<AudioMixerTrackTests>(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<AudioMixerTrackTests>(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<AudioMixerTrackTests>(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<AudioMixerTrackTests>(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<AudioMixerTrackTests>(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<AudioMixerTrackTests>(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)!)
}
*/
}

Loading

0 comments on commit 5c1e931

Please sign in to comment.