diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-03 20:28:20 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-03 20:28:20 +0000 |
commit | 02d55ac989bf29d6a87d63e93dc49941438f495b (patch) | |
tree | 4ce30bdfe91e4b2386a6e26daf31bcf8d2d20e88 /test | |
parent | b9e0294edaceecb177401902f3809a45af666d7e (diff) | |
download | ruby-02d55ac989bf29d6a87d63e93dc49941438f495b.tar.gz |
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@25636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/dl/test_cptr.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/dl/test_cptr.rb b/test/dl/test_cptr.rb index c03abbe73e..3c4b5e6867 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 |