From e40c43a1bf03782eeab068b66abc7c3af64f2cc5 Mon Sep 17 00:00:00 2001 From: wanabe Date: Fri, 19 Mar 2010 16:18:05 +0000 Subject: * 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 --- test/dl/test_dl2.rb | 13 +++++++++---- 1 file 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 -- cgit v1.2.3