2018-05-23 11:03:39 +00:00
|
|
|
# Asyncdispatch2 Test Suite
|
|
|
|
# (c) Copyright 2018
|
|
|
|
# Status Research & Development GmbH
|
|
|
|
#
|
|
|
|
# Licensed under either of
|
|
|
|
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
|
|
|
# MIT license (LICENSE-MIT)
|
|
|
|
|
|
|
|
import strutils, unittest
|
2018-06-04 09:57:17 +00:00
|
|
|
import ../asyncdispatch2
|
2018-05-23 11:03:39 +00:00
|
|
|
|
2018-06-04 09:57:17 +00:00
|
|
|
proc serveStreamClient(server: StreamServer,
|
|
|
|
transp: StreamTransport, udata: pointer) {.async.} =
|
|
|
|
discard
|
2018-05-23 11:03:39 +00:00
|
|
|
|
2018-06-04 09:57:17 +00:00
|
|
|
proc serveDatagramClient(transp: DatagramTransport,
|
|
|
|
pbytes: pointer, nbytes: int,
|
|
|
|
raddr: TransportAddress,
|
|
|
|
udata: pointer): Future[void] {.async.} =
|
|
|
|
discard
|
2018-05-23 11:03:39 +00:00
|
|
|
|
2018-06-04 09:57:17 +00:00
|
|
|
proc test1(): bool =
|
|
|
|
var ta = initTAddress("127.0.0.1:31354")
|
|
|
|
var server1 = createStreamServer(ta, serveStreamClient, {ReuseAddr})
|
|
|
|
server1.start()
|
|
|
|
server1.stop()
|
|
|
|
server1.close()
|
|
|
|
var server2 = createStreamServer(ta, serveStreamClient, {ReuseAddr})
|
|
|
|
server2.start()
|
|
|
|
server2.stop()
|
|
|
|
server2.close()
|
|
|
|
result = true
|
2018-05-23 11:03:39 +00:00
|
|
|
|
2018-06-04 09:57:17 +00:00
|
|
|
proc test2(): bool =
|
2018-06-02 14:30:36 +00:00
|
|
|
var ta = initTAddress("127.0.0.1:31354")
|
2018-06-04 09:57:17 +00:00
|
|
|
var server1 = createDatagramServer(ta, serveDatagramClient, {ReuseAddr})
|
|
|
|
server1.start()
|
|
|
|
server1.stop()
|
|
|
|
server1.close()
|
|
|
|
var server2 = createDatagramServer(ta, serveDatagramClient, {ReuseAddr})
|
|
|
|
server2.start()
|
|
|
|
server2.stop()
|
|
|
|
server2.close()
|
|
|
|
result = true
|
2018-05-23 11:03:39 +00:00
|
|
|
|
|
|
|
when isMainModule:
|
2018-06-02 14:30:36 +00:00
|
|
|
suite "Server's test suite":
|
2018-06-04 09:57:17 +00:00
|
|
|
test "Stream Server start/stop test":
|
|
|
|
check test1() == true
|
|
|
|
test "Datagram Server start/stop test":
|
|
|
|
check test2() == true
|