|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the swift-libgit2 open source project. |
| 4 | +// |
| 5 | +// Copyright (c) Margins Technologies LLC. |
| 6 | +// Licensed under the Apache License, Version 2.0. |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +import CLibgit2 |
| 11 | +import XCTest |
| 12 | +@testable import SwiftLibgit2 |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +final class StreamAdvancedTests: XCTestCaseStopOnFail |
| 17 | +{ |
| 18 | + func testGitStreamCB() throws |
| 19 | + { |
| 20 | + let streamCB: GitStreamCB = |
| 21 | + { |
| 22 | + _, _, _ in |
| 23 | + |
| 24 | + return GitErrorCode.gitOK.rawValue |
| 25 | + } |
| 26 | + |
| 27 | + let streamCBResult: Int32 = streamCB( |
| 28 | + nil, |
| 29 | + nil, |
| 30 | + nil |
| 31 | + ) |
| 32 | + |
| 33 | + XCTAssertOK(GitErrorCode(rawValue: streamCBResult)) |
| 34 | + } |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + func testGitStreamRegister() throws |
| 39 | + { |
| 40 | + let initialize: GitStreamRegistration.Initialize = |
| 41 | + { |
| 42 | + _, _, _ in |
| 43 | + |
| 44 | + return GitErrorCode.gitOK.rawValue |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + let wrap: GitStreamRegistration.Wrap = |
| 50 | + { |
| 51 | + _, _, _ in |
| 52 | + |
| 53 | + return GitErrorCode.gitOK.rawValue |
| 54 | + } |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + var streamRegistration = git_stream_registration() |
| 59 | + |
| 60 | + streamRegistration.version = gitStreamVersion |
| 61 | + streamRegistration.`init` = initialize |
| 62 | + streamRegistration.wrap = wrap |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + var streamRegisterResult: GitErrorCode = gitStreamRegister( |
| 67 | + type: .gitStreamStandard, |
| 68 | + registration: &streamRegistration |
| 69 | + ) |
| 70 | + |
| 71 | + XCTAssertOK(streamRegisterResult) |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + streamRegisterResult = gitStreamRegister( |
| 76 | + type: .gitStreamTLS, |
| 77 | + registration: &streamRegistration |
| 78 | + ) |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + for _ in 0..<2 |
| 83 | + { |
| 84 | + streamRegisterResult = gitStreamRegister( |
| 85 | + type: .gitStreamStandard, |
| 86 | + registration: nil |
| 87 | + ) |
| 88 | + |
| 89 | + XCTAssertOK(streamRegisterResult) |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + streamRegisterResult = gitStreamRegister( |
| 94 | + type: .gitStreamTLS, |
| 95 | + registration: nil |
| 96 | + ) |
| 97 | + |
| 98 | + XCTAssertOK(streamRegisterResult) |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + func testGitStreamRegisterTLS() throws |
| 105 | + { |
| 106 | + let streamCB: GitStreamCB = |
| 107 | + { |
| 108 | + _, _, _ in |
| 109 | + |
| 110 | + return GitErrorCode.gitOK.rawValue |
| 111 | + } |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + var streamRegisterTLSResult: GitErrorCode |
| 116 | + = gitStreamRegisterTLS(ctor: streamCB) |
| 117 | + |
| 118 | + XCTAssertOK(streamRegisterTLSResult) |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + for _ in 0..<2 |
| 123 | + { |
| 124 | + streamRegisterTLSResult = gitStreamRegisterTLS(ctor: nil) |
| 125 | + |
| 126 | + XCTAssertOK(streamRegisterTLSResult) |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + func testGitStreamT() throws |
| 133 | + { |
| 134 | + XCTAssertEqual(GitStreamT.gitStreamStandard.rawValue, GIT_STREAM_STANDARD.rawValue) |
| 135 | + XCTAssertEqual(GitStreamT.gitStreamTLS.rawValue, GIT_STREAM_TLS.rawValue) |
| 136 | + |
| 137 | + XCTAssertNil(GitStreamT(rawValue: 123)) |
| 138 | + |
| 139 | + XCTAssertEqual(GitStreamT.gitStreamStandard.cValue(), GIT_STREAM_STANDARD) |
| 140 | + XCTAssertEqual(GitStreamT.gitStreamTLS.cValue(), GIT_STREAM_TLS) |
| 141 | + |
| 142 | + XCTAssertEqual(GitStreamT(cValue: GIT_STREAM_STANDARD), .gitStreamStandard) |
| 143 | + XCTAssertEqual(GitStreamT(cValue: GIT_STREAM_TLS), .gitStreamTLS) |
| 144 | + } |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | + func testGitStreamVersion() throws |
| 149 | + { |
| 150 | + XCTAssertEqual(gitStreamVersion, GIT_STREAM_VERSION) |
| 151 | + } |
| 152 | +} |
0 commit comments