ATTN: GitHub is currently in read-only mode. Please check GitHub's Twitter account for status updates.

public
Description: Use rbgccxml and rice to automatically generate C++ Ruby extensions.
Homepage: http://rbplusplus.rubyforge.org/rbplusplus
Clone URL: git://github.com/jameskilton/rbplusplus.git
rbplusplus / test / function_pointer_test.rb
100644 57 lines (40 sloc) 0.998 kb
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require File.dirname(__FILE__) + '/test_helper'
 
context "properly handles and wraps function pointer arguments" do
 
  def setup
    if !defined?(@@function_pointers)
      super
      @@function_pointers = true
      Extension.new "function_pointers" do |e|
        e.sources full_dir("headers/function_pointers.h")
        node = e.namespace "function_pointers"
      end
 
      require 'function_pointers'
    end
  end
 
  specify "no arguments, no return" do
    proc_called = false
 
    set_callback do
      proc_called = true
    end
 
    call_callback
 
    assert proc_called
  end
 
  specify "arguments, no return" do
    proc_arg = nil
 
    set_callback_with_args do |i|
      proc_arg = i
    end
 
    call_callback_with_args(10)
 
    proc_arg.should == 10
  end
 
  specify "arguments and return" do
    proc_arg = nil
    set_callback_returns do |i|
      proc_arg = i
      i * 10
    end
 
    ret = call_callback_returns(8)
 
    proc_arg.should == 8
    ret.should == 80
  end
 
end