summaryrefslogtreecommitdiffstats
path: root/test/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-09 23:01:05 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-09 23:01:05 +0000
commit1c33cc894bb3e9578b1eae5da0435684349cbffe (patch)
tree49e0733e7402d8232cdd3d13540346cd1be23106 /test/lua
parentdabf6b6e482e06b5b51177fa50e903c231c16b2f (diff)
downloadrspamd-1c33cc894bb3e9578b1eae5da0435684349cbffe.tar.gz
rspamd-1c33cc894bb3e9578b1eae5da0435684349cbffe.zip
Add basic base32 tests.
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/unit/base32.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/lua/unit/base32.lua b/test/lua/unit/base32.lua
new file mode 100644
index 000000000..d0a40cdd8
--- /dev/null
+++ b/test/lua/unit/base32.lua
@@ -0,0 +1,34 @@
+-- Test zbase32 encoding/decoding
+
+context("Base32 encodning", function()
+ local ffi = require("ffi")
+ ffi.cdef[[
+ void ottery_rand_bytes(void *buf, size_t n);
+ unsigned ottery_rand_unsigned(void);
+ unsigned char* rspamd_decode_base32 (const char *in, size_t inlen, size_t *outlen);
+ char * rspamd_encode_base32 (const unsigned char *in, size_t inlen);
+ void g_free(void *ptr);
+ ]]
+
+ local function random_buf(max_size)
+ local l = ffi.C.ottery_rand_unsigned()
+ local buf = ffi.new("unsigned char[?]", l)
+ ffi.C.ottery_rand_bytes(buf, l)
+
+ return buf, l
+ end
+
+ test("Base32 exact test", function()
+ local cases = {
+ {'test123', 'wm3g84fg13cy'},
+ {'hello', 'em3ags7p'}
+ }
+
+ for _,c in ipairs(cases) do
+ local b = ffi.C.rspamd_encode_base32(c[1], #c[1])
+ local s = ffi.string(b)
+ ffi.C.g_free(b)
+ assert_equal(s, c[2], s .. " not equal " .. c[2])
+ end
+ end)
+end) \ No newline at end of file