rice 4.5.0 → 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 +23 -0
- data/CMakeLists.txt +31 -0
- data/CMakePresets.json +75 -0
- data/COPYING +3 -2
- data/FindRuby.cmake +437 -0
- data/Rakefile +5 -4
- data/include/rice/rice.hpp +5436 -3201
- data/include/rice/stl.hpp +2355 -1269
- data/lib/make_rice_headers.rb +79 -0
- data/lib/mkmf-rice.rb +4 -0
- 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/Arg.hpp +7 -1
- data/rice/Arg.ipp +11 -2
- data/rice/Buffer.hpp +123 -0
- data/rice/Buffer.ipp +599 -0
- data/rice/Constructor.ipp +3 -3
- data/rice/Data_Object.hpp +2 -3
- data/rice/Data_Object.ipp +188 -188
- data/rice/Data_Type.hpp +4 -5
- data/rice/Data_Type.ipp +42 -26
- data/rice/Enum.hpp +0 -1
- data/rice/Enum.ipp +26 -23
- data/rice/Init.hpp +8 -0
- data/rice/Init.ipp +8 -0
- data/rice/MemoryView.ipp +1 -41
- data/rice/Return.hpp +1 -1
- data/rice/Return.ipp +6 -0
- 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/cpp_api/Identifier.hpp +46 -0
- data/rice/cpp_api/Identifier.ipp +31 -0
- 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/MethodInfo.hpp +1 -9
- data/rice/detail/MethodInfo.ipp +5 -72
- data/rice/detail/Native.hpp +3 -2
- data/rice/detail/Native.ipp +32 -4
- data/rice/detail/NativeAttributeGet.hpp +3 -2
- data/rice/detail/NativeAttributeGet.ipp +8 -2
- data/rice/detail/NativeAttributeSet.hpp +3 -2
- data/rice/detail/NativeAttributeSet.ipp +8 -2
- data/rice/detail/NativeCallbackFFI.ipp +1 -1
- data/rice/detail/NativeFunction.hpp +17 -6
- data/rice/detail/NativeFunction.ipp +168 -64
- data/rice/detail/NativeIterator.hpp +3 -2
- data/rice/detail/NativeIterator.ipp +8 -2
- data/rice/detail/RubyType.hpp +2 -5
- data/rice/detail/RubyType.ipp +50 -5
- data/rice/detail/Type.hpp +3 -1
- data/rice/detail/Type.ipp +61 -31
- data/rice/detail/Wrapper.hpp +68 -33
- data/rice/detail/Wrapper.ipp +103 -113
- data/rice/detail/from_ruby.hpp +5 -4
- data/rice/detail/from_ruby.ipp +737 -365
- data/rice/detail/to_ruby.ipp +1092 -186
- data/rice/global_function.ipp +1 -1
- data/rice/libc/file.hpp +11 -0
- data/rice/libc/file.ipp +32 -0
- data/rice/rice.hpp +23 -16
- 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 +7 -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 +3 -0
- data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
- data/test/test_Array.cpp +6 -3
- data/test/test_Attribute.cpp +34 -1
- data/test/test_Buffer.cpp +285 -0
- data/test/test_Callback.cpp +2 -3
- data/test/test_Data_Object.cpp +88 -34
- data/test/test_Data_Type.cpp +106 -65
- data/test/test_Director.cpp +7 -3
- data/test/test_Enum.cpp +5 -2
- data/test/test_File.cpp +1 -1
- data/test/test_From_Ruby.cpp +181 -114
- data/test/test_Iterator.cpp +1 -1
- data/test/{test_JumpException.cpp → test_Jump_Exception.cpp} +1 -0
- data/test/test_Keep_Alive.cpp +7 -18
- data/test/test_Keep_Alive_No_Wrapper.cpp +0 -1
- data/test/test_Module.cpp +13 -6
- data/test/test_Native_Registry.cpp +0 -1
- data/test/test_Overloads.cpp +180 -5
- data/test/test_Ownership.cpp +100 -57
- data/test/test_Proc.cpp +0 -1
- data/test/test_Self.cpp +4 -4
- data/test/test_Stl_Map.cpp +37 -39
- data/test/test_Stl_Multimap.cpp +693 -0
- data/test/test_Stl_Pair.cpp +8 -8
- data/test/test_Stl_Reference_Wrapper.cpp +4 -2
- data/test/test_Stl_Set.cpp +790 -0
- data/test/{test_Stl_SmartPointer.cpp → test_Stl_SharedPtr.cpp} +97 -127
- data/test/test_Stl_Tuple.cpp +116 -0
- data/test/test_Stl_Type.cpp +1 -1
- data/test/test_Stl_UniquePtr.cpp +202 -0
- data/test/test_Stl_Unordered_Map.cpp +28 -34
- data/test/test_Stl_Variant.cpp +217 -89
- data/test/test_Stl_Vector.cpp +209 -83
- data/test/test_To_Ruby.cpp +373 -1
- data/test/test_Type.cpp +85 -14
- data/test/test_global_functions.cpp +17 -4
- metadata +94 -10
- data/rice/detail/TupleIterator.hpp +0 -14
data/test/test_To_Ruby.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "unittest.hpp"
|
1
|
+
#include "unittest.hpp"
|
2
2
|
#include "embed_ruby.hpp"
|
3
3
|
#include <rice/rice.hpp>
|
4
4
|
|
@@ -6,12 +6,14 @@
|
|
6
6
|
#include <cmath>
|
7
7
|
|
8
8
|
using namespace Rice;
|
9
|
+
using namespace std::string_literals;
|
9
10
|
|
10
11
|
TESTSUITE(ToRuby);
|
11
12
|
|
12
13
|
SETUP(ToRuby)
|
13
14
|
{
|
14
15
|
embed_ruby();
|
16
|
+
define_fundamental_buffer_types();
|
15
17
|
}
|
16
18
|
|
17
19
|
TEARDOWN(ToRuby)
|
@@ -150,3 +152,373 @@ TESTCASE(char_const_array_to_ruby_symbol)
|
|
150
152
|
{
|
151
153
|
ASSERT(rb_equal(Symbol("foo").value(), detail::to_ruby(":foo")));
|
152
154
|
}
|
155
|
+
|
156
|
+
namespace
|
157
|
+
{
|
158
|
+
template<typename T>
|
159
|
+
class Matrix2
|
160
|
+
{
|
161
|
+
public:
|
162
|
+
T* ptr()
|
163
|
+
{
|
164
|
+
return this->data;
|
165
|
+
}
|
166
|
+
|
167
|
+
T data[5] = { 1,2,3,4,5 };
|
168
|
+
};
|
169
|
+
|
170
|
+
using Matrix2UnsignedChar = Matrix2<unsigned char>;
|
171
|
+
using Matrix2Char = Matrix2<char>;
|
172
|
+
using Matrix2UnsignedShort = Matrix2<unsigned short>;
|
173
|
+
using Matrix2Short = Matrix2<short>;
|
174
|
+
using Matrix2UnsignedInt = Matrix2<unsigned int>;
|
175
|
+
using Matrix2Int = Matrix2<int>;
|
176
|
+
using Matrix2Float = Matrix2<float>;
|
177
|
+
using Matrix2Double = Matrix2<double>;
|
178
|
+
|
179
|
+
template<typename T>
|
180
|
+
class Matrix3
|
181
|
+
{
|
182
|
+
public:
|
183
|
+
T** ptr()
|
184
|
+
{
|
185
|
+
return this->data;
|
186
|
+
}
|
187
|
+
|
188
|
+
private:
|
189
|
+
T one = 1;
|
190
|
+
T two = 2;
|
191
|
+
T three = 3;
|
192
|
+
T four = 4;
|
193
|
+
T five = 5;
|
194
|
+
|
195
|
+
public:
|
196
|
+
T* data[5] = { &one, &two, &three, &four, &five };
|
197
|
+
|
198
|
+
};
|
199
|
+
|
200
|
+
using Matrix3UnsignedChar = Matrix3<unsigned char>;
|
201
|
+
}
|
202
|
+
|
203
|
+
TESTCASE(unsigned_char_ptr_buffer)
|
204
|
+
{
|
205
|
+
Module m = define_module("ToRubyPtr");
|
206
|
+
|
207
|
+
Class c = define_class_under<Matrix2UnsignedChar>(m, "Matrix2UnsignedChar")
|
208
|
+
.define_constructor(Constructor<Matrix2UnsignedChar>())
|
209
|
+
.define_method("ptr", &Matrix2UnsignedChar::ptr)
|
210
|
+
.define_attr("data", &Matrix2UnsignedChar::data, Rice::AttrAccess::Read);
|
211
|
+
|
212
|
+
std::string code = R"(matrix = Matrix2UnsignedChar.new
|
213
|
+
buffer = matrix.ptr
|
214
|
+
buffer.bytes(5))";
|
215
|
+
String buffer = m.module_eval(code);
|
216
|
+
ASSERT_EQUAL("\x1\x2\x3\x4\x5", buffer.str());
|
217
|
+
|
218
|
+
code = R"(matrix = Matrix2UnsignedChar.new
|
219
|
+
buffer = matrix.ptr
|
220
|
+
buffer.bytes(0))";
|
221
|
+
buffer = m.module_eval(code);
|
222
|
+
ASSERT_EQUAL("", buffer.str());
|
223
|
+
|
224
|
+
code = R"(matrix = Matrix2UnsignedChar.new
|
225
|
+
buffer = matrix.data
|
226
|
+
buffer.bytes)";
|
227
|
+
|
228
|
+
buffer = m.module_eval(code);
|
229
|
+
ASSERT_EQUAL("\x1\x2\x3\x4\x5", buffer.str());
|
230
|
+
}
|
231
|
+
|
232
|
+
TESTCASE(unsigned_char_ptr_array)
|
233
|
+
{
|
234
|
+
Module m = define_module("ToRubyPtr");
|
235
|
+
|
236
|
+
Class c = define_class_under<Matrix2UnsignedChar>(m, "Matrix2UnsignedChar")
|
237
|
+
.define_constructor(Constructor<Matrix2UnsignedChar>())
|
238
|
+
.define_method("ptr", &Matrix2UnsignedChar::ptr);
|
239
|
+
|
240
|
+
std::string code = R"(matrix = Matrix2UnsignedChar.new
|
241
|
+
buffer = matrix.ptr
|
242
|
+
buffer.to_ary(5))";
|
243
|
+
|
244
|
+
std::vector<unsigned char> expected = std::vector<unsigned char>{ 1,2,3,4,5 };
|
245
|
+
Array array = m.module_eval(code);
|
246
|
+
std::vector<unsigned char> actual = array.to_vector<unsigned char>();
|
247
|
+
ASSERT_EQUAL(expected, actual);
|
248
|
+
|
249
|
+
code = R"(matrix = Matrix2UnsignedChar.new
|
250
|
+
buffer = matrix.ptr
|
251
|
+
buffer.to_ary(1))";
|
252
|
+
|
253
|
+
expected = std::vector<unsigned char>{ 1 };
|
254
|
+
array = m.module_eval(code);
|
255
|
+
actual = array.to_vector<unsigned char>();
|
256
|
+
ASSERT_EQUAL(expected, actual);
|
257
|
+
}
|
258
|
+
|
259
|
+
TESTCASE(unsigned_char_ptr_ptr_buffer)
|
260
|
+
{
|
261
|
+
Module m = define_module("ToRubyPtr");
|
262
|
+
|
263
|
+
Class c = define_class_under<Matrix3UnsignedChar>(m, "Matrix3UnsignedChar")
|
264
|
+
.define_constructor(Constructor<Matrix3UnsignedChar>())
|
265
|
+
.define_method("ptr", &Matrix3UnsignedChar::ptr)
|
266
|
+
.define_attr("data", &Matrix3UnsignedChar::data, Rice::AttrAccess::Read);
|
267
|
+
|
268
|
+
std::string code = R"(matrix = Matrix3UnsignedChar.new
|
269
|
+
buffer = matrix.ptr
|
270
|
+
buffer2 = buffer.to_ary(1).first
|
271
|
+
buffer2.to_ary(5))";
|
272
|
+
Array array = m.module_eval(code);
|
273
|
+
ASSERT_EQUAL(5, array.size());
|
274
|
+
|
275
|
+
std::vector<unsigned char> expected{ 1, 2, 3, 4, 5 };
|
276
|
+
std::vector<unsigned char> actual = array.to_vector<unsigned char>();
|
277
|
+
ASSERT_EQUAL(expected, actual);
|
278
|
+
}
|
279
|
+
|
280
|
+
TESTCASE(unsigned_char_ptr_ptr_array)
|
281
|
+
{
|
282
|
+
Module m = define_module("ToRubyPtr");
|
283
|
+
|
284
|
+
Class c = define_class_under<Matrix3UnsignedChar>(m, "Matrix3UnsignedChar")
|
285
|
+
.define_constructor(Constructor<Matrix3UnsignedChar>())
|
286
|
+
.define_method("ptr", &Matrix3UnsignedChar::ptr);
|
287
|
+
|
288
|
+
std::string code = R"(matrix = Matrix3UnsignedChar.new
|
289
|
+
buffer = matrix.ptr
|
290
|
+
buffer.to_ary(5))";
|
291
|
+
|
292
|
+
Array pointers = m.module_eval(code);
|
293
|
+
ASSERT_EQUAL(5, pointers.size());
|
294
|
+
|
295
|
+
for (int i = 0; i < pointers.size(); i++)
|
296
|
+
{
|
297
|
+
Object buffer = pointers[i];
|
298
|
+
Array array = buffer.call("to_ary", 1);
|
299
|
+
|
300
|
+
std::vector<unsigned char> expected = std::vector<unsigned char>{ (unsigned char)(i + 1) };
|
301
|
+
std::vector<unsigned char> actual = array.to_vector<unsigned char>();
|
302
|
+
ASSERT_EQUAL(expected, actual);
|
303
|
+
}
|
304
|
+
}
|
305
|
+
|
306
|
+
TESTCASE(short_ptr_buffer)
|
307
|
+
{
|
308
|
+
Module m = define_module("ToRubyPtr");
|
309
|
+
|
310
|
+
Class c = define_class_under<Matrix2Short>(m, "Matrix2Short")
|
311
|
+
.define_constructor(Constructor<Matrix2Short>())
|
312
|
+
.define_method("ptr", &Matrix2Short::ptr);
|
313
|
+
|
314
|
+
std::string code = R"(matrix = Matrix2Short.new
|
315
|
+
buffer = matrix.ptr
|
316
|
+
buffer.bytes(5))";
|
317
|
+
|
318
|
+
std::string expected = "\x1\0\x2\0\x3\0\x4\0\x5\0"s;
|
319
|
+
String buffer = m.module_eval(code);
|
320
|
+
ASSERT_EQUAL(expected, buffer.str());
|
321
|
+
|
322
|
+
code = R"(matrix = Matrix2Short.new
|
323
|
+
buffer = matrix.ptr
|
324
|
+
buffer.bytes(0))";
|
325
|
+
expected = ""s;
|
326
|
+
buffer = m.module_eval(code);
|
327
|
+
ASSERT_EQUAL(expected, buffer.str());
|
328
|
+
}
|
329
|
+
|
330
|
+
TESTCASE(short_ptr_array)
|
331
|
+
{
|
332
|
+
Module m = define_module("ToRubyPtr");
|
333
|
+
|
334
|
+
Class c = define_class_under<Matrix2Short>(m, "Matrix2Short")
|
335
|
+
.define_constructor(Constructor<Matrix2Short>())
|
336
|
+
.define_method("ptr", &Matrix2Short::ptr);
|
337
|
+
|
338
|
+
std::string code = R"(matrix = Matrix2Short.new
|
339
|
+
buffer = matrix.ptr
|
340
|
+
buffer.to_ary(5))";
|
341
|
+
|
342
|
+
std::vector<short> expected = std::vector<short>{1,2,3,4,5};
|
343
|
+
Array array = m.module_eval(code);
|
344
|
+
std::vector<short> actual = array.to_vector<short>();
|
345
|
+
ASSERT_EQUAL(expected, actual);
|
346
|
+
}
|
347
|
+
|
348
|
+
TESTCASE(unsigned_short_ptr_buffer)
|
349
|
+
{
|
350
|
+
Module m = define_module("ToRubyPtr");
|
351
|
+
|
352
|
+
Class c = define_class_under<Matrix2UnsignedShort>(m, "Matrix2UnsignedShort")
|
353
|
+
.define_constructor(Constructor<Matrix2UnsignedShort>())
|
354
|
+
.define_method("ptr", &Matrix2UnsignedShort::ptr);
|
355
|
+
|
356
|
+
std::string code = R"(matrix = Matrix2UnsignedShort.new
|
357
|
+
buffer = matrix.ptr
|
358
|
+
buffer.bytes(5))";
|
359
|
+
|
360
|
+
std::string expected = "\x1\0\x2\0\x3\0\x4\0\x5\0"s;
|
361
|
+
String buffer = m.module_eval(code);
|
362
|
+
ASSERT_EQUAL(expected, buffer.str());
|
363
|
+
|
364
|
+
code = R"(matrix = Matrix2UnsignedShort.new
|
365
|
+
buffer = matrix.ptr
|
366
|
+
buffer.bytes(0))";
|
367
|
+
expected = ""s;
|
368
|
+
buffer = m.module_eval(code);
|
369
|
+
ASSERT_EQUAL(expected, buffer.str());
|
370
|
+
}
|
371
|
+
|
372
|
+
TESTCASE(unsigned_short_ptr_array)
|
373
|
+
{
|
374
|
+
Module m = define_module("ToRubyPtr");
|
375
|
+
|
376
|
+
Class c = define_class_under<Matrix2UnsignedShort>(m, "Matrix2UnsignedShort")
|
377
|
+
.define_constructor(Constructor<Matrix2UnsignedShort>())
|
378
|
+
.define_method("ptr", &Matrix2UnsignedShort::ptr);
|
379
|
+
|
380
|
+
std::string code = R"(matrix = Matrix2UnsignedShort.new
|
381
|
+
buffer = matrix.ptr
|
382
|
+
buffer.to_ary(5))";
|
383
|
+
|
384
|
+
std::vector<unsigned short> expected = std::vector<unsigned short>{ 1,2,3,4,5 };
|
385
|
+
Array array = m.module_eval(code);
|
386
|
+
std::vector<unsigned short> actual = array.to_vector<unsigned short>();
|
387
|
+
ASSERT_EQUAL(expected, actual);
|
388
|
+
}
|
389
|
+
|
390
|
+
TESTCASE(int_ptr_buffer)
|
391
|
+
{
|
392
|
+
Module m = define_module("ToRubyPtr");
|
393
|
+
|
394
|
+
Class c = define_class_under<Matrix2Int>(m, "Matrix2Int")
|
395
|
+
.define_constructor(Constructor<Matrix2Int>())
|
396
|
+
.define_method("ptr", &Matrix2Int::ptr);
|
397
|
+
|
398
|
+
std::string code = R"(matrix = Matrix2Int.new
|
399
|
+
buffer = matrix.ptr
|
400
|
+
buffer.bytes(5))";
|
401
|
+
|
402
|
+
std::string expected = "\x1\0\0\0\x2\0\0\0\x3\0\0\0\x4\0\0\0\x5\0\0\0"s;
|
403
|
+
String buffer = m.module_eval(code);
|
404
|
+
ASSERT_EQUAL(expected, buffer.str());
|
405
|
+
|
406
|
+
code = R"(matrix = Matrix2Int.new
|
407
|
+
buffer = matrix.ptr
|
408
|
+
buffer.bytes(0))";
|
409
|
+
expected = ""s;
|
410
|
+
buffer = m.module_eval(code);
|
411
|
+
ASSERT_EQUAL(expected, buffer.str());
|
412
|
+
}
|
413
|
+
|
414
|
+
TESTCASE(int_ptr_array)
|
415
|
+
{
|
416
|
+
Module m = define_module("ToRubyPtr");
|
417
|
+
|
418
|
+
Class c = define_class_under<Matrix2Int>(m, "Matrix2Int")
|
419
|
+
.define_constructor(Constructor<Matrix2Int>())
|
420
|
+
.define_method("ptr", &Matrix2Int::ptr);
|
421
|
+
|
422
|
+
std::string code = R"(matrix = Matrix2Int.new
|
423
|
+
buffer = matrix.ptr
|
424
|
+
buffer.to_ary(5))";
|
425
|
+
|
426
|
+
std::vector<int> expected = std::vector<int>{ 1,2,3,4,5 };
|
427
|
+
Array array = m.module_eval(code);
|
428
|
+
std::vector<int> actual = array.to_vector<int>();
|
429
|
+
ASSERT_EQUAL(expected, actual);
|
430
|
+
}
|
431
|
+
|
432
|
+
TESTCASE(float_ptr_buffer)
|
433
|
+
{
|
434
|
+
Module m = define_module("ToRubyPtr");
|
435
|
+
|
436
|
+
Class c = define_class_under<Matrix2Float>(m, "Matrix2Float")
|
437
|
+
.define_constructor(Constructor<Matrix2Float>())
|
438
|
+
.define_method("ptr", &Matrix2Float::ptr);
|
439
|
+
|
440
|
+
std::string code = R"(matrix = Matrix2Float.new
|
441
|
+
buffer = matrix.ptr
|
442
|
+
buffer.bytes(5))";
|
443
|
+
|
444
|
+
std::string expected = "\0\0\x80\x3f\0\0\0\x40\0\0\x40\x40\0\0\x80\x40\0\0\xa0\x40"s;
|
445
|
+
String buffer = m.module_eval(code);
|
446
|
+
ASSERT_EQUAL(expected, buffer.str());
|
447
|
+
|
448
|
+
code = R"(matrix = Matrix2Float.new
|
449
|
+
buffer = matrix.ptr
|
450
|
+
buffer.bytes(0))";
|
451
|
+
expected = ""s;
|
452
|
+
buffer = m.module_eval(code);
|
453
|
+
ASSERT_EQUAL(expected, buffer.str());
|
454
|
+
}
|
455
|
+
|
456
|
+
TESTCASE(float_ptr_array)
|
457
|
+
{
|
458
|
+
Module m = define_module("ToRubyPtr");
|
459
|
+
|
460
|
+
Class c = define_class_under<Matrix2Float>(m, "Matrix2Float")
|
461
|
+
.define_constructor(Constructor<Matrix2Float>())
|
462
|
+
.define_method("ptr", &Matrix2Float::ptr);
|
463
|
+
|
464
|
+
std::string code = R"(matrix = Matrix2Float.new
|
465
|
+
buffer = matrix.ptr
|
466
|
+
buffer.to_ary(5))";
|
467
|
+
|
468
|
+
std::vector<float> expected = std::vector<float>{ 1.0,2.0,3.0,4.0,5.0 };
|
469
|
+
Array array = m.module_eval(code);
|
470
|
+
std::vector<float> actual = array.to_vector<float>();
|
471
|
+
ASSERT_EQUAL(expected, actual);
|
472
|
+
}
|
473
|
+
|
474
|
+
TESTCASE(double_ptr_buffer)
|
475
|
+
{
|
476
|
+
Module m = define_module("ToRubyPtr");
|
477
|
+
|
478
|
+
Class c = define_class_under<Matrix2Double>(m, "Matrix2Double")
|
479
|
+
.define_constructor(Constructor<Matrix2Double>())
|
480
|
+
.define_method("ptr", &Matrix2Double::ptr);
|
481
|
+
|
482
|
+
std::string code = R"(matrix = Matrix2Double.new
|
483
|
+
buffer = matrix.ptr
|
484
|
+
buffer.bytes(5))";
|
485
|
+
|
486
|
+
std::string expected = "\0\0\0\0\0\0\xf0\x3f\0\0\0\0\0\0\0\x40\0\0\0\0\0\0\x08\x40\0\0\0\0\0\0\x10\x40\0\0\0\0\0\0\x14\x40"s;
|
487
|
+
String buffer = m.module_eval(code);
|
488
|
+
const char* ptr = RSTRING_PTR(buffer.value());
|
489
|
+
ASSERT_EQUAL(expected, buffer.str());
|
490
|
+
|
491
|
+
code = R"(matrix = Matrix2Double.new
|
492
|
+
buffer = matrix.ptr
|
493
|
+
buffer.bytes(0))";
|
494
|
+
expected = ""s;
|
495
|
+
buffer = m.module_eval(code);
|
496
|
+
ASSERT_EQUAL(expected, buffer.str());
|
497
|
+
}
|
498
|
+
|
499
|
+
TESTCASE(double_ptr_array)
|
500
|
+
{
|
501
|
+
Module m = define_module("ToRubyPtr");
|
502
|
+
|
503
|
+
Class c = define_class_under<Matrix2Double>(m, "Matrix2Double")
|
504
|
+
.define_constructor(Constructor<Matrix2Double>())
|
505
|
+
.define_method("ptr", &Matrix2Double::ptr);
|
506
|
+
|
507
|
+
std::string code = R"(matrix = Matrix2Double.new
|
508
|
+
buffer = matrix.ptr
|
509
|
+
buffer.to_ary(5))";
|
510
|
+
|
511
|
+
std::vector<double> expected = std::vector<double>{ 1.0,2.0,3.0,4.0,5.0 };
|
512
|
+
Array array = m.module_eval(code);
|
513
|
+
std::vector<double> actual = array.to_vector<double>();
|
514
|
+
ASSERT_EQUAL(expected, actual);
|
515
|
+
|
516
|
+
code = R"(matrix = Matrix2Double.new
|
517
|
+
buffer = matrix.ptr
|
518
|
+
buffer.to_ary(0))";
|
519
|
+
|
520
|
+
expected = std::vector<double>{ };
|
521
|
+
array = m.module_eval(code);
|
522
|
+
actual = array.to_vector<double>();
|
523
|
+
ASSERT_EQUAL(expected, actual);
|
524
|
+
}
|
data/test/test_Type.cpp
CHANGED
@@ -56,33 +56,104 @@ TESTCASE(FindGroup)
|
|
56
56
|
);
|
57
57
|
}
|
58
58
|
|
59
|
-
TESTCASE(
|
59
|
+
TESTCASE(CppClassName)
|
60
60
|
{
|
61
|
-
std::string typeName = detail::typeName(typeid(
|
62
|
-
std::string className = detail::
|
63
|
-
ASSERT_EQUAL(
|
61
|
+
std::string typeName = detail::typeName(typeid(std::string));
|
62
|
+
std::string className = detail::cppClassName(typeName);
|
63
|
+
ASSERT_EQUAL("std::string", className.c_str());
|
64
|
+
|
65
|
+
typeName = detail::typeName(typeid(std::wstring));
|
66
|
+
className = detail::cppClassName(typeName);
|
67
|
+
ASSERT_EQUAL("std::wstring", className.c_str());
|
68
|
+
|
69
|
+
typeName = detail::typeName(typeid(std::vector<std::string>));
|
70
|
+
className = detail::cppClassName(typeName);
|
71
|
+
ASSERT_EQUAL("std::vector<std::string>", className.c_str());
|
72
|
+
|
73
|
+
typeName = detail::typeName(typeid(std::vector<std::wstring>));
|
74
|
+
className = detail::cppClassName(typeName);
|
75
|
+
ASSERT_EQUAL("std::vector<std::wstring>", className.c_str());
|
76
|
+
|
77
|
+
typeName = detail::typeName(typeid(std::vector<double*>));
|
78
|
+
className = detail::cppClassName(typeName);
|
79
|
+
ASSERT_EQUAL("std::vector<double*>", className.c_str());
|
80
|
+
|
81
|
+
typeName = detail::typeName(typeid(std::vector<double**>));
|
82
|
+
className = detail::cppClassName(typeName);
|
83
|
+
ASSERT_EQUAL("std::vector<double**>", className.c_str());
|
84
|
+
|
85
|
+
typeName = detail::typeName(typeid(Outer::Inner::Vec1));
|
86
|
+
className = detail::cppClassName(typeName);
|
87
|
+
ASSERT_EQUAL("std::vector<std::complex<float>>", className.c_str());
|
88
|
+
|
89
|
+
typeName = detail::typeName(typeid(Outer::Inner::Vec2));
|
90
|
+
className = detail::cppClassName(typeName);
|
91
|
+
ASSERT_EQUAL("std::vector<unsigned char*>", className.c_str());
|
92
|
+
|
93
|
+
typeName = detail::typeName(typeid(Outer::Inner::Vec3));
|
94
|
+
className = detail::cppClassName(typeName);
|
95
|
+
ASSERT_EQUAL("std::vector<Outer::Inner::SomeClass>", className.c_str());
|
96
|
+
|
97
|
+
typeName = detail::typeName(typeid(Outer::Inner::Map1));
|
98
|
+
className = detail::cppClassName(typeName);
|
99
|
+
ASSERT_EQUAL("std::map<std::string, std::vector<std::complex<float>>>", className.c_str());
|
100
|
+
|
101
|
+
typeName = detail::typeName(typeid(Outer::Inner::UnorderedMap1));
|
102
|
+
className = detail::cppClassName(typeName);
|
103
|
+
ASSERT_EQUAL("std::unordered_map<std::string, std::complex<float>>", className.c_str());
|
104
|
+
}
|
105
|
+
|
106
|
+
TESTCASE(RubyClassName)
|
107
|
+
{
|
108
|
+
std::string typeName = detail::typeName(typeid(std::string));
|
109
|
+
std::string className = detail::rubyClassName(typeName);
|
110
|
+
ASSERT_EQUAL("String", className.c_str());
|
111
|
+
|
112
|
+
typeName = detail::typeName(typeid(std::wstring));
|
113
|
+
className = detail::rubyClassName(typeName);
|
114
|
+
ASSERT_EQUAL("Wstring", className.c_str());
|
115
|
+
|
116
|
+
typeName = detail::typeName(typeid(std::vector<std::string>));
|
117
|
+
className = detail::rubyClassName(typeName);
|
118
|
+
ASSERT_EQUAL("Vector≺string≻", className.c_str());
|
119
|
+
|
120
|
+
typeName = detail::typeName(typeid(std::vector<std::wstring>));
|
121
|
+
className = detail::rubyClassName(typeName);
|
122
|
+
ASSERT_EQUAL("Vector≺wstring≻", className.c_str());
|
123
|
+
|
124
|
+
typeName = detail::typeName(typeid(std::vector<double*>));
|
125
|
+
className = detail::rubyClassName(typeName);
|
126
|
+
ASSERT_EQUAL("Vector≺double∗≻", className.c_str());
|
127
|
+
|
128
|
+
typeName = detail::typeName(typeid(std::vector<double**>));
|
129
|
+
className = detail::rubyClassName(typeName);
|
130
|
+
ASSERT_EQUAL("Vector≺double∗∗≻", className.c_str());
|
131
|
+
|
132
|
+
typeName = detail::typeName(typeid(Outer::Inner::Vec1));
|
133
|
+
className = detail::rubyClassName(typeName);
|
134
|
+
ASSERT_EQUAL("Vector≺complex≺float≻≻", className.c_str());
|
64
135
|
|
65
136
|
typeName = detail::typeName(typeid(Outer::Inner::Vec2));
|
66
|
-
className = detail::
|
67
|
-
ASSERT_EQUAL(
|
137
|
+
className = detail::rubyClassName(typeName);
|
138
|
+
ASSERT_EQUAL("Vector≺unsigned char∗≻", className.c_str());
|
68
139
|
|
69
140
|
typeName = detail::typeName(typeid(Outer::Inner::Vec3));
|
70
|
-
className = detail::
|
71
|
-
ASSERT_EQUAL(
|
141
|
+
className = detail::rubyClassName(typeName);
|
142
|
+
ASSERT_EQUAL("Vector≺Outer꞉꞉Inner꞉꞉SomeClass≻", className.c_str());
|
72
143
|
|
73
144
|
typeName = detail::typeName(typeid(Outer::Inner::Map1));
|
74
|
-
className = detail::
|
75
|
-
ASSERT_EQUAL(
|
145
|
+
className = detail::rubyClassName(typeName);
|
146
|
+
ASSERT_EQUAL("Map≺string‚ vector≺complex≺float≻≻≻", className.c_str());
|
76
147
|
|
77
148
|
typeName = detail::typeName(typeid(Outer::Inner::UnorderedMap1));
|
78
|
-
className = detail::
|
79
|
-
ASSERT_EQUAL(
|
149
|
+
className = detail::rubyClassName(typeName);
|
150
|
+
ASSERT_EQUAL("UnorderedMap≺string‚ complex≺float≻≻", className.c_str());
|
80
151
|
}
|
81
152
|
|
82
153
|
TESTCASE(MakeRubyClass)
|
83
154
|
{
|
84
155
|
std::string typeName = detail::typeName(typeid(Outer::Inner::Vec1));
|
85
|
-
std::string rubyClassName = detail::
|
156
|
+
std::string rubyClassName = detail::rubyClassName(typeName);
|
86
157
|
|
87
158
|
Module module = define_module("Testing");
|
88
159
|
|
@@ -96,5 +167,5 @@ TESTCASE(MakeRubyClass)
|
|
96
167
|
|
97
168
|
// FIXME - fails compilation on GCC
|
98
169
|
// Symbol element = result[0];
|
99
|
-
// ASSERT_EQUAL(
|
170
|
+
// ASSERT_EQUAL("Vector≺complex≺float≻≻", element.c_str());
|
100
171
|
}
|
@@ -16,8 +16,8 @@ TEARDOWN(GlobalFunctions)
|
|
16
16
|
rb_gc_start();
|
17
17
|
}
|
18
18
|
|
19
|
-
namespace
|
20
|
-
|
19
|
+
namespace
|
20
|
+
{
|
21
21
|
bool no_args()
|
22
22
|
{
|
23
23
|
return true;
|
@@ -136,8 +136,8 @@ TESTCASE(default_arguments_for_define_global_function)
|
|
136
136
|
|
137
137
|
TESTCASE(default_arguments_kw)
|
138
138
|
{
|
139
|
-
define_global_function("defaults_method_one_kw", &defaults_method_one,
|
140
|
-
Arg("arg1"), Arg("arg2"), Arg("arg3") = true);
|
139
|
+
define_global_function("defaults_method_one_kw", &defaults_method_one,
|
140
|
+
Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true);
|
141
141
|
Module m = Module(rb_mKernel);
|
142
142
|
|
143
143
|
std::string code = R"(defaults_method_one_kw(4, arg2: 5))";
|
@@ -151,6 +151,19 @@ TESTCASE(default_arguments_kw)
|
|
151
151
|
ASSERT_EQUAL(9, defaults_method_one_arg1);
|
152
152
|
ASSERT_EQUAL(11, defaults_method_one_arg2);
|
153
153
|
ASSERT(!defaults_method_one_arg3);
|
154
|
+
|
155
|
+
code = R"(defaults_method_one_kw(4, arg3: false))";
|
156
|
+
m.instance_eval(code);
|
157
|
+
ASSERT_EQUAL(4, defaults_method_one_arg1);
|
158
|
+
ASSERT_EQUAL(3, defaults_method_one_arg2);
|
159
|
+
ASSERT_EQUAL(false, defaults_method_one_arg3);
|
160
|
+
|
161
|
+
code = R"(defaults_method_one_kw(arg2: 5))";
|
162
|
+
ASSERT_EXCEPTION_CHECK(
|
163
|
+
Exception,
|
164
|
+
m.instance_eval(code),
|
165
|
+
ASSERT_EQUAL("Missing argument. Name: arg1. Index: 0.", ex.what())
|
166
|
+
);
|
154
167
|
}
|
155
168
|
|
156
169
|
TESTCASE(default_arguments_and_returning)
|