summaryrefslogtreecommitdiffstats
path: root/tests/014/inaddr-str.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-07-24 19:59:13 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-07-24 19:59:13 -0700
commitccf6309c1716a221c881d610af8b3c11d363f5f3 (patch)
tree713f5a3e1ac5b59762970f5f052019f1e782f2eb /tests/014/inaddr-str.tl
parente0092558ad119f9a3c16b9f357e7ca0dcdf1044c (diff)
downloadtxr-ccf6309c1716a221c881d610af8b3c11d363f5f3.tar.gz
txr-ccf6309c1716a221c881d610af8b3c11d363f5f3.tar.bz2
txr-ccf6309c1716a221c881d610af8b3c11d363f5f3.zip
New inaddr-str and in6addr-str functions.
* lisplib.c (sock_set_entries): Register autoload entries for inaddr-str and in6addr-str. Register prefix symbol to be interned. * share/txr/stdlib/socket.tl (sockaddr-in, sockaddr-in6): Both structs get a new member, prefix, defaulting to the respective number of bits in the address. (inaddr-str, in6addr-str): New functions. * tests/014/iaddr-str, tests/014/inaddr-str.expected, tests/014/in6addr-str.tl, tests/014/in6addr-str.expected: New files * txr.1: Documented.
Diffstat (limited to 'tests/014/inaddr-str.tl')
-rw-r--r--tests/014/inaddr-str.tl78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/014/inaddr-str.tl b/tests/014/inaddr-str.tl
new file mode 100644
index 00000000..67283188
--- /dev/null
+++ b/tests/014/inaddr-str.tl
@@ -0,0 +1,78 @@
+(load "../common.tl")
+
+(test (inaddr-str "junk") :error)
+(test (inaddr-str "0.0.0.0.0") :error)
+(test (inaddr-str "0.0.0") :error)
+(test (inaddr-str "0") :error)
+(test (inaddr-str "") :error)
+(test (inaddr-str "0.0.0.nnn") :error)
+(test (inaddr-str "0.0.0.256") :error)
+(test (inaddr-str "0.0.256.0") :error)
+(test (inaddr-str "0.256.0.0") :error)
+(test (inaddr-str "256.0.0.0") :error)
+(test (inaddr-str "0.0.0.0:65537") :error)
+(test (inaddr-str "0.0.0.0/33") :error)
+(test (inaddr-str "0.0.0.0/32:65537") :error)
+(test (inaddr-str "0.0.0.0/33:0") :error)
+(test (inaddr-str "0.0.0.0:0/0") :error)
+(test (inaddr-str "0.0.0.") :error)
+(test (inaddr-str "0.0..0") :error)
+(test (inaddr-str "0..0.0") :error)
+(test (inaddr-str ".0.0.0") :error)
+(test (inaddr-str "0.0.0.0:") :error)
+
+(test (inaddr-str "0.0.0.0")
+ #S(sockaddr-in addr 0 port 0 prefix 32))
+(test (inaddr-str "1.2.3.4")
+ #S(sockaddr-in addr 16909060 port 0 prefix 32))
+(test (inaddr-str "255.255.255.255")
+ #S(sockaddr-in addr 4294967295 port 0 prefix 32))
+
+(test (inaddr-str "0.0.0.0:0")
+ #S(sockaddr-in addr 0 port 0 prefix 32))
+(test (inaddr-str "1.2.3.4:5")
+ #S(sockaddr-in addr 16909060 port 5 prefix 32))
+(test (inaddr-str "255.255.255.255:65535")
+ #S(sockaddr-in addr 4294967295 port 65535 prefix 32))
+
+(test (inaddr-str "0.0.0.0/0")
+ #S(sockaddr-in addr 0 port 0 prefix 0))
+(test (inaddr-str "1.2.3.4/8")
+ #S(sockaddr-in addr 16777216 port 0 prefix 8))
+(test (inaddr-str "255.255.255.255/24")
+ #S(sockaddr-in addr 4294967040 port 0 prefix 24))
+
+(test (inaddr-str "0.0.0/0")
+ #S(sockaddr-in addr 0 port 0 prefix 0))
+(test (inaddr-str "0.0/0")
+ #S(sockaddr-in addr 0 port 0 prefix 0))
+(test (inaddr-str "0/0")
+ #S(sockaddr-in addr 0 port 0 prefix 0))
+
+(test (inaddr-str "1.2.3/8")
+ #S(sockaddr-in addr 16777216 port 0 prefix 8))
+(test (inaddr-str "1.2/8")
+ #S(sockaddr-in addr 16777216 port 0 prefix 8))
+(test (inaddr-str "1/8")
+ #S(sockaddr-in addr 16777216 port 0 prefix 8))
+
+(test (inaddr-str "0.0.0.0/0:1234")
+ #S(sockaddr-in addr 0 port 1234 prefix 0))
+(test (inaddr-str "1.2.3.4/8:1234")
+ #S(sockaddr-in addr 16777216 port 1234 prefix 8))
+(test (inaddr-str "255.255.255.255/24:1234")
+ #S(sockaddr-in addr 4294967040 port 1234 prefix 24))
+
+(test (inaddr-str "0.0.0/0:1234")
+ #S(sockaddr-in addr 0 port 1234 prefix 0))
+(test (inaddr-str "0.0/0:1234")
+ #S(sockaddr-in addr 0 port 1234 prefix 0))
+(test (inaddr-str "0/0:1234")
+ #S(sockaddr-in addr 0 port 1234 prefix 0))
+
+(test (inaddr-str "1.2.3/8:1234")
+ #S(sockaddr-in addr 16777216 port 1234 prefix 8))
+(test (inaddr-str "1.2/8:1234")
+ #S(sockaddr-in addr 16777216 port 1234 prefix 8))
+(test (inaddr-str "1/8:1234")
+ #S(sockaddr-in addr 16777216 port 1234 prefix 8))