aboutsummaryrefslogtreecommitdiffstats
path: root/test/dl/test_callback.rb
blob: f3dd665febdd06e609f9709c015b1daf78839b72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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