Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions IntegrationTests/AnyPublisher+Test.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// Copyright (c) 2023 gematik GmbH
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Combine
import Foundation

extension AnyPublisher {
/// Convenience function for testing a Publisher's emitted values
func test() throws -> Self.Output {
try testWithTimeout(timeout: 0)
}

/// Convenience function for testing a Publisher's emitted values
func testWithTimeout(timeout millis: Int = 3000, sleep interval: TimeInterval = 0.1) throws -> Self.Output {
var done = false
var output: Self.Output?
var error: Self.Failure?
let timeoutTime = DispatchTime.now() + DispatchTimeInterval.milliseconds(millis)
let cancellable = sink(
receiveCompletion: { completion in
switch completion {
case .finished: done = true
case let .failure(failure):
error = failure
done = true
}
},
receiveValue: { receivedValue in
output = receivedValue
}
)

while !done && (timeoutTime > DispatchTime.now() || millis <= 0) {
RunLoop.current.run(mode: .default, before: Date(timeIntervalSinceNow: interval))
}
if !done {
cancellable.cancel()
throw AnyPublisherTestError.timeoutError
}

if let output = output {
return output
} else if let error = error {
throw error
} else {
throw AnyPublisherTestError.noValuesPublished
}
}
}

enum AnyPublisherTestError: Error {
case noValuesPublished
case timeoutError
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

final class AuthenticateChallengeE256Test: CardSimulationTerminalTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

final class AuthenticateChallengeR2048Test: CardSimulationTerminalTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

final class CardChannelTypeExtVersionIntegrationTest: CardSimulationTerminalTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

final class DetermineCardAidIntegrationTest: CardSimulationTerminalTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

final class HealthCardTypeExtChangeReferenceDataIntegrationTest: CardSimulationTerminalTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

// Note: This continuation of `HealthCardTypeExtChangeReferenceDataIntegrationTest` exists to separate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

final class HealthCardTypeExtESIGNIntegrationTest: CardSimulationTerminalTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import CardReaderProviderApi
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

final class HealthCardTypeExtEfCardAccessIntTest: CardSimulationTerminalTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

final class HealthCardTypeExtResetRetryCounterIntegrationTest: CardSimulationTerminalTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

// Note: This continuation of `HealthCardTypeExtResetRetryCounterIntegrationTest` exists to separate the count dependent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

// Note: This continuation of `HealthCardTypeExtResetRetryCounterIntegrationTest` exists to separate the count dependent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

final class HealthCardTypeExtVerifyPinTest: CardSimulationTerminalTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

final class KeyAgreementIntegrationTest: CardSimulationTerminalTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Foundation
import HealthCardAccess
@testable import HealthCardControl
import Nimble
import Util
import XCTest

final class OpenSecureSessionIntegrationTest: CardSimulationTerminalTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import HealthCardAccess
@testable import HealthCardControl
import Nimble
import OSLog
import Util
import XCTest

final class ReadAutCertificateE256Test: CardSimulationTerminalTestCase {
Expand Down
32 changes: 21 additions & 11 deletions IntegrationTests/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ targets:
sources:
- path: IntegrationTests
dependencies:
- target: CardReaderAccess_macOS
- target: CardReaderProviderApi_macOS
- target: HealthCardAccess_macOS
- target: HealthCardControl_macOS
- target: Util_macOS
- framework: Carthage/Build/Nimble.xcframework
- package: Openhealthcardkit
product: CardReaderAccess
- package: Openhealthcardkit
product: CardReaderProviderApi
- package: Openhealthcardkit
product: HealthCardAccess
- package: Openhealthcardkit
product: HealthCardControl
- package: Nimble
- target: CardSimulationCardReaderProvider
- target: CardSimulationLoader
- package: AEXML
Expand Down Expand Up @@ -123,8 +126,10 @@ targets:
dependencies:
- target: CardSimulationLoader
- package: ASN1Kit
- target: CardReaderProviderApi_macOS
- target: CardReaderAccess_macOS
- package: Openhealthcardkit
product: CardReaderProviderApi
- package: Openhealthcardkit
product: CardReaderAccess
- framework: Carthage/Build/SwiftSocket.xcframework
transitivelyLinkDependencies: true
CardSimulationLoaderTests:
Expand All @@ -140,18 +145,21 @@ targets:
- package: AEXML
- target: AEXMLExt
- target: CardSimulationLoader
- framework: Carthage/Build/Nimble.xcframework
- package: Nimble
gatherCoverageData: true
AEXMLExtTests:
type: bundle.unit-test
platform: macOS
bundleIdPrefix: de.gematik.ti.openhealthcard.cardsimulation
settings:
base:
OTHER_SWIFT_FLAGS: -no-verify-emitted-module-interface
sources:
- CardSimulationTestKit/Tests/AEXMLExtTests
dependencies:
- target: AEXMLExt
- package: AEXML
- framework: Carthage/Build/Nimble.xcframework
- package: Nimble
gatherCoverageData: true
CardSimulationCardReaderProviderTests:
type: bundle.unit-test
Expand All @@ -165,5 +173,7 @@ targets:
dependencies:
- target: CardSimulationCardReaderProvider
- target: AEXMLExt
- framework: Carthage/Build/Nimble.xcframework
- package: Openhealthcardkit
product: CardReaderAccess
- package: Nimble
gatherCoverageData: true
2 changes: 1 addition & 1 deletion Mintfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
realm/SwiftLint@0.44.0
yonaskolb/xcodegen@2.38.0
yonaskolb/xcodegen@2.42.0
Carthage/Carthage@0.40.0
nicklockwood/SwiftFormat@0.48.7
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 31 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,19 @@ let package = Package(
.macOS(.v12)
],
products: [
.library(
name: "HealthCardControl",
targets: ["HealthCardControl"]),
.library(
name: "NFCCardReaderProvider",
targets: ["NFCCardReaderProvider"]),
.library(
name: "HealthCardAccess",
targets: ["HealthCardAccess"]),
.library(
name: "CardReaderProviderApi",
targets: ["CardReaderProviderApi"]),
.library(
name: "Helper",
targets: ["Helper"]),
.library(name: "HealthCardControl", targets: ["HealthCardControl"]),
.library(name: "NFCCardReaderProvider", targets: ["NFCCardReaderProvider"]),
.library(name: "HealthCardAccess", targets: ["HealthCardAccess"]),
.library(name: "CardReaderProviderApi", targets: ["CardReaderProviderApi"]),
.library(name: "Helper", targets: ["Helper"]),
// TODO: Remove this (and the .target) at a later time. For now it's only needed for the CardSimulationTests
.library(name: "CardReaderAccess", targets: ["CardReaderAccess"]),
],
dependencies: [
.package(url: "https://github.com/gematik/ASN1Kit.git", from: "1.2.0"),
.package(url: "https://github.com/gematik/OpenSSL-Swift", from: "4.2.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
.package(url: "https://github.com/Quick/Nimble", from: "12.0.0"),
],
targets: [
.target(
Expand All @@ -49,7 +42,7 @@ let package = Package(
),
.target(
name: "HealthCardAccess",
dependencies: ["CardReaderAccess", "CardReaderProviderApi", "ASN1Kit"]
dependencies: ["CardReaderProviderApi", "ASN1Kit"]
),
.target(
name: "CardReaderAccess",
Expand All @@ -62,5 +55,27 @@ let package = Package(
.target(
name: "Helper"
),
.testTarget(
name: "HealthCardControlTests",
dependencies: ["HealthCardControl", "Nimble"],
resources: [
.process("Resources.bundle")
]
),
.testTarget(
name: "HealthCardAccessTests",
dependencies: ["HealthCardAccess", "Nimble"],
resources: [
.process("Resources.bundle")
]
),
.testTarget(
name: "CardReaderAccessTests",
dependencies: ["CardReaderAccess", "Nimble"]
),
.testTarget(
name: "CardReaderProviderApiTests",
dependencies: ["CardReaderProviderApi", "Nimble"]
),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ extension NFCTagReaderSession.Publisher {
}
}

#endif

@propertyWrapper
struct Synchronized<T> {
private let backing: SynchronizedVar<T>
Expand Down Expand Up @@ -333,3 +331,4 @@ class SynchronizedVar<T> {
mutex.unlock()
}
}
#endif
Loading