rice 4.3.3 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -26
  3. data/README.md +7 -2
  4. data/Rakefile +7 -1
  5. data/include/rice/rice.hpp +7291 -4430
  6. data/include/rice/stl.hpp +769 -222
  7. data/lib/mkmf-rice.rb +37 -95
  8. data/rice/Address_Registration_Guard.hpp +72 -3
  9. data/rice/Arg.hpp +19 -5
  10. data/rice/Arg.ipp +24 -0
  11. data/rice/Callback.hpp +21 -0
  12. data/rice/Callback.ipp +13 -0
  13. data/rice/Constructor.hpp +4 -27
  14. data/rice/Constructor.ipp +79 -0
  15. data/rice/Data_Object.hpp +74 -3
  16. data/rice/Data_Object.ipp +324 -32
  17. data/rice/Data_Type.hpp +215 -3
  18. data/rice/Data_Type.ipp +125 -64
  19. data/rice/Director.hpp +0 -2
  20. data/rice/Enum.hpp +4 -6
  21. data/rice/Enum.ipp +101 -57
  22. data/rice/Exception.hpp +62 -2
  23. data/rice/Exception.ipp +7 -12
  24. data/rice/JumpException.hpp +44 -0
  25. data/rice/JumpException.ipp +48 -0
  26. data/rice/MemoryView.hpp +11 -0
  27. data/rice/MemoryView.ipp +43 -0
  28. data/rice/Return.hpp +6 -26
  29. data/rice/Return.ipp +10 -16
  30. data/rice/detail/DefaultHandler.hpp +12 -0
  31. data/rice/detail/DefaultHandler.ipp +8 -0
  32. data/rice/detail/HandlerRegistry.hpp +5 -35
  33. data/rice/detail/HandlerRegistry.ipp +7 -11
  34. data/rice/detail/InstanceRegistry.hpp +1 -4
  35. data/rice/detail/MethodInfo.hpp +15 -5
  36. data/rice/detail/MethodInfo.ipp +78 -6
  37. data/rice/detail/Native.hpp +32 -0
  38. data/rice/detail/Native.ipp +129 -0
  39. data/rice/detail/NativeAttributeGet.hpp +51 -0
  40. data/rice/detail/NativeAttributeGet.ipp +51 -0
  41. data/rice/detail/NativeAttributeSet.hpp +43 -0
  42. data/rice/detail/NativeAttributeSet.ipp +82 -0
  43. data/rice/detail/NativeCallbackFFI.hpp +55 -0
  44. data/rice/detail/NativeCallbackFFI.ipp +151 -0
  45. data/rice/detail/NativeCallbackSimple.hpp +30 -0
  46. data/rice/detail/NativeCallbackSimple.ipp +29 -0
  47. data/rice/detail/NativeFunction.hpp +20 -21
  48. data/rice/detail/NativeFunction.ipp +199 -64
  49. data/rice/detail/NativeIterator.hpp +8 -11
  50. data/rice/detail/NativeIterator.ipp +27 -31
  51. data/rice/detail/NativeRegistry.hpp +24 -15
  52. data/rice/detail/NativeRegistry.ipp +23 -48
  53. data/rice/detail/Proc.hpp +4 -0
  54. data/rice/detail/Proc.ipp +85 -0
  55. data/rice/detail/Registries.hpp +0 -7
  56. data/rice/detail/Registries.ipp +0 -18
  57. data/rice/detail/RubyFunction.hpp +0 -3
  58. data/rice/detail/RubyFunction.ipp +4 -8
  59. data/rice/detail/RubyType.hpp +19 -0
  60. data/rice/detail/RubyType.ipp +187 -0
  61. data/rice/detail/TupleIterator.hpp +14 -0
  62. data/rice/detail/Type.hpp +5 -6
  63. data/rice/detail/Type.ipp +150 -33
  64. data/rice/detail/TypeRegistry.hpp +15 -7
  65. data/rice/detail/TypeRegistry.ipp +105 -12
  66. data/rice/detail/Wrapper.hpp +6 -5
  67. data/rice/detail/Wrapper.ipp +45 -23
  68. data/rice/detail/cpp_protect.hpp +5 -6
  69. data/rice/detail/default_allocation_func.ipp +0 -2
  70. data/rice/detail/from_ruby.hpp +37 -3
  71. data/rice/detail/from_ruby.ipp +911 -454
  72. data/rice/detail/ruby.hpp +18 -0
  73. data/rice/detail/to_ruby.hpp +41 -3
  74. data/rice/detail/to_ruby.ipp +437 -113
  75. data/rice/global_function.hpp +0 -4
  76. data/rice/global_function.ipp +1 -2
  77. data/rice/rice.hpp +105 -22
  78. data/rice/ruby_mark.hpp +4 -3
  79. data/rice/stl.hpp +4 -0
  80. data/test/embed_ruby.cpp +4 -1
  81. data/test/extconf.rb +2 -0
  82. data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
  83. data/test/test_Address_Registration_Guard.cpp +5 -0
  84. data/test/test_Array.cpp +12 -1
  85. data/test/test_Attribute.cpp +103 -21
  86. data/test/test_Builtin_Object.cpp +5 -0
  87. data/test/test_Callback.cpp +231 -0
  88. data/test/test_Class.cpp +5 -31
  89. data/test/test_Constructor.cpp +69 -6
  90. data/test/test_Data_Object.cpp +9 -4
  91. data/test/test_Data_Type.cpp +428 -64
  92. data/test/test_Director.cpp +10 -5
  93. data/test/test_Enum.cpp +152 -40
  94. data/test/test_Exception.cpp +235 -0
  95. data/test/test_File.cpp +70 -0
  96. data/test/test_From_Ruby.cpp +542 -0
  97. data/test/test_Hash.cpp +5 -0
  98. data/test/test_Identifier.cpp +5 -0
  99. data/test/test_Inheritance.cpp +6 -1
  100. data/test/test_Iterator.cpp +5 -0
  101. data/test/test_JumpException.cpp +22 -0
  102. data/test/test_Keep_Alive.cpp +6 -1
  103. data/test/test_Keep_Alive_No_Wrapper.cpp +5 -0
  104. data/test/test_Memory_Management.cpp +5 -0
  105. data/test/test_Module.cpp +118 -64
  106. data/test/test_Native_Registry.cpp +2 -33
  107. data/test/test_Object.cpp +5 -0
  108. data/test/test_Overloads.cpp +631 -0
  109. data/test/test_Ownership.cpp +67 -4
  110. data/test/test_Proc.cpp +45 -0
  111. data/test/test_Self.cpp +5 -0
  112. data/test/test_Stl_Exception.cpp +109 -0
  113. data/test/test_Stl_Map.cpp +22 -8
  114. data/test/test_Stl_Optional.cpp +5 -0
  115. data/test/test_Stl_Pair.cpp +7 -2
  116. data/test/test_Stl_Reference_Wrapper.cpp +5 -0
  117. data/test/test_Stl_SmartPointer.cpp +210 -5
  118. data/test/test_Stl_String.cpp +5 -0
  119. data/test/test_Stl_String_View.cpp +5 -0
  120. data/test/test_Stl_Type.cpp +147 -0
  121. data/test/test_Stl_Unordered_Map.cpp +18 -7
  122. data/test/test_Stl_Variant.cpp +5 -0
  123. data/test/test_Stl_Vector.cpp +130 -8
  124. data/test/test_String.cpp +5 -0
  125. data/test/test_Struct.cpp +5 -0
  126. data/test/test_Symbol.cpp +5 -0
  127. data/test/test_Template.cpp +192 -0
  128. data/test/test_To_Ruby.cpp +152 -0
  129. data/test/test_Tracking.cpp +1 -0
  130. data/test/test_Type.cpp +100 -0
  131. data/test/test_global_functions.cpp +53 -6
  132. data/test/unittest.cpp +8 -0
  133. metadata +37 -20
  134. data/lib/version.rb +0 -3
  135. data/rice/Address_Registration_Guard_defn.hpp +0 -79
  136. data/rice/Data_Object_defn.hpp +0 -84
  137. data/rice/Data_Type_defn.hpp +0 -190
  138. data/rice/Exception_defn.hpp +0 -68
  139. data/rice/HandlerRegistration.hpp +0 -15
  140. data/rice/Identifier.hpp +0 -50
  141. data/rice/Identifier.ipp +0 -29
  142. data/rice/detail/ExceptionHandler.hpp +0 -8
  143. data/rice/detail/ExceptionHandler.ipp +0 -28
  144. data/rice/detail/ExceptionHandler_defn.hpp +0 -77
  145. data/rice/detail/Jump_Tag.hpp +0 -21
  146. data/rice/detail/NativeAttribute.hpp +0 -64
  147. data/rice/detail/NativeAttribute.ipp +0 -112
  148. data/rice/detail/from_ruby_defn.hpp +0 -38
  149. data/rice/detail/to_ruby_defn.hpp +0 -48
  150. data/test/test_Jump_Tag.cpp +0 -17
  151. data/test/test_To_From_Ruby.cpp +0 -399
@@ -0,0 +1,631 @@
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
+ ASSERT_EXCEPTION_CHECK(
323
+ Exception,
324
+ Rice::String result = m.module_eval(code),
325
+ ASSERT_EQUAL("Could not resolve method call for MyClass#run\n 6 overload(s) were evaluated based on the types of Ruby parameters provided.",
326
+ ex.what()));
327
+ }
328
+
329
+ namespace
330
+ {
331
+ class MyClass2
332
+ {
333
+ public:
334
+ MyClass2()
335
+ {
336
+ this->constructor = "constructor<void>";
337
+ }
338
+
339
+ MyClass2(int a)
340
+ {
341
+ this->constructor = "constructor<int>";
342
+ }
343
+
344
+ MyClass2(float a)
345
+ {
346
+ this->constructor = "constructor<float>";
347
+ }
348
+
349
+ MyClass2(std::string a)
350
+ {
351
+ this->constructor = "constructor<string>";
352
+ }
353
+
354
+ MyClass2(int a, float b)
355
+ {
356
+ this->constructor = "constructor<int,float>";
357
+ }
358
+
359
+ MyClass2(float a, int b)
360
+ {
361
+ this->constructor = "constructor<float,int>";
362
+ }
363
+
364
+ std::string constructor;
365
+ };
366
+ } // namespace
367
+
368
+ Class createMyClass2()
369
+ {
370
+ Class c = define_class<MyClass2>("MyClass")
371
+ .define_constructor(Constructor<MyClass2>())
372
+ .define_constructor(Constructor<MyClass2, int>())
373
+ .define_constructor(Constructor<MyClass2, float>())
374
+ .define_constructor(Constructor<MyClass2, std::string>())
375
+ .define_constructor(Constructor<MyClass2, int, float>())
376
+ .define_constructor(Constructor<MyClass2, float, int>())
377
+ .define_attr("constructor", &MyClass2::constructor);
378
+
379
+ return c;
380
+ }
381
+
382
+ TESTCASE(constructor_zero_parameters)
383
+ {
384
+ Module m = define_module("Testing");
385
+ Class c = createMyClass2();
386
+
387
+ std::string code = R"(MyClass.new)";
388
+
389
+ Rice::Object result = m.module_eval(code);
390
+ Rice::String constructor = result.call("constructor");
391
+ ASSERT_EQUAL("constructor<void>", constructor.str());
392
+ }
393
+
394
+ TESTCASE(constructor_one_parameter)
395
+ {
396
+ Module m = define_module("Testing");
397
+ Class c = createMyClass2();
398
+
399
+ std::string code = R"(MyClass.new(1))";
400
+
401
+ Rice::Object result = m.module_eval(code);
402
+ Rice::String constructor = result.call("constructor");
403
+ ASSERT_EQUAL("constructor<int>", constructor.str());
404
+
405
+ code = R"(my_class = MyClass.new(1.0))";
406
+
407
+ result = m.module_eval(code);
408
+ constructor = result.call("constructor");
409
+ ASSERT_EQUAL("constructor<float>", constructor.str());
410
+
411
+ code = R"(my_class = MyClass.new('hello'))";
412
+
413
+ result = m.module_eval(code);
414
+ constructor = result.call("constructor");
415
+ ASSERT_EQUAL("constructor<string>", constructor.str());
416
+ }
417
+
418
+ TESTCASE(constructor_two_parameters)
419
+ {
420
+ Module m = define_module("Testing");
421
+ Class c = createMyClass2();
422
+
423
+ std::string code = R"(MyClass.new(1, 1.0))";
424
+
425
+ Rice::Object result = m.module_eval(code);
426
+ Rice::String constructor = result.call("constructor");
427
+ ASSERT_EQUAL("constructor<int,float>", constructor.str());
428
+
429
+ code = R"(my_class = MyClass.new(1.0, 1))";
430
+
431
+ result = m.module_eval(code);
432
+ constructor = result.call("constructor");
433
+ ASSERT_EQUAL("constructor<float,int>", constructor.str());
434
+ }
435
+
436
+ namespace
437
+ {
438
+ class MyClass3
439
+ {
440
+ public:
441
+ std::string run(char value)
442
+ {
443
+ return "run<char>";
444
+ }
445
+
446
+ std::string run(unsigned char value)
447
+ {
448
+ return "run<unsigned char>";
449
+ }
450
+
451
+ std::string run(char* value)
452
+ {
453
+ return "run<char*>";
454
+ }
455
+
456
+ std::string run(unsigned char* value)
457
+ {
458
+ return "run<unsigned char*>";
459
+ }
460
+
461
+ std::string run(short value)
462
+ {
463
+ return "run<short>";
464
+ }
465
+
466
+ std::string run(int value)
467
+ {
468
+ return "run<int>";
469
+ }
470
+
471
+ std::string run(float value)
472
+ {
473
+ return "run<float>";
474
+ }
475
+
476
+ std::string run(double value)
477
+ {
478
+ return "run<double>";
479
+ }
480
+
481
+ std::string run(long value)
482
+ {
483
+ return "run<long>";
484
+ }
485
+
486
+ std::string run(long long value)
487
+ {
488
+ return "run<long long>";
489
+ }
490
+ };
491
+ } // namespace
492
+
493
+
494
+ TESTCASE(int_conversion_1)
495
+ {
496
+ Class c = define_class<MyClass3>("MyClass3").
497
+ define_constructor(Constructor<MyClass3>()).
498
+ define_method<std::string(MyClass3::*)(char*)>("run", &MyClass3::run).
499
+ define_method<std::string(MyClass3::*)(unsigned char*)>("run", &MyClass3::run).
500
+ define_method<std::string(MyClass3::*)(short)>("run", &MyClass3::run).
501
+ define_method<std::string(MyClass3::*)(long)>("run", &MyClass3::run).
502
+ define_method<std::string(MyClass3::*)(long long)>("run", &MyClass3::run);
503
+
504
+ Module m = define_module("Testing");
505
+
506
+ std::string code = R"(my_class = MyClass3.new
507
+ value = 1
508
+ my_class.run(value))";
509
+ String result = m.module_eval(code);
510
+ ASSERT_EQUAL("run<long>", result.str());
511
+
512
+ code = R"(my_class = MyClass3.new
513
+ value = 2**60
514
+ my_class.run(value))";
515
+ result = m.module_eval(code);
516
+
517
+ #ifdef _WIN32
518
+ const char* expected = "run<long long>";
519
+ #else
520
+ const char* expected = "run<long>";
521
+ #endif
522
+
523
+ ASSERT_EQUAL(expected, result.str());
524
+ }
525
+
526
+ TESTCASE(int_conversion_2)
527
+ {
528
+ Class c = define_class<MyClass3>("MyClass3").
529
+ define_constructor(Constructor<MyClass3>()).
530
+ define_method<std::string(MyClass3::*)(short)>("run", &MyClass3::run).
531
+ define_method<std::string(MyClass3::*)(float)>("run", &MyClass3::run);
532
+
533
+ Module m = define_module("Testing");
534
+
535
+ std::string code = R"(my_class = MyClass3.new
536
+ value = 1
537
+ my_class.run(value))";
538
+ String result = m.module_eval(code);
539
+ ASSERT_EQUAL("run<float>", result.str());
540
+
541
+ code = R"(my_class = MyClass3.new
542
+ value = 2**64
543
+ my_class.run(value))";
544
+
545
+ ASSERT_EXCEPTION_CHECK(
546
+ Exception,
547
+ result = m.module_eval(code),
548
+ ASSERT_EQUAL("Could not resolve method call for MyClass3#run\n 2 overload(s) were evaluated based on the types of Ruby parameters provided.",
549
+ ex.what()));
550
+ }
551
+
552
+ TESTCASE(int_conversion_3)
553
+ {
554
+ Class c = define_class<MyClass3>("MyClass3").
555
+ define_constructor(Constructor<MyClass3>()).
556
+ define_method<std::string(MyClass3::*)(short)>("run", &MyClass3::run).
557
+ define_method<std::string(MyClass3::*)(double)>("run", &MyClass3::run);
558
+
559
+ Module m = define_module("Testing");
560
+
561
+ std::string code = R"(my_class = MyClass3.new
562
+ value = 1
563
+ my_class.run(value))";
564
+ String result = m.module_eval(code);
565
+ ASSERT_EQUAL("run<double>", result.str());
566
+
567
+ code = R"(my_class = MyClass3.new
568
+ value = 2**32
569
+ my_class.run(value))";
570
+
571
+ result = m.module_eval(code);
572
+ ASSERT_EQUAL("run<double>", result.str());
573
+ }
574
+
575
+ TESTCASE(int_conversion_4)
576
+ {
577
+ Class c = define_class<MyClass3>("MyClass3").
578
+ define_constructor(Constructor<MyClass3>()).
579
+ define_method<std::string(MyClass3::*)(short)>("run", &MyClass3::run);
580
+
581
+ Module m = define_module("Testing");
582
+
583
+ std::string code = R"(my_class = MyClass3.new
584
+ value = 1
585
+ my_class.run(value))";
586
+ String result = m.module_eval(code);
587
+ ASSERT_EQUAL("run<short>", result.str());
588
+
589
+ code = R"(my_class = MyClass3.new
590
+ value = 2**42
591
+ my_class.run(value))";
592
+
593
+ #ifdef _WIN32
594
+
595
+ #if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 4
596
+ const char* expected = "bignum too big to convert into 'long'";
597
+ #else
598
+ const char* expected = "bignum too big to convert into `long'";
599
+ #endif
600
+
601
+ #else
602
+
603
+ #if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 4
604
+ const char* expected = "integer 4398046511104 too big to convert to 'short'";
605
+ #else
606
+ const char* expected = "integer 4398046511104 too big to convert to `short'";
607
+ #endif
608
+
609
+ #endif
610
+
611
+ ASSERT_EXCEPTION_CHECK(
612
+ Exception,
613
+ result = m.module_eval(code),
614
+ ASSERT_EQUAL(expected, ex.what()));
615
+ }
616
+
617
+ TESTCASE(int_conversion_5)
618
+ {
619
+ Class c = define_class<MyClass3>("MyClass3").
620
+ define_constructor(Constructor<MyClass3>()).
621
+ define_method<std::string(MyClass3::*)(unsigned char)>("run", &MyClass3::run).
622
+ define_method<std::string(MyClass3::*)(unsigned char*)>("run", &MyClass3::run);
623
+
624
+ Module m = define_module("Testing");
625
+
626
+ std::string code = R"(my_class = MyClass3.new
627
+ value = "54"
628
+ my_class.run(value))";
629
+ String result = m.module_eval(code);
630
+ ASSERT_EQUAL("run<unsigned char*>", result.str());
631
+ }