Correctly try to unwrap InboundIn

This commit is contained in:
Cory Benfield committed 2017-09-13 08:26:07 +01:00
1 parent 251e63e82b
commit 0c3d04580b
3 files changed
+18 -1

No files matched your search

+1 -1
View File
@@ -46,7 +46,7 @@ public extension ChannelInboundHandler {
}
func tryUnwrapInboundIn(_ value: IOData) -> InboundIn? {
return value.forceAs()
return value.tryAs()
}
func wrapInboundOut(_ value: InboundOut) -> IOData {
@@ -26,6 +26,7 @@ extension TypeAssistedChannelHandlerTest {
static var allTests : [(String, (TypeAssistedChannelHandlerTest) -> () throws -> Void)] {
return [
("testOptionalInboundIn", testOptionalInboundIn),
("testCanDefineBothInboundAndOutbound", testCanDefineBothInboundAndOutbound),
]
}
@@ -17,6 +17,22 @@ import XCTest
@testable import NIO
class TypeAssistedChannelHandlerTest: XCTestCase {
func testOptionalInboundIn() throws {
class TestClass: ChannelInboundHandler {
public typealias InboundIn = String
func canUnwrap(_ data: IOData) -> Bool {
return tryUnwrapInboundIn(data) != nil
}
}
let c = TestClass()
let goodIOData = IOData("Hello, world!")
let badIOData = IOData(42)
XCTAssertTrue(c.canUnwrap(goodIOData))
XCTAssertFalse(c.canUnwrap(badIOData))
}
func testCanDefineBothInboundAndOutbound() throws {
class TestClass: ChannelInboundHandler, ChannelOutboundHandler {
public typealias OutboundIn = ByteBuffer