/* * Copyright 2017, gRPC Authors All rights reserved. * * 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 XCTest import Foundation import Dispatch @testable import gRPC func Log(_ message : String) { FileHandle.standardError.write((message + "\n").data(using:.utf8)!) } class gRPCTests: XCTestCase { func testBasicSanity() { gRPC.initialize() let latch = CountDownLatch(2) DispatchQueue.global().async() { do { try server() } catch (let error) { XCTFail("server error \(error)") } latch.signal() } DispatchQueue.global().async() { do { try client() } catch (let error) { XCTFail("client error \(error)") } latch.signal() } latch.wait() } } extension gRPCTests { static var allTests : [(String, (gRPCTests) -> () throws -> Void)] { return [ ("testBasicSanity", testBasicSanity), ] } } let address = "localhost:8999" let host = "foo.test.google.fr" let clientText = "hello, server!" let serverText = "hello, client!" let initialClientMetadata = ["x": "xylophone", "y": "yu", "z": "zither"] let initialServerMetadata = ["a": "Apple", "b": "Banana", "c": "Cherry"] let trailingServerMetadata = ["0": "zero", "1": "one", "2": "two"] let steps = 30 let hello = "/hello" let goodbye = "/goodbye" let statusCode = 0 let statusMessage = "OK" func verify_metadata(_ metadata: Metadata, expected: [String:String]) { XCTAssertGreaterThanOrEqual(metadata.count(), expected.count) for i in 0..