diff options
author | ngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-11 15:24:31 +0000 |
---|---|---|
committer | ngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-11 15:24:31 +0000 |
commit | 1fcde7c2e2bd780fc3bf4bf98fad7054177de5aa (patch) | |
tree | 5197f7212f58ded52d4c355e9643d870bf2854e9 /test/dl/test_func.rb | |
parent | 80e1f46ff07436b3c95624046f50667dde6b7da6 (diff) | |
download | ruby-1fcde7c2e2bd780fc3bf4bf98fad7054177de5aa.tar.gz |
* ext/dl/lib/dl/func.rb (DL::Function#unbind, #bound?): suppress NoMethodError when Fiddle is available. [ruby-core:50756] [Bug #7543]
* test/dl/test_func.rb (test_bound*, test_unbind*): tests for the above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38324 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/dl/test_func.rb')
-rw-r--r-- | test/dl/test_func.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/dl/test_func.rb b/test/dl/test_func.rb index b1aac15dd2..62e15422c4 100644 --- a/test/dl/test_func.rb +++ b/test/dl/test_func.rb @@ -15,6 +15,49 @@ module DL assert_equal('<callback>qsort', cb.name) end + def test_bound + f = Function.new(CFunc.new(0, TYPE_INT, 'test'), [TYPE_INT, TYPE_INT]) + assert_equal false, f.bound? + begin + f.bind { |x,y| x + y } + assert_equal true, f.bound? + ensure + f.unbind # max number of callbacks is limited to MAX_CALLBACK + end + end + + def test_bound_for_callback_closure + begin + f = Function.new(CFunc.new(0, TYPE_INT, 'test'), + [TYPE_INT, TYPE_INT]) { |x,y| x + y } + assert_equal true, f.bound? + ensure + f.unbind if f # max number of callbacks is limited to MAX_CALLBACK + end + end + + def test_unbind + f = Function.new(CFunc.new(0, TYPE_INT, 'test'), [TYPE_INT, TYPE_INT]) + begin + f.bind { |x, y| x + y } + assert_nothing_raised { f.unbind } + assert_equal false, f.bound? + # unbind() after unbind() should not raise error + assert_nothing_raised { f.unbind } + ensure + f.unbind # max number of callbacks is limited to MAX_CALLBACK + end + end + + def test_unbind_normal_function + f = Function.new(CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy'), + [TYPE_VOIDP, TYPE_VOIDP]) + assert_nothing_raised { f.unbind } + assert_equal false, f.bound? + # unbind() after unbind() should not raise error + assert_nothing_raised { f.unbind } + end + def test_bind f = Function.new(CFunc.new(0, TYPE_INT, 'test'), [TYPE_INT, TYPE_INT]) assert_nothing_raised { |