summaryrefslogtreecommitdiffstats
path: root/test/dl
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-03 20:28:20 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-03 20:28:20 +0000
commitbd442249cc787b1fd626c87702ef23993028e64b (patch)
tree4ce30bdfe91e4b2386a6e26daf31bcf8d2d20e88 /test/dl
parent3b50d03ae9c188fdb90ee7a625ba155f665aa8e0 (diff)
downloadruby-bd442249cc787b1fd626c87702ef23993028e64b.tar.gz
ruby-bd442249cc787b1fd626c87702ef23993028e64b.tar.xz
ruby-bd442249cc787b1fd626c87702ef23993028e64b.zip
* test/dl/test_cptr.rb (test_to_ptr*): testing DL::CPtr#to_ptr
* ext/dl/cptr.c (rb_dlptr_free_set, rb_dlptr_free_get, rb_dlptr_s_to_ptr): adding documentation, fixing indentation git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/dl')
-rw-r--r--test/dl/test_cptr.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/dl/test_cptr.rb b/test/dl/test_cptr.rb
index c03abbe73..3c4b5e686 100644
--- a/test/dl/test_cptr.rb
+++ b/test/dl/test_cptr.rb
@@ -3,6 +3,42 @@ require_relative '../ruby/envutil'
module DL
class TestCPtr < TestBase
+ def test_to_ptr_string
+ str = "hello world"
+ ptr = CPtr[str]
+ assert ptr.tainted?, 'pointer should be tainted'
+ assert_equal str.length, ptr.size
+ assert_equal 'hello', ptr[0,5]
+ end
+
+ def test_to_ptr_io
+ buf = CPtr.malloc(10)
+ File.open(__FILE__, 'r') do |f|
+ ptr = CPtr.to_ptr f
+ fread = CFunc.new(@libc['fread'], TYPE_VOID, 'fread')
+ fread.call([buf.to_i, DL::SIZEOF_CHAR, buf.size - 1, ptr.to_i])
+ end
+
+ File.open(__FILE__, 'r') do |f|
+ assert_equal f.read(9), buf.to_s
+ end
+ end
+
+ def test_to_ptr_with_ptr
+ ptr = CPtr.new 0
+ ptr2 = CPtr.to_ptr Struct.new(:to_ptr).new(ptr)
+ assert_equal ptr, ptr2
+
+ assert_raises(DL::DLError) do
+ CPtr.to_ptr Struct.new(:to_ptr).new(nil)
+ end
+ end
+
+ def test_to_ptr_with_num
+ ptr = CPtr.new 0
+ assert_equal ptr, CPtr[0]
+ end
+
def test_equals
ptr = CPtr.new 0
ptr2 = CPtr.new 0