-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.0.3] Added unit tests for DelegatesManager and PermissionsManager …
…and did some small improvements
- Loading branch information
Showing
8 changed files
with
222 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// DelegatesManager.swift | ||
// | ||
// | ||
// Created by Lobont Andrei on 29.05.2023. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol DelegatesManagerProtocol { | ||
var delegates: NSHashTable<AnyObject> { get } | ||
|
||
func registerDelegate(_ delegate: CameraKageDelegate) | ||
func unregisterDelegate(_ delegate: CameraKageDelegate) | ||
func invokeDelegates(_ execute: (CameraKageDelegate) -> Void) | ||
} | ||
|
||
final class DelegatesManager: DelegatesManagerProtocol { | ||
let delegates: NSHashTable<AnyObject> = NSHashTable.weakObjects() | ||
|
||
func registerDelegate(_ delegate: CameraKageDelegate) { | ||
delegates.add(delegate as AnyObject) | ||
} | ||
|
||
func unregisterDelegate(_ delegate: CameraKageDelegate) { | ||
delegates.remove(delegate as AnyObject) | ||
} | ||
|
||
func invokeDelegates(_ execute: (CameraKageDelegate) -> Void) { | ||
delegates.allObjects.forEach { delegate in | ||
guard let delegate = delegate as? CameraKageDelegate else { return } | ||
execute(delegate) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Lobont Andrei on 29.05.2023. | ||
// | ||
|
||
import Foundation | ||
@testable import CameraKage | ||
|
||
final class CameraKageDelegateMock: CameraKageDelegate { | ||
var invoked = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// DelegatesManagerMock.swift | ||
// | ||
// | ||
// Created by Lobont Andrei on 29.05.2023. | ||
// | ||
|
||
import Foundation | ||
@testable import CameraKage | ||
|
||
final class DelegatesManagerMock: DelegatesManagerProtocol { | ||
var delegates: NSHashTable<AnyObject> = NSHashTable.weakObjects() | ||
|
||
func registerDelegate(_ delegate: CameraKageDelegate) { | ||
delegates.add(delegate as AnyObject) | ||
} | ||
|
||
func unregisterDelegate(_ delegate: CameraKageDelegate) { | ||
delegates.remove(delegate as AnyObject) | ||
} | ||
|
||
func invokeDelegates(_ execute: (CameraKageDelegate) -> Void) { | ||
delegates.allObjects.forEach { delegate in | ||
guard let delegate = delegate as? CameraKageDelegateMock else { return } | ||
delegate.invoked = true | ||
execute(delegate) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Lobont Andrei on 29.05.2023. | ||
// | ||
|
||
import AVFoundation | ||
@testable import CameraKage | ||
|
||
class PermissionManagerMock: PermissionsManagerProtocol { | ||
private var authorizedVideo = false | ||
private var authorizedAudio = false | ||
|
||
func getAuthorizationStatus(for media: AVMediaType) -> PermissionStatus { | ||
switch media { | ||
case .audio: return authorizedAudio ? .authorized : .denied | ||
case .video: return authorizedVideo ? .authorized : .denied | ||
default: return .notDetermined // not using other media type yet | ||
} | ||
} | ||
|
||
func requestAccess(for media: AVMediaType) async -> Bool { | ||
switch media { | ||
case .audio: | ||
authorizedAudio = true | ||
return authorizedAudio | ||
case .video: | ||
authorizedVideo = true | ||
return authorizedVideo | ||
default: | ||
return false // not using other media type yet | ||
} | ||
} | ||
|
||
func requestAccess(for media: AVMediaType, completion: @escaping ((Bool) -> Void)) { | ||
switch media { | ||
case .audio: | ||
authorizedAudio = true | ||
completion(authorizedAudio) | ||
case .video: | ||
authorizedVideo = true | ||
completion(authorizedVideo) | ||
default: | ||
break // not using other media type yet | ||
} | ||
} | ||
} |