diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-01 01:46:27 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-01 01:46:27 +0000 |
commit | 7030430fcbf5730dd1b661b1a49228cfca805dc9 (patch) | |
tree | 783639ffe9661183276c8dc50c8135c5a03e8805 /test | |
parent | b164e6adb40198566f9aeaa7a059468274c5074e (diff) | |
download | ruby-7030430fcbf5730dd1b661b1a49228cfca805dc9.tar.gz ruby-7030430fcbf5730dd1b661b1a49228cfca805dc9.tar.xz ruby-7030430fcbf5730dd1b661b1a49228cfca805dc9.zip |
* test/dl/test_dl2.rb (**) testing malloc and realloc
* ext/dl/dl.c (**) adding documentation
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25605 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/dl/test_dl2.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/dl/test_dl2.rb b/test/dl/test_dl2.rb index 5a9daba42..d391e976e 100644 --- a/test/dl/test_dl2.rb +++ b/test/dl/test_dl2.rb @@ -3,6 +3,53 @@ require 'dl/callback' module DL class TestDL < TestBase + # TODO: refactor test repetition + + def test_realloc + str = "abc" + ptr_id = DL.realloc(0, 4) + ptr = CPtr.new(ptr_id, 4) + + assert_equal ptr_id, ptr.to_i + + cfunc = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy') + x = cfunc.call([ptr_id,str].pack("l!p").unpack("l!*")) + assert_equal("abc\0", ptr[0,4]) + DL.free ptr_id + end + + def test_realloc_secure + assert_raises(SecurityError) do + Thread.new do + $SAFE = 4 + DL.realloc(0, 4) + end.join + end + end + + def test_malloc + str = "abc" + + ptr_id = DL.malloc(4) + ptr = CPtr.new(ptr_id, 4) + + assert_equal ptr_id, ptr.to_i + + cfunc = CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy') + x = cfunc.call([ptr_id,str].pack("l!p").unpack("l!*")) + assert_equal("abc\0", ptr[0,4]) + DL.free ptr_id + end + + def test_malloc_security + assert_raises(SecurityError) do + Thread.new do + $SAFE = 4 + DL.malloc(4) + end.join + end + end + def test_call_int() cfunc = CFunc.new(@libc['atoi'], TYPE_INT, 'atoi') x = cfunc.call(["100"].pack("p").unpack("l!*")) |