Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Threema/ThreemaFrameworkTests/   (Social Medium ©)  Datei vom 26.9.2026 mit Größe 1 kB image not shown  

Quelle  URLProtocolMocks.swift   Sprache: JAVA

 

import Foundation
@testable import ThreemaFramework

final class URLProtocolMock: URLProtocol {
    
    enum URLProtocolMockError: Error {
        case noURL
        case noMockResponse
    }
    
    typealias MockURLResponse = (
        error: Error?,
        data: Data?,
        response: HTTPURLResponse?,
        challenges: [URLAuthenticationChallenge]?
    )
    typealias RequestCompletedCallback = () -> Void
    
    static var requests = [URL: URLRequest]()
    static var mockResponses = [URL: (MockURLResponse, RequestCompletedCallback?)]()
    
    // MARK: - URLProtocol
    
    override class func canInit(with request: URLRequest) -> Bool {
        true
    }

    override class func canonicalRequest(for request: URLRequest) -> URLRequest {
        request
    }

    override func startLoading() {
        guard let url = request.url else {
            client?.urlProtocol(self, didFailWithError: URLProtocolMockError.noURL)
            return
        }
        
        URLProtocolMock.requests[url] = request
        
        guard let ((error, data, response, challenges), completion) = URLProtocolMock.mockResponses[url] else {
            client?.urlProtocol(self, didFailWithError: URLProtocolMockError.noMockResponse)
            return
        }

        if let errorStrong = error {
            client?.urlProtocol(self, didFailWithError: errorStrong)
        }
        
        if let responseStrong = response {
            client?.urlProtocol(self, didReceive: responseStrong, cacheStoragePolicy: .notAllowed)
        }
        
        if let dataStrong = data {
            client?.urlProtocol(self, didLoad: dataStrong)
        }

        if let challenges {
            for challenge in challenges {
                client?.urlProtocol(self, didReceive: challenge)
            }
        }

        client?.urlProtocolDidFinishLoading(self)
        completion?()
    }

    override func stopLoading() {
        // Required by the superclass.
    }
}

Messung
CHZG
909810096

¤ Dauer der Verarbeitung: 0.0 Sekunden  (vorverarbeitet am  2026-11-04) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.