rice 4.3.3 → 4.6.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 +86 -26
- data/CMakeLists.txt +31 -0
- data/CMakePresets.json +75 -0
- data/COPYING +3 -2
- data/FindRuby.cmake +437 -0
- data/README.md +7 -2
- data/Rakefile +12 -5
- data/include/rice/rice.hpp +9522 -4426
- data/include/rice/stl.hpp +2831 -1198
- data/lib/make_rice_headers.rb +79 -0
- data/lib/mkmf-rice.rb +40 -94
- data/lib/rice/version.rb +3 -0
- data/lib/rice.rb +1 -0
- data/lib/rubygems/builder.rb +11 -0
- data/lib/rubygems/cmake_builder.rb +113 -0
- data/lib/rubygems_plugin.rb +9 -0
- data/rice/Address_Registration_Guard.hpp +72 -3
- data/rice/Arg.hpp +26 -6
- data/rice/Arg.ipp +35 -2
- data/rice/Buffer.hpp +123 -0
- data/rice/Buffer.ipp +599 -0
- data/rice/Callback.hpp +21 -0
- data/rice/Callback.ipp +13 -0
- data/rice/Constructor.hpp +4 -27
- data/rice/Constructor.ipp +79 -0
- data/rice/Data_Object.hpp +73 -3
- data/rice/Data_Object.ipp +388 -96
- data/rice/Data_Type.hpp +214 -3
- data/rice/Data_Type.ipp +144 -67
- data/rice/Director.hpp +0 -2
- data/rice/Enum.hpp +4 -7
- data/rice/Enum.ipp +102 -55
- data/rice/Exception.hpp +62 -2
- data/rice/Exception.ipp +7 -12
- data/rice/Init.hpp +8 -0
- data/rice/Init.ipp +8 -0
- data/rice/JumpException.hpp +44 -0
- data/rice/JumpException.ipp +48 -0
- data/rice/MemoryView.hpp +11 -0
- data/rice/MemoryView.ipp +3 -0
- data/rice/Return.hpp +7 -27
- data/rice/Return.ipp +13 -13
- data/rice/cpp_api/Array.hpp +209 -0
- data/rice/cpp_api/Array.ipp +304 -0
- data/rice/cpp_api/Builtin_Object.hpp +31 -0
- data/rice/cpp_api/Builtin_Object.ipp +37 -0
- data/rice/cpp_api/Class.hpp +70 -0
- data/rice/cpp_api/Class.ipp +97 -0
- data/rice/cpp_api/Encoding.hpp +32 -0
- data/rice/cpp_api/Encoding.ipp +59 -0
- data/rice/cpp_api/Hash.hpp +194 -0
- data/rice/cpp_api/Hash.ipp +257 -0
- data/rice/{Identifier.hpp → cpp_api/Identifier.hpp} +2 -6
- data/rice/{Identifier.ipp → cpp_api/Identifier.ipp} +4 -2
- data/rice/cpp_api/Module.hpp +72 -0
- data/rice/cpp_api/Module.ipp +101 -0
- data/rice/cpp_api/Object.hpp +272 -0
- data/rice/cpp_api/Object.ipp +235 -0
- data/rice/cpp_api/String.hpp +74 -0
- data/rice/cpp_api/String.ipp +120 -0
- data/rice/cpp_api/Struct.hpp +113 -0
- data/rice/cpp_api/Struct.ipp +92 -0
- data/rice/cpp_api/Symbol.hpp +46 -0
- data/rice/cpp_api/Symbol.ipp +93 -0
- data/rice/cpp_api/shared_methods.hpp +134 -0
- data/rice/detail/DefaultHandler.hpp +12 -0
- data/rice/detail/DefaultHandler.ipp +8 -0
- data/rice/detail/HandlerRegistry.hpp +5 -35
- data/rice/detail/HandlerRegistry.ipp +7 -11
- data/rice/detail/InstanceRegistry.hpp +1 -4
- data/rice/detail/MethodInfo.hpp +12 -10
- data/rice/detail/MethodInfo.ipp +26 -21
- data/rice/detail/Native.hpp +33 -0
- data/rice/detail/Native.ipp +157 -0
- data/rice/detail/NativeAttributeGet.hpp +52 -0
- data/rice/detail/NativeAttributeGet.ipp +57 -0
- data/rice/detail/NativeAttributeSet.hpp +44 -0
- data/rice/detail/NativeAttributeSet.ipp +88 -0
- data/rice/detail/NativeCallbackFFI.hpp +55 -0
- data/rice/detail/NativeCallbackFFI.ipp +151 -0
- data/rice/detail/NativeCallbackSimple.hpp +30 -0
- data/rice/detail/NativeCallbackSimple.ipp +29 -0
- data/rice/detail/NativeFunction.hpp +33 -23
- data/rice/detail/NativeFunction.ipp +309 -70
- data/rice/detail/NativeIterator.hpp +9 -11
- data/rice/detail/NativeIterator.ipp +33 -31
- data/rice/detail/NativeRegistry.hpp +24 -15
- data/rice/detail/NativeRegistry.ipp +23 -48
- data/rice/detail/Proc.hpp +4 -0
- data/rice/detail/Proc.ipp +85 -0
- data/rice/detail/Registries.hpp +0 -7
- data/rice/detail/Registries.ipp +0 -18
- data/rice/detail/RubyFunction.hpp +0 -3
- data/rice/detail/RubyFunction.ipp +4 -8
- data/rice/detail/RubyType.hpp +16 -0
- data/rice/detail/RubyType.ipp +232 -0
- data/rice/detail/Type.hpp +7 -6
- data/rice/detail/Type.ipp +192 -45
- data/rice/detail/TypeRegistry.hpp +15 -7
- data/rice/detail/TypeRegistry.ipp +105 -12
- data/rice/detail/Wrapper.hpp +68 -32
- data/rice/detail/Wrapper.ipp +121 -109
- data/rice/detail/cpp_protect.hpp +5 -6
- data/rice/detail/default_allocation_func.ipp +0 -2
- data/rice/detail/from_ruby.hpp +38 -3
- data/rice/detail/from_ruby.ipp +1321 -492
- data/rice/detail/ruby.hpp +18 -0
- data/rice/detail/to_ruby.hpp +41 -3
- data/rice/detail/to_ruby.ipp +1424 -194
- data/rice/global_function.hpp +0 -4
- data/rice/global_function.ipp +0 -1
- data/rice/libc/file.hpp +11 -0
- data/rice/libc/file.ipp +32 -0
- data/rice/rice.hpp +116 -26
- data/rice/ruby_mark.hpp +4 -3
- data/rice/stl/complex.hpp +6 -0
- data/rice/stl/complex.ipp +93 -0
- data/rice/stl/exception.hpp +11 -0
- data/rice/stl/exception.ipp +29 -0
- data/rice/stl/exception_ptr.hpp +6 -0
- data/rice/stl/exception_ptr.ipp +27 -0
- data/rice/stl/map.hpp +12 -0
- data/rice/stl/map.ipp +469 -0
- data/rice/stl/monostate.hpp +6 -0
- data/rice/stl/monostate.ipp +80 -0
- data/rice/stl/multimap.hpp +14 -0
- data/rice/stl/multimap.ipp +448 -0
- data/rice/stl/optional.hpp +6 -0
- data/rice/stl/optional.ipp +118 -0
- data/rice/stl/pair.hpp +13 -0
- data/rice/stl/pair.ipp +155 -0
- data/rice/stl/reference_wrapper.hpp +6 -0
- data/rice/stl/reference_wrapper.ipp +41 -0
- data/rice/stl/set.hpp +12 -0
- data/rice/stl/set.ipp +495 -0
- data/rice/stl/shared_ptr.hpp +28 -0
- data/rice/stl/shared_ptr.ipp +224 -0
- data/rice/stl/string.hpp +6 -0
- data/rice/stl/string.ipp +158 -0
- data/rice/stl/string_view.hpp +6 -0
- data/rice/stl/string_view.ipp +65 -0
- data/rice/stl/tuple.hpp +6 -0
- data/rice/stl/tuple.ipp +128 -0
- data/rice/stl/type_index.hpp +6 -0
- data/rice/stl/type_index.ipp +30 -0
- data/rice/stl/type_info.hpp +6 -0
- data/rice/stl/type_info.ipp +29 -0
- data/rice/stl/unique_ptr.hpp +22 -0
- data/rice/stl/unique_ptr.ipp +139 -0
- data/rice/stl/unordered_map.hpp +12 -0
- data/rice/stl/unordered_map.ipp +469 -0
- data/rice/stl/variant.hpp +6 -0
- data/rice/stl/variant.ipp +242 -0
- data/rice/stl/vector.hpp +12 -0
- data/rice/stl/vector.ipp +590 -0
- data/rice/stl.hpp +11 -3
- data/rice/traits/attribute_traits.hpp +26 -0
- data/rice/traits/function_traits.hpp +95 -0
- data/rice/traits/method_traits.hpp +47 -0
- data/rice/traits/rice_traits.hpp +160 -0
- data/rice.gemspec +85 -0
- data/test/embed_ruby.cpp +7 -1
- data/test/extconf.rb +2 -0
- data/test/test_Address_Registration_Guard.cpp +5 -0
- data/test/test_Array.cpp +18 -4
- data/test/test_Attribute.cpp +136 -21
- data/test/test_Buffer.cpp +285 -0
- data/test/test_Builtin_Object.cpp +5 -0
- data/test/test_Callback.cpp +230 -0
- data/test/test_Class.cpp +5 -31
- data/test/test_Constructor.cpp +69 -6
- data/test/test_Data_Object.cpp +97 -38
- data/test/test_Data_Type.cpp +470 -65
- data/test/test_Director.cpp +17 -8
- data/test/test_Enum.cpp +155 -40
- data/test/test_Exception.cpp +235 -0
- data/test/test_File.cpp +70 -0
- data/test/test_From_Ruby.cpp +609 -0
- data/test/test_Hash.cpp +5 -0
- data/test/test_Identifier.cpp +5 -0
- data/test/test_Inheritance.cpp +6 -1
- data/test/test_Iterator.cpp +6 -1
- data/test/test_Jump_Exception.cpp +23 -0
- data/test/test_Keep_Alive.cpp +13 -19
- data/test/test_Keep_Alive_No_Wrapper.cpp +5 -1
- data/test/test_Memory_Management.cpp +5 -0
- data/test/test_Module.cpp +128 -67
- data/test/test_Native_Registry.cpp +2 -34
- data/test/test_Object.cpp +5 -0
- data/test/test_Overloads.cpp +806 -0
- data/test/test_Ownership.cpp +160 -54
- data/test/test_Proc.cpp +44 -0
- data/test/test_Self.cpp +9 -4
- data/test/test_Stl_Exception.cpp +109 -0
- data/test/test_Stl_Map.cpp +54 -42
- data/test/test_Stl_Multimap.cpp +693 -0
- data/test/test_Stl_Optional.cpp +5 -0
- data/test/test_Stl_Pair.cpp +14 -9
- data/test/test_Stl_Reference_Wrapper.cpp +9 -2
- data/test/test_Stl_Set.cpp +790 -0
- data/test/test_Stl_SharedPtr.cpp +458 -0
- data/test/test_Stl_String.cpp +5 -0
- data/test/test_Stl_String_View.cpp +5 -0
- data/test/test_Stl_Tuple.cpp +116 -0
- data/test/test_Stl_Type.cpp +147 -0
- data/test/test_Stl_UniquePtr.cpp +202 -0
- data/test/test_Stl_Unordered_Map.cpp +43 -38
- data/test/test_Stl_Variant.cpp +217 -84
- data/test/test_Stl_Vector.cpp +306 -58
- data/test/test_String.cpp +5 -0
- data/test/test_Struct.cpp +5 -0
- data/test/test_Symbol.cpp +5 -0
- data/test/test_Template.cpp +192 -0
- data/test/test_To_Ruby.cpp +524 -0
- data/test/test_Tracking.cpp +1 -0
- data/test/test_Type.cpp +171 -0
- data/test/test_global_functions.cpp +67 -7
- data/test/unittest.cpp +8 -0
- metadata +127 -26
- data/lib/version.rb +0 -3
- data/rice/Address_Registration_Guard_defn.hpp +0 -79
- data/rice/Data_Object_defn.hpp +0 -84
- data/rice/Data_Type_defn.hpp +0 -190
- data/rice/Exception_defn.hpp +0 -68
- data/rice/HandlerRegistration.hpp +0 -15
- data/rice/detail/ExceptionHandler.hpp +0 -8
- data/rice/detail/ExceptionHandler.ipp +0 -28
- data/rice/detail/ExceptionHandler_defn.hpp +0 -77
- data/rice/detail/Jump_Tag.hpp +0 -21
- data/rice/detail/NativeAttribute.hpp +0 -64
- data/rice/detail/NativeAttribute.ipp +0 -112
- data/rice/detail/from_ruby_defn.hpp +0 -38
- data/rice/detail/to_ruby_defn.hpp +0 -48
- data/test/test_Jump_Tag.cpp +0 -17
- data/test/test_Stl_SmartPointer.cpp +0 -283
- data/test/test_To_From_Ruby.cpp +0 -399
@@ -0,0 +1,806 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "embed_ruby.hpp"
|
3
|
+
#include <rice/rice.hpp>
|
4
|
+
#include <rice/stl.hpp>
|
5
|
+
#include <ruby/version.h>
|
6
|
+
|
7
|
+
using namespace Rice;
|
8
|
+
|
9
|
+
TESTSUITE(Overloads);
|
10
|
+
|
11
|
+
SETUP(Overloads)
|
12
|
+
{
|
13
|
+
embed_ruby();
|
14
|
+
}
|
15
|
+
|
16
|
+
namespace
|
17
|
+
{
|
18
|
+
class MyClass;
|
19
|
+
class MyClass2;
|
20
|
+
class MyClass3;
|
21
|
+
}
|
22
|
+
|
23
|
+
TEARDOWN(Overloads)
|
24
|
+
{
|
25
|
+
Data_Type<MyClass>::unbind();
|
26
|
+
Data_Type<MyClass2>::unbind();
|
27
|
+
Data_Type<MyClass3>::unbind();
|
28
|
+
Rice::detail::Registries::instance.types.remove<MyClass>();
|
29
|
+
Rice::detail::Registries::instance.types.remove<MyClass2>();
|
30
|
+
Rice::detail::Registries::instance.types.remove<MyClass3>();
|
31
|
+
rb_gc_start();
|
32
|
+
}
|
33
|
+
|
34
|
+
namespace
|
35
|
+
{
|
36
|
+
class Container
|
37
|
+
{
|
38
|
+
public:
|
39
|
+
size_t capacity()
|
40
|
+
{
|
41
|
+
return this->capacity_;
|
42
|
+
}
|
43
|
+
|
44
|
+
void capacity(size_t value)
|
45
|
+
{
|
46
|
+
this->capacity_ = value;
|
47
|
+
}
|
48
|
+
|
49
|
+
private:
|
50
|
+
size_t capacity_;
|
51
|
+
};
|
52
|
+
}
|
53
|
+
|
54
|
+
TESTCASE(OverloadsWithTemplateParameter)
|
55
|
+
{
|
56
|
+
Class c = define_class<Container>("Container")
|
57
|
+
.define_constructor(Constructor<Container>())
|
58
|
+
.define_method<size_t(Container::*)()>("capacity", &Container::capacity)
|
59
|
+
.define_method<void(Container::*)(size_t)>("capacity=", &Container::capacity);
|
60
|
+
|
61
|
+
|
62
|
+
Module m = define_module("Testing");
|
63
|
+
|
64
|
+
std::string code = R"(container = Container.new
|
65
|
+
container.capacity = 5
|
66
|
+
container.capacity)";
|
67
|
+
|
68
|
+
Object result = m.module_eval(code);
|
69
|
+
ASSERT_EQUAL(5, detail::From_Ruby<int>().convert(result.value()));
|
70
|
+
}
|
71
|
+
|
72
|
+
TESTCASE(OverloadsWithUsing)
|
73
|
+
{
|
74
|
+
using Getter_T = size_t(Container::*)();
|
75
|
+
using Setter_T = void(Container::*)(size_t);
|
76
|
+
|
77
|
+
Class c = define_class<Container>("Container")
|
78
|
+
.define_constructor(Constructor<Container>())
|
79
|
+
.define_method("capacity", (Getter_T)&Container::capacity)
|
80
|
+
.define_method("capacity=", (Setter_T)&Container::capacity);
|
81
|
+
|
82
|
+
Module m = define_module("Testing");
|
83
|
+
|
84
|
+
std::string code = R"(container = Container.new
|
85
|
+
container.capacity = 6
|
86
|
+
container.capacity)";
|
87
|
+
|
88
|
+
Object result = m.module_eval(code);
|
89
|
+
ASSERT_EQUAL(6, detail::From_Ruby<int>().convert(result.value()));
|
90
|
+
}
|
91
|
+
|
92
|
+
TESTCASE(OverloadsWithTypedef)
|
93
|
+
{
|
94
|
+
typedef size_t(Container::* Getter_T)();
|
95
|
+
typedef void (Container::* Setter_T)(size_t);
|
96
|
+
|
97
|
+
Class c = define_class<Container>("Container")
|
98
|
+
.define_constructor(Constructor<Container>())
|
99
|
+
.define_method("capacity", (Getter_T)&Container::capacity)
|
100
|
+
.define_method("capacity=", (Setter_T)&Container::capacity);
|
101
|
+
|
102
|
+
Module m = define_module("Testing");
|
103
|
+
|
104
|
+
std::string code = R"(container = Container.new
|
105
|
+
container.capacity = 7
|
106
|
+
container.capacity)";
|
107
|
+
|
108
|
+
Object result = m.module_eval(code);
|
109
|
+
ASSERT_EQUAL(7, detail::From_Ruby<int>().convert(result.value()));
|
110
|
+
}
|
111
|
+
|
112
|
+
namespace
|
113
|
+
{
|
114
|
+
std::string run()
|
115
|
+
{
|
116
|
+
return "run<void>";
|
117
|
+
}
|
118
|
+
|
119
|
+
std::string run(int a)
|
120
|
+
{
|
121
|
+
return "run<int>";
|
122
|
+
}
|
123
|
+
|
124
|
+
std::string run(float a)
|
125
|
+
{
|
126
|
+
return "run<float>";
|
127
|
+
}
|
128
|
+
|
129
|
+
std::string run(std::string a)
|
130
|
+
{
|
131
|
+
return "run<string>";
|
132
|
+
}
|
133
|
+
|
134
|
+
std::string run(int a, float b = 1.0)
|
135
|
+
{
|
136
|
+
return "run<int,float>";
|
137
|
+
}
|
138
|
+
|
139
|
+
std::string run(float a, int b = 1)
|
140
|
+
{
|
141
|
+
return "run<float,int>";
|
142
|
+
}
|
143
|
+
} // namespace
|
144
|
+
|
145
|
+
void create_globals()
|
146
|
+
{
|
147
|
+
define_global_function<std::string(*)()>("run", &run);
|
148
|
+
define_global_function<std::string(*)(std::string)>("run", &run);
|
149
|
+
define_global_function<std::string(*)(int, float)>("run", &run, Arg("a"), Arg("b") = 1.0f);
|
150
|
+
define_global_function<std::string(*)(float, int)>("run", &run, Arg("a"), Arg("b") = 1);
|
151
|
+
define_global_function<std::string(*)(int)>("run", &run);
|
152
|
+
define_global_function<std::string(*)(float)>("run", &run);
|
153
|
+
}
|
154
|
+
|
155
|
+
TESTCASE(function_zero_parameters)
|
156
|
+
{
|
157
|
+
Module m = define_module("Testing");
|
158
|
+
create_globals();
|
159
|
+
|
160
|
+
std::string code = R"(run())";
|
161
|
+
|
162
|
+
Rice::String result = m.module_eval(code);
|
163
|
+
ASSERT_EQUAL("run<void>", result.str());
|
164
|
+
}
|
165
|
+
|
166
|
+
TESTCASE(function_one_parameter)
|
167
|
+
{
|
168
|
+
Module m = define_module("Testing");
|
169
|
+
create_globals();
|
170
|
+
|
171
|
+
std::string code = R"(run(1))";
|
172
|
+
|
173
|
+
Rice::String result = m.module_eval(code);
|
174
|
+
ASSERT_EQUAL("run<int>", result.str());
|
175
|
+
|
176
|
+
code = R"(run(1.0))";
|
177
|
+
|
178
|
+
result = m.module_eval(code);
|
179
|
+
ASSERT_EQUAL("run<float>", result.str());
|
180
|
+
|
181
|
+
code = R"(run('hello'))";
|
182
|
+
|
183
|
+
result = m.module_eval(code);
|
184
|
+
ASSERT_EQUAL("run<string>", result.str());
|
185
|
+
}
|
186
|
+
|
187
|
+
TESTCASE(function_two_parameters)
|
188
|
+
{
|
189
|
+
Module m = define_module("Testing");
|
190
|
+
create_globals();
|
191
|
+
|
192
|
+
std::string code = R"(run(1, 1.0))";
|
193
|
+
|
194
|
+
Rice::String result = m.module_eval(code);
|
195
|
+
ASSERT_EQUAL("run<int,float>", result.str());
|
196
|
+
|
197
|
+
code = R"(run(1.0, 1))";
|
198
|
+
|
199
|
+
result = m.module_eval(code);
|
200
|
+
ASSERT_EQUAL("run<float,int>", result.str());
|
201
|
+
}
|
202
|
+
|
203
|
+
namespace
|
204
|
+
{
|
205
|
+
class MyClass
|
206
|
+
{
|
207
|
+
public:
|
208
|
+
MyClass() = default;
|
209
|
+
|
210
|
+
std::string run()
|
211
|
+
{
|
212
|
+
return "run<void>";
|
213
|
+
}
|
214
|
+
|
215
|
+
std::string run(int a)
|
216
|
+
{
|
217
|
+
return "run<int>";
|
218
|
+
}
|
219
|
+
|
220
|
+
std::string run(float a)
|
221
|
+
{
|
222
|
+
return "run<float>";
|
223
|
+
}
|
224
|
+
|
225
|
+
std::string run(std::string a)
|
226
|
+
{
|
227
|
+
return "run<string>";
|
228
|
+
}
|
229
|
+
|
230
|
+
std::string run(int a, float b = 1.0)
|
231
|
+
{
|
232
|
+
return "run<int,float>";
|
233
|
+
}
|
234
|
+
|
235
|
+
std::string run(float a, int b = 1)
|
236
|
+
{
|
237
|
+
return "run<float,int>";
|
238
|
+
}
|
239
|
+
};
|
240
|
+
} // namespace
|
241
|
+
|
242
|
+
Class createMyClass()
|
243
|
+
{
|
244
|
+
using Data_Type_T = Data_Type<MyClass>;
|
245
|
+
if (Data_Type_T::is_bound())
|
246
|
+
detail::Registries::instance.natives.reset(Data_Type_T::klass());
|
247
|
+
|
248
|
+
Class c = define_class<MyClass>("MyClass")
|
249
|
+
.define_constructor(Constructor<MyClass>())
|
250
|
+
.define_method<std::string(MyClass::*)()>("run", &MyClass::run)
|
251
|
+
.define_method<std::string(MyClass::*)(std::string)>("run", &MyClass::run)
|
252
|
+
.define_method<std::string(MyClass::*)(int, float)>("run", &MyClass::run, Arg("a"), Arg("b") = 1.0f)
|
253
|
+
.define_method<std::string(MyClass::*)(float, int)>("run", &MyClass::run, Arg("a"), Arg("b") = 1)
|
254
|
+
.define_method<std::string(MyClass::*)(int)>("run", &MyClass::run)
|
255
|
+
.define_method<std::string(MyClass::*)(float)>("run", &MyClass::run);
|
256
|
+
|
257
|
+
return c;
|
258
|
+
}
|
259
|
+
|
260
|
+
TESTCASE(method_zero_parameters)
|
261
|
+
{
|
262
|
+
Module m = define_module("Testing");
|
263
|
+
Class c = createMyClass();
|
264
|
+
|
265
|
+
std::string code = R"(my_class = MyClass.new
|
266
|
+
my_class.run())";
|
267
|
+
|
268
|
+
Rice::String result = m.module_eval(code);
|
269
|
+
ASSERT_EQUAL("run<void>", result.str());
|
270
|
+
}
|
271
|
+
|
272
|
+
TESTCASE(method_one_parameter)
|
273
|
+
{
|
274
|
+
Module m = define_module("Testing");
|
275
|
+
Class c = createMyClass();
|
276
|
+
|
277
|
+
std::string code = R"(my_class = MyClass.new
|
278
|
+
my_class.run(1))";
|
279
|
+
|
280
|
+
Rice::String result = m.module_eval(code);
|
281
|
+
ASSERT_EQUAL("run<int>", result.str());
|
282
|
+
|
283
|
+
code = R"(my_class = MyClass.new
|
284
|
+
my_class.run(1.0))";
|
285
|
+
|
286
|
+
result = m.module_eval(code);
|
287
|
+
ASSERT_EQUAL("run<float>", result.str());
|
288
|
+
|
289
|
+
code = R"(my_class = MyClass.new
|
290
|
+
my_class.run('hello'))";
|
291
|
+
|
292
|
+
result = m.module_eval(code);
|
293
|
+
ASSERT_EQUAL("run<string>", result.str());
|
294
|
+
}
|
295
|
+
|
296
|
+
TESTCASE(method_two_parameters)
|
297
|
+
{
|
298
|
+
Module m = define_module("Testing");
|
299
|
+
Class c = createMyClass();
|
300
|
+
|
301
|
+
std::string code = R"(my_class = MyClass.new
|
302
|
+
my_class.run(1, 1.0))";
|
303
|
+
|
304
|
+
Rice::String result = m.module_eval(code);
|
305
|
+
ASSERT_EQUAL("run<int,float>", result.str());
|
306
|
+
|
307
|
+
code = R"(my_class = MyClass.new
|
308
|
+
my_class.run(1.0, 1))";
|
309
|
+
|
310
|
+
result = m.module_eval(code);
|
311
|
+
ASSERT_EQUAL("run<float,int>", result.str());
|
312
|
+
}
|
313
|
+
|
314
|
+
TESTCASE(invalid_parameters)
|
315
|
+
{
|
316
|
+
Module m = define_module("Testing");
|
317
|
+
Class c = createMyClass();
|
318
|
+
|
319
|
+
std::string code = R"(my_class = MyClass.new
|
320
|
+
my_class.run("abc", "def"))";
|
321
|
+
|
322
|
+
std::string expected = R"(Could not resolve method call for MyClass#run
|
323
|
+
6 overload(s) were evaluated based on the types of Ruby parameters provided:
|
324
|
+
std::string AnonymousNamespace::MyClass*::run(int, float)
|
325
|
+
std::string AnonymousNamespace::MyClass*::run(float, int)
|
326
|
+
std::string AnonymousNamespace::MyClass*::run()
|
327
|
+
std::string AnonymousNamespace::MyClass*::run(std::string)
|
328
|
+
std::string AnonymousNamespace::MyClass*::run(int)
|
329
|
+
std::string AnonymousNamespace::MyClass*::run(float))";
|
330
|
+
|
331
|
+
ASSERT_EXCEPTION_CHECK(
|
332
|
+
Exception,
|
333
|
+
Rice::String result = m.module_eval(code),
|
334
|
+
ASSERT_EQUAL(expected.c_str(), ex.what()));
|
335
|
+
}
|
336
|
+
|
337
|
+
namespace
|
338
|
+
{
|
339
|
+
class MyClass2
|
340
|
+
{
|
341
|
+
public:
|
342
|
+
MyClass2()
|
343
|
+
{
|
344
|
+
this->constructor = "constructor<void>";
|
345
|
+
}
|
346
|
+
|
347
|
+
MyClass2(int a)
|
348
|
+
{
|
349
|
+
this->constructor = "constructor<int>";
|
350
|
+
}
|
351
|
+
|
352
|
+
MyClass2(float a)
|
353
|
+
{
|
354
|
+
this->constructor = "constructor<float>";
|
355
|
+
}
|
356
|
+
|
357
|
+
MyClass2(std::string a)
|
358
|
+
{
|
359
|
+
this->constructor = "constructor<string>";
|
360
|
+
}
|
361
|
+
|
362
|
+
MyClass2(int a, float b)
|
363
|
+
{
|
364
|
+
this->constructor = "constructor<int,float>";
|
365
|
+
}
|
366
|
+
|
367
|
+
MyClass2(float a, int b)
|
368
|
+
{
|
369
|
+
this->constructor = "constructor<float,int>";
|
370
|
+
}
|
371
|
+
|
372
|
+
std::string constructor;
|
373
|
+
};
|
374
|
+
} // namespace
|
375
|
+
|
376
|
+
Class createMyClass2()
|
377
|
+
{
|
378
|
+
Class c = define_class<MyClass2>("MyClass")
|
379
|
+
.define_constructor(Constructor<MyClass2>())
|
380
|
+
.define_constructor(Constructor<MyClass2, int>())
|
381
|
+
.define_constructor(Constructor<MyClass2, float>())
|
382
|
+
.define_constructor(Constructor<MyClass2, std::string>())
|
383
|
+
.define_constructor(Constructor<MyClass2, int, float>())
|
384
|
+
.define_constructor(Constructor<MyClass2, float, int>())
|
385
|
+
.define_attr("constructor", &MyClass2::constructor);
|
386
|
+
|
387
|
+
return c;
|
388
|
+
}
|
389
|
+
|
390
|
+
TESTCASE(constructor_zero_parameters)
|
391
|
+
{
|
392
|
+
Module m = define_module("Testing");
|
393
|
+
Class c = createMyClass2();
|
394
|
+
|
395
|
+
std::string code = R"(MyClass.new)";
|
396
|
+
|
397
|
+
Rice::Object result = m.module_eval(code);
|
398
|
+
Rice::String constructor = result.call("constructor");
|
399
|
+
ASSERT_EQUAL("constructor<void>", constructor.str());
|
400
|
+
}
|
401
|
+
|
402
|
+
TESTCASE(constructor_one_parameter)
|
403
|
+
{
|
404
|
+
Module m = define_module("Testing");
|
405
|
+
Class c = createMyClass2();
|
406
|
+
|
407
|
+
std::string code = R"(MyClass.new(1))";
|
408
|
+
|
409
|
+
Rice::Object result = m.module_eval(code);
|
410
|
+
Rice::String constructor = result.call("constructor");
|
411
|
+
ASSERT_EQUAL("constructor<int>", constructor.str());
|
412
|
+
|
413
|
+
code = R"(my_class = MyClass.new(1.0))";
|
414
|
+
|
415
|
+
result = m.module_eval(code);
|
416
|
+
constructor = result.call("constructor");
|
417
|
+
ASSERT_EQUAL("constructor<float>", constructor.str());
|
418
|
+
|
419
|
+
code = R"(my_class = MyClass.new('hello'))";
|
420
|
+
|
421
|
+
result = m.module_eval(code);
|
422
|
+
constructor = result.call("constructor");
|
423
|
+
ASSERT_EQUAL("constructor<string>", constructor.str());
|
424
|
+
}
|
425
|
+
|
426
|
+
TESTCASE(constructor_two_parameters)
|
427
|
+
{
|
428
|
+
Module m = define_module("Testing");
|
429
|
+
Class c = createMyClass2();
|
430
|
+
|
431
|
+
std::string code = R"(MyClass.new(1, 1.0))";
|
432
|
+
|
433
|
+
Rice::Object result = m.module_eval(code);
|
434
|
+
Rice::String constructor = result.call("constructor");
|
435
|
+
ASSERT_EQUAL("constructor<int,float>", constructor.str());
|
436
|
+
|
437
|
+
code = R"(my_class = MyClass.new(1.0, 1))";
|
438
|
+
|
439
|
+
result = m.module_eval(code);
|
440
|
+
constructor = result.call("constructor");
|
441
|
+
ASSERT_EQUAL("constructor<float,int>", constructor.str());
|
442
|
+
}
|
443
|
+
|
444
|
+
namespace
|
445
|
+
{
|
446
|
+
class MyClass3
|
447
|
+
{
|
448
|
+
public:
|
449
|
+
std::string run(char value)
|
450
|
+
{
|
451
|
+
return "run<char>";
|
452
|
+
}
|
453
|
+
|
454
|
+
std::string run(unsigned char value)
|
455
|
+
{
|
456
|
+
return "run<unsigned char>";
|
457
|
+
}
|
458
|
+
|
459
|
+
std::string run(char* value)
|
460
|
+
{
|
461
|
+
return "run<char*>";
|
462
|
+
}
|
463
|
+
|
464
|
+
std::string run(unsigned char* value)
|
465
|
+
{
|
466
|
+
return "run<unsigned char*>";
|
467
|
+
}
|
468
|
+
|
469
|
+
std::string run(short value)
|
470
|
+
{
|
471
|
+
return "run<short>";
|
472
|
+
}
|
473
|
+
|
474
|
+
std::string run(int value)
|
475
|
+
{
|
476
|
+
return "run<int>";
|
477
|
+
}
|
478
|
+
|
479
|
+
std::string run(float value)
|
480
|
+
{
|
481
|
+
return "run<float>";
|
482
|
+
}
|
483
|
+
|
484
|
+
std::string run(double value)
|
485
|
+
{
|
486
|
+
return "run<double>";
|
487
|
+
}
|
488
|
+
|
489
|
+
std::string run(long value)
|
490
|
+
{
|
491
|
+
return "run<long>";
|
492
|
+
}
|
493
|
+
|
494
|
+
std::string run(long long value)
|
495
|
+
{
|
496
|
+
return "run<long long>";
|
497
|
+
}
|
498
|
+
};
|
499
|
+
} // namespace
|
500
|
+
|
501
|
+
|
502
|
+
TESTCASE(int_conversion_1)
|
503
|
+
{
|
504
|
+
Class c = define_class<MyClass3>("MyClass3").
|
505
|
+
define_constructor(Constructor<MyClass3>()).
|
506
|
+
define_method<std::string(MyClass3::*)(char*)>("run", &MyClass3::run).
|
507
|
+
define_method<std::string(MyClass3::*)(unsigned char*)>("run", &MyClass3::run).
|
508
|
+
define_method<std::string(MyClass3::*)(short)>("run", &MyClass3::run).
|
509
|
+
define_method<std::string(MyClass3::*)(long)>("run", &MyClass3::run).
|
510
|
+
define_method<std::string(MyClass3::*)(long long)>("run", &MyClass3::run);
|
511
|
+
|
512
|
+
Module m = define_module("Testing");
|
513
|
+
|
514
|
+
std::string code = R"(my_class = MyClass3.new
|
515
|
+
value = 1
|
516
|
+
my_class.run(value))";
|
517
|
+
String result = m.module_eval(code);
|
518
|
+
ASSERT_EQUAL("run<long>", result.str());
|
519
|
+
|
520
|
+
code = R"(my_class = MyClass3.new
|
521
|
+
value = 2**60
|
522
|
+
my_class.run(value))";
|
523
|
+
result = m.module_eval(code);
|
524
|
+
|
525
|
+
#ifdef _WIN32
|
526
|
+
const char* expected = "run<long long>";
|
527
|
+
#else
|
528
|
+
const char* expected = "run<long>";
|
529
|
+
#endif
|
530
|
+
|
531
|
+
ASSERT_EQUAL(expected, result.str());
|
532
|
+
}
|
533
|
+
|
534
|
+
TESTCASE(int_conversion_2)
|
535
|
+
{
|
536
|
+
Class c = define_class<MyClass3>("MyClass3").
|
537
|
+
define_constructor(Constructor<MyClass3>()).
|
538
|
+
define_method<std::string(MyClass3::*)(short)>("run", &MyClass3::run).
|
539
|
+
define_method<std::string(MyClass3::*)(float)>("run", &MyClass3::run);
|
540
|
+
|
541
|
+
Module m = define_module("Testing");
|
542
|
+
|
543
|
+
std::string code = R"(my_class = MyClass3.new
|
544
|
+
value = 1
|
545
|
+
my_class.run(value))";
|
546
|
+
String result = m.module_eval(code);
|
547
|
+
ASSERT_EQUAL("run<float>", result.str());
|
548
|
+
|
549
|
+
code = R"(my_class = MyClass3.new
|
550
|
+
value = 2**64
|
551
|
+
my_class.run(value))";
|
552
|
+
|
553
|
+
std::string expected = R"(Could not resolve method call for MyClass3#run
|
554
|
+
2 overload(s) were evaluated based on the types of Ruby parameters provided:
|
555
|
+
std::string AnonymousNamespace::MyClass3*::run(short)
|
556
|
+
std::string AnonymousNamespace::MyClass3*::run(float))";
|
557
|
+
|
558
|
+
ASSERT_EXCEPTION_CHECK(
|
559
|
+
Exception,
|
560
|
+
result = m.module_eval(code),
|
561
|
+
ASSERT_EQUAL(expected.c_str(), ex.what()));
|
562
|
+
}
|
563
|
+
|
564
|
+
TESTCASE(int_conversion_3)
|
565
|
+
{
|
566
|
+
Class c = define_class<MyClass3>("MyClass3").
|
567
|
+
define_constructor(Constructor<MyClass3>()).
|
568
|
+
define_method<std::string(MyClass3::*)(short)>("run", &MyClass3::run).
|
569
|
+
define_method<std::string(MyClass3::*)(double)>("run", &MyClass3::run);
|
570
|
+
|
571
|
+
Module m = define_module("Testing");
|
572
|
+
|
573
|
+
std::string code = R"(my_class = MyClass3.new
|
574
|
+
value = 1
|
575
|
+
my_class.run(value))";
|
576
|
+
String result = m.module_eval(code);
|
577
|
+
ASSERT_EQUAL("run<double>", result.str());
|
578
|
+
|
579
|
+
code = R"(my_class = MyClass3.new
|
580
|
+
value = 2**32
|
581
|
+
my_class.run(value))";
|
582
|
+
|
583
|
+
result = m.module_eval(code);
|
584
|
+
ASSERT_EQUAL("run<double>", result.str());
|
585
|
+
}
|
586
|
+
|
587
|
+
TESTCASE(int_conversion_4)
|
588
|
+
{
|
589
|
+
Class c = define_class<MyClass3>("MyClass3").
|
590
|
+
define_constructor(Constructor<MyClass3>()).
|
591
|
+
define_method<std::string(MyClass3::*)(short)>("run", &MyClass3::run);
|
592
|
+
|
593
|
+
Module m = define_module("Testing");
|
594
|
+
|
595
|
+
std::string code = R"(my_class = MyClass3.new
|
596
|
+
value = 1
|
597
|
+
my_class.run(value))";
|
598
|
+
String result = m.module_eval(code);
|
599
|
+
ASSERT_EQUAL("run<short>", result.str());
|
600
|
+
|
601
|
+
code = R"(my_class = MyClass3.new
|
602
|
+
value = 2**42
|
603
|
+
my_class.run(value))";
|
604
|
+
|
605
|
+
#ifdef _WIN32
|
606
|
+
|
607
|
+
#if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 4
|
608
|
+
const char* expected = "bignum too big to convert into 'long'";
|
609
|
+
#else
|
610
|
+
const char* expected = "bignum too big to convert into `long'";
|
611
|
+
#endif
|
612
|
+
|
613
|
+
#else
|
614
|
+
|
615
|
+
#if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 4
|
616
|
+
const char* expected = "integer 4398046511104 too big to convert to 'short'";
|
617
|
+
#else
|
618
|
+
const char* expected = "integer 4398046511104 too big to convert to `short'";
|
619
|
+
#endif
|
620
|
+
|
621
|
+
#endif
|
622
|
+
|
623
|
+
ASSERT_EXCEPTION_CHECK(
|
624
|
+
Exception,
|
625
|
+
result = m.module_eval(code),
|
626
|
+
ASSERT_EQUAL(expected, ex.what()));
|
627
|
+
}
|
628
|
+
|
629
|
+
TESTCASE(int_conversion_5)
|
630
|
+
{
|
631
|
+
Class c = define_class<MyClass3>("MyClass3").
|
632
|
+
define_constructor(Constructor<MyClass3>()).
|
633
|
+
define_method<std::string(MyClass3::*)(unsigned char)>("run", &MyClass3::run).
|
634
|
+
define_method<std::string(MyClass3::*)(unsigned char*)>("run", &MyClass3::run);
|
635
|
+
|
636
|
+
Module m = define_module("Testing");
|
637
|
+
|
638
|
+
std::string code = R"(my_class = MyClass3.new
|
639
|
+
value = "54"
|
640
|
+
my_class.run(value))";
|
641
|
+
String result = m.module_eval(code);
|
642
|
+
ASSERT_EQUAL("run<unsigned char>", result.str());
|
643
|
+
}
|
644
|
+
|
645
|
+
TESTCASE(int_conversion_6)
|
646
|
+
{
|
647
|
+
Class c = define_class<MyClass3>("MyClass3").
|
648
|
+
define_constructor(Constructor<MyClass3>()).
|
649
|
+
define_method<std::string(MyClass3::*)(unsigned char)>("run", &MyClass3::run).
|
650
|
+
define_method<std::string(MyClass3::*)(unsigned char*)>("run", &MyClass3::run);
|
651
|
+
|
652
|
+
Module m = define_module("Testing");
|
653
|
+
|
654
|
+
std::string code = R"(my_class = MyClass3.new
|
655
|
+
buffer = Rice::Buffer≺unsigned char≻.new("54")
|
656
|
+
my_class.run(buffer))";
|
657
|
+
String result = m.module_eval(code);
|
658
|
+
ASSERT_EQUAL("run<unsigned char*>", result.str());
|
659
|
+
}
|
660
|
+
|
661
|
+
namespace
|
662
|
+
{
|
663
|
+
class MyClass4
|
664
|
+
{
|
665
|
+
public:
|
666
|
+
static const MyClass4& constRef()
|
667
|
+
{
|
668
|
+
if (!instance_)
|
669
|
+
{
|
670
|
+
instance_ = new MyClass4();
|
671
|
+
}
|
672
|
+
return *instance_;
|
673
|
+
}
|
674
|
+
|
675
|
+
private:
|
676
|
+
static inline MyClass4* instance_ = nullptr;
|
677
|
+
};
|
678
|
+
|
679
|
+
class MyClass5
|
680
|
+
{
|
681
|
+
public:
|
682
|
+
MyClass5(MyClass4& class4)
|
683
|
+
{
|
684
|
+
this->result = "non-const ref";
|
685
|
+
}
|
686
|
+
|
687
|
+
MyClass5(const MyClass4& class4)
|
688
|
+
{
|
689
|
+
this->result = "const ref";
|
690
|
+
}
|
691
|
+
|
692
|
+
public:
|
693
|
+
std::string result = "";
|
694
|
+
};
|
695
|
+
}
|
696
|
+
|
697
|
+
TESTCASE(NonConstRef)
|
698
|
+
{
|
699
|
+
Class c4 = define_class<MyClass4>("MyClass4").
|
700
|
+
define_constructor(Constructor<MyClass4>());
|
701
|
+
|
702
|
+
Class c5 = define_class<MyClass5>("MyClass5").
|
703
|
+
define_constructor(Constructor<MyClass5, const MyClass4&>()).
|
704
|
+
define_constructor(Constructor<MyClass5, MyClass4&>()).
|
705
|
+
define_attr("result", &MyClass5::result);
|
706
|
+
|
707
|
+
Module m = define_module("Testing");
|
708
|
+
|
709
|
+
std::string code = R"(my_class4 = MyClass4.new
|
710
|
+
my_class5 = MyClass5.new(my_class4)
|
711
|
+
my_class5.result)";
|
712
|
+
String result = m.module_eval(code);
|
713
|
+
ASSERT_EQUAL("non-const ref", result.str());
|
714
|
+
}
|
715
|
+
|
716
|
+
TESTCASE(ConstRef)
|
717
|
+
{
|
718
|
+
Class c4 = define_class<MyClass4>("MyClass4").
|
719
|
+
define_singleton_function("const_instance", MyClass4::constRef);
|
720
|
+
|
721
|
+
Class c5 = define_class<MyClass5>("MyClass5").
|
722
|
+
define_constructor(Constructor<MyClass5, const MyClass4&>()).
|
723
|
+
define_constructor(Constructor<MyClass5, MyClass4&>()).
|
724
|
+
define_attr("result", &MyClass5::result);
|
725
|
+
|
726
|
+
Module m = define_module("Testing");
|
727
|
+
|
728
|
+
std::string code = R"(my_class4 = MyClass4.const_instance
|
729
|
+
my_class5 = MyClass5.new(my_class4)
|
730
|
+
my_class5.result)";
|
731
|
+
String result = m.module_eval(code);
|
732
|
+
ASSERT_EQUAL("const ref", result.str());
|
733
|
+
}
|
734
|
+
|
735
|
+
namespace
|
736
|
+
{
|
737
|
+
class MyClass6
|
738
|
+
{
|
739
|
+
public:
|
740
|
+
static const MyClass6* constPointer()
|
741
|
+
{
|
742
|
+
if (!instance_)
|
743
|
+
{
|
744
|
+
instance_ = new MyClass6();
|
745
|
+
}
|
746
|
+
return instance_;
|
747
|
+
}
|
748
|
+
|
749
|
+
private:
|
750
|
+
static inline MyClass6* instance_ = nullptr;
|
751
|
+
};
|
752
|
+
|
753
|
+
class MyClass7
|
754
|
+
{
|
755
|
+
public:
|
756
|
+
MyClass7(MyClass6* class6)
|
757
|
+
{
|
758
|
+
this->result = "non-const pointer";
|
759
|
+
}
|
760
|
+
|
761
|
+
MyClass7(const MyClass6* class6)
|
762
|
+
{
|
763
|
+
this->result = "const pointer";
|
764
|
+
}
|
765
|
+
public:
|
766
|
+
std::string result = "";
|
767
|
+
};
|
768
|
+
}
|
769
|
+
|
770
|
+
TESTCASE(NonConstPointer)
|
771
|
+
{
|
772
|
+
Class c6 = define_class<MyClass6>("MyClass6").
|
773
|
+
define_constructor(Constructor<MyClass6>());
|
774
|
+
|
775
|
+
Class c7 = define_class<MyClass7>("MyClass7").
|
776
|
+
define_constructor(Constructor<MyClass7, const MyClass6*>()).
|
777
|
+
define_constructor(Constructor<MyClass7, MyClass6*>()).
|
778
|
+
define_attr("result", &MyClass7::result);
|
779
|
+
|
780
|
+
Module m = define_module("Testing");
|
781
|
+
|
782
|
+
std::string code = R"(my_class6 = MyClass6.new
|
783
|
+
my_class7 = MyClass7.new(my_class6)
|
784
|
+
my_class7.result)";
|
785
|
+
String result = m.module_eval(code);
|
786
|
+
ASSERT_EQUAL("non-const pointer", result.str());
|
787
|
+
}
|
788
|
+
|
789
|
+
TESTCASE(ConstPointer)
|
790
|
+
{
|
791
|
+
Class c6 = define_class<MyClass6>("MyClass6").
|
792
|
+
define_singleton_function("const_instance", MyClass6::constPointer);
|
793
|
+
|
794
|
+
Class c7 = define_class<MyClass7>("MyClass7").
|
795
|
+
define_constructor(Constructor<MyClass7, const MyClass6*>()).
|
796
|
+
define_constructor(Constructor<MyClass7, MyClass6*>()).
|
797
|
+
define_attr("result", &MyClass7::result);
|
798
|
+
|
799
|
+
Module m = define_module("Testing");
|
800
|
+
|
801
|
+
std::string code = R"(my_class6 = MyClass6.const_instance
|
802
|
+
my_class7 = MyClass7.new(my_class6)
|
803
|
+
my_class7.result)";
|
804
|
+
String result = m.module_eval(code);
|
805
|
+
ASSERT_EQUAL("const pointer", result.str());
|
806
|
+
}
|