Skip to content

Commit

Permalink
Add/Update tests III
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis committed Dec 20, 2024
1 parent 2079691 commit 8a2a853
Show file tree
Hide file tree
Showing 9 changed files with 1,885 additions and 1,660 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import StreamWebRTC

final class StreamCaptureDeviceProvider {

private let firstResultIfMiss: Bool
private let useFallback: Bool

private var devices: [AVCaptureDevice] {
RTCCameraVideoCapturer.captureDevices()
}

init(firstResultIfMiss: Bool = true) {
self.firstResultIfMiss = firstResultIfMiss
init(useFallback: Bool = true) {
self.useFallback = useFallback
}

func device(for position: AVCaptureDevice.Position) -> AVCaptureDevice? {
if let deviceFound = devices.first(where: { $0.position == position }) {
return deviceFound
} else if firstResultIfMiss {
} else if useFallback {
return devices.first
} else {
return nil
Expand Down
28 changes: 28 additions & 0 deletions StreamVideo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@
40B48C402D14DB26002C4EAB /* MediaTransceiverStorage_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B48C3F2D14DB26002C4EAB /* MediaTransceiverStorage_Tests.swift */; };
40B48C472D14E803002C4EAB /* StreamVideoCapturing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B48C462D14E803002C4EAB /* StreamVideoCapturing.swift */; };
40B48C492D14E822002C4EAB /* MockStreamVideoCapturer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B48C482D14E822002C4EAB /* MockStreamVideoCapturer.swift */; };
40B48C4C2D14F721002C4EAB /* RTPMapVisitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B48C4B2D14F721002C4EAB /* RTPMapVisitorTests.swift */; };
40B48C4F2D14F77B002C4EAB /* SupportedPrefix_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B48C4E2D14F77B002C4EAB /* SupportedPrefix_Tests.swift */; };
40B48C512D14F7AE002C4EAB /* SDPParser_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B48C502D14F7AE002C4EAB /* SDPParser_Tests.swift */; };
40B499CA2AC1A5E100A53B60 /* OSLogDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B499C92AC1A5E100A53B60 /* OSLogDestination.swift */; };
40B499CC2AC1A90F00A53B60 /* DeeplinkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B499CB2AC1A90F00A53B60 /* DeeplinkTests.swift */; };
40B499CE2AC1AA0900A53B60 /* AppEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4030E59F2A9DF5BD003E8CBA /* AppEnvironment.swift */; };
Expand Down Expand Up @@ -1803,6 +1806,9 @@
40B48C3F2D14DB26002C4EAB /* MediaTransceiverStorage_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaTransceiverStorage_Tests.swift; sourceTree = "<group>"; };
40B48C462D14E803002C4EAB /* StreamVideoCapturing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamVideoCapturing.swift; sourceTree = "<group>"; };
40B48C482D14E822002C4EAB /* MockStreamVideoCapturer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStreamVideoCapturer.swift; sourceTree = "<group>"; };
40B48C4B2D14F721002C4EAB /* RTPMapVisitorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RTPMapVisitorTests.swift; sourceTree = "<group>"; };
40B48C4E2D14F77B002C4EAB /* SupportedPrefix_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportedPrefix_Tests.swift; sourceTree = "<group>"; };
40B48C502D14F7AE002C4EAB /* SDPParser_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDPParser_Tests.swift; sourceTree = "<group>"; };
40B499C92AC1A5E100A53B60 /* OSLogDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSLogDestination.swift; sourceTree = "<group>"; };
40B499CB2AC1A90F00A53B60 /* DeeplinkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeeplinkTests.swift; sourceTree = "<group>"; };
40BBC4762C6227D5002AEF92 /* DemoTranscriptionButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoTranscriptionButtonView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3367,6 +3373,7 @@
406B3C072C8F602D00FC93A1 /* v2 */ = {
isa = PBXGroup;
children = (
40B48C4A2D14F718002C4EAB /* SDP Parsing */,
4029E9582CB9445D00E1D571 /* Extensions */,
408CF9C12CAE885800F56833 /* IntegrationTests */,
40C9E4632C99886200802B28 /* WebRTCCoorindator_Tests.swift */,
Expand Down Expand Up @@ -3894,6 +3901,24 @@
path = Utilities;
sourceTree = "<group>";
};
40B48C4A2D14F718002C4EAB /* SDP Parsing */ = {
isa = PBXGroup;
children = (
40B48C4D2D14F76A002C4EAB /* Visitors */,
40B48C502D14F7AE002C4EAB /* SDPParser_Tests.swift */,
40B48C4E2D14F77B002C4EAB /* SupportedPrefix_Tests.swift */,
);
path = "SDP Parsing";
sourceTree = "<group>";
};
40B48C4D2D14F76A002C4EAB /* Visitors */ = {
isa = PBXGroup;
children = (
40B48C4B2D14F721002C4EAB /* RTPMapVisitorTests.swift */,
);
path = Visitors;
sourceTree = "<group>";
};
40BBC47A2C6227DF002AEF92 /* Extensions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -7158,6 +7183,7 @@
4067F3192CDA469F002E28BD /* MockAudioSession.swift in Sources */,
40AB34C92C5D3F2E00B5B6B3 /* ParticipantsStats+Dummy.swift in Sources */,
84F58B7629EE92BF00010C4C /* UniqueValues.swift in Sources */,
40B48C512D14F7AE002C4EAB /* SDPParser_Tests.swift in Sources */,
84F58B9529EEBA3900010C4C /* EquatableEvent.swift in Sources */,
40A0E9682B88E04D0089E8D3 /* CIImage_Resize_Tests.swift in Sources */,
40C9E4572C98B06E00802B28 /* WebRTCConfiguration_Tests.swift in Sources */,
Expand Down Expand Up @@ -7210,6 +7236,7 @@
406B3C532C92007900FC93A1 /* WebRTCCoordinatorStateMachine_ConnectedStageTests.swift in Sources */,
40B48C172D14C97F002C4EAB /* CGSize_DefaultValuesTests.swift in Sources */,
40B48C342D14D3E6002C4EAB /* StreamVideoSfuSignalTrackSubscriptionDetails_ConvenienceTests.swift in Sources */,
40B48C4F2D14F77B002C4EAB /* SupportedPrefix_Tests.swift in Sources */,
84F58B8129EE9C4900010C4C /* WebSocketPingController_Delegate.swift in Sources */,
40AB34D02C5D443F00B5B6B3 /* MockWebSocketEngine.swift in Sources */,
40B48C322D14D361002C4EAB /* StreamVideoSfuModelsVideoLayer_ConvenienceTests.swift in Sources */,
Expand Down Expand Up @@ -7270,6 +7297,7 @@
84DC44982BA3ACC70050290C /* CallStatsReporting_Tests.swift in Sources */,
84F58B7229EE922700010C4C /* WebSocketConnectionState_Tests.swift in Sources */,
40FE5EBD2C9C82A6006B0881 /* MockRTCVideoCapturerDelegate.swift in Sources */,
40B48C4C2D14F721002C4EAB /* RTPMapVisitorTests.swift in Sources */,
40B48C152D14C93B002C4EAB /* CGSize_AdaptTests.swift in Sources */,
40382F3D2C89C11D00C2D00F /* MockRTCPeerConnectionCoordinatorFactory.swift in Sources */,
40AB31262A49838000C270E1 /* EventTests.swift in Sources */,
Expand Down
24 changes: 24 additions & 0 deletions StreamVideoTests/WebRTC/SFU/SFUEventAdapter_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,30 @@ final class SFUEventAdapter_Tests: XCTestCase, @unchecked Sendable {
}
}

// MARK: publishOptionsChanged

func test_handleChangePublishOptions_givenEvent_whenPublished_thenUpdatesPublishOptions() async throws {
try await stateAdapter.configurePeerConnections()
let publisher = await stateAdapter.publisher

let participantA = CallParticipant.dummy()
let participantB = CallParticipant.dummy()
var event = Stream_Video_Sfu_Event_ChangePublishOptions()
var option = Stream_Video_Sfu_Models_PublishOption()
option.bitrate = 100
option.codec = .dummy(name: "av1")
option.trackType = .video
event.publishOptions = [option]
event.reason = .unique
let expected = PublishOptions(event.publishOptions)

try await assert(
event,
wrappedEvent: .sfuEvent(.changePublishOptions(event)),
initialState: [participantA, participantB].reduce(into: [String: CallParticipant]()) { $0[$1.sessionId] = $1 }
) { _ in await self.stateAdapter.publishOptions == expected }
}

// MARK: - Private helpers

private func assert<T>(
Expand Down
57 changes: 57 additions & 0 deletions StreamVideoTests/WebRTC/v2/SDP Parsing/SDPParser_Tests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Copyright © 2024 Stream.io Inc. All rights reserved.
//

@testable import StreamVideo
import XCTest

final class SDPParser_Tests: XCTestCase {

private var visitor: RTPMapVisitor! = .init()
private var subject: SDPParser! = .init()

override func setUp() {
super.setUp()
subject.registerVisitor(visitor)
}

override func tearDown() {
subject = nil
visitor = nil
super.tearDown()
}

// MARK: - parse(sdp:)

func test_parse_withValidSDP() async {
let sdp = "v=0\r\no=- 46117317 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=rtpmap:96 opus/48000/2\r\na=rtpmap:97 VP8/90000\r\n"
await subject.parse(sdp: sdp)
XCTAssertEqual(visitor.payloadType(for: "opus"), 96)
XCTAssertEqual(visitor.payloadType(for: "vp8"), 97)
}

func test_parse_withInvalidSDP() async {
let sdp = """
v=0
o=- 46117317 2 IN IP4 127.0.0.1
s=-
t=0 0
a=invalid:96 opus/48000/2
"""
await subject.parse(sdp: sdp)
XCTAssertNil(visitor.payloadType(for: "opus"))
}

func test_parse_withMultipleVisitors() async {
let sdp = "v=0\r\no=- 46117317 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=rtpmap:96 opus/48000/2\r\na=rtpmap:97 VP8/90000\r\n"
let visitor1 = RTPMapVisitor()
let visitor2 = RTPMapVisitor()
subject.registerVisitor(visitor1)
subject.registerVisitor(visitor2)
await subject.parse(sdp: sdp)
XCTAssertEqual(visitor1.payloadType(for: "opus"), 96)
XCTAssertEqual(visitor1.payloadType(for: "vp8"), 97)
XCTAssertEqual(visitor2.payloadType(for: "opus"), 96)
XCTAssertEqual(visitor2.payloadType(for: "vp8"), 97)
}
}
22 changes: 22 additions & 0 deletions StreamVideoTests/WebRTC/v2/SDP Parsing/SupportedPrefix_Tests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Copyright © 2024 Stream.io Inc. All rights reserved.
//

@testable import StreamVideo
import XCTest

final class SupportedPrefix_Tests: XCTestCase {

// MARK: - SupportedPrefix Cases

func test_supportedPrefixCases() {
XCTAssertEqual(SupportedPrefix.rtmap.rawValue, "a=rtpmap:")
}

// MARK: - SupportedPrefix Set

func test_supportedPrefixSetContainsRtmap() {
let supportedPrefixes: Set<SupportedPrefix> = [.rtmap]
XCTAssertTrue(supportedPrefixes.contains(.rtmap))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Copyright © 2024 Stream.io Inc. All rights reserved.
//

@testable import StreamVideo
import XCTest

final class RTPMapVisitor_Tests: XCTestCase {

private var subject: RTPMapVisitor! = .init()

override func tearDown() {
subject = nil
super.tearDown()
}

// MARK: - visit(line:)

func test_visit_withValidRTPMapLine() {
let line = "a=rtpmap:96 opus/48000/2"
subject.visit(line: line)
XCTAssertEqual(subject.payloadType(for: "opus"), 96)
}

func test_visit_withInvalidRTPMapLine() {
let line = "a=rtpmap:invalid opus/48000/2"
subject.visit(line: line)
XCTAssertNil(subject.payloadType(for: "opus"))
}

func test_visit_withMissingCodecName() {
let line = "a=rtpmap:96"
subject.visit(line: line)
XCTAssertNil(subject.payloadType(for: ""))
}

func test_visit_withMultipleRTPMapLines() {
let lines = [
"a=rtpmap:96 opus/48000/2",
"a=rtpmap:97 VP8/90000",
"a=rtpmap:98 H264/90000"
]
lines.forEach { subject.visit(line: $0) }
XCTAssertEqual(subject.payloadType(for: "opus"), 96)
XCTAssertEqual(subject.payloadType(for: "vp8"), 97)
XCTAssertEqual(subject.payloadType(for: "h264"), 98)
}

// MARK: - payloadType(for:)

func test_payloadType_forExistingCodec() {
let line = "a=rtpmap:96 opus/48000/2"
subject.visit(line: line)
XCTAssertEqual(subject.payloadType(for: "opus"), 96)
}

func test_payloadType_forNonExistingCodec() {
XCTAssertNil(subject.payloadType(for: "nonexistent"))
}
}
Loading

0 comments on commit 8a2a853

Please sign in to comment.