rice2 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +23 -0
- data/Doxyfile +2268 -0
- data/Makefile.am +26 -0
- data/Makefile.in +929 -0
- data/README.md +1054 -0
- data/README.mingw +8 -0
- data/Rakefile +24 -0
- data/aclocal.m4 +1090 -0
- data/bootstrap +8 -0
- data/config.guess +1667 -0
- data/config.sub +1793 -0
- data/configure +8209 -0
- data/configure.ac +55 -0
- data/depcomp +791 -0
- data/doxygen.ac +314 -0
- data/doxygen.am +186 -0
- data/extconf.rb +66 -0
- data/install-sh +529 -0
- data/missing +215 -0
- data/post-autoconf.rb +22 -0
- data/post-automake.rb +28 -0
- data/rice/Address_Registration_Guard.cpp +22 -0
- data/rice/Address_Registration_Guard.hpp +7 -0
- data/rice/Address_Registration_Guard.ipp +37 -0
- data/rice/Address_Registration_Guard_defn.hpp +75 -0
- data/rice/Arg.hpp +8 -0
- data/rice/Arg_impl.hpp +129 -0
- data/rice/Arg_operators.cpp +21 -0
- data/rice/Arg_operators.hpp +19 -0
- data/rice/Array.hpp +214 -0
- data/rice/Array.ipp +256 -0
- data/rice/Builtin_Object.hpp +8 -0
- data/rice/Builtin_Object.ipp +50 -0
- data/rice/Builtin_Object_defn.hpp +50 -0
- data/rice/Class.cpp +57 -0
- data/rice/Class.hpp +8 -0
- data/rice/Class.ipp +6 -0
- data/rice/Class_defn.hpp +83 -0
- data/rice/Constructor.hpp +47 -0
- data/rice/Data_Object.hpp +8 -0
- data/rice/Data_Object.ipp +133 -0
- data/rice/Data_Object_defn.hpp +138 -0
- data/rice/Data_Type.cpp +54 -0
- data/rice/Data_Type.hpp +8 -0
- data/rice/Data_Type.ipp +365 -0
- data/rice/Data_Type_defn.hpp +261 -0
- data/rice/Data_Type_fwd.hpp +12 -0
- data/rice/Director.cpp +13 -0
- data/rice/Director.hpp +39 -0
- data/rice/Enum.hpp +117 -0
- data/rice/Enum.ipp +246 -0
- data/rice/Exception.cpp +59 -0
- data/rice/Exception.hpp +13 -0
- data/rice/Exception_Base.hpp +8 -0
- data/rice/Exception_Base.ipp +13 -0
- data/rice/Exception_Base_defn.hpp +27 -0
- data/rice/Exception_defn.hpp +69 -0
- data/rice/Hash.hpp +227 -0
- data/rice/Hash.ipp +329 -0
- data/rice/Identifier.cpp +8 -0
- data/rice/Identifier.hpp +50 -0
- data/rice/Identifier.ipp +33 -0
- data/rice/Jump_Tag.hpp +24 -0
- data/rice/Makefile.am +122 -0
- data/rice/Makefile.in +885 -0
- data/rice/Module.cpp +84 -0
- data/rice/Module.hpp +8 -0
- data/rice/Module.ipp +6 -0
- data/rice/Module_defn.hpp +88 -0
- data/rice/Module_impl.hpp +281 -0
- data/rice/Module_impl.ipp +345 -0
- data/rice/Object.cpp +169 -0
- data/rice/Object.hpp +8 -0
- data/rice/Object.ipp +33 -0
- data/rice/Object_defn.hpp +214 -0
- data/rice/Require_Guard.hpp +21 -0
- data/rice/String.cpp +94 -0
- data/rice/String.hpp +91 -0
- data/rice/Struct.cpp +117 -0
- data/rice/Struct.hpp +162 -0
- data/rice/Struct.ipp +26 -0
- data/rice/Symbol.cpp +25 -0
- data/rice/Symbol.hpp +66 -0
- data/rice/Symbol.ipp +44 -0
- data/rice/config.hpp +47 -0
- data/rice/config.hpp.in +46 -0
- data/rice/detail/Arguments.hpp +118 -0
- data/rice/detail/Auto_Function_Wrapper.hpp +898 -0
- data/rice/detail/Auto_Function_Wrapper.ipp +3694 -0
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +897 -0
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +2774 -0
- data/rice/detail/Caster.hpp +103 -0
- data/rice/detail/Exception_Handler.hpp +8 -0
- data/rice/detail/Exception_Handler.ipp +68 -0
- data/rice/detail/Exception_Handler_defn.hpp +96 -0
- data/rice/detail/Iterator.hpp +93 -0
- data/rice/detail/Not_Copyable.hpp +25 -0
- data/rice/detail/Wrapped_Function.hpp +33 -0
- data/rice/detail/cfp.hpp +24 -0
- data/rice/detail/cfp.ipp +51 -0
- data/rice/detail/check_ruby_type.cpp +27 -0
- data/rice/detail/check_ruby_type.hpp +23 -0
- data/rice/detail/creation_funcs.hpp +37 -0
- data/rice/detail/creation_funcs.ipp +36 -0
- data/rice/detail/default_allocation_func.hpp +23 -0
- data/rice/detail/default_allocation_func.ipp +11 -0
- data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
- data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
- data/rice/detail/demangle.cpp +56 -0
- data/rice/detail/demangle.hpp +19 -0
- data/rice/detail/env.hpp +11 -0
- data/rice/detail/from_ruby.hpp +43 -0
- data/rice/detail/from_ruby.ipp +60 -0
- data/rice/detail/method_data.cpp +92 -0
- data/rice/detail/method_data.hpp +21 -0
- data/rice/detail/node.hpp +13 -0
- data/rice/detail/protect.cpp +29 -0
- data/rice/detail/protect.hpp +34 -0
- data/rice/detail/ruby.hpp +74 -0
- data/rice/detail/ruby_version_code.hpp +6 -0
- data/rice/detail/ruby_version_code.hpp.in +6 -0
- data/rice/detail/st.hpp +22 -0
- data/rice/detail/to_ruby.hpp +22 -0
- data/rice/detail/to_ruby.ipp +36 -0
- data/rice/detail/traits.hpp +43 -0
- data/rice/detail/win32.hpp +16 -0
- data/rice/detail/wrap_function.hpp +66 -0
- data/rice/global_function.hpp +33 -0
- data/rice/global_function.ipp +22 -0
- data/rice/protect.hpp +38 -0
- data/rice/protect.ipp +1134 -0
- data/rice/ruby_mark.hpp +13 -0
- data/rice/ruby_try_catch.hpp +86 -0
- data/rice/rubypp.rb +97 -0
- data/rice/to_from_ruby.hpp +8 -0
- data/rice/to_from_ruby.ipp +418 -0
- data/rice/to_from_ruby_defn.hpp +70 -0
- data/ruby.ac +135 -0
- data/ruby/Makefile.am +1 -0
- data/ruby/Makefile.in +628 -0
- data/ruby/lib/Makefile.am +3 -0
- data/ruby/lib/Makefile.in +506 -0
- data/ruby/lib/mkmf-rice.rb.in +217 -0
- data/ruby/lib/version.rb +3 -0
- data/sample/Makefile.am +47 -0
- data/sample/Makefile.in +489 -0
- data/sample/enum/extconf.rb +3 -0
- data/sample/enum/sample_enum.cpp +54 -0
- data/sample/enum/test.rb +8 -0
- data/sample/inheritance/animals.cpp +98 -0
- data/sample/inheritance/extconf.rb +3 -0
- data/sample/inheritance/test.rb +7 -0
- data/sample/map/extconf.rb +3 -0
- data/sample/map/map.cpp +81 -0
- data/sample/map/test.rb +7 -0
- data/test/Makefile.am +72 -0
- data/test/Makefile.in +1213 -0
- data/test/ext/Makefile.am +41 -0
- data/test/ext/Makefile.in +483 -0
- data/test/ext/t1/Foo.hpp +10 -0
- data/test/ext/t1/extconf.rb +2 -0
- data/test/ext/t1/t1.cpp +15 -0
- data/test/ext/t2/extconf.rb +2 -0
- data/test/ext/t2/t2.cpp +11 -0
- data/test/test_Address_Registration_Guard.cpp +43 -0
- data/test/test_Array.cpp +248 -0
- data/test/test_Builtin_Object.cpp +71 -0
- data/test/test_Class.cpp +496 -0
- data/test/test_Constructor.cpp +128 -0
- data/test/test_Data_Object.cpp +275 -0
- data/test/test_Data_Type.cpp +348 -0
- data/test/test_Director.cpp +308 -0
- data/test/test_Enum.cpp +215 -0
- data/test/test_Exception.cpp +47 -0
- data/test/test_Hash.cpp +212 -0
- data/test/test_Identifier.cpp +70 -0
- data/test/test_Jump_Tag.cpp +17 -0
- data/test/test_Memory_Management.cpp +50 -0
- data/test/test_Module.cpp +497 -0
- data/test/test_Object.cpp +159 -0
- data/test/test_String.cpp +107 -0
- data/test/test_Struct.cpp +205 -0
- data/test/test_Symbol.cpp +63 -0
- data/test/test_To_From_Ruby.cpp +428 -0
- data/test/test_global_functions.cpp +114 -0
- data/test/test_rice.rb +41 -0
- data/test/unittest.cpp +136 -0
- data/test/unittest.hpp +294 -0
- metadata +297 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/Exception.hpp"
|
3
|
+
#include "rice/String.hpp"
|
4
|
+
|
5
|
+
using namespace Rice;
|
6
|
+
|
7
|
+
TESTSUITE(Exception);
|
8
|
+
|
9
|
+
SETUP(Exception)
|
10
|
+
{
|
11
|
+
ruby_init();
|
12
|
+
}
|
13
|
+
|
14
|
+
TESTCASE(construct_from_exception_object)
|
15
|
+
{
|
16
|
+
VALUE v = protect(rb_exc_new2, rb_eRuntimeError, "foo");
|
17
|
+
Exception ex(v);
|
18
|
+
ASSERT_EQUAL(ex.value(), v);
|
19
|
+
}
|
20
|
+
|
21
|
+
TESTCASE(copy_construct)
|
22
|
+
{
|
23
|
+
VALUE v = protect(rb_exc_new2, rb_eRuntimeError, "foo");
|
24
|
+
Exception ex1(v);
|
25
|
+
Exception ex2(v);
|
26
|
+
ASSERT_EQUAL(ex2.value(), v);
|
27
|
+
}
|
28
|
+
|
29
|
+
TESTCASE(construct_from_format_string)
|
30
|
+
{
|
31
|
+
Exception ex(rb_eRuntimeError, "%s", "foo");
|
32
|
+
ASSERT_EQUAL(ex.class_of(), Object(rb_eRuntimeError));
|
33
|
+
}
|
34
|
+
|
35
|
+
TESTCASE(message)
|
36
|
+
{
|
37
|
+
Exception ex(rb_eRuntimeError, "%s", "foo");
|
38
|
+
ASSERT_EQUAL(String("foo"), ex.message());
|
39
|
+
}
|
40
|
+
|
41
|
+
TESTCASE(what)
|
42
|
+
{
|
43
|
+
const char* foo = "foo";
|
44
|
+
Exception ex(rb_eRuntimeError, "%s", "foo");
|
45
|
+
ASSERT_EQUAL(foo, ex.what());
|
46
|
+
}
|
47
|
+
|
data/test/test_Hash.cpp
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/Hash.hpp"
|
3
|
+
#include "rice/global_function.hpp"
|
4
|
+
#include <vector>
|
5
|
+
#include <map>
|
6
|
+
#include <algorithm>
|
7
|
+
|
8
|
+
using namespace Rice;
|
9
|
+
|
10
|
+
TESTSUITE(Hash);
|
11
|
+
|
12
|
+
SETUP(Hash)
|
13
|
+
{
|
14
|
+
ruby_init();
|
15
|
+
}
|
16
|
+
|
17
|
+
TESTCASE(default_construct)
|
18
|
+
{
|
19
|
+
Hash h;
|
20
|
+
ASSERT_EQUAL(T_HASH, rb_type(h));
|
21
|
+
ASSERT_EQUAL(0, RHASH_SIZE(h.value()));
|
22
|
+
}
|
23
|
+
|
24
|
+
TESTCASE(construct_from_object)
|
25
|
+
{
|
26
|
+
Object o(rb_hash_new());
|
27
|
+
Hash h(o);
|
28
|
+
ASSERT_EQUAL(T_HASH, rb_type(h));
|
29
|
+
ASSERT_EQUAL(0, RHASH_SIZE(h.value()));
|
30
|
+
}
|
31
|
+
|
32
|
+
TESTCASE(construct_from_value)
|
33
|
+
{
|
34
|
+
VALUE v(rb_hash_new());
|
35
|
+
Hash h(v);
|
36
|
+
ASSERT_EQUAL(T_HASH, rb_type(h));
|
37
|
+
ASSERT_EQUAL(0, RHASH_SIZE(h.value()));
|
38
|
+
}
|
39
|
+
|
40
|
+
TESTCASE(copy_construct)
|
41
|
+
{
|
42
|
+
Hash h;
|
43
|
+
Hash h2(h);
|
44
|
+
ASSERT_EQUAL(h.value(), h2.value());
|
45
|
+
}
|
46
|
+
|
47
|
+
TESTCASE(assignment)
|
48
|
+
{
|
49
|
+
Hash h;
|
50
|
+
Hash h2;
|
51
|
+
h = h2;
|
52
|
+
}
|
53
|
+
|
54
|
+
TESTCASE(size)
|
55
|
+
{
|
56
|
+
Hash h;
|
57
|
+
ASSERT_EQUAL(0u, h.size());
|
58
|
+
h[1] = 5;
|
59
|
+
ASSERT_EQUAL(1u, h.size());
|
60
|
+
h[6] = 9;
|
61
|
+
ASSERT_EQUAL(2u, h.size());
|
62
|
+
h[42] = 42;
|
63
|
+
ASSERT_EQUAL(3u, h.size());
|
64
|
+
h[6] = 1;
|
65
|
+
ASSERT_EQUAL(3u, h.size());
|
66
|
+
}
|
67
|
+
|
68
|
+
TESTCASE(bracket)
|
69
|
+
{
|
70
|
+
Hash h;
|
71
|
+
h[1] = 5;
|
72
|
+
h[6] = 9;
|
73
|
+
h[42] = 42;
|
74
|
+
h[6] = 1;
|
75
|
+
ASSERT_EQUAL(to_ruby(5), Object(h[1]));
|
76
|
+
ASSERT_EQUAL(to_ruby(42), Object(h[42]));
|
77
|
+
ASSERT_EQUAL(to_ruby(1), Object(h[6]));
|
78
|
+
}
|
79
|
+
|
80
|
+
TESTCASE(get)
|
81
|
+
{
|
82
|
+
Hash h;
|
83
|
+
h[1] = 5;
|
84
|
+
h[6] = 9;
|
85
|
+
h[42] = 42;
|
86
|
+
h[6] = 1;
|
87
|
+
ASSERT_EQUAL(5, h.get<int>(1));
|
88
|
+
ASSERT_EQUAL(42, h.get<int>(42));
|
89
|
+
ASSERT_EQUAL(1, h.get<int>(6));
|
90
|
+
}
|
91
|
+
|
92
|
+
TESTCASE(construct_vector_from_hash_iterators)
|
93
|
+
{
|
94
|
+
Hash h;
|
95
|
+
h[1] = 5;
|
96
|
+
h[6] = 9;
|
97
|
+
h[42] = 42;
|
98
|
+
h[6] = 1;
|
99
|
+
|
100
|
+
std::vector<Hash::Entry> v(h.begin(), h.end());
|
101
|
+
std::sort(v.begin(), v.end());
|
102
|
+
ASSERT_EQUAL(3u, v.size());
|
103
|
+
ASSERT_EQUAL(v[0].key, to_ruby(1));
|
104
|
+
ASSERT_EQUAL(v[1].key, to_ruby(6));
|
105
|
+
ASSERT_EQUAL(v[2].key, to_ruby(42));
|
106
|
+
ASSERT_EQUAL(&v[0].key, &v[0].first);
|
107
|
+
ASSERT_EQUAL(&v[1].key, &v[1].first);
|
108
|
+
ASSERT_EQUAL(&v[2].key, &v[2].first);
|
109
|
+
ASSERT_EQUAL(v[0].value, to_ruby(5));
|
110
|
+
ASSERT_EQUAL(v[1].value, to_ruby(1));
|
111
|
+
ASSERT_EQUAL(v[2].value, to_ruby(42));
|
112
|
+
ASSERT_EQUAL(&v[0].value, &v[0].second);
|
113
|
+
ASSERT_EQUAL(&v[1].value, &v[1].second);
|
114
|
+
ASSERT_EQUAL(&v[2].value, &v[2].second);
|
115
|
+
}
|
116
|
+
|
117
|
+
TESTCASE(iterate)
|
118
|
+
{
|
119
|
+
Hash h;
|
120
|
+
h[1] = 5;
|
121
|
+
h[6] = 9;
|
122
|
+
h[42] = 42;
|
123
|
+
h[6] = 1;
|
124
|
+
|
125
|
+
std::vector<Hash::Entry> v;
|
126
|
+
Hash::iterator it = h.begin();
|
127
|
+
Hash::iterator end = h.end();
|
128
|
+
|
129
|
+
for(; it != end; ++it)
|
130
|
+
{
|
131
|
+
v.push_back(*it);
|
132
|
+
}
|
133
|
+
|
134
|
+
std::sort(v.begin(), v.end());
|
135
|
+
ASSERT_EQUAL(3u, v.size());
|
136
|
+
ASSERT_EQUAL(v[0].key, to_ruby(1));
|
137
|
+
ASSERT_EQUAL(v[1].key, to_ruby(6));
|
138
|
+
ASSERT_EQUAL(v[2].key, to_ruby(42));
|
139
|
+
ASSERT_EQUAL(&v[0].key, &v[0].first);
|
140
|
+
ASSERT_EQUAL(&v[1].key, &v[1].first);
|
141
|
+
ASSERT_EQUAL(&v[2].key, &v[2].first);
|
142
|
+
ASSERT_EQUAL(v[0].value, to_ruby(5));
|
143
|
+
ASSERT_EQUAL(v[1].value, to_ruby(1));
|
144
|
+
ASSERT_EQUAL(v[2].value, to_ruby(42));
|
145
|
+
ASSERT_EQUAL(&v[0].value, &v[0].second);
|
146
|
+
ASSERT_EQUAL(&v[1].value, &v[1].second);
|
147
|
+
ASSERT_EQUAL(&v[2].value, &v[2].second);
|
148
|
+
}
|
149
|
+
|
150
|
+
TESTCASE(const_iterate)
|
151
|
+
{
|
152
|
+
Hash h;
|
153
|
+
h[1] = 5;
|
154
|
+
h[6] = 9;
|
155
|
+
h[42] = 42;
|
156
|
+
h[6] = 1;
|
157
|
+
std::vector<Hash::Entry> v;
|
158
|
+
Hash::const_iterator it = h.begin();
|
159
|
+
Hash::const_iterator end = h.end();
|
160
|
+
for(; it != end; ++it)
|
161
|
+
{
|
162
|
+
v.push_back(*it);
|
163
|
+
}
|
164
|
+
std::sort(v.begin(), v.end());
|
165
|
+
ASSERT_EQUAL(3u, v.size());
|
166
|
+
ASSERT_EQUAL(v[0].key, to_ruby(1));
|
167
|
+
ASSERT_EQUAL(v[1].key, to_ruby(6));
|
168
|
+
ASSERT_EQUAL(v[2].key, to_ruby(42));
|
169
|
+
ASSERT_EQUAL(&v[0].key, &v[0].first);
|
170
|
+
ASSERT_EQUAL(&v[1].key, &v[1].first);
|
171
|
+
ASSERT_EQUAL(&v[2].key, &v[2].first);
|
172
|
+
ASSERT_EQUAL(v[0].value, to_ruby(5));
|
173
|
+
ASSERT_EQUAL(v[1].value, to_ruby(1));
|
174
|
+
ASSERT_EQUAL(v[2].value, to_ruby(42));
|
175
|
+
ASSERT_EQUAL(&v[0].value, &v[0].value);
|
176
|
+
ASSERT_EQUAL(&v[1].value, &v[1].value);
|
177
|
+
ASSERT_EQUAL(&v[2].value, &v[2].value);
|
178
|
+
}
|
179
|
+
|
180
|
+
TESTCASE(iterate_and_change)
|
181
|
+
{
|
182
|
+
Hash h;
|
183
|
+
h[1] = 5;
|
184
|
+
h[6] = 9;
|
185
|
+
h[42] = 42;
|
186
|
+
h[6] = 1;
|
187
|
+
Hash::const_iterator it = h.begin();
|
188
|
+
Hash::const_iterator end = h.end();
|
189
|
+
std::map<int, int> m;
|
190
|
+
for(int j = 0; it != end; ++j, ++it)
|
191
|
+
{
|
192
|
+
it->second = j;
|
193
|
+
m[from_ruby<int>(it->first)] = j;
|
194
|
+
}
|
195
|
+
ASSERT_EQUAL(3u, m.size());
|
196
|
+
ASSERT_EQUAL(to_ruby(m[1]), h[1]);
|
197
|
+
ASSERT_EQUAL(to_ruby(m[6]), h[6]);
|
198
|
+
ASSERT_EQUAL(to_ruby(m[42]), h[42]);
|
199
|
+
}
|
200
|
+
|
201
|
+
/**
|
202
|
+
* Issue 59 - Copy constructor compilation problem.
|
203
|
+
*/
|
204
|
+
|
205
|
+
namespace {
|
206
|
+
void testHashArg(Object self, Hash string) {
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
TESTCASE(use_hash_in_wrapped_function) {
|
211
|
+
define_global_function("test_hash_arg", &testHashArg);
|
212
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/Identifier.hpp"
|
3
|
+
#include "rice/Symbol.hpp"
|
4
|
+
|
5
|
+
using namespace Rice;
|
6
|
+
|
7
|
+
TESTSUITE(Identifier);
|
8
|
+
|
9
|
+
SETUP(Identifier)
|
10
|
+
{
|
11
|
+
ruby_init();
|
12
|
+
}
|
13
|
+
|
14
|
+
TESTCASE(construct_from_id)
|
15
|
+
{
|
16
|
+
ID id = rb_intern("foo");
|
17
|
+
Identifier identifier(id);
|
18
|
+
ASSERT_EQUAL(id, identifier.id());
|
19
|
+
}
|
20
|
+
|
21
|
+
TESTCASE(construct_from_symbol)
|
22
|
+
{
|
23
|
+
Symbol symbol("FOO");
|
24
|
+
Identifier identifier(symbol);
|
25
|
+
ASSERT_EQUAL(rb_intern("FOO"), identifier.id());
|
26
|
+
}
|
27
|
+
|
28
|
+
TESTCASE(construct_from_c_string)
|
29
|
+
{
|
30
|
+
Identifier identifier("Foo");
|
31
|
+
ASSERT_EQUAL(rb_intern("Foo"), identifier.id());
|
32
|
+
}
|
33
|
+
|
34
|
+
TESTCASE(default_construct)
|
35
|
+
{
|
36
|
+
Identifier identifier;
|
37
|
+
ASSERT_EQUAL(rb_intern(""), identifier.id());
|
38
|
+
}
|
39
|
+
|
40
|
+
TESTCASE(copy_construct)
|
41
|
+
{
|
42
|
+
Identifier identifier1("Foo");
|
43
|
+
Identifier identifier2(identifier1);
|
44
|
+
ASSERT_EQUAL(rb_intern("Foo"), identifier2.id());
|
45
|
+
}
|
46
|
+
|
47
|
+
TESTCASE(c_str)
|
48
|
+
{
|
49
|
+
Identifier identifier("Foo");
|
50
|
+
ASSERT_EQUAL("Foo", identifier.c_str());
|
51
|
+
}
|
52
|
+
|
53
|
+
TESTCASE(str)
|
54
|
+
{
|
55
|
+
Identifier identifier("Foo");
|
56
|
+
ASSERT_EQUAL(std::string("Foo"), identifier.str());
|
57
|
+
}
|
58
|
+
|
59
|
+
TESTCASE(implicit_conversion_to_id)
|
60
|
+
{
|
61
|
+
Identifier identifier("Foo");
|
62
|
+
ASSERT_EQUAL(rb_intern("Foo"), static_cast<ID>(identifier));
|
63
|
+
}
|
64
|
+
|
65
|
+
TESTCASE(to_sym)
|
66
|
+
{
|
67
|
+
Identifier identifier("Foo");
|
68
|
+
ASSERT_EQUAL(Symbol("Foo"), Symbol(identifier.to_sym()));
|
69
|
+
}
|
70
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/String.hpp"
|
3
|
+
#include "rice/Class.hpp"
|
4
|
+
#include "rice/global_function.hpp"
|
5
|
+
|
6
|
+
using namespace Rice;
|
7
|
+
|
8
|
+
TESTSUITE(Memory_Management);
|
9
|
+
|
10
|
+
SETUP(Memory_Management)
|
11
|
+
{
|
12
|
+
ruby_init();
|
13
|
+
}
|
14
|
+
|
15
|
+
namespace
|
16
|
+
{
|
17
|
+
class TestClass {
|
18
|
+
double tmp;
|
19
|
+
public:
|
20
|
+
TestClass() {tmp=0;}
|
21
|
+
|
22
|
+
double getTmp() {
|
23
|
+
return tmp;
|
24
|
+
}
|
25
|
+
|
26
|
+
void setTmp(double x) {
|
27
|
+
tmp = x;
|
28
|
+
}
|
29
|
+
};
|
30
|
+
|
31
|
+
TestClass returnTestClass() {
|
32
|
+
TestClass x = TestClass();
|
33
|
+
x.setTmp(8);
|
34
|
+
return x;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
TESTCASE(allows_copy_contructors_to_work)
|
39
|
+
{
|
40
|
+
define_class<TestClass>("TestClass")
|
41
|
+
.define_method("tmp=", &TestClass::setTmp)
|
42
|
+
.define_method("tmp", &TestClass::getTmp);
|
43
|
+
|
44
|
+
define_global_function("return_test_class", &returnTestClass);
|
45
|
+
|
46
|
+
Module m = define_module("TestingModule");
|
47
|
+
|
48
|
+
Object result = m.instance_eval("return_test_class.tmp");
|
49
|
+
ASSERT_EQUAL(8.0, from_ruby<double>(result.value()));
|
50
|
+
}
|
@@ -0,0 +1,497 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/Module.hpp"
|
3
|
+
#include "rice/Exception.hpp"
|
4
|
+
#include "rice/Array.hpp"
|
5
|
+
#include "rice/Arg.hpp"
|
6
|
+
#include "rice/global_function.hpp"
|
7
|
+
#include "rice/Constructor.hpp"
|
8
|
+
|
9
|
+
using namespace Rice;
|
10
|
+
|
11
|
+
TESTSUITE(Module);
|
12
|
+
|
13
|
+
SETUP(Object)
|
14
|
+
{
|
15
|
+
ruby_init();
|
16
|
+
}
|
17
|
+
|
18
|
+
TESTCASE(construct_from_value)
|
19
|
+
{
|
20
|
+
Module m(rb_mEnumerable);
|
21
|
+
ASSERT_EQUAL(rb_mEnumerable, m.value());
|
22
|
+
}
|
23
|
+
|
24
|
+
namespace
|
25
|
+
{
|
26
|
+
|
27
|
+
class Quite_Silly_Exception
|
28
|
+
: public std::exception
|
29
|
+
{
|
30
|
+
};
|
31
|
+
|
32
|
+
void handle_silly_exception(Quite_Silly_Exception const & ex)
|
33
|
+
{
|
34
|
+
throw Exception(rb_eRuntimeError, "SILLY");
|
35
|
+
}
|
36
|
+
|
37
|
+
void throw_silly_exception(Object self)
|
38
|
+
{
|
39
|
+
throw Quite_Silly_Exception();
|
40
|
+
}
|
41
|
+
|
42
|
+
} // namespace
|
43
|
+
|
44
|
+
TESTCASE(add_handler)
|
45
|
+
{
|
46
|
+
Module m(anonymous_module());
|
47
|
+
m.add_handler<Quite_Silly_Exception>(handle_silly_exception);
|
48
|
+
m.define_singleton_method("foo", throw_silly_exception);
|
49
|
+
Object exc = m.instance_eval("begin; foo; rescue Exception; $!; end");
|
50
|
+
ASSERT_EQUAL(rb_eRuntimeError, CLASS_OF(exc));
|
51
|
+
Exception ex(exc);
|
52
|
+
ASSERT_EQUAL(String("SILLY"), String(ex.message()));
|
53
|
+
}
|
54
|
+
|
55
|
+
namespace
|
56
|
+
{
|
57
|
+
|
58
|
+
bool define_method_simple_ok;
|
59
|
+
|
60
|
+
void define_method_simple_helper(Object o)
|
61
|
+
{
|
62
|
+
define_method_simple_ok = true;
|
63
|
+
}
|
64
|
+
|
65
|
+
} // namespace
|
66
|
+
|
67
|
+
TESTCASE(define_method_simple)
|
68
|
+
{
|
69
|
+
Module m(anonymous_module());
|
70
|
+
m.define_method("foo", define_method_simple_helper);
|
71
|
+
define_method_simple_ok = false;
|
72
|
+
Object o = m.instance_eval("o = Object.new; o.extend(self); o.foo");
|
73
|
+
ASSERT(define_method_simple_ok);
|
74
|
+
}
|
75
|
+
|
76
|
+
TESTCASE(define_singleton_method_simple)
|
77
|
+
{
|
78
|
+
Module m(anonymous_module());
|
79
|
+
m.define_singleton_method("foo", define_method_simple_helper);
|
80
|
+
define_method_simple_ok = false;
|
81
|
+
Object o = m.call("foo");
|
82
|
+
ASSERT(define_method_simple_ok);
|
83
|
+
}
|
84
|
+
|
85
|
+
TESTCASE(define_module_function_simple)
|
86
|
+
{
|
87
|
+
Module m(anonymous_module());
|
88
|
+
m.define_module_function("foo", define_method_simple_helper);
|
89
|
+
define_method_simple_ok = false;
|
90
|
+
m.instance_eval("o = Object.new; o.extend(self); o.instance_eval { foo }");
|
91
|
+
ASSERT(define_method_simple_ok);
|
92
|
+
define_method_simple_ok = false;
|
93
|
+
m.call("foo");
|
94
|
+
ASSERT(define_method_simple_ok);
|
95
|
+
}
|
96
|
+
|
97
|
+
TESTCASE(define_module_does_not_leak_method_to_Object)
|
98
|
+
{
|
99
|
+
Module m = define_module("TestModule");
|
100
|
+
m.define_module_function("test_module_function", &define_method_simple_helper);
|
101
|
+
|
102
|
+
Module runner(anonymous_module());
|
103
|
+
ASSERT_EXCEPTION_CHECK(
|
104
|
+
Exception,
|
105
|
+
runner.instance_eval("Object.test_module_function"),
|
106
|
+
ASSERT_EQUAL(
|
107
|
+
Object(rb_eNoMethodError),
|
108
|
+
Object(CLASS_OF(ex.value()))
|
109
|
+
)
|
110
|
+
);
|
111
|
+
}
|
112
|
+
|
113
|
+
namespace
|
114
|
+
{
|
115
|
+
|
116
|
+
int define_method_int_result;
|
117
|
+
|
118
|
+
void define_method_int_helper(Object o, int i)
|
119
|
+
{
|
120
|
+
define_method_int_result = i;
|
121
|
+
}
|
122
|
+
|
123
|
+
} // namespace
|
124
|
+
|
125
|
+
TESTCASE(define_method_int)
|
126
|
+
{
|
127
|
+
Module m(anonymous_module());
|
128
|
+
m.define_method("foo", define_method_int_helper);
|
129
|
+
define_method_int_result = 0;
|
130
|
+
Object o = m.instance_eval("o = Object.new; o.extend(self); o.foo(42)");
|
131
|
+
ASSERT_EQUAL(42, define_method_int_result);
|
132
|
+
}
|
133
|
+
|
134
|
+
TESTCASE(define_singleton_method_int)
|
135
|
+
{
|
136
|
+
Module m(anonymous_module());
|
137
|
+
m.define_singleton_method("foo", define_method_int_helper);
|
138
|
+
define_method_int_result = 0;
|
139
|
+
Object o = m.call("foo", 42);
|
140
|
+
ASSERT_EQUAL(42, define_method_int_result);
|
141
|
+
}
|
142
|
+
|
143
|
+
TESTCASE(define_module_function_int)
|
144
|
+
{
|
145
|
+
Module m(anonymous_module());
|
146
|
+
m.define_module_function("foo", define_method_int_helper);
|
147
|
+
define_method_int_result = 0;
|
148
|
+
m.instance_eval("o = Object.new; o.extend(self); o.instance_eval { foo(42) }");
|
149
|
+
ASSERT_EQUAL(42, define_method_int_result);
|
150
|
+
define_method_int_result = 0;
|
151
|
+
m.call("foo", 42);
|
152
|
+
ASSERT_EQUAL(42, define_method_int_result);
|
153
|
+
}
|
154
|
+
|
155
|
+
TESTCASE(define_method_int_passed_no_args)
|
156
|
+
{
|
157
|
+
Module m(anonymous_module());
|
158
|
+
m.define_method("foo", define_method_int_helper);
|
159
|
+
ASSERT_EXCEPTION_CHECK(
|
160
|
+
Exception,
|
161
|
+
m.instance_eval("o = Object.new; o.extend(self); o.foo"),
|
162
|
+
ASSERT_EQUAL(
|
163
|
+
Object(rb_eArgError),
|
164
|
+
Object(CLASS_OF(ex.value()))
|
165
|
+
)
|
166
|
+
);
|
167
|
+
}
|
168
|
+
|
169
|
+
namespace
|
170
|
+
{
|
171
|
+
|
172
|
+
struct Foo
|
173
|
+
{
|
174
|
+
int x;
|
175
|
+
};
|
176
|
+
|
177
|
+
int define_method_int_foo_result_i;
|
178
|
+
Foo * define_method_int_foo_result_x;
|
179
|
+
|
180
|
+
void define_method_int_foo_helper(Object o, int i, Foo * x)
|
181
|
+
{
|
182
|
+
define_method_int_foo_result_i = i;
|
183
|
+
define_method_int_foo_result_x = x;
|
184
|
+
}
|
185
|
+
|
186
|
+
} // namespace
|
187
|
+
|
188
|
+
template<>
|
189
|
+
Foo * from_ruby<Foo *>(Object x)
|
190
|
+
{
|
191
|
+
Foo * retval;
|
192
|
+
Data_Get_Struct(x.value(), Foo, retval);
|
193
|
+
return retval;
|
194
|
+
}
|
195
|
+
|
196
|
+
TESTCASE(define_singleton_method_int_foo)
|
197
|
+
{
|
198
|
+
Module m(anonymous_module());
|
199
|
+
m.define_singleton_method("int_and_foo", define_method_int_foo_helper);
|
200
|
+
define_method_int_result = 0;
|
201
|
+
Foo * foo = new Foo;
|
202
|
+
foo->x = 1024;
|
203
|
+
VALUE f = Data_Wrap_Struct(rb_cObject, 0, Default_Free_Function<Foo>::free, foo);
|
204
|
+
m.call("int_and_foo", 42, Object(f));
|
205
|
+
ASSERT_EQUAL(42, define_method_int_foo_result_i);
|
206
|
+
ASSERT_EQUAL(foo, define_method_int_foo_result_x);
|
207
|
+
}
|
208
|
+
|
209
|
+
// TODO: how to test define_iterator?
|
210
|
+
|
211
|
+
TESTCASE(include_module)
|
212
|
+
{
|
213
|
+
Module m(anonymous_module());
|
214
|
+
Module & m2(m.include_module(rb_mEnumerable));
|
215
|
+
ASSERT_EQUAL(&m, &m2);
|
216
|
+
Array ancestors(m.ancestors());
|
217
|
+
Array expected_ancestors;
|
218
|
+
expected_ancestors.push(m);
|
219
|
+
expected_ancestors.push(Module(rb_mEnumerable));
|
220
|
+
ASSERT_EQUAL(expected_ancestors, ancestors);
|
221
|
+
}
|
222
|
+
|
223
|
+
TESTCASE(const_set_get_by_id)
|
224
|
+
{
|
225
|
+
Module m(anonymous_module());
|
226
|
+
Object v = to_ruby(42);
|
227
|
+
Module & m2(m.const_set(rb_intern("FOO"), v));
|
228
|
+
ASSERT_EQUAL(&m, &m2);
|
229
|
+
ASSERT_EQUAL(v, m.const_get(rb_intern("FOO")));
|
230
|
+
}
|
231
|
+
|
232
|
+
TESTCASE(const_set_get_by_identifier)
|
233
|
+
{
|
234
|
+
Module m(anonymous_module());
|
235
|
+
Object v = to_ruby(42);
|
236
|
+
Module & m2(m.const_set(Identifier("FOO"), v));
|
237
|
+
ASSERT_EQUAL(&m, &m2);
|
238
|
+
ASSERT_EQUAL(v, m.const_get(Identifier("FOO")));
|
239
|
+
}
|
240
|
+
|
241
|
+
TESTCASE(const_set_get_by_string)
|
242
|
+
{
|
243
|
+
Module m(anonymous_module());
|
244
|
+
Object v = to_ruby(42);
|
245
|
+
Module & m2(m.const_set("FOO", v));
|
246
|
+
ASSERT_EQUAL(&m, &m2);
|
247
|
+
ASSERT_EQUAL(v, m.const_get("FOO"));
|
248
|
+
}
|
249
|
+
|
250
|
+
TESTCASE(remove_const)
|
251
|
+
{
|
252
|
+
Module m(anonymous_module());
|
253
|
+
Object v = to_ruby(42);
|
254
|
+
m.const_set("FOO", v);
|
255
|
+
ASSERT_EQUAL(v, m.const_get("FOO"));
|
256
|
+
m.remove_const("FOO");
|
257
|
+
ASSERT_EXCEPTION_CHECK(
|
258
|
+
Exception,
|
259
|
+
m.const_get("FOO"),
|
260
|
+
ASSERT_EQUAL(
|
261
|
+
Object(rb_eNameError),
|
262
|
+
Object(CLASS_OF(ex.value()))
|
263
|
+
)
|
264
|
+
);
|
265
|
+
}
|
266
|
+
|
267
|
+
TESTCASE(mod_name_anonymous)
|
268
|
+
{
|
269
|
+
Module m(anonymous_module());
|
270
|
+
ASSERT_EQUAL(String(""), m.name());
|
271
|
+
}
|
272
|
+
|
273
|
+
/**
|
274
|
+
* Tests for default arguments
|
275
|
+
*/
|
276
|
+
namespace
|
277
|
+
{
|
278
|
+
int defaults_method_one_arg1;
|
279
|
+
int defaults_method_one_arg2;
|
280
|
+
bool defaults_method_one_arg3 = false;
|
281
|
+
|
282
|
+
void defaults_method_one(int arg1, int arg2 = 3, bool arg3 = true)
|
283
|
+
{
|
284
|
+
defaults_method_one_arg1 = arg1;
|
285
|
+
defaults_method_one_arg2 = arg2;
|
286
|
+
defaults_method_one_arg3 = arg3;
|
287
|
+
}
|
288
|
+
}
|
289
|
+
|
290
|
+
TESTCASE(define_method_default_arguments)
|
291
|
+
{
|
292
|
+
Module m(anonymous_module());
|
293
|
+
m.define_method("foo", &defaults_method_one, (Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true));
|
294
|
+
|
295
|
+
Object o = m.instance_eval("o = Object.new; o.extend(self); o");
|
296
|
+
o.call("foo", 2);
|
297
|
+
|
298
|
+
ASSERT_EQUAL(2, defaults_method_one_arg1);
|
299
|
+
ASSERT_EQUAL(3, defaults_method_one_arg2);
|
300
|
+
ASSERT(defaults_method_one_arg3);
|
301
|
+
|
302
|
+
o.call("foo", 11, 10);
|
303
|
+
|
304
|
+
ASSERT_EQUAL(11, defaults_method_one_arg1);
|
305
|
+
ASSERT_EQUAL(10, defaults_method_one_arg2);
|
306
|
+
ASSERT(defaults_method_one_arg3);
|
307
|
+
|
308
|
+
o.call("foo", 22, 33, false);
|
309
|
+
|
310
|
+
ASSERT_EQUAL(22, defaults_method_one_arg1);
|
311
|
+
ASSERT_EQUAL(33, defaults_method_one_arg2);
|
312
|
+
ASSERT(!defaults_method_one_arg3);
|
313
|
+
}
|
314
|
+
|
315
|
+
TESTCASE(default_arguments_still_throws_argument_error)
|
316
|
+
{
|
317
|
+
Module m(anonymous_module());
|
318
|
+
m.define_method("foo", &defaults_method_one, (Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true));
|
319
|
+
|
320
|
+
ASSERT_EXCEPTION_CHECK(
|
321
|
+
Exception,
|
322
|
+
m.instance_eval("o = Object.new; o.extend(self); o.foo()"),
|
323
|
+
ASSERT_EQUAL(
|
324
|
+
Object(rb_eArgError),
|
325
|
+
Object(CLASS_OF(ex.value()))
|
326
|
+
)
|
327
|
+
);
|
328
|
+
|
329
|
+
ASSERT_EXCEPTION_CHECK(
|
330
|
+
Exception,
|
331
|
+
m.instance_eval("o = Object.new; o.extend(self); o.foo(3, 4, false, 17)"),
|
332
|
+
ASSERT_EQUAL(
|
333
|
+
Object(rb_eArgError),
|
334
|
+
Object(CLASS_OF(ex.value()))
|
335
|
+
)
|
336
|
+
);
|
337
|
+
}
|
338
|
+
|
339
|
+
namespace {
|
340
|
+
int the_one_default_arg = 0;
|
341
|
+
void method_with_one_default_arg(int num = 4) {
|
342
|
+
the_one_default_arg = num;
|
343
|
+
}
|
344
|
+
}
|
345
|
+
|
346
|
+
TESTCASE(defining_methods_with_single_default_argument)
|
347
|
+
{
|
348
|
+
// define_method
|
349
|
+
Module m(anonymous_module());
|
350
|
+
m.define_method("foo", &method_with_one_default_arg, (Arg("num") = 4));
|
351
|
+
m.instance_eval("o = Object.new; o.extend(self); o.foo()");
|
352
|
+
ASSERT_EQUAL(4, the_one_default_arg);
|
353
|
+
|
354
|
+
the_one_default_arg = 0;
|
355
|
+
|
356
|
+
// define_singleton_method
|
357
|
+
Class c(anonymous_class());
|
358
|
+
c.define_singleton_method("foo", &method_with_one_default_arg, (Arg("num") = 4));
|
359
|
+
c.call("foo");
|
360
|
+
ASSERT_EQUAL(4, the_one_default_arg);
|
361
|
+
|
362
|
+
the_one_default_arg = 0;
|
363
|
+
|
364
|
+
// define_module_function
|
365
|
+
m.define_module_function("foo2", &method_with_one_default_arg, (Arg("num") = 4));
|
366
|
+
|
367
|
+
m.call("foo2");
|
368
|
+
ASSERT_EQUAL(4, the_one_default_arg);
|
369
|
+
}
|
370
|
+
|
371
|
+
TESTCASE(default_arguments_for_define_singleton_method)
|
372
|
+
{
|
373
|
+
Class c(anonymous_class());
|
374
|
+
c.define_singleton_method("foo", &defaults_method_one, (Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true));
|
375
|
+
|
376
|
+
c.call("foo", 2);
|
377
|
+
|
378
|
+
ASSERT_EQUAL(2, defaults_method_one_arg1);
|
379
|
+
ASSERT_EQUAL(3, defaults_method_one_arg2);
|
380
|
+
ASSERT(defaults_method_one_arg3);
|
381
|
+
|
382
|
+
c.call("foo", 11, 10);
|
383
|
+
|
384
|
+
ASSERT_EQUAL(11, defaults_method_one_arg1);
|
385
|
+
ASSERT_EQUAL(10, defaults_method_one_arg2);
|
386
|
+
ASSERT(defaults_method_one_arg3);
|
387
|
+
|
388
|
+
c.call("foo", 22, 33, false);
|
389
|
+
|
390
|
+
ASSERT_EQUAL(22, defaults_method_one_arg1);
|
391
|
+
ASSERT_EQUAL(33, defaults_method_one_arg2);
|
392
|
+
ASSERT(!defaults_method_one_arg3);
|
393
|
+
}
|
394
|
+
|
395
|
+
TESTCASE(default_arguments_for_define_module_function)
|
396
|
+
{
|
397
|
+
Module m(anonymous_module());
|
398
|
+
m.define_module_function("foo", &defaults_method_one, (Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true));
|
399
|
+
|
400
|
+
m.call("foo", 2);
|
401
|
+
|
402
|
+
ASSERT_EQUAL(2, defaults_method_one_arg1);
|
403
|
+
ASSERT_EQUAL(3, defaults_method_one_arg2);
|
404
|
+
ASSERT(defaults_method_one_arg3);
|
405
|
+
|
406
|
+
m.call("foo", 11, 10);
|
407
|
+
|
408
|
+
ASSERT_EQUAL(11, defaults_method_one_arg1);
|
409
|
+
ASSERT_EQUAL(10, defaults_method_one_arg2);
|
410
|
+
ASSERT(defaults_method_one_arg3);
|
411
|
+
|
412
|
+
m.call("foo", 22, 33, false);
|
413
|
+
|
414
|
+
ASSERT_EQUAL(22, defaults_method_one_arg1);
|
415
|
+
ASSERT_EQUAL(33, defaults_method_one_arg2);
|
416
|
+
ASSERT(!defaults_method_one_arg3);
|
417
|
+
}
|
418
|
+
|
419
|
+
namespace {
|
420
|
+
std::string with_defaults_and_references_x;
|
421
|
+
bool with_defaults_and_references_doIt;
|
422
|
+
|
423
|
+
void with_defaults_and_references(std::string const& x, bool doIt = false)
|
424
|
+
{
|
425
|
+
with_defaults_and_references_x = x;
|
426
|
+
with_defaults_and_references_doIt = doIt;
|
427
|
+
}
|
428
|
+
}
|
429
|
+
|
430
|
+
TESTCASE(define_method_works_with_reference_arguments)
|
431
|
+
{
|
432
|
+
Module m(anonymous_module());
|
433
|
+
m.define_module_function("foo", &with_defaults_and_references,
|
434
|
+
(Arg("x"), Arg("doIt") = false));
|
435
|
+
|
436
|
+
m.call("foo", "test");
|
437
|
+
|
438
|
+
ASSERT_EQUAL("test", with_defaults_and_references_x);
|
439
|
+
ASSERT(!with_defaults_and_references_doIt);
|
440
|
+
}
|
441
|
+
|
442
|
+
namespace {
|
443
|
+
class ReturnTest { };
|
444
|
+
|
445
|
+
class Factory {
|
446
|
+
public:
|
447
|
+
Factory() { returnTest_ = new ReturnTest(); }
|
448
|
+
|
449
|
+
const ReturnTest& getReturnTest() const {
|
450
|
+
return *returnTest_;
|
451
|
+
}
|
452
|
+
|
453
|
+
private:
|
454
|
+
const ReturnTest* returnTest_;
|
455
|
+
};
|
456
|
+
}
|
457
|
+
|
458
|
+
TESTCASE(define_method_works_with_const_reference_return)
|
459
|
+
{
|
460
|
+
define_class<ReturnTest>("ReturnTest")
|
461
|
+
.define_constructor(Constructor<ReturnTest>());
|
462
|
+
|
463
|
+
define_class<Factory>("Factory")
|
464
|
+
.define_constructor(Constructor<Factory>())
|
465
|
+
.define_method("get_return_test", &Factory::getReturnTest);
|
466
|
+
|
467
|
+
Module m(anonymous_module());
|
468
|
+
|
469
|
+
Object result = m.instance_eval("Factory.new.get_return_test");
|
470
|
+
|
471
|
+
ASSERT_EQUAL("ReturnTest", result.class_of().name().c_str());
|
472
|
+
}
|
473
|
+
|
474
|
+
/*
|
475
|
+
namespace {
|
476
|
+
float with_reference_defaults_x;
|
477
|
+
std::string with_reference_defaults_str;
|
478
|
+
|
479
|
+
void with_reference_defaults(float x, std::string const& str = std::string("testing"))
|
480
|
+
{
|
481
|
+
with_reference_defaults_x = x;
|
482
|
+
with_reference_defaults_str = str;
|
483
|
+
}
|
484
|
+
}
|
485
|
+
|
486
|
+
TESTCASE(define_method_works_with_reference_const_default_values)
|
487
|
+
{
|
488
|
+
Module m(anonymous_module());
|
489
|
+
m.define_module_function("bar", &with_reference_defaults,
|
490
|
+
(Arg("x"), Arg("str") = std::string("testing")));
|
491
|
+
|
492
|
+
m.call("bar", 3);
|
493
|
+
|
494
|
+
ASSERT_EQUAL(3, with_reference_defaults_x);
|
495
|
+
ASSERT_EQUAL("testing", with_reference_defaults_str);
|
496
|
+
}
|
497
|
+
*/
|