rice 3.0.0 → 4.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +121 -0
- data/CONTRIBUTORS.md +19 -0
- data/Gemfile +3 -0
- data/README.md +44 -1025
- data/Rakefile +95 -12
- data/include/rice/rice.hpp +7766 -0
- data/lib/mkmf-rice.rb +127 -0
- data/lib/version.rb +3 -0
- data/rice/Address_Registration_Guard.ipp +75 -32
- data/rice/Address_Registration_Guard_defn.hpp +60 -56
- data/rice/Arg.hpp +80 -4
- data/rice/Arg.ipp +51 -0
- data/rice/Constructor.hpp +12 -14
- data/rice/Data_Object.ipp +234 -107
- data/rice/Data_Object_defn.hpp +77 -117
- data/rice/Data_Type.hpp +1 -2
- data/rice/Data_Type.ipp +251 -295
- data/rice/Data_Type_defn.hpp +175 -243
- data/rice/Director.hpp +11 -6
- data/rice/Enum.hpp +54 -104
- data/rice/Enum.ipp +104 -230
- data/rice/Exception.hpp +2 -8
- data/rice/Exception.ipp +65 -0
- data/rice/Exception_defn.hpp +46 -47
- data/rice/Identifier.hpp +28 -28
- data/rice/Identifier.ipp +23 -27
- data/rice/Return.hpp +39 -0
- data/rice/Return.ipp +33 -0
- data/rice/detail/Exception_Handler.ipp +22 -62
- data/rice/detail/Exception_Handler_defn.hpp +76 -91
- data/rice/detail/Iterator.hpp +18 -88
- data/rice/detail/Iterator.ipp +47 -0
- data/rice/detail/Jump_Tag.hpp +21 -0
- data/rice/detail/MethodInfo.hpp +44 -0
- data/rice/detail/MethodInfo.ipp +78 -0
- data/rice/detail/NativeAttribute.hpp +53 -0
- data/rice/detail/NativeAttribute.ipp +83 -0
- data/rice/detail/NativeFunction.hpp +69 -0
- data/rice/detail/NativeFunction.ipp +248 -0
- data/rice/detail/RubyFunction.hpp +39 -0
- data/rice/detail/RubyFunction.ipp +92 -0
- data/rice/detail/Type.hpp +29 -0
- data/rice/detail/Type.ipp +138 -0
- data/rice/detail/TypeRegistry.hpp +50 -0
- data/rice/detail/TypeRegistry.ipp +106 -0
- data/rice/detail/Wrapper.hpp +51 -0
- data/rice/detail/Wrapper.ipp +151 -0
- data/rice/detail/default_allocation_func.hpp +8 -19
- data/rice/detail/default_allocation_func.ipp +9 -8
- data/rice/detail/from_ruby.hpp +2 -37
- data/rice/detail/from_ruby.ipp +1020 -46
- data/rice/detail/from_ruby_defn.hpp +38 -0
- data/rice/detail/function_traits.hpp +124 -0
- data/rice/detail/method_data.hpp +23 -15
- data/rice/detail/method_data.ipp +53 -0
- data/rice/detail/rice_traits.hpp +116 -0
- data/rice/detail/ruby.hpp +9 -46
- data/rice/detail/to_ruby.hpp +3 -17
- data/rice/detail/to_ruby.ipp +409 -31
- data/rice/detail/to_ruby_defn.hpp +48 -0
- data/rice/forward_declares.ipp +82 -0
- data/rice/global_function.hpp +16 -20
- data/rice/global_function.ipp +8 -17
- data/rice/rice.hpp +59 -0
- data/rice/ruby_mark.hpp +5 -3
- data/rice/ruby_try_catch.hpp +4 -4
- data/rice/stl.hpp +11 -0
- data/sample/callbacks/extconf.rb +3 -0
- data/sample/callbacks/sample_callbacks.cpp +10 -13
- data/sample/enum/extconf.rb +3 -0
- data/sample/enum/sample_enum.cpp +3 -17
- data/sample/enum/test.rb +2 -2
- data/sample/inheritance/animals.cpp +8 -24
- data/sample/inheritance/extconf.rb +3 -0
- data/sample/inheritance/test.rb +1 -1
- data/sample/map/extconf.rb +3 -0
- data/sample/map/map.cpp +10 -18
- data/sample/map/test.rb +1 -1
- data/test/embed_ruby.cpp +18 -5
- data/test/ext/t1/extconf.rb +3 -0
- data/test/ext/t1/t1.cpp +1 -3
- data/test/ext/t2/extconf.rb +3 -0
- data/test/ext/t2/t2.cpp +1 -1
- data/test/extconf.rb +23 -0
- data/test/ruby/test_callbacks_sample.rb +28 -0
- data/test/ruby/test_multiple_extensions.rb +18 -0
- data/test/ruby/test_multiple_extensions_same_class.rb +14 -0
- data/test/ruby/test_multiple_extensions_with_inheritance.rb +20 -0
- data/test/test_Address_Registration_Guard.cpp +23 -10
- data/test/test_Array.cpp +129 -73
- data/test/test_Attribute.cpp +147 -0
- data/test/test_Builtin_Object.cpp +34 -14
- data/test/test_Class.cpp +149 -275
- data/test/test_Constructor.cpp +10 -9
- data/test/test_Data_Object.cpp +133 -192
- data/test/test_Data_Type.cpp +322 -252
- data/test/test_Director.cpp +54 -41
- data/test/test_Enum.cpp +228 -103
- data/test/test_Exception.cpp +5 -6
- data/test/test_Hash.cpp +31 -30
- data/test/test_Identifier.cpp +4 -5
- data/test/test_Inheritance.cpp +221 -0
- data/test/test_Iterator.cpp +161 -0
- data/test/test_Jump_Tag.cpp +1 -1
- data/test/test_Keep_Alive.cpp +161 -0
- data/test/test_Memory_Management.cpp +2 -4
- data/test/test_Module.cpp +167 -110
- data/test/test_Object.cpp +41 -21
- data/test/test_Ownership.cpp +275 -0
- data/test/test_Self.cpp +205 -0
- data/test/test_Stl_Optional.cpp +90 -0
- data/test/test_Stl_Pair.cpp +144 -0
- data/test/test_Stl_SmartPointer.cpp +200 -0
- data/test/test_Stl_String.cpp +74 -0
- data/test/test_Stl_Vector.cpp +652 -0
- data/test/test_String.cpp +1 -2
- data/test/test_Struct.cpp +29 -39
- data/test/test_Symbol.cpp +1 -2
- data/test/test_To_From_Ruby.cpp +249 -285
- data/test/test_global_functions.cpp +39 -19
- data/test/unittest.hpp +0 -4
- metadata +63 -139
- data/Doxyfile +0 -2268
- data/Makefile.am +0 -26
- data/Makefile.in +0 -931
- data/README.mingw +0 -8
- data/aclocal.m4 +0 -1085
- data/ax_cxx_compile_stdcxx.m4 +0 -951
- data/bootstrap +0 -8
- data/config.guess +0 -1421
- data/config.sub +0 -1807
- data/configure +0 -7792
- data/configure.ac +0 -55
- data/depcomp +0 -791
- data/doxygen.ac +0 -314
- data/doxygen.am +0 -186
- data/extconf.rb +0 -70
- data/install-sh +0 -501
- data/missing +0 -215
- data/post-autoconf.rb +0 -22
- data/post-automake.rb +0 -28
- data/rice/Address_Registration_Guard.cpp +0 -22
- data/rice/Arg_impl.hpp +0 -129
- data/rice/Arg_operators.cpp +0 -21
- data/rice/Arg_operators.hpp +0 -19
- data/rice/Array.hpp +0 -214
- data/rice/Array.ipp +0 -256
- data/rice/Builtin_Object.hpp +0 -8
- data/rice/Builtin_Object.ipp +0 -50
- data/rice/Builtin_Object_defn.hpp +0 -50
- data/rice/Class.cpp +0 -57
- data/rice/Class.hpp +0 -8
- data/rice/Class.ipp +0 -6
- data/rice/Class_defn.hpp +0 -84
- data/rice/Data_Type.cpp +0 -54
- data/rice/Data_Type_fwd.hpp +0 -12
- data/rice/Director.cpp +0 -13
- data/rice/Exception.cpp +0 -54
- data/rice/Exception_Base.hpp +0 -8
- data/rice/Exception_Base.ipp +0 -13
- data/rice/Exception_Base_defn.hpp +0 -27
- data/rice/Hash.hpp +0 -230
- data/rice/Hash.ipp +0 -329
- data/rice/Identifier.cpp +0 -8
- data/rice/Jump_Tag.hpp +0 -24
- data/rice/Makefile.am +0 -121
- data/rice/Makefile.in +0 -884
- data/rice/Module.cpp +0 -84
- data/rice/Module.hpp +0 -8
- data/rice/Module.ipp +0 -6
- data/rice/Module_defn.hpp +0 -88
- data/rice/Module_impl.hpp +0 -281
- data/rice/Module_impl.ipp +0 -345
- data/rice/Object.cpp +0 -169
- data/rice/Object.hpp +0 -8
- data/rice/Object.ipp +0 -33
- data/rice/Object_defn.hpp +0 -214
- data/rice/Require_Guard.hpp +0 -21
- data/rice/String.cpp +0 -89
- data/rice/String.hpp +0 -91
- data/rice/Struct.cpp +0 -117
- data/rice/Struct.hpp +0 -162
- data/rice/Struct.ipp +0 -26
- data/rice/Symbol.cpp +0 -25
- data/rice/Symbol.hpp +0 -66
- data/rice/Symbol.ipp +0 -44
- data/rice/config.hpp +0 -47
- data/rice/config.hpp.in +0 -46
- data/rice/detail/Arguments.hpp +0 -118
- data/rice/detail/Auto_Function_Wrapper.hpp +0 -898
- data/rice/detail/Auto_Function_Wrapper.ipp +0 -3181
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +0 -897
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +0 -2501
- data/rice/detail/Caster.hpp +0 -103
- data/rice/detail/Not_Copyable.hpp +0 -25
- data/rice/detail/Wrapped_Function.hpp +0 -33
- data/rice/detail/cfp.hpp +0 -24
- data/rice/detail/cfp.ipp +0 -51
- data/rice/detail/check_ruby_type.cpp +0 -27
- data/rice/detail/check_ruby_type.hpp +0 -23
- data/rice/detail/creation_funcs.hpp +0 -37
- data/rice/detail/creation_funcs.ipp +0 -36
- data/rice/detail/define_method_and_auto_wrap.hpp +0 -31
- data/rice/detail/define_method_and_auto_wrap.ipp +0 -30
- data/rice/detail/demangle.cpp +0 -56
- data/rice/detail/demangle.hpp +0 -19
- data/rice/detail/env.hpp +0 -11
- data/rice/detail/method_data.cpp +0 -92
- data/rice/detail/node.hpp +0 -13
- data/rice/detail/protect.cpp +0 -29
- data/rice/detail/protect.hpp +0 -34
- data/rice/detail/ruby_version_code.hpp +0 -6
- data/rice/detail/ruby_version_code.hpp.in +0 -6
- data/rice/detail/st.hpp +0 -22
- data/rice/detail/win32.hpp +0 -16
- data/rice/detail/wrap_function.hpp +0 -66
- data/rice/protect.hpp +0 -38
- data/rice/protect.ipp +0 -1134
- data/rice/rubypp.rb +0 -97
- data/rice/to_from_ruby.hpp +0 -8
- data/rice/to_from_ruby.ipp +0 -418
- data/rice/to_from_ruby_defn.hpp +0 -70
- data/ruby.ac +0 -135
- data/ruby/Makefile.am +0 -1
- data/ruby/Makefile.in +0 -628
- data/ruby/lib/Makefile.am +0 -3
- data/ruby/lib/Makefile.in +0 -506
- data/ruby/lib/mkmf-rice.rb.in +0 -217
- data/ruby/lib/version.rb +0 -3
- data/sample/Makefile.am +0 -53
- data/sample/Makefile.in +0 -495
- data/test/Makefile.am +0 -73
- data/test/Makefile.in +0 -1219
- data/test/ext/Makefile.am +0 -41
- data/test/ext/Makefile.in +0 -483
- data/test/test_rice.rb +0 -45
data/test/test_Director.cpp
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
#include "unittest.hpp"
|
2
2
|
#include "embed_ruby.hpp"
|
3
|
-
#include
|
4
|
-
#include "rice/Director.hpp"
|
5
|
-
#include "rice/Constructor.hpp"
|
6
|
-
#include "rice/Data_Type.hpp"
|
3
|
+
#include <rice/rice.hpp>
|
7
4
|
|
8
5
|
#include <vector>
|
9
6
|
#include <iostream>
|
10
7
|
|
11
|
-
using namespace std;
|
12
8
|
using namespace Rice;
|
13
9
|
|
14
10
|
TESTSUITE(Director);
|
@@ -17,9 +13,10 @@ namespace {
|
|
17
13
|
/**
|
18
14
|
* Abstract base class
|
19
15
|
*/
|
20
|
-
class Worker
|
16
|
+
class Worker
|
17
|
+
{
|
21
18
|
public:
|
22
|
-
virtual ~Worker()
|
19
|
+
virtual ~Worker() = default;
|
23
20
|
|
24
21
|
int getNumber() { return 12; }
|
25
22
|
|
@@ -41,18 +38,24 @@ namespace {
|
|
41
38
|
/**
|
42
39
|
* Class to handle workers
|
43
40
|
*/
|
44
|
-
class Handler
|
41
|
+
class Handler
|
42
|
+
{
|
45
43
|
std::vector<Worker*> mWorkers;
|
46
44
|
|
47
45
|
public:
|
48
46
|
|
49
|
-
void addWorker(Worker* worker)
|
47
|
+
void addWorker(Worker* worker)
|
48
|
+
{
|
49
|
+
mWorkers.push_back(worker);
|
50
|
+
}
|
50
51
|
|
51
|
-
int processWorkers(int start)
|
52
|
+
int processWorkers(int start)
|
53
|
+
{
|
52
54
|
std::vector<Worker*>::iterator i = mWorkers.begin();
|
53
55
|
int results = start;
|
54
56
|
|
55
|
-
for(; i != mWorkers.end(); i++)
|
57
|
+
for(; i != mWorkers.end(); i++)
|
58
|
+
{
|
56
59
|
results = (*i)->process(results);
|
57
60
|
}
|
58
61
|
|
@@ -63,24 +66,29 @@ namespace {
|
|
63
66
|
/**
|
64
67
|
* Our Director wrapper of Worker
|
65
68
|
*/
|
66
|
-
class WorkerDirector : public Worker, public Rice::Director
|
69
|
+
class WorkerDirector : public Worker, public Rice::Director
|
70
|
+
{
|
67
71
|
public:
|
68
72
|
WorkerDirector(Object self) : Director(self) { }
|
69
73
|
|
70
|
-
virtual int process(int num)
|
71
|
-
|
74
|
+
virtual int process(int num)
|
75
|
+
{
|
76
|
+
return detail::From_Ruby<int>().convert( getSelf().call("process", num) );
|
72
77
|
}
|
73
78
|
|
74
|
-
int default_process(int num)
|
79
|
+
int default_process(int num)
|
80
|
+
{
|
75
81
|
raisePureVirtual();
|
76
82
|
return 0;
|
77
83
|
}
|
78
84
|
|
79
|
-
virtual int doSomething(int num)
|
80
|
-
|
85
|
+
virtual int doSomething(int num)
|
86
|
+
{
|
87
|
+
return detail::From_Ruby<int>().convert( getSelf().call("do_something", num) );
|
81
88
|
}
|
82
89
|
|
83
|
-
int default_doSomething(int num)
|
90
|
+
int default_doSomething(int num)
|
91
|
+
{
|
84
92
|
return Worker::doSomething(num);
|
85
93
|
}
|
86
94
|
};
|
@@ -101,7 +109,7 @@ TESTCASE(exposes_worker_as_instantiatable_class)
|
|
101
109
|
Module m = define_module("Testing");
|
102
110
|
Object result = m.instance_eval("worker = Worker.new; worker.get_number");
|
103
111
|
|
104
|
-
ASSERT_EQUAL(12,
|
112
|
+
ASSERT_EQUAL(12, detail::From_Ruby<int>().convert(result.value()));
|
105
113
|
}
|
106
114
|
|
107
115
|
TESTCASE(can_call_virtual_methods_on_base_class)
|
@@ -116,7 +124,7 @@ TESTCASE(can_call_virtual_methods_on_base_class)
|
|
116
124
|
|
117
125
|
Object result = m.instance_eval("worker = Worker.new; worker.do_something(4)");
|
118
126
|
|
119
|
-
ASSERT_EQUAL(16,
|
127
|
+
ASSERT_EQUAL(16, detail::From_Ruby<int>().convert(result.value()));
|
120
128
|
}
|
121
129
|
|
122
130
|
TESTCASE(super_calls_pass_execution_up_the_inheritance_chain)
|
@@ -131,7 +139,7 @@ TESTCASE(super_calls_pass_execution_up_the_inheritance_chain)
|
|
131
139
|
|
132
140
|
Object result = m.instance_eval("worker = RubyWorker.new; worker.do_something(10)");
|
133
141
|
|
134
|
-
ASSERT_EQUAL(400,
|
142
|
+
ASSERT_EQUAL(400, detail::From_Ruby<int>().convert(result.value()));
|
135
143
|
}
|
136
144
|
|
137
145
|
TESTCASE(super_calls_on_pure_virtual_raise_error)
|
@@ -158,7 +166,7 @@ TESTCASE(polymorphic_calls_head_down_the_call_chain)
|
|
158
166
|
{
|
159
167
|
define_class<Handler>("Handler")
|
160
168
|
.define_constructor(Constructor<Handler>())
|
161
|
-
.define_method("add_worker", &Handler::addWorker)
|
169
|
+
.define_method("add_worker", &Handler::addWorker, Arg("worker").keepAlive())
|
162
170
|
.define_method("process_workers", &Handler::processWorkers);
|
163
171
|
|
164
172
|
define_class<Worker>("Worker")
|
@@ -179,7 +187,7 @@ TESTCASE(polymorphic_calls_head_down_the_call_chain)
|
|
179
187
|
Object result = m.instance_eval("$handler.process_workers(5)");
|
180
188
|
|
181
189
|
// Hit's EchoWorker, so 5 + 2, then passes that to DoubleWorker, so 7 * 2 = 14
|
182
|
-
ASSERT_EQUAL(14,
|
190
|
+
ASSERT_EQUAL(14, detail::From_Ruby<int>().convert(result.value()));
|
183
191
|
}
|
184
192
|
|
185
193
|
namespace {
|
@@ -195,23 +203,26 @@ namespace {
|
|
195
203
|
virtual int doItImpl(int in) = 0;
|
196
204
|
};
|
197
205
|
|
198
|
-
class CallsSelfDirector : public CallsSelf, public Director
|
199
|
-
|
206
|
+
class CallsSelfDirector : public CallsSelf, public Director
|
207
|
+
{
|
200
208
|
public:
|
201
209
|
CallsSelfDirector(Object self) : Director(self) { }
|
202
210
|
virtual ~CallsSelfDirector() { }
|
203
211
|
|
204
|
-
virtual int doItImpl(int in)
|
205
|
-
|
212
|
+
virtual int doItImpl(int in)
|
213
|
+
{
|
214
|
+
return detail::From_Ruby<int>().convert( getSelf().call("do_it_impl", in) );
|
206
215
|
}
|
207
216
|
|
208
|
-
int default_doItImpl(int in)
|
217
|
+
int default_doItImpl(int in)
|
218
|
+
{
|
209
219
|
raisePureVirtual();
|
210
220
|
return 0;
|
211
221
|
}
|
212
222
|
};
|
213
223
|
|
214
|
-
struct MyCallsSelf : CallsSelf
|
224
|
+
struct MyCallsSelf : CallsSelf
|
225
|
+
{
|
215
226
|
MyCallsSelf() { }
|
216
227
|
virtual ~MyCallsSelf() { }
|
217
228
|
|
@@ -219,19 +230,21 @@ namespace {
|
|
219
230
|
};
|
220
231
|
|
221
232
|
// Abstract type return types handled properly
|
222
|
-
CallsSelf* getCallsSelf()
|
233
|
+
CallsSelf* getCallsSelf()
|
234
|
+
{
|
223
235
|
return new MyCallsSelf();
|
224
236
|
}
|
225
237
|
|
226
238
|
// Abstract type Argument types handled properly
|
227
|
-
int doItOnPointer(CallsSelf* obj, int in)
|
239
|
+
int doItOnPointer(CallsSelf* obj, int in)
|
240
|
+
{
|
228
241
|
return obj->doIt(in);
|
229
242
|
}
|
230
243
|
|
231
|
-
int doItOnReference(CallsSelf& obj, int in)
|
244
|
+
int doItOnReference(CallsSelf& obj, int in)
|
245
|
+
{
|
232
246
|
return obj.doIt(in);
|
233
247
|
}
|
234
|
-
|
235
248
|
}
|
236
249
|
|
237
250
|
TESTCASE(mix_of_polymorphic_calls_and_inheritance_dont_cause_infinite_loops)
|
@@ -249,7 +262,7 @@ TESTCASE(mix_of_polymorphic_calls_and_inheritance_dont_cause_infinite_loops)
|
|
249
262
|
"c = MySelf.new; c.do_it(10)"
|
250
263
|
);
|
251
264
|
|
252
|
-
ASSERT_EQUAL(100,
|
265
|
+
ASSERT_EQUAL(100, detail::From_Ruby<int>().convert(result.value()));
|
253
266
|
}
|
254
267
|
|
255
268
|
TESTCASE(director_class_super_classes_get_type_bound)
|
@@ -263,8 +276,9 @@ TESTCASE(director_class_super_classes_get_type_bound)
|
|
263
276
|
.define_method("do_it_impl", &CallsSelfDirector::default_doItImpl)
|
264
277
|
.define_method("do_it", &CallsSelf::doIt);
|
265
278
|
|
266
|
-
Object result = m.instance_eval("cs = Testing::get_calls_self
|
267
|
-
|
279
|
+
Object result = m.instance_eval(R"(cs = Testing::get_calls_self
|
280
|
+
cs.do_it(3))");
|
281
|
+
ASSERT_EQUAL(36, detail::From_Ruby<int>().convert(result.value()));
|
268
282
|
}
|
269
283
|
|
270
284
|
TESTCASE(director_allows_abstract_types_used_as_parameters_pointers)
|
@@ -284,9 +298,9 @@ TESTCASE(director_allows_abstract_types_used_as_parameters_pointers)
|
|
284
298
|
"Testing::do_it_on_pointer(c, 5)"
|
285
299
|
);
|
286
300
|
|
287
|
-
ASSERT_EQUAL(50,
|
301
|
+
ASSERT_EQUAL(50, detail::From_Ruby<int>().convert(result.value()));
|
288
302
|
}
|
289
|
-
|
303
|
+
|
290
304
|
TESTCASE(director_allows_abstract_types_used_as_parameters_reference)
|
291
305
|
{
|
292
306
|
Module m = define_module("Testing");
|
@@ -304,6 +318,5 @@ TESTCASE(director_allows_abstract_types_used_as_parameters_reference)
|
|
304
318
|
"Testing::do_it_on_ref(c, 3)"
|
305
319
|
);
|
306
320
|
|
307
|
-
ASSERT_EQUAL(30,
|
308
|
-
}
|
309
|
-
*/
|
321
|
+
ASSERT_EQUAL(30, detail::From_Ruby<int>().convert(result.value()));
|
322
|
+
}
|
data/test/test_Enum.cpp
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
+
#include <iostream>
|
2
|
+
|
1
3
|
#include "unittest.hpp"
|
2
4
|
#include "embed_ruby.hpp"
|
3
|
-
|
4
|
-
#include
|
5
|
-
#include "rice/String.hpp"
|
6
|
-
#include "rice/Constructor.hpp"
|
7
|
-
#include "rice/global_function.hpp"
|
8
|
-
#include <iostream>
|
5
|
+
|
6
|
+
#include <rice/rice.hpp>
|
9
7
|
|
10
8
|
using namespace Rice;
|
11
9
|
|
@@ -23,6 +21,26 @@ namespace
|
|
23
21
|
.define_value("GREEN", GREEN);
|
24
22
|
return colors;
|
25
23
|
}
|
24
|
+
|
25
|
+
enum class Season { Spring, Summer, Fall, Winter };
|
26
|
+
|
27
|
+
// This is needed to make unittest compile (it uses ostream to report errors)
|
28
|
+
inline std::ostream& operator<<(std::ostream& os, const Season& season)
|
29
|
+
{
|
30
|
+
os << static_cast<std::underlying_type_t<Season>>(season);
|
31
|
+
return os;
|
32
|
+
}
|
33
|
+
|
34
|
+
Enum<Season> define_season_enum()
|
35
|
+
{
|
36
|
+
static Enum<Season> seasons = define_enum<Season>("Season")
|
37
|
+
.define_value("Spring", Season::Spring)
|
38
|
+
.define_value("Summer", Season::Summer)
|
39
|
+
.define_value("Fall", Season::Fall)
|
40
|
+
.define_value("Winter", Season::Winter);
|
41
|
+
|
42
|
+
return seasons;
|
43
|
+
}
|
26
44
|
}
|
27
45
|
|
28
46
|
SETUP(Enum)
|
@@ -32,135 +50,173 @@ SETUP(Enum)
|
|
32
50
|
|
33
51
|
TESTCASE(copy_construct)
|
34
52
|
{
|
35
|
-
Enum<Color>
|
36
|
-
ASSERT_EQUAL(define_color_enum().value(),
|
53
|
+
Enum<Color> colorEnum(define_color_enum());
|
54
|
+
ASSERT_EQUAL(define_color_enum().value(), colorEnum.value());
|
37
55
|
}
|
38
56
|
|
39
57
|
TESTCASE(assignment)
|
40
58
|
{
|
41
|
-
Enum<Color>
|
42
|
-
|
43
|
-
ASSERT_EQUAL(define_color_enum().value(),
|
59
|
+
Enum<Color> colorEnum;
|
60
|
+
colorEnum = define_color_enum();
|
61
|
+
ASSERT_EQUAL(define_color_enum().value(), colorEnum.value());
|
44
62
|
}
|
45
63
|
|
46
64
|
TESTCASE(each)
|
47
65
|
{
|
48
|
-
|
49
|
-
|
66
|
+
Module m = define_module("Testing");
|
67
|
+
|
68
|
+
Enum<Color> colorEnum = define_color_enum();
|
69
|
+
|
70
|
+
std::string code = R"(a = []
|
71
|
+
Color.each { |x| a << x }
|
72
|
+
a)";
|
73
|
+
Array a = m.instance_eval(code);
|
50
74
|
ASSERT_EQUAL(3u, a.size());
|
51
|
-
|
52
|
-
|
53
|
-
ASSERT_EQUAL(
|
75
|
+
|
76
|
+
Data_Object<Color> enum_0(a[0]);
|
77
|
+
ASSERT_EQUAL(RED, *enum_0);
|
78
|
+
|
79
|
+
Data_Object<Color> enum_1(a[1]);
|
80
|
+
ASSERT_EQUAL(BLACK, *enum_1);
|
81
|
+
|
82
|
+
Data_Object<Color> enum_2(a[2]);
|
83
|
+
ASSERT_EQUAL(GREEN, *enum_2);
|
84
|
+
}
|
85
|
+
|
86
|
+
TESTCASE(each_seasons)
|
87
|
+
{
|
88
|
+
Module m = define_module("Testing");
|
89
|
+
|
90
|
+
Enum<Season> rb_cSeason = define_season_enum();
|
91
|
+
std::string code = R"(a = []
|
92
|
+
Season.each { |x| a << x }
|
93
|
+
a)";
|
94
|
+
|
95
|
+
Array a = m.instance_eval(code);
|
96
|
+
ASSERT_EQUAL(4u, a.size());
|
97
|
+
|
98
|
+
Data_Object<Season> enum_0(a[0]);
|
99
|
+
ASSERT_EQUAL(Season::Spring, *enum_0);
|
100
|
+
|
101
|
+
Data_Object<Season> enum_1(a[1]);
|
102
|
+
ASSERT_EQUAL(Season::Summer, *enum_1);
|
103
|
+
|
104
|
+
Data_Object<Season> enum_2(a[2]);
|
105
|
+
ASSERT_EQUAL(Season::Fall, *enum_2);
|
106
|
+
|
107
|
+
Data_Object<Season> enum_3(a[3]);
|
108
|
+
ASSERT_EQUAL(Season::Winter, *enum_3);
|
54
109
|
}
|
55
110
|
|
56
111
|
TESTCASE(to_s)
|
57
112
|
{
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
ASSERT_EQUAL(String("
|
113
|
+
Module m = define_module("Testing");
|
114
|
+
|
115
|
+
Enum<Color> colorEnum = define_color_enum();
|
116
|
+
ASSERT_EQUAL(String("RED"), String(m.instance_eval("Color::RED.to_s")));
|
117
|
+
ASSERT_EQUAL(String("BLACK"), String(m.instance_eval("Color::BLACK.to_s")));
|
118
|
+
ASSERT_EQUAL(String("GREEN"), String(m.instance_eval("Color::GREEN.to_s")));
|
62
119
|
}
|
63
120
|
|
64
121
|
TESTCASE(to_i)
|
65
122
|
{
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
ASSERT_EQUAL(to_ruby(int(
|
123
|
+
Module m = define_module("Testing");
|
124
|
+
|
125
|
+
Enum<Color> colorEnum = define_color_enum();
|
126
|
+
ASSERT_EQUAL(detail::to_ruby(int(RED)), m.instance_eval("Color::RED.to_i").value());
|
127
|
+
ASSERT_EQUAL(detail::to_ruby(int(BLACK)), m.instance_eval("Color::BLACK.to_i").value());
|
128
|
+
ASSERT_EQUAL(detail::to_ruby(int(GREEN)), m.instance_eval("Color::GREEN.to_i").value());
|
70
129
|
}
|
71
130
|
|
72
131
|
TESTCASE(inspect)
|
73
132
|
{
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
ASSERT_EQUAL(String("#<Color::
|
133
|
+
Module m = define_module("Testing");
|
134
|
+
|
135
|
+
Enum<Color> colorEnum = define_color_enum();
|
136
|
+
ASSERT_EQUAL(String("#<Color::RED>"), String(m.instance_eval("Color::RED.inspect")));
|
137
|
+
ASSERT_EQUAL(String("#<Color::BLACK>"), String(m.instance_eval("Color::BLACK.inspect")));
|
138
|
+
ASSERT_EQUAL(String("#<Color::GREEN>"), String(m.instance_eval("Color::GREEN.inspect")));
|
78
139
|
}
|
79
140
|
|
80
141
|
TESTCASE(compare)
|
81
142
|
{
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
ASSERT_EQUAL(to_ruby(
|
143
|
+
Module m = define_module("Testing");
|
144
|
+
|
145
|
+
Enum<Color> colorEnum = define_color_enum();
|
146
|
+
ASSERT_EQUAL(detail::to_ruby(-1), m.instance_eval("Color::RED <=> Color::BLACK").value());
|
147
|
+
ASSERT_EQUAL(detail::to_ruby(1), m.instance_eval("Color::GREEN <=> Color::RED").value());
|
148
|
+
ASSERT_EQUAL(detail::to_ruby(0), m.instance_eval("Color::BLACK <=> Color::BLACK").value());
|
86
149
|
}
|
87
150
|
|
88
151
|
TESTCASE(eql)
|
89
152
|
{
|
90
|
-
|
91
|
-
ASSERT_EQUAL(to_ruby(false), Object(protect(rb_eval_string, "Color::RED == Color::BLACK")));
|
92
|
-
ASSERT_EQUAL(to_ruby(true), Object(protect(rb_eval_string, "Color::GREEN == Color::GREEN")));
|
93
|
-
}
|
153
|
+
Module m = define_module("Testing");
|
94
154
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
|
99
|
-
ASSERT_EQUAL(String("INVALID(42)"), invalid.to_s());
|
155
|
+
Enum<Color> colorEnum = define_color_enum();
|
156
|
+
ASSERT_EQUAL(detail::to_ruby(false), m.instance_eval("Color::RED == Color::BLACK").value());
|
157
|
+
ASSERT_EQUAL(detail::to_ruby(true), m.instance_eval("Color::GREEN == Color::GREEN").value());
|
100
158
|
}
|
101
159
|
|
102
|
-
TESTCASE(
|
160
|
+
TESTCASE(compare_equal)
|
103
161
|
{
|
104
|
-
Enum<Color>
|
105
|
-
|
106
|
-
|
162
|
+
Enum<Color> colorEnum = define_color_enum();
|
163
|
+
Object color1 = colorEnum.const_get("RED");
|
164
|
+
Object color2 = colorEnum.const_get("RED");
|
165
|
+
Object result = color1.call("<=>", color2);
|
166
|
+
ASSERT_EQUAL(0, detail::From_Ruby<int>().convert(result));
|
107
167
|
}
|
108
168
|
|
109
|
-
TESTCASE(
|
169
|
+
TESTCASE(compare_less)
|
110
170
|
{
|
111
|
-
Enum<Color>
|
112
|
-
|
113
|
-
|
171
|
+
Enum<Color> colorEnum = define_color_enum();
|
172
|
+
Object color1 = colorEnum.const_get("RED");
|
173
|
+
Object color2 = colorEnum.const_get("BLACK");
|
174
|
+
Object result = color1.call("<=>", color2);
|
175
|
+
ASSERT_EQUAL(-1, detail::From_Ruby<int>().convert(result));
|
114
176
|
}
|
115
177
|
|
116
|
-
TESTCASE(
|
178
|
+
TESTCASE(compare_more)
|
117
179
|
{
|
118
|
-
Enum<Color>
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
ASSERT_EQUAL(
|
123
|
-
ASSERT_EQUAL(0, invalid.compare(invalid));
|
180
|
+
Enum<Color> colorEnum = define_color_enum();
|
181
|
+
Object color1 = colorEnum.const_get("GREEN");
|
182
|
+
Object color2 = colorEnum.const_get("BLACK");
|
183
|
+
Object result = color1.call("<=>", color2);
|
184
|
+
ASSERT_EQUAL(1, detail::From_Ruby<int>().convert(result));
|
124
185
|
}
|
125
186
|
|
126
|
-
TESTCASE(
|
187
|
+
TESTCASE(different_objects_eql)
|
127
188
|
{
|
128
|
-
Enum<Color>
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
ASSERT_EQUAL(
|
133
|
-
ASSERT_EQUAL(true, invalid == invalid);
|
189
|
+
Enum<Color> colorEnum = define_color_enum();
|
190
|
+
Object black1 = colorEnum.const_get("BLACK");
|
191
|
+
Object black2 = colorEnum.const_get("BLACK");
|
192
|
+
Object result = black1.call("==", black2);
|
193
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
134
194
|
}
|
135
195
|
|
136
|
-
TESTCASE(
|
196
|
+
TESTCASE(hash)
|
137
197
|
{
|
138
|
-
Enum<Color>
|
139
|
-
|
140
|
-
|
141
|
-
ASSERT_EQUAL(
|
198
|
+
Enum<Color> colorEnum = define_color_enum();
|
199
|
+
Object color = colorEnum.const_get("GREEN");
|
200
|
+
Object result = color.call("hash");
|
201
|
+
ASSERT_EQUAL((int)Color::GREEN, detail::From_Ruby<int>().convert(result));
|
142
202
|
}
|
143
203
|
|
144
|
-
TESTCASE(
|
204
|
+
TESTCASE(from_int)
|
145
205
|
{
|
146
|
-
Enum<Color>
|
147
|
-
|
148
|
-
|
149
|
-
ASSERT_EQUAL(true, red1 == red2);
|
206
|
+
Enum<Color> colorEnum = define_color_enum();
|
207
|
+
Object result = colorEnum.call("from_int", 2);
|
208
|
+
ASSERT_EQUAL(result, colorEnum.const_get("GREEN"));
|
150
209
|
}
|
151
210
|
|
152
|
-
TESTCASE(
|
211
|
+
TESTCASE(from_int_invalid)
|
153
212
|
{
|
154
|
-
Enum<Color>
|
155
|
-
Data_Object<Color> red(new Color(RED));
|
156
|
-
ASSERT_EQUAL(to_ruby(int(RED)), red.call("hash"));
|
157
|
-
}
|
213
|
+
Enum<Color> colorEnum = define_color_enum();
|
158
214
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
215
|
+
ASSERT_EXCEPTION_CHECK(
|
216
|
+
Exception,
|
217
|
+
Object result = colorEnum.call("from_int", 22),
|
218
|
+
ASSERT_EQUAL("Unknown enum value: 22", ex.what())
|
219
|
+
);
|
164
220
|
}
|
165
221
|
|
166
222
|
namespace
|
@@ -179,38 +235,107 @@ namespace
|
|
179
235
|
|
180
236
|
TESTCASE(nested_enums)
|
181
237
|
{
|
238
|
+
Data_Type<Inner> inner = define_class<Inner>("Inner");
|
239
|
+
define_enum<Inner::Props>("Props", inner)
|
240
|
+
.define_value("VALUE1", Inner::VALUE1)
|
241
|
+
.define_value("VALUE2", Inner::VALUE2)
|
242
|
+
.define_value("VALUE3", Inner::VALUE3);
|
243
|
+
inner.define_constructor(Constructor<Inner>());
|
244
|
+
|
245
|
+
Module m = define_module("Testing");
|
246
|
+
|
247
|
+
ASSERT_EQUAL(detail::to_ruby(int(0)), m.instance_eval("Inner::Props::VALUE1.to_i").value());
|
248
|
+
ASSERT_EQUAL(detail::to_ruby(int(1)), m.instance_eval("Inner::Props::VALUE2.to_i").value());
|
249
|
+
ASSERT_EQUAL(detail::to_ruby(int(2)), m.instance_eval("Inner::Props::VALUE3.to_i").value());
|
250
|
+
}
|
251
|
+
|
252
|
+
namespace
|
253
|
+
{
|
254
|
+
Color myFavoriteColor()
|
182
255
|
{
|
183
|
-
|
184
|
-
define_enum<Inner::Props>("Props", inner)
|
185
|
-
.define_value("VALUE1", Inner::VALUE1)
|
186
|
-
.define_value("VALUE2", Inner::VALUE2)
|
187
|
-
.define_value("VALUE3", Inner::VALUE3);
|
188
|
-
inner.define_constructor(Constructor<Inner>());
|
256
|
+
return RED;
|
189
257
|
}
|
190
258
|
|
191
|
-
|
192
|
-
|
193
|
-
|
259
|
+
bool isMyFavoriteColor(Color aColor)
|
260
|
+
{
|
261
|
+
return aColor == RED;
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
265
|
+
TESTCASE(using_enums)
|
266
|
+
{
|
267
|
+
Enum<Color> colorEnum = define_color_enum();
|
268
|
+
colorEnum.define_singleton_function("my_favorite_color", &myFavoriteColor)
|
269
|
+
.define_singleton_function("is_my_favorite_color", &isMyFavoriteColor)
|
270
|
+
.define_singleton_function("is_my_favorite_color", &isMyFavoriteColor)
|
271
|
+
.define_method("is_my_favorite_color", &isMyFavoriteColor);
|
272
|
+
|
273
|
+
Module m = define_module("Testing");
|
274
|
+
|
275
|
+
Object result = m.instance_eval("Color.my_favorite_color");
|
276
|
+
ASSERT_EQUAL(RED, detail::From_Ruby<Color>().convert(result.value()));
|
277
|
+
|
278
|
+
result = m.instance_eval("Color.is_my_favorite_color(Color::RED)");
|
279
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
280
|
+
|
281
|
+
result = m.instance_eval("Color.is_my_favorite_color(Color::BLACK)");
|
282
|
+
ASSERT_EQUAL(Qfalse, result.value());
|
283
|
+
|
284
|
+
result = m.instance_eval("Color::RED.is_my_favorite_color");
|
285
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
286
|
+
|
287
|
+
result = m.instance_eval("Color::BLACK.is_my_favorite_color");
|
288
|
+
ASSERT_EQUAL(Qfalse, result.value());
|
194
289
|
}
|
195
290
|
|
196
291
|
namespace
|
197
292
|
{
|
198
|
-
Color
|
293
|
+
Color defaultColor(Color aColor = BLACK)
|
199
294
|
{
|
200
|
-
return
|
295
|
+
return aColor;
|
201
296
|
}
|
202
297
|
}
|
203
298
|
|
204
|
-
TESTCASE(
|
299
|
+
TESTCASE(default_argument)
|
205
300
|
{
|
206
|
-
|
207
|
-
define_global_function("get_enum", &getEnum);
|
301
|
+
define_global_function("default_color", &defaultColor, Arg("aColor") = Color::BLACK);
|
208
302
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
303
|
+
Module m = define_module("Testing");
|
304
|
+
Object result = m.instance_eval("default_color");
|
305
|
+
ASSERT_EQUAL(Color::BLACK, detail::From_Ruby<Color>().convert(result.value()));
|
306
|
+
}
|
307
|
+
|
308
|
+
namespace
|
309
|
+
{
|
310
|
+
enum class Undefined { A, B, C };
|
311
|
+
|
312
|
+
void undefinedArg(Undefined undefined)
|
313
|
+
{
|
314
|
+
}
|
213
315
|
|
214
|
-
|
215
|
-
|
316
|
+
Undefined undefinedReturn()
|
317
|
+
{
|
318
|
+
return Undefined::B;
|
319
|
+
}
|
216
320
|
}
|
321
|
+
|
322
|
+
TESTCASE(not_defined)
|
323
|
+
{
|
324
|
+
#ifdef _MSC_VER
|
325
|
+
const char* message = "Type is not defined with Rice: enum `anonymous namespace'::Undefined";
|
326
|
+
#else
|
327
|
+
const char* message = "Type is not defined with Rice: (anonymous namespace)::Undefined";
|
328
|
+
#endif
|
329
|
+
|
330
|
+
ASSERT_EXCEPTION_CHECK(
|
331
|
+
std::invalid_argument,
|
332
|
+
define_global_function("undefined_arg", &undefinedArg),
|
333
|
+
ASSERT_EQUAL(message, ex.what())
|
334
|
+
);
|
335
|
+
|
336
|
+
ASSERT_EXCEPTION_CHECK(
|
337
|
+
std::invalid_argument,
|
338
|
+
define_global_function("undefined_return", &undefinedReturn),
|
339
|
+
ASSERT_EQUAL(message, ex.what())
|
340
|
+
);
|
341
|
+
}
|