keyme-rice 1.5.1.keyme
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.
- checksums.yaml +15 -0
- data/COPYING +23 -0
- data/Doxyfile +1253 -0
- data/Makefile.am +26 -0
- data/Makefile.in +853 -0
- data/README +1124 -0
- data/README.mingw +8 -0
- data/Rakefile +34 -0
- data/aclocal.m4 +971 -0
- data/bootstrap +8 -0
- data/config.guess +1530 -0
- data/config.sub +1773 -0
- data/configure +7121 -0
- data/configure.ac +52 -0
- data/depcomp +688 -0
- data/doxygen.ac +314 -0
- data/doxygen.am +186 -0
- data/extconf.rb +51 -0
- data/install-sh +527 -0
- data/missing +331 -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 +127 -0
- data/rice/Arg_operators.cpp +21 -0
- data/rice/Arg_operators.hpp +19 -0
- data/rice/Array.hpp +220 -0
- data/rice/Array.ipp +263 -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 +368 -0
- data/rice/Critical_Guard.hpp +40 -0
- data/rice/Critical_Guard.ipp +26 -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 +9 -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 +330 -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 +129 -0
- data/rice/Makefile.in +769 -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 +348 -0
- data/rice/Object.cpp +160 -0
- data/rice/Object.hpp +8 -0
- data/rice/Object.ipp +19 -0
- data/rice/Object_defn.hpp +191 -0
- data/rice/Require_Guard.hpp +21 -0
- data/rice/String.cpp +94 -0
- data/rice/String.hpp +89 -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/VM.cpp +82 -0
- data/rice/VM.hpp +32 -0
- data/rice/config.hpp +44 -0
- data/rice/config.hpp.in +43 -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 +19 -0
- data/rice/detail/from_ruby.hpp +43 -0
- data/rice/detail/from_ruby.ipp +60 -0
- data/rice/detail/method_data.cpp +159 -0
- data/rice/detail/method_data.hpp +21 -0
- data/rice/detail/mininode.cpp +1220 -0
- data/rice/detail/mininode.hpp +320 -0
- data/rice/detail/node.hpp +13 -0
- data/rice/detail/object_call.hpp +69 -0
- data/rice/detail/object_call.ipp +131 -0
- data/rice/detail/protect.cpp +29 -0
- data/rice/detail/protect.hpp +34 -0
- data/rice/detail/ruby.hpp +84 -0
- data/rice/detail/ruby_version_code.hpp +6 -0
- data/rice/detail/ruby_version_code.hpp.in +6 -0
- data/rice/detail/rubysig.hpp +19 -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 +341 -0
- data/rice/detail/wrap_function.ipp +514 -0
- data/rice/global_function.hpp +33 -0
- data/rice/global_function.ipp +22 -0
- data/rice/protect.hpp +92 -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 +294 -0
- data/rice/to_from_ruby_defn.hpp +71 -0
- data/ruby/Makefile.am +1 -0
- data/ruby/Makefile.in +569 -0
- data/ruby/lib/Makefile.am +3 -0
- data/ruby/lib/Makefile.in +423 -0
- data/ruby/lib/mkmf-rice.rb.in +213 -0
- data/ruby/lib/version.rb +3 -0
- data/ruby.ac +136 -0
- data/sample/Makefile.am +47 -0
- data/sample/Makefile.in +408 -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 +77 -0
- data/test/Makefile.in +820 -0
- data/test/ext/Makefile.am +43 -0
- data/test/ext/Makefile.in +404 -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 +241 -0
- data/test/test_Builtin_Object.cpp +72 -0
- data/test/test_Class.cpp +498 -0
- data/test/test_Constructor.cpp +128 -0
- data/test/test_Critical_Guard.cpp +51 -0
- data/test/test_Data_Object.cpp +275 -0
- data/test/test_Data_Type.cpp +348 -0
- data/test/test_Director.cpp +303 -0
- data/test/test_Enum.cpp +195 -0
- data/test/test_Exception.cpp +46 -0
- data/test/test_Hash.cpp +198 -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 +148 -0
- data/test/test_String.cpp +94 -0
- data/test/test_Struct.cpp +192 -0
- data/test/test_Symbol.cpp +63 -0
- data/test/test_To_From_Ruby.cpp +321 -0
- data/test/test_VM.cpp +26 -0
- data/test/test_global_functions.cpp +114 -0
- data/test/test_rice.rb +43 -0
- data/test/unittest.cpp +136 -0
- data/test/unittest.hpp +294 -0
- metadata +259 -0
|
@@ -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
|
+
*/
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#include "unittest.hpp"
|
|
2
|
+
#include "rice/Object.hpp"
|
|
3
|
+
#include "rice/Class.hpp"
|
|
4
|
+
#include "rice/String.hpp"
|
|
5
|
+
#include "rice/Array.hpp"
|
|
6
|
+
|
|
7
|
+
using namespace Rice;
|
|
8
|
+
|
|
9
|
+
TESTSUITE(Object);
|
|
10
|
+
|
|
11
|
+
SETUP(Object)
|
|
12
|
+
{
|
|
13
|
+
ruby_init();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
TESTCASE(default_construct)
|
|
17
|
+
{
|
|
18
|
+
Object o;
|
|
19
|
+
ASSERT_EQUAL(Qnil, o.value());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
TESTCASE(construct_with_value)
|
|
23
|
+
{
|
|
24
|
+
Object o(INT2NUM(42));
|
|
25
|
+
ASSERT_EQUAL(INT2NUM(42), o.value());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
TESTCASE(copy_construct)
|
|
29
|
+
{
|
|
30
|
+
Object o(INT2NUM(42));
|
|
31
|
+
Object o2(o);
|
|
32
|
+
ASSERT_EQUAL(INT2NUM(42), o2.value());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
TESTCASE(test)
|
|
36
|
+
{
|
|
37
|
+
ASSERT_EQUAL(true, Object(Qtrue).test());
|
|
38
|
+
ASSERT_EQUAL(true, Object(INT2NUM(42)).test());
|
|
39
|
+
ASSERT_EQUAL(false, Object(Qfalse).test());
|
|
40
|
+
ASSERT_EQUAL(false, Object(Qnil).test());
|
|
41
|
+
ASSERT_EQUAL(true, Object(Qundef).test());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
TESTCASE(explicit_conversion_to_bool)
|
|
45
|
+
{
|
|
46
|
+
// g++ 3.3.3 can't handle constructor-style inside the assert, which
|
|
47
|
+
// is why we use cast-style here.
|
|
48
|
+
ASSERT_EQUAL(true, (bool)Object(Qtrue));
|
|
49
|
+
ASSERT_EQUAL(true, (bool)Object(INT2NUM(42)));
|
|
50
|
+
ASSERT_EQUAL(false, (bool)Object(Qfalse));
|
|
51
|
+
ASSERT_EQUAL(false, (bool)Object(Qnil));
|
|
52
|
+
ASSERT_EQUAL(true, (bool)Object(Qundef));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
TESTCASE(is_nil)
|
|
56
|
+
{
|
|
57
|
+
ASSERT_EQUAL(false, Object(Qtrue).is_nil());
|
|
58
|
+
ASSERT_EQUAL(false, Object(INT2NUM(42)).is_nil());
|
|
59
|
+
ASSERT_EQUAL(false, Object(Qfalse).is_nil());
|
|
60
|
+
ASSERT_EQUAL(true, Object(Qnil).is_nil());
|
|
61
|
+
ASSERT_EQUAL(false, Object(Qundef).is_nil());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
TESTCASE(implicit_conversion_to_value)
|
|
65
|
+
{
|
|
66
|
+
// g++ 3.3.3 can't handle constructor-style inside the assert, which
|
|
67
|
+
// is why we use cast-style here.
|
|
68
|
+
ASSERT_EQUAL(Qtrue, (VALUE)Object(Qtrue));
|
|
69
|
+
ASSERT_EQUAL(INT2NUM(42), (VALUE)Object(INT2NUM(42)));
|
|
70
|
+
ASSERT_EQUAL(Qfalse, (VALUE)Object(Qfalse));
|
|
71
|
+
ASSERT_EQUAL(Qnil, (VALUE)Object(Qnil));
|
|
72
|
+
ASSERT_EQUAL(Qundef, (VALUE)Object(Qundef));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
TESTCASE(explicit_conversion_to_value)
|
|
76
|
+
{
|
|
77
|
+
ASSERT_EQUAL(Qtrue, Object(Qtrue).value());
|
|
78
|
+
ASSERT_EQUAL(INT2NUM(42), Object(INT2NUM(42)).value());
|
|
79
|
+
ASSERT_EQUAL(Qfalse, Object(Qfalse).value());
|
|
80
|
+
ASSERT_EQUAL(Qnil, Object(Qnil).value());
|
|
81
|
+
ASSERT_EQUAL(Qundef, Object(Qundef).value());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
TESTCASE(class_of)
|
|
85
|
+
{
|
|
86
|
+
ASSERT_EQUAL(Class(rb_cObject), Class(rb_cObject).call("new").class_of());
|
|
87
|
+
ASSERT_EQUAL(Class(rb_cFloat), Object(rb_float_new(42.0)).class_of());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
TESTCASE(compare)
|
|
91
|
+
{
|
|
92
|
+
ASSERT_EQUAL(0, Object(INT2NUM(42)).compare(Object(INT2NUM(42))));
|
|
93
|
+
ASSERT_EQUAL(-1, Object(INT2NUM(42)).compare(Object(INT2NUM(43))));
|
|
94
|
+
ASSERT_EQUAL(1, Object(INT2NUM(42)).compare(Object(INT2NUM(41))));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
TESTCASE(to_s)
|
|
98
|
+
{
|
|
99
|
+
ASSERT_EQUAL(String("42"), Object(INT2NUM(42)).to_s());
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
TESTCASE(inspect)
|
|
103
|
+
{
|
|
104
|
+
ASSERT_EQUAL(String("42"), Object(INT2NUM(42)).inspect());
|
|
105
|
+
ASSERT_EQUAL(String("\"foo\""), Object(rb_str_new2("foo")).inspect());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
TESTCASE(freeze)
|
|
109
|
+
{
|
|
110
|
+
Object o(Class(rb_cObject).call("new"));
|
|
111
|
+
ASSERT(!OBJ_FROZEN(o.value()));
|
|
112
|
+
o.freeze();
|
|
113
|
+
ASSERT(OBJ_FROZEN(o.value()));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
TESTCASE(is_frozen)
|
|
117
|
+
{
|
|
118
|
+
Object o(Class(rb_cObject).call("new"));
|
|
119
|
+
ASSERT(!o.is_frozen());
|
|
120
|
+
rb_obj_freeze(o);
|
|
121
|
+
ASSERT(o.is_frozen());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
TESTCASE(swap)
|
|
125
|
+
{
|
|
126
|
+
Object o1(INT2NUM(42));
|
|
127
|
+
Object o2(rb_ary_new());
|
|
128
|
+
o1.swap(o2);
|
|
129
|
+
ASSERT_EQUAL(to_ruby(42), o2);
|
|
130
|
+
ASSERT_EQUAL(Class(rb_cArray), o1.class_of());
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
TESTCASE(instance_eval)
|
|
134
|
+
{
|
|
135
|
+
Object o(Class(rb_cObject).call("new"));
|
|
136
|
+
o.iv_set("@foo", 42);
|
|
137
|
+
ASSERT_EQUAL(to_ruby(42), o.instance_eval("@foo"));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
TESTCASE(rb_type)
|
|
141
|
+
{
|
|
142
|
+
ASSERT_EQUAL(T_TRUE, Object(Qtrue).rb_type());
|
|
143
|
+
ASSERT_EQUAL(T_FIXNUM, Object(INT2NUM(42)).rb_type());
|
|
144
|
+
ASSERT_EQUAL(T_FALSE, Object(Qfalse).rb_type());
|
|
145
|
+
ASSERT_EQUAL(T_NIL, Object(Qnil).rb_type());
|
|
146
|
+
ASSERT_EQUAL(T_UNDEF, Object(Qundef).rb_type());
|
|
147
|
+
}
|
|
148
|
+
|