summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/dl/test_dl2.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/test/dl/test_dl2.rb b/test/dl/test_dl2.rb
index 5d3af94b3d..431c5b2ae4 100644
--- a/test/dl/test_dl2.rb
+++ b/test/dl/test_dl2.rb
@@ -1,9 +1,14 @@
require_relative 'test_base.rb'
require 'dl/callback'
require 'dl/func'
+require 'dl/pack'
module DL
class TestDL < TestBase
+ def ptr2num(*list)
+ list.pack("p*").unpack(PackInfo::PACK_MAP[TYPE_VOIDP] + "*")
+ end
+
# TODO: refactor test repetition
def test_free_secure
@@ -112,21 +117,21 @@ class TestDL < TestBase
buff = "xxxx"
str = "abc"
cfunc = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy')
- x = cfunc.call([buff,str].pack("pp").unpack("l!*"))
+ x = cfunc.call(ptr2num(buff,str))
assert_equal("abc\0", buff)
assert_equal("abc\0", CPtr.new(x).to_s(4))
buff = "xxxx"
str = "abc"
cfunc = CFunc.new(@libc['strncpy'], TYPE_VOIDP, 'strncpy')
- x = cfunc.call([buff,str,3].pack("ppL!").unpack("l!*"))
+ x = cfunc.call(ptr2num(buff,str) + [3])
assert_equal("abcx", buff)
assert_equal("abcx", CPtr.new(x).to_s(4))
ptr = CPtr.malloc(4)
str = "abc"
cfunc = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy')
- x = cfunc.call([ptr.to_i,str].pack("l!p").unpack("l!*"))
+ x = cfunc.call([ptr.to_i, *ptr2num(str)])
assert_equal("abc\0", ptr[0,4])
assert_equal("abc\0", CPtr.new(x).to_s(4))
end
@@ -135,7 +140,7 @@ class TestDL < TestBase
buff = "foobarbaz"
cb = set_callback(TYPE_INT,2){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
cfunc = CFunc.new(@libc['qsort'], TYPE_VOID, 'qsort')
- cfunc.call([buff, buff.size, 1, cb].pack("pL!L!L!").unpack("l!*"))
+ cfunc.call(ptr2num(buff) + [buff.size, 1, cb])
assert_equal('aabbfoorz', buff)
end