ruby-changes:13885
From: tenderlove <ko1@a...>
Date: Sun, 8 Nov 2009 09:21:59 +0900 (JST)
Subject: [ruby-changes:13885] Ruby:r25687 (trunk): * test/dl/test_callback.rb (**) adding a callback test file
tenderlove 2009-11-08 09:21:50 +0900 (Sun, 08 Nov 2009) New Revision: 25687 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25687 Log: * test/dl/test_callback.rb (**) adding a callback test file Added files: trunk/test/dl/test_callback.rb Index: test/dl/test_callback.rb =================================================================== --- test/dl/test_callback.rb (revision 0) +++ test/dl/test_callback.rb (revision 25687) @@ -0,0 +1,32 @@ +require_relative 'test_base' +require_relative '../ruby/envutil' + +module DL + class TestCallback < TestBase + include DL + + def test_callback_with_string + called_with = nil + addr = set_callback(TYPE_VOID, 1) do |str| + called_with = dlunwrap(str) + end + func = CFunc.new(addr, TYPE_VOID, 'test') + + func.call([dlwrap('foo')]) + assert_equal 'foo', called_with + end + + def test_call_callback + called = false + + addr = set_callback(TYPE_VOID, 0) do + called = true + end + + func = CFunc.new(addr, TYPE_VOID, 'test') + func.call([]) + + assert called, 'function should be called' + end + end +end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/