diff options
author | Yuriy Glukhov <yuriy.glukhov@gmail.com> | 2018-03-15 15:44:12 +0200 |
---|---|---|
committer | Yuriy Glukhov <yuriy.glukhov@gmail.com> | 2018-03-15 15:49:41 +0200 |
commit | 1bd0efb067b7c1939f4d68c9014b7d67cb4e7020 (patch) | |
tree | de19132fa3bbcc961e9c3ea1ecb2d448ce949afb /tests | |
parent | 29bb10b1854206015ad411f5b77c8fcd8aa90024 (diff) | |
download | Nim-1bd0efb067b7c1939f4d68c9014b7d67cb4e7020.tar.gz |
Fixed crash/interface. Added tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stdlib/tnet.nim | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/tests/stdlib/tnet.nim b/tests/stdlib/tnet.nim index e8ada05e7..64d690fc9 100644 --- a/tests/stdlib/tnet.nim +++ b/tests/stdlib/tnet.nim @@ -1,4 +1,4 @@ -import net +import net, nativesockets import unittest suite "isIpAddress tests": @@ -45,3 +45,33 @@ suite "parseIpAddress tests": test "invalid ipv6": expect(ValueError): discard parseIpAddress("gggg:cdba:0000:0000:0000:0000:3257:9652") + +block: # "IpAddress/Sockaddr conversion" + proc test(ipaddrstr: string) = + var ipaddr_1 = parseIpAddress(ipaddrstr) + # echo ipaddrstr, " ", $ipaddr_1 + + doAssert($ipaddrstr == $ipaddr_1) + + var sockaddr: Sockaddr_storage + var socklen: Socklen + var ipaddr_2: IpAddress + var port_2: Port + + toSockAddr(ipaddr_1, Port(0), sockaddr, socklen) + fromSockAddr(sockaddr, socklen, ipaddr_2, port_2) + + doAssert(ipaddrstr == $ipaddr_1) + + doAssert(ipaddr_1 == ipaddr_2) + doAssert($ipaddr_1 == $ipaddr_2) + + + # ipv6 address of example.com + test("2606:2800:220:1:248:1893:25c8:1946") + # ipv6 address of localhost + test("::1") + # ipv4 address of example.com + test("93.184.216.34") + # ipv4 address of localhost + test("127.0.0.1") |