diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-14 22:25:54 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-14 22:25:54 +0000 |
commit | 7b6ff345af8128520e47ea91b9fb75277e625801 (patch) | |
tree | 0f59cac5b70b71bd3614796c7c6823d0a2ba52d6 | |
parent | cf1beeb1b2c3b39c5aa091868bc432c21bdb9f54 (diff) | |
download | rspamd-7b6ff345af8128520e47ea91b9fb75277e625801.tar.gz rspamd-7b6ff345af8128520e47ea91b9fb75277e625801.zip |
Add inet addr unit test.
-rw-r--r-- | test/lua/unit/addr.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/lua/unit/addr.lua b/test/lua/unit/addr.lua new file mode 100644 index 000000000..519be358c --- /dev/null +++ b/test/lua/unit/addr.lua @@ -0,0 +1,31 @@ +-- inet addr tests + +context("Inet addr check functions", function() + local ffi = require("ffi") + + ffi.cdef[[ + typedef struct rspamd_inet_addr_s rspamd_inet_addr_t; + bool rspamd_parse_inet_address (rspamd_inet_addr_t **target, + const char *src); + void rspamd_inet_address_destroy (rspamd_inet_addr_t *addr); + ]] + + test("Create inet addr from string", function() + local cases = { + {'192.168.1.1', true}, + {'2a01:4f8:190:43b5::99', true}, + {'256.1.1.1', false}, + {'/tmp/socket', true}, + {'./socket', true}, + } + + for _,c in ipairs(cases) do + local ip = ffi.new("rspamd_inet_addr_t* [1]"); + local res = ffi.C.rspamd_parse_inet_address(ip, c[1]) + assert_equal(res, c[2], "Expect " .. tostring(c[2]) .. " while parsing " .. c[1]) + if res then + ffi.C.rspamd_inet_address_destroy(ip[0]) + end + end + end) +end)
\ No newline at end of file |