* test/dl/test_dl2.rb (DL::TestDL#ptr2num): add for LLP64.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
wanabe 2010-03-19 16:18:05 +00:00
Родитель faee1b6f78
Коммит e40c43a1bf
1 изменённых файлов: 9 добавлений и 4 удалений

Просмотреть файл

@ -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