summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-11 15:44:22 +0000
committerngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-11 15:44:22 +0000
commita1a5c879f74720d729f1c6f5db994ad0d2905345 (patch)
tree75a506e911dc85b4f92c5a7b1ee4e850fe0b3063 /test
parentef12c29f3c3b9717606ff44c95f318a520e0c86e (diff)
* test/dl/test_func.rb (test_name_with_block, test_bind, test_qsort1): call unbind to release the callback closure because maximum number of callbacks is limited to DL::MAX_CALLBACK (== 5) with pure DL without Fiddle.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38326 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/dl/test_func.rb50
1 files changed, 31 insertions, 19 deletions
diff --git a/test/dl/test_func.rb b/test/dl/test_func.rb
index 62e15422c4..3b5ad3394f 100644
--- a/test/dl/test_func.rb
+++ b/test/dl/test_func.rb
@@ -10,9 +10,13 @@ module DL
end
def test_name_with_block
- cb = Function.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
- [TYPE_VOIDP, TYPE_VOIDP]){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
- assert_equal('<callback>qsort', cb.name)
+ begin
+ cb = Function.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
+ [TYPE_VOIDP, TYPE_VOIDP]){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
+ assert_equal('<callback>qsort', cb.name)
+ ensure
+ cb.unbind if cb # max number of callbacks is limited to MAX_CALLBACK
+ end
end
def test_bound
@@ -60,10 +64,14 @@ module DL
def test_bind
f = Function.new(CFunc.new(0, TYPE_INT, 'test'), [TYPE_INT, TYPE_INT])
- assert_nothing_raised {
- f.bind { |x, y| x + y }
- }
- assert_equal 579, f.call(123, 456)
+ begin
+ assert_nothing_raised {
+ f.bind { |x, y| x + y }
+ }
+ assert_equal 579, f.call(123, 456)
+ ensure
+ f.unbind # max number of callbacks is limited to MAX_CALLBACK
+ end
end
def test_to_i
@@ -145,18 +153,22 @@ module DL
end
def test_qsort1()
- cb = Function.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
- [TYPE_VOIDP, TYPE_VOIDP]){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
- qsort = Function.new(CFunc.new(@libc['qsort'], TYPE_VOID, 'qsort'),
- [TYPE_VOIDP, TYPE_SIZE_T, TYPE_SIZE_T, TYPE_VOIDP])
- buff = "9341"
- qsort.call(buff, buff.size, 1, cb)
- assert_equal("1349", buff)
-
- bug4929 = '[ruby-core:37395]'
- buff = "9341"
- EnvUtil.under_gc_stress {qsort.call(buff, buff.size, 1, cb)}
- assert_equal("1349", buff, bug4929)
+ begin
+ cb = Function.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
+ [TYPE_VOIDP, TYPE_VOIDP]){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
+ qsort = Function.new(CFunc.new(@libc['qsort'], TYPE_VOID, 'qsort'),
+ [TYPE_VOIDP, TYPE_SIZE_T, TYPE_SIZE_T, TYPE_VOIDP])
+ buff = "9341"
+ qsort.call(buff, buff.size, 1, cb)
+ assert_equal("1349", buff)
+
+ bug4929 = '[ruby-core:37395]'
+ buff = "9341"
+ EnvUtil.under_gc_stress {qsort.call(buff, buff.size, 1, cb)}
+ assert_equal("1349", buff, bug4929)
+ ensure
+ cb.unbind if cb # max number of callbacks is limited to MAX_CALLBACK
+ end
end
def test_qsort2()