rbplusplus 0.9.1 → 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +4 -9
- data/lib/rbplusplus/builders/allocation_strategy.rb +0 -7
- data/lib/rbplusplus/builders/base.rb +11 -5
- data/lib/rbplusplus/builders/class.rb +5 -14
- data/lib/rbplusplus/builders/const.rb +1 -1
- data/lib/rbplusplus/builders/constructor.rb +1 -1
- data/lib/rbplusplus/builders/director.rb +13 -13
- data/lib/rbplusplus/builders/enumeration.rb +2 -2
- data/lib/rbplusplus/builders/helpers/class.rb +17 -2
- data/lib/rbplusplus/builders/helpers/implicit_caster.rb +0 -0
- data/lib/rbplusplus/builders/implicit_caster.rb +24 -0
- data/lib/rbplusplus/builders/instance_variable.rb +4 -4
- data/lib/rbplusplus/builders/method_base.rb +8 -7
- data/lib/rbplusplus/builders/module.rb +1 -1
- data/lib/rbplusplus/logger.rb +13 -4
- data/lib/rbplusplus/transformers/class.rb +43 -34
- data/lib/rbplusplus/transformers/constructor.rb +30 -0
- data/lib/rbplusplus/transformers/function.rb +3 -3
- data/lib/rbplusplus/transformers/method.rb +2 -2
- data/lib/rbplusplus/transformers/node.rb +10 -17
- data/lib/rbplusplus/writers/multiple_files_writer.rb +8 -6
- data/lib/rbplusplus.rb +2 -1
- data/test/allocation_strategies_test.rb +21 -14
- data/test/class_methods_encapsulate_test.rb +25 -25
- data/test/class_methods_test.rb +7 -12
- data/test/classes_test.rb +36 -40
- data/test/compiling_test.rb +23 -19
- data/test/constructors_test.rb +5 -5
- data/test/custom_code_test.rb +25 -32
- data/test/default_arguments_test.rb +38 -42
- data/test/director_test.rb +51 -53
- data/test/enumerations_test.rb +37 -41
- data/test/extension_test.rb +10 -10
- data/test/file_writers_test.rb +17 -21
- data/test/function_pointer_test.rb +9 -13
- data/test/function_pointers_classes_test.rb +7 -11
- data/test/functions_test.rb +4 -10
- data/test/generated/extconf.rb +2 -2
- data/test/headers/alloc_strats.h +3 -1
- data/test/headers/implicit_cast.h +107 -0
- data/test/headers/to_from_ruby.h +13 -6
- data/test/headers/to_from_ruby_source.cpp +2 -2
- data/test/implicit_cast_test.rb +67 -0
- data/test/modules_test.rb +39 -40
- data/test/nested_test.rb +14 -16
- data/test/overloading_test.rb +17 -20
- data/test/struct_test.rb +4 -6
- data/test/subclass_test.rb +10 -12
- data/test/test_helper.rb +21 -12
- data/test/to_from_ruby_test.rb +7 -1
- data/test/wrap_as_test.rb +32 -29
- metadata +170 -108
- data/lib/rbplusplus/transformers/node_cache.rb +0 -15
@@ -19,9 +19,9 @@ module RbGCCXML
|
|
19
19
|
# example of this functionality.
|
20
20
|
def default_return_value(value = nil)
|
21
21
|
if value
|
22
|
-
|
22
|
+
@default_return_value = value
|
23
23
|
else
|
24
|
-
|
24
|
+
@default_return_value
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -3,44 +3,44 @@ module RbGCCXML
|
|
3
3
|
|
4
4
|
# Specify to Rb++ that this node is not to be wrapped
|
5
5
|
def ignore
|
6
|
-
|
6
|
+
@ignored = true
|
7
7
|
end
|
8
8
|
|
9
9
|
# Un-ignore this node, useful if there's a glob ignore and the wrapper
|
10
10
|
# just wants a few of the classes
|
11
11
|
def unignore
|
12
|
-
|
12
|
+
@ignored = false
|
13
13
|
end
|
14
14
|
|
15
15
|
# Has this node been previously declared to not be wrapped?
|
16
16
|
def ignored?
|
17
|
-
|
17
|
+
!!@ignored
|
18
18
|
end
|
19
19
|
|
20
20
|
# Specifies that this node has been included somewhere else
|
21
21
|
def moved_to=(val)
|
22
|
-
|
22
|
+
@moved_to = val
|
23
23
|
end
|
24
24
|
|
25
25
|
# Change what the name of this node will be when wrapped into Ruby
|
26
26
|
def wrap_as(name)
|
27
|
-
|
27
|
+
@wrap_as = name
|
28
28
|
self
|
29
29
|
end
|
30
30
|
|
31
31
|
# Where has this node moved to?
|
32
32
|
def moved_to
|
33
|
-
|
33
|
+
@moved_to
|
34
34
|
end
|
35
35
|
|
36
36
|
# Has this node been renamed
|
37
37
|
def renamed?
|
38
|
-
|
38
|
+
!!@wrap_as
|
39
39
|
end
|
40
40
|
|
41
41
|
alias_method :rbgccxml_name, :name
|
42
42
|
def name #:nodoc:
|
43
|
-
|
43
|
+
@wrap_as || rbgccxml_name
|
44
44
|
end
|
45
45
|
|
46
46
|
def cpp_name
|
@@ -53,11 +53,11 @@ module RbGCCXML
|
|
53
53
|
# Flag a given class as ignoring this typedef lookup if this
|
54
54
|
# situation happens.
|
55
55
|
def disable_typedef_lookup
|
56
|
-
|
56
|
+
@disable_typedef_lookup = true
|
57
57
|
end
|
58
58
|
|
59
59
|
def _disable_typedef_lookup? #:nodoc:
|
60
|
-
|
60
|
+
!!@disable_typedef_lookup
|
61
61
|
end
|
62
62
|
|
63
63
|
# Is this node an incomplete node?
|
@@ -65,12 +65,5 @@ module RbGCCXML
|
|
65
65
|
def incomplete?
|
66
66
|
self["incomplete"] ? self["incomplete"] == "1" : false
|
67
67
|
end
|
68
|
-
|
69
|
-
protected
|
70
|
-
|
71
|
-
# Get this node's settings cache
|
72
|
-
def cache
|
73
|
-
NodeCache.get(self)
|
74
|
-
end
|
75
68
|
end
|
76
69
|
end
|
@@ -253,16 +253,18 @@ module RbPlusPlus
|
|
253
253
|
cpp.puts "#{@register_method}(#{parent_signature}) {"
|
254
254
|
end
|
255
255
|
|
256
|
-
if (regs = @registrations.flatten.compact).any?
|
257
|
-
cpp.puts regs.join("\n")
|
258
|
-
end
|
259
|
-
|
260
256
|
if @register_methods
|
261
|
-
|
262
|
-
|
257
|
+
# Ug, hack. I've seriously got to rethink this whole
|
258
|
+
# code generation system ... again
|
259
|
+
@register_methods.reverse.each do |reg|
|
260
|
+
@registrations.insert(3, reg)
|
263
261
|
end
|
264
262
|
end
|
265
263
|
|
264
|
+
if (regs = @registrations.flatten.compact).any?
|
265
|
+
cpp.puts regs.join("\n")
|
266
|
+
end
|
267
|
+
|
266
268
|
# I really need a better way of handling this
|
267
269
|
if @needs_closing
|
268
270
|
cpp.puts "} RUBY_CATCH" unless @parent
|
data/lib/rbplusplus.rb
CHANGED
@@ -33,6 +33,7 @@ module RbPlusPlus
|
|
33
33
|
autoload :ClassNode, "rbplusplus/builders/class"
|
34
34
|
autoload :DirectorNode, "rbplusplus/builders/director"
|
35
35
|
autoload :ConstructorNode, "rbplusplus/builders/constructor"
|
36
|
+
autoload :ImplicitCasterNode, "rbplusplus/builders/implicit_caster"
|
36
37
|
autoload :InstanceVariableNode, "rbplusplus/builders/instance_variable"
|
37
38
|
|
38
39
|
# Rice type-management nodes
|
@@ -73,10 +74,10 @@ end
|
|
73
74
|
|
74
75
|
# Transformer classes that reopen RbGCCXML classes to add functionality
|
75
76
|
require 'rbplusplus/transformers/rbgccxml'
|
76
|
-
require 'rbplusplus/transformers/node_cache'
|
77
77
|
require 'rbplusplus/transformers/node'
|
78
78
|
require 'rbplusplus/transformers/function'
|
79
79
|
require 'rbplusplus/transformers/class'
|
80
|
+
require 'rbplusplus/transformers/constructor'
|
80
81
|
require 'rbplusplus/transformers/method'
|
81
82
|
require 'rbplusplus/transformers/namespace'
|
82
83
|
|
@@ -1,15 +1,11 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
Extension.new "alloc_strats" do |e|
|
10
|
-
e.sources full_dir("headers/alloc_strats.h")
|
11
|
-
node = e.namespace "alloc_strats"
|
12
|
-
end
|
3
|
+
describe "Allocation Strategies" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Extension.new "alloc_strats" do |e|
|
7
|
+
e.sources full_dir("headers/alloc_strats.h")
|
8
|
+
node = e.namespace "alloc_strats"
|
13
9
|
end
|
14
10
|
end
|
15
11
|
|
@@ -19,15 +15,26 @@ context "Allocation Strategies" do
|
|
19
15
|
# instantiate an object with a non-public constructor
|
20
16
|
# and it all dies.
|
21
17
|
specify "properly figures out what allocation to do" do
|
22
|
-
|
18
|
+
lambda do
|
23
19
|
require 'alloc_strats'
|
24
|
-
end
|
20
|
+
end.should_not raise_error(LoadError)
|
25
21
|
|
26
22
|
# Private constructor, public destructor
|
27
|
-
|
23
|
+
lambda do
|
24
|
+
NoConstructor
|
25
|
+
end.should_not raise_error(NameError)
|
28
26
|
|
29
27
|
# Private constructor and destructor
|
30
|
-
|
28
|
+
lambda do
|
29
|
+
Neither
|
30
|
+
end.should_not raise_error(NameError)
|
31
|
+
end
|
32
|
+
|
33
|
+
specify "can get access to Neither object" do
|
34
|
+
n = Neither.get_instance
|
35
|
+
n.should_not be_nil
|
36
|
+
|
37
|
+
n.process(4, 5).should == 20
|
31
38
|
end
|
32
39
|
|
33
40
|
end
|
@@ -1,28 +1,26 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
Extension.new "encapsulation" do |e|
|
9
|
-
e.sources full_dir("headers/class_methods.h")
|
10
|
-
node = e.namespace "encapsulation"
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'encapsulation'
|
3
|
+
describe "Correct handling of encapsulated methods" do
|
4
|
+
before(:all) do
|
5
|
+
Extension.new "encapsulation" do |e|
|
6
|
+
e.sources full_dir("headers/class_methods.h")
|
7
|
+
node = e.namespace "encapsulation"
|
14
8
|
end
|
9
|
+
|
10
|
+
require 'encapsulation'
|
15
11
|
end
|
16
12
|
|
17
13
|
specify "should handle private/protected/public" do
|
18
14
|
ext = Extended.new
|
19
15
|
ext.public_method.should == 1
|
20
|
-
|
16
|
+
|
17
|
+
lambda do
|
21
18
|
ext.private_method
|
22
|
-
end
|
23
|
-
|
19
|
+
end.should raise_error(NoMethodError)
|
20
|
+
|
21
|
+
lambda do
|
24
22
|
ext.protected_method
|
25
|
-
end
|
23
|
+
end.should raise_error(NoMethodError)
|
26
24
|
end
|
27
25
|
|
28
26
|
specify "should handle virtual methods" do
|
@@ -36,24 +34,26 @@ context "Correct handling of encapsulated methods" do
|
|
36
34
|
arg = ArgumentAccess.new
|
37
35
|
|
38
36
|
# Single argument methods
|
39
|
-
|
37
|
+
lambda do
|
40
38
|
arg.wrap_me_private
|
41
|
-
end
|
42
|
-
|
39
|
+
end.should raise_error(NoMethodError)
|
40
|
+
|
41
|
+
lambda do
|
43
42
|
arg.wrap_me_protected
|
44
|
-
end
|
43
|
+
end.should raise_error(NoMethodError)
|
45
44
|
|
46
|
-
|
45
|
+
lambda do
|
47
46
|
arg.wrap_me_public ArgumentAccess::PublicStruct.new
|
48
|
-
end
|
47
|
+
end.should_not raise_error(NoMethodError)
|
49
48
|
|
50
49
|
# Multiple argument methods
|
51
|
-
|
50
|
+
lambda do
|
52
51
|
arg.wrap_me_many_no
|
53
|
-
end
|
54
|
-
|
52
|
+
end.should raise_error(NoMethodError)
|
53
|
+
|
54
|
+
lambda do
|
55
55
|
arg.wrap_me_many_yes(1, 2.0, ArgumentAccess::PublicStruct.new)
|
56
|
-
end
|
56
|
+
end.should_not raise_error(NoMethodError)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
data/test/class_methods_test.rb
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
def setup
|
5
|
-
if !defined?(@@complex_static)
|
6
|
-
super
|
7
|
-
@@complex_static = true
|
8
|
-
Extension.new "complex_test" do |e|
|
9
|
-
e.sources full_dir("headers/complex_static_methods.h")
|
10
|
-
node = e.namespace "complex"
|
11
|
-
end
|
3
|
+
describe "Correct handling of static methods" do
|
12
4
|
|
13
|
-
|
5
|
+
specify "should handle complex static methods" do
|
6
|
+
Extension.new "complex_test" do |e|
|
7
|
+
e.sources full_dir("headers/complex_static_methods.h")
|
8
|
+
node = e.namespace "complex"
|
14
9
|
end
|
15
|
-
end
|
16
10
|
|
17
|
-
|
11
|
+
require 'complex_test'
|
12
|
+
|
18
13
|
Multiply.multiply(SmallInteger.new(2),SmallInteger.new(2)).should == 4
|
19
14
|
end
|
20
15
|
|
data/test/classes_test.rb
CHANGED
@@ -1,45 +1,41 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
adder.constants("HideMe").ignore
|
22
|
-
adder.disable_typedef_lookup
|
23
|
-
end
|
24
|
-
|
25
|
-
require 'adder'
|
3
|
+
describe "Extension with wrapped classes" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Extension.new "adder" do |e|
|
7
|
+
e.sources full_dir("headers/Adder.h"),
|
8
|
+
:include_source_files => [
|
9
|
+
full_dir("headers/Adder.h"),
|
10
|
+
full_dir("headers/Adder.cpp")
|
11
|
+
]
|
12
|
+
node = e.namespace "classes"
|
13
|
+
adder = node.classes("Adder")
|
14
|
+
adder.use_constructor(
|
15
|
+
adder.constructors.find(:arguments => [])
|
16
|
+
)
|
17
|
+
|
18
|
+
adder.constants("HideMe").ignore
|
19
|
+
adder.disable_typedef_lookup
|
26
20
|
end
|
21
|
+
|
22
|
+
require 'adder'
|
27
23
|
end
|
28
24
|
|
29
25
|
specify "should make classes available as Ruby runtime constants" do
|
30
|
-
|
26
|
+
lambda { Adder }.should_not raise_error
|
31
27
|
end
|
32
28
|
|
33
29
|
specify "should make wrapped classes constructable" do
|
34
30
|
a = Adder.new
|
35
|
-
a.
|
31
|
+
a.should_not be_nil
|
36
32
|
end
|
37
33
|
|
38
34
|
specify "should make functions of the class available" do
|
39
35
|
# Wrapped method names default to underscore'd
|
40
36
|
adder = Adder.new
|
41
37
|
adder.add_integers(1,2).should == 3
|
42
|
-
adder.add_floats(1.0, 2.0).should
|
38
|
+
adder.add_floats(1.0, 2.0).should be_close(3.0, 0.001)
|
43
39
|
adder.add_strings("Hello", "World").should == "HelloWorld"
|
44
40
|
adder.get_class_name.should == "Adder"
|
45
41
|
end
|
@@ -50,15 +46,15 @@ context "Extension with wrapped classes" do
|
|
50
46
|
end
|
51
47
|
|
52
48
|
specify "should use typedefs when findable" do
|
53
|
-
|
49
|
+
lambda { IntAdder }.should_not raise_error
|
54
50
|
end
|
55
51
|
|
56
52
|
specify "finds and uses multi-nested typedefs" do
|
57
|
-
|
53
|
+
lambda { ShouldFindMe }.should_not raise_error
|
58
54
|
end
|
59
55
|
|
60
56
|
specify "can turn off typedef lookup for certain classes" do
|
61
|
-
|
57
|
+
lambda { DontFindMeBro }.should raise_error
|
62
58
|
end
|
63
59
|
|
64
60
|
specify "makes class constants available" do
|
@@ -66,7 +62,7 @@ context "Extension with wrapped classes" do
|
|
66
62
|
end
|
67
63
|
|
68
64
|
specify "can ignore constants" do
|
69
|
-
|
65
|
+
lambda { Adder::HideMe }.should raise_error
|
70
66
|
end
|
71
67
|
|
72
68
|
specify "makes public instance variables accessible" do
|
@@ -76,21 +72,21 @@ context "Extension with wrapped classes" do
|
|
76
72
|
a.value3 = "This is a value!"
|
77
73
|
a.should_be_transformed = "TRANSFORM"
|
78
74
|
|
79
|
-
a.value1.should
|
80
|
-
a.value2.should
|
81
|
-
a.value3.should
|
75
|
+
a.value1.should == 10
|
76
|
+
a.value2.should be_close(15.5, 0.01)
|
77
|
+
a.value3.should == "This is a value!"
|
82
78
|
|
83
|
-
a.should_be_transformed.should
|
79
|
+
a.should_be_transformed.should == "TRANSFORM"
|
84
80
|
end
|
85
81
|
|
86
82
|
specify "const variables are exported as read-only" do
|
87
83
|
a = Adder.new
|
88
84
|
|
89
|
-
|
85
|
+
lambda do
|
90
86
|
a.const_var = "This is a value!"
|
91
|
-
end
|
87
|
+
end.should raise_error
|
92
88
|
|
93
|
-
a.const_var.should
|
89
|
+
a.const_var.should == 14
|
94
90
|
end
|
95
91
|
|
96
92
|
specify "can subclass a wrapped class and go from there" do
|
@@ -105,12 +101,12 @@ context "Extension with wrapped classes" do
|
|
105
101
|
end
|
106
102
|
|
107
103
|
a = MyAdder.new
|
108
|
-
a.add_integers(3, 7).should
|
109
|
-
a.add_strings("piz", "owned").should
|
104
|
+
a.add_integers(3, 7).should == 21
|
105
|
+
a.add_strings("piz", "owned").should == "pizownedwoot"
|
110
106
|
end
|
111
107
|
|
112
108
|
specify "should not wrap incomplete types" do
|
113
|
-
|
109
|
+
lambda { Forwarder }.should raise_error
|
114
110
|
end
|
115
111
|
end
|
116
112
|
|
data/test/compiling_test.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe "Compiler settings" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
test_setup
|
7
|
+
end
|
4
8
|
|
5
9
|
specify "should be able to specify include paths" do
|
6
10
|
Extension.new "compiler" do |e|
|
@@ -11,7 +15,7 @@ context "Compiler settings" do
|
|
11
15
|
|
12
16
|
require 'compiler'
|
13
17
|
|
14
|
-
|
18
|
+
func(1, 2).should == 3
|
15
19
|
end
|
16
20
|
|
17
21
|
specify "should be able to specify library paths" do
|
@@ -27,7 +31,7 @@ context "Compiler settings" do
|
|
27
31
|
|
28
32
|
contents = File.read(ext_file)
|
29
33
|
|
30
|
-
contents.should
|
34
|
+
contents.should =~ %r(-L/usr/lib/testing/123)
|
31
35
|
|
32
36
|
# Clean up
|
33
37
|
`rm -rf #{full_dir('generated')}/*`
|
@@ -44,8 +48,8 @@ context "Compiler settings" do
|
|
44
48
|
|
45
49
|
contents = File.read(ext_file)
|
46
50
|
|
47
|
-
contents.should
|
48
|
-
contents.should
|
51
|
+
contents.should =~ %r(-L/usr/lib/testing/456)
|
52
|
+
contents.should =~ %r(-L/var/lib/stuff)
|
49
53
|
end
|
50
54
|
|
51
55
|
specify "should be able to link to external libraries" do
|
@@ -61,7 +65,7 @@ context "Compiler settings" do
|
|
61
65
|
|
62
66
|
contents = File.read(ext_file)
|
63
67
|
|
64
|
-
contents.should
|
68
|
+
contents.should =~ %r(-llib123)
|
65
69
|
|
66
70
|
# Clean up
|
67
71
|
`rm -rf #{full_dir('generated')}/*`
|
@@ -78,9 +82,9 @@ context "Compiler settings" do
|
|
78
82
|
|
79
83
|
contents = File.read(ext_file)
|
80
84
|
|
81
|
-
contents.should
|
82
|
-
contents.should
|
83
|
-
contents.should
|
85
|
+
contents.should =~ %r(-lponzor)
|
86
|
+
contents.should =~ %r(-lwonko)
|
87
|
+
contents.should =~ %r(-lprankit)
|
84
88
|
end
|
85
89
|
|
86
90
|
specify "can add extra cxxflags for gccxml and compiling" do
|
@@ -95,8 +99,8 @@ context "Compiler settings" do
|
|
95
99
|
|
96
100
|
contents = File.read(ext_file)
|
97
101
|
|
98
|
-
contents.should
|
99
|
-
contents.should
|
102
|
+
contents.should =~ %r(-I/i/love/scotch)
|
103
|
+
contents.should =~ %r(-D__AND_DEFINE_THAT)
|
100
104
|
end
|
101
105
|
|
102
106
|
specify "can add extra ldflags for gccxml and compiling" do
|
@@ -111,24 +115,24 @@ context "Compiler settings" do
|
|
111
115
|
|
112
116
|
contents = File.read(ext_file)
|
113
117
|
|
114
|
-
contents.should
|
115
|
-
contents.should
|
116
|
-
contents.should
|
118
|
+
contents.should =~ %r(-R/wootage/to/you)
|
119
|
+
contents.should =~ %r(-lthisandthat)
|
120
|
+
contents.should =~ %r(-nothing_here)
|
117
121
|
end
|
118
122
|
|
119
123
|
specify "should pass cxxflags to rbgccxml" do
|
120
|
-
|
124
|
+
lambda do
|
121
125
|
e = Extension.new "parsing_test"
|
122
126
|
e.working_dir = full_dir("generated")
|
123
127
|
e.sources full_dir("headers/requires_define.h"),
|
124
128
|
:cxxflags => "-DMUST_BE_DEFINED"
|
125
129
|
e.build
|
126
130
|
e.write
|
127
|
-
end
|
131
|
+
end.should_not raise_error
|
128
132
|
end
|
129
133
|
|
130
134
|
specify "should be able to add additional headers as needed" do
|
131
|
-
|
135
|
+
lambda do
|
132
136
|
e = Extension.new "external"
|
133
137
|
e.working_dir = full_dir("generated")
|
134
138
|
e.sources full_dir("headers/external_mapping.h"),
|
@@ -138,8 +142,8 @@ context "Compiler settings" do
|
|
138
142
|
|
139
143
|
file = full_dir("generated/external.rb.cpp")
|
140
144
|
contents = File.read(file)
|
141
|
-
contents.should
|
142
|
-
end
|
145
|
+
contents.should =~ %r(headers/external_mapping_rice.h)
|
146
|
+
end.should_not raise_error
|
143
147
|
end
|
144
148
|
|
145
149
|
specify "can specify other source files to be compiled into the extension" do
|
data/test/constructors_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe "Extension with constructors out the whazoo" do
|
4
4
|
|
5
5
|
specify "should make constructors available" do
|
6
6
|
Extension.new "constructors" do |e|
|
@@ -15,17 +15,17 @@ context "Extension with constructors out the whazoo" do
|
|
15
15
|
|
16
16
|
require 'constructors'
|
17
17
|
|
18
|
-
|
18
|
+
lambda do
|
19
19
|
# Test complex constructors
|
20
20
|
d = DoubleStringHolder.new("one", "two")
|
21
21
|
one = d.get_one
|
22
22
|
d.get_one.should == "one"
|
23
23
|
d.get_two.should == "two"
|
24
|
-
end
|
24
|
+
end.should_not raise_error(NameError)
|
25
25
|
|
26
|
-
|
26
|
+
lambda do
|
27
27
|
PrivateConstructor.new
|
28
|
-
end
|
28
|
+
end.should raise_error(TypeError)
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
data/test/custom_code_test.rb
CHANGED
@@ -1,52 +1,45 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
adder.disable_typedef_lookup
|
20
|
-
|
21
|
-
decl = <<-END
|
3
|
+
describe "Extension with wrapped classes" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Extension.new "adder" do |e|
|
7
|
+
e.sources full_dir("headers/Adder.h"),
|
8
|
+
:include_source_files => [
|
9
|
+
full_dir("headers/Adder.h"),
|
10
|
+
full_dir("headers/Adder.cpp")
|
11
|
+
]
|
12
|
+
node = e.namespace "classes"
|
13
|
+
adder = node.classes("Adder")
|
14
|
+
|
15
|
+
adder.use_constructor( adder.constructors.find(:arguments => []))
|
16
|
+
adder.disable_typedef_lookup
|
17
|
+
|
18
|
+
decl = <<-END
|
22
19
|
int subtractIntegers(classes::Adder* self, int a, int b) {
|
23
|
-
|
20
|
+
return a - b;
|
24
21
|
}
|
25
22
|
|
26
23
|
int multiplyIntegers(classes::Adder* self, int a, int b) {
|
27
|
-
|
24
|
+
return a * b;
|
28
25
|
}
|
29
|
-
|
26
|
+
END
|
30
27
|
|
31
|
-
|
28
|
+
wrapping = <<-END
|
32
29
|
<class>.define_method(\"sub_ints\", &subtractIntegers);
|
33
30
|
<class>.define_method(\"mult_ints\", &multiplyIntegers);
|
34
31
|
END
|
35
32
|
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
require 'adder'
|
33
|
+
adder.add_custom_code( decl, wrapping )
|
40
34
|
end
|
35
|
+
|
36
|
+
require 'adder'
|
41
37
|
end
|
42
38
|
|
43
39
|
specify "Adder has new custom methods" do
|
44
40
|
a = Adder.new
|
45
|
-
a.
|
46
|
-
a.
|
47
|
-
|
48
|
-
a.sub_ints(5, 4).should.equal 1
|
49
|
-
a.mult_ints(5, 4).should.equal 20
|
41
|
+
a.sub_ints(5, 4).should == 1
|
42
|
+
a.mult_ints(5, 4).should == 20
|
50
43
|
end
|
51
44
|
|
52
45
|
end
|