mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/dl/cptr.c (rb_dlptr_size) splitting function to reduce complexity
* ext/dl/cptr.c (rb_dlptr_null_p, rb_dlptr_aref, rb_dlptr_aset) adding documentation * ext/dl/dl.c (rb_dl_free) adding documentation * test/dl/test_cptr.rb (test_null?, test_size, test_size=, test_aref_aset) Improving test coverage * test/dl/test_dl2.rb (test_free_secure) improving test coverage git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5f3d0f5233
commit
6cf6d8556c
4 changed files with 110 additions and 34 deletions
|
@ -29,5 +29,57 @@ module DL
|
|||
|
||||
assert_equal free.ptr, ptr.free.ptr
|
||||
end
|
||||
|
||||
def test_null?
|
||||
ptr = CPtr.new(0)
|
||||
assert ptr.null?
|
||||
end
|
||||
|
||||
def test_size
|
||||
ptr = CPtr.malloc(4)
|
||||
assert_equal 4, ptr.size
|
||||
DL.free ptr.to_i
|
||||
end
|
||||
|
||||
def test_size=
|
||||
ptr = CPtr.malloc(4)
|
||||
ptr.size = 10
|
||||
assert_equal 10, ptr.size
|
||||
DL.free ptr.to_i
|
||||
end
|
||||
|
||||
def test_aref_aset
|
||||
check = Proc.new{|str,ptr|
|
||||
assert_equal(str.size(), ptr.size())
|
||||
assert_equal(str, ptr.to_s())
|
||||
assert_equal(str[0,2], ptr.to_s(2))
|
||||
assert_equal(str[0,2], ptr[0,2])
|
||||
assert_equal(str[1,2], ptr[1,2])
|
||||
assert_equal(str[1,0], ptr[1,0])
|
||||
assert_equal(str[0].ord, ptr[0])
|
||||
assert_equal(str[1].ord, ptr[1])
|
||||
}
|
||||
str = 'abc'
|
||||
ptr = CPtr[str]
|
||||
check.call(str, ptr)
|
||||
|
||||
str[0] = "c"
|
||||
assert_equal 'c'.ord, ptr[0] = "c".ord
|
||||
check.call(str, ptr)
|
||||
|
||||
str[0,2] = "aa"
|
||||
assert_equal 'aa', ptr[0,2] = "aa"
|
||||
check.call(str, ptr)
|
||||
|
||||
ptr2 = CPtr['cdeeee']
|
||||
str[0,2] = "cd"
|
||||
assert_equal ptr2, ptr[0,2] = ptr2
|
||||
check.call(str, ptr)
|
||||
|
||||
ptr3 = CPtr['vvvv']
|
||||
str[0,2] = "vv"
|
||||
assert_equal ptr3.to_i, ptr[0,2] = ptr3.to_i
|
||||
check.call(str, ptr)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue