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,542 @@
1
+ #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
3
+ #include <rice/rice.hpp>
4
+ #include <rice/stl.hpp>
5
+
6
+ #include <limits>
7
+ #include <cmath>
8
+
9
+ using namespace Rice;
10
+
11
+ TESTSUITE(FromRuby);
12
+
13
+ SETUP(FromRuby)
14
+ {
15
+ embed_ruby();
16
+ }
17
+
18
+ TEARDOWN(FromRuby)
19
+ {
20
+ rb_gc_start();
21
+ }
22
+
23
+ namespace
24
+ {
25
+ template<typename T>
26
+ std::string toString(T* buffer, int size)
27
+ {
28
+ std::ostringstream result;
29
+ result << "[";
30
+
31
+ for (int i = 0; i < size; i++)
32
+ {
33
+ T item = buffer[i];
34
+ result << item;
35
+ if (i < size - 1)
36
+ {
37
+ result << ", ";
38
+ }
39
+ }
40
+ result << "]";
41
+ return result.str();
42
+ }
43
+
44
+ template<typename T>
45
+ std::string voidToString(void* buffer, int size)
46
+ {
47
+ return toString<T>((T*)buffer, size/sizeof(T));
48
+ }
49
+ }
50
+
51
+ TESTCASE(bool)
52
+ {
53
+ ASSERT_EQUAL(detail::Convertible::Exact, detail::From_Ruby<bool>().is_convertible(Qfalse));
54
+ ASSERT_EQUAL(detail::Convertible::Exact, detail::From_Ruby<bool>().is_convertible(Qtrue));
55
+ ASSERT_EQUAL(detail::Convertible::Cast, detail::From_Ruby<bool>().is_convertible(Qnil));
56
+ ASSERT_EQUAL(detail::Convertible::None, detail::From_Ruby<bool>().is_convertible(INT2NUM(3)));
57
+ ASSERT_EQUAL(detail::Convertible::None, detail::From_Ruby<bool>().is_convertible(rb_float_new(3.33)));
58
+ ASSERT_EQUAL(detail::Convertible::None, detail::From_Ruby<bool>().is_convertible(rb_str_new2("some string")));
59
+
60
+ ASSERT_EQUAL(false, detail::From_Ruby<bool>().convert(Qfalse));
61
+ ASSERT_EQUAL(false, detail::From_Ruby<bool>().convert(Qnil));
62
+ ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(Qtrue));
63
+ ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(INT2NUM(3)));
64
+ ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(INT2NUM(0)));
65
+ ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_float_new(3.33)));
66
+ ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_float_new(0.0)));
67
+ ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_str_new2("some string")));
68
+ ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_str_new2("true")));
69
+ ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_str_new2("false")));
70
+ }
71
+
72
+ TESTCASE(char)
73
+ {
74
+ unsigned char expected = 10;
75
+ ASSERT_EQUAL(expected, detail::From_Ruby<signed char>().convert(INT2NUM(10)));
76
+ }
77
+
78
+ TESTCASE(char_single_character_string)
79
+ {
80
+ ASSERT_EQUAL('x', detail::From_Ruby<char>().convert(rb_str_new2("x")));
81
+ }
82
+
83
+ TESTCASE(char_longer_string)
84
+ {
85
+ ASSERT_EQUAL('x', detail::From_Ruby<char>().convert(rb_str_new2("xy")));
86
+ }
87
+
88
+ TESTCASE(char_float)
89
+ {
90
+ // '/' is 47
91
+ ASSERT_EQUAL('/', detail::From_Ruby<char>().convert(rb_float_new(47.2)));
92
+ }
93
+
94
+ TESTCASE(char_fixnum)
95
+ {
96
+ // '1' is 49
97
+ ASSERT_EQUAL('1', detail::From_Ruby<char>().convert(INT2NUM(49)));
98
+ }
99
+
100
+ TESTCASE(char_pointer)
101
+ {
102
+ Module m = define_module("Testing");
103
+ detail::From_Ruby<char*> fromRuby;
104
+
105
+ char* expected = nullptr;
106
+ char* result = fromRuby.convert(Qnil);
107
+ ASSERT_EQUAL(expected, result);
108
+
109
+ const char* expected2 = "my string";
110
+ result = fromRuby.convert(rb_str_new2(expected2));
111
+ ASSERT_EQUAL(*expected2, *result);
112
+
113
+ std::string code = R"(arr = [0, 127, 128, 255, 256, -128, -129, -255])";
114
+ Array array = m.instance_eval(code);
115
+ result = fromRuby.convert(array.value());
116
+
117
+ ASSERT_EQUAL(result[0], 0);
118
+ ASSERT_EQUAL(result[1], 127);
119
+ ASSERT_EQUAL(result[2], -128);
120
+ ASSERT_EQUAL(result[3], -1);
121
+ ASSERT_EQUAL(result[4], 0);
122
+ ASSERT_EQUAL(result[5], -128);
123
+ ASSERT_EQUAL(result[6], 127);
124
+ ASSERT_EQUAL(result[7], 1);
125
+
126
+ std::string format = CHAR_MIN < 0 ? "c*" : "C*";
127
+ String packed = array.call("pack", format);
128
+ result = fromRuby.convert(packed.value());
129
+
130
+ ASSERT_EQUAL(result[0], 0);
131
+ ASSERT_EQUAL(result[1], 127);
132
+ ASSERT_EQUAL(result[2], -128);
133
+ ASSERT_EQUAL(result[3], -1);
134
+ ASSERT_EQUAL(result[4], 0);
135
+ ASSERT_EQUAL(result[5], -128);
136
+ ASSERT_EQUAL(result[6], 127);
137
+ ASSERT_EQUAL(result[7], 1);
138
+
139
+ ASSERT_EXCEPTION_CHECK(
140
+ Exception,
141
+ fromRuby.convert(rb_float_new(11.11)),
142
+ ASSERT_EQUAL("wrong argument type Float (expected char*)", ex.what())
143
+ );
144
+ }
145
+
146
+ TESTCASE(signed_char_pointer)
147
+ {
148
+ Module m = define_module("Testing");
149
+ detail::From_Ruby<signed char*> fromRuby;
150
+
151
+ signed char* expected = nullptr;
152
+ signed char* result = fromRuby.convert(Qnil);
153
+ ASSERT_EQUAL(expected, result);
154
+
155
+ expected = (signed char*)"my string";
156
+ result = fromRuby.convert(rb_str_new2("my string"));
157
+ ASSERT_EQUAL(*expected, *result);
158
+
159
+ std::string code = R"(arr = [0, 127, 128, 255, 256, -128, -129, -255])";
160
+ Array array = m.instance_eval(code);
161
+ result = fromRuby.convert(array.value());
162
+
163
+ ASSERT_EQUAL(result[0], 0);
164
+ ASSERT_EQUAL(result[1], 127);
165
+ ASSERT_EQUAL(result[2], -128);
166
+ ASSERT_EQUAL(result[3], -1);
167
+ ASSERT_EQUAL(result[4], 0);
168
+ ASSERT_EQUAL(result[5], -128);
169
+ ASSERT_EQUAL(result[6], 127);
170
+ ASSERT_EQUAL(result[7], 1);
171
+
172
+ std::string format = CHAR_MIN < 0 ? "c*" : "C*";
173
+ String packed = array.call("pack", format);
174
+ result = fromRuby.convert(packed.value());
175
+
176
+ ASSERT_EQUAL(result[0], 0);
177
+ ASSERT_EQUAL(result[1], 127);
178
+ ASSERT_EQUAL(result[2], -128);
179
+ ASSERT_EQUAL(result[3], -1);
180
+ ASSERT_EQUAL(result[4], 0);
181
+ ASSERT_EQUAL(result[5], -128);
182
+ ASSERT_EQUAL(result[6], 127);
183
+ ASSERT_EQUAL(result[7], 1);
184
+
185
+ ASSERT_EXCEPTION_CHECK(
186
+ Exception,
187
+ fromRuby.convert(rb_float_new(11.11)),
188
+ ASSERT_EQUAL("wrong argument type Float (expected signed char*)", ex.what())
189
+ );
190
+ }
191
+
192
+ TESTCASE(char_pointer_const)
193
+ {
194
+ char const* foo = "foo";
195
+ ASSERT_EQUAL(foo, detail::From_Ruby<char const*>().convert(rb_str_new2("foo")));
196
+ ASSERT_EQUAL("", detail::From_Ruby<char const*>().convert(rb_str_new2("")));
197
+
198
+ ASSERT_EXCEPTION_CHECK(
199
+ Exception,
200
+ detail::From_Ruby<char const*>().convert(rb_float_new(32.3)),
201
+ ASSERT_EQUAL("wrong argument type Float (expected char*)", ex.what())
202
+ );
203
+ }
204
+
205
+ TESTCASE(unsigned_char)
206
+ {
207
+ unsigned char expected = -1;
208
+ ASSERT_EQUAL(expected, detail::From_Ruby<unsigned char>().convert(INT2NUM(-1)));
209
+
210
+ expected = 1;
211
+ ASSERT_EQUAL(expected, detail::From_Ruby<unsigned char>().convert(rb_float_new(1.3)));
212
+ }
213
+
214
+ TESTCASE(unsigned_char_pointer)
215
+ {
216
+ Module m = define_module("Testing");
217
+
218
+ detail::From_Ruby<unsigned char*> fromRuby;
219
+
220
+ unsigned char* expected = nullptr;
221
+ unsigned char* result = fromRuby.convert(Qnil);
222
+ ASSERT_EQUAL(expected, result);
223
+
224
+ std::string code = R"(arr = [0, 127, 128, 255, 256, -128, -129, -255])";
225
+ Array array = m.instance_eval(code);
226
+ result = fromRuby.convert(array.value());
227
+
228
+ ASSERT_EQUAL(result[0], 0x0);
229
+ ASSERT_EQUAL(result[1], 0x7F);
230
+ ASSERT_EQUAL(result[2], 0x80);
231
+ ASSERT_EQUAL(result[3], 0xFF);
232
+ ASSERT_EQUAL(result[4], 0x00);
233
+ ASSERT_EQUAL(result[5], 0x80);
234
+ ASSERT_EQUAL(result[6], 0x7F);
235
+ ASSERT_EQUAL(result[7], 0x01);
236
+
237
+ String packed = array.call("pack", "C*");
238
+ result = fromRuby.convert(packed.value());
239
+
240
+ ASSERT_EQUAL(result[0], 0x0);
241
+ ASSERT_EQUAL(result[1], 0x7F);
242
+ ASSERT_EQUAL(result[2], 0x80);
243
+ ASSERT_EQUAL(result[3], 0xFF);
244
+ ASSERT_EQUAL(result[4], 0x00);
245
+ ASSERT_EQUAL(result[5], 0x80);
246
+ ASSERT_EQUAL(result[6], 0x7F);
247
+ ASSERT_EQUAL(result[7], 0x01);
248
+
249
+ ASSERT_EXCEPTION_CHECK(
250
+ Exception,
251
+ detail::From_Ruby<const char*>().convert(rb_float_new(11.11)),
252
+ ASSERT_EQUAL("wrong argument type Float (expected char*)", ex.what())
253
+ );
254
+ }
255
+
256
+ TESTCASE(unsigned_char_pointer_array)
257
+ {
258
+ Module m = define_module("Testing");
259
+
260
+ m.define_singleton_function("unsigned_char_pointer", &toString<unsigned char>);
261
+
262
+ std::string code = R"(arr = ["A", "B"]
263
+ unsigned_char_pointer(arr, arr.size))";
264
+
265
+ ASSERT_EXCEPTION_CHECK(
266
+ Exception,
267
+ Object result = m.module_eval(code),
268
+ ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
269
+ );
270
+
271
+ code = R"(arr = ["A", "B"].map do |char|
272
+ char.ord
273
+ end
274
+ unsigned_char_pointer(arr, arr.size))";
275
+
276
+ Object result = m.module_eval(code);
277
+ ASSERT_EQUAL("[A, B]", detail::From_Ruby<std::string>().convert(result.value()));
278
+
279
+ code = R"(arr = [65, 66]
280
+ unsigned_char_pointer(arr, arr.size))";
281
+ result = m.module_eval(code);
282
+ ASSERT_EQUAL("[A, B]", detail::From_Ruby<std::string>().convert(result.value()));
283
+
284
+ code = R"(arr = [true]
285
+ unsigned_char_pointer(arr, arr.size))";
286
+
287
+ ASSERT_EXCEPTION_CHECK(
288
+ Exception,
289
+ m.module_eval(code),
290
+ ASSERT_EQUAL("no implicit conversion of true into Integer", ex.what())
291
+ );
292
+ }
293
+
294
+ TESTCASE(double)
295
+ {
296
+ ASSERT_EQUAL(0.0, detail::From_Ruby<double>().convert(rb_float_new(0.0)));
297
+ ASSERT_EQUAL(-1.0, detail::From_Ruby<double>().convert(rb_float_new(-1.0)));
298
+ ASSERT_EQUAL(1.0, detail::From_Ruby<double>().convert(rb_float_new(1.0)));
299
+ ASSERT_EQUAL(std::numeric_limits<double>::min(),
300
+ detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::min())));
301
+ ASSERT_EQUAL(std::numeric_limits<double>::max(),
302
+ detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::max())));
303
+ ASSERT(std::isnan(detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::quiet_NaN()))));
304
+ ASSERT(std::isnan(detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::signaling_NaN()))));
305
+ ASSERT_EQUAL(std::numeric_limits<double>::epsilon(),
306
+ detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::epsilon())));
307
+
308
+ ASSERT_EXCEPTION_CHECK(
309
+ Exception,
310
+ detail::From_Ruby<double>().convert(rb_str_new2("bad value")),
311
+ ASSERT_EQUAL("no implicit conversion to float from string", ex.what())
312
+ );
313
+ }
314
+
315
+ TESTCASE(double_pointer_array)
316
+ {
317
+ Module m = define_module("Testing");
318
+ m.define_singleton_function("double_pointer", &toString<double>);
319
+
320
+ std::string code = R"(arr = [1.1, 2.2, 3.3, 4.4]
321
+ double_pointer(arr, arr.size))";
322
+
323
+ Object result = m.module_eval(code);
324
+
325
+ ASSERT_EQUAL("[1.1, 2.2, 3.3, 4.4]", detail::From_Ruby<std::string>().convert(result.value()));
326
+ }
327
+
328
+ TESTCASE(float)
329
+ {
330
+ ASSERT_EQUAL(0.0f, detail::From_Ruby<float>().convert(rb_float_new(0.0f)));
331
+ ASSERT_EQUAL(-1.0f, detail::From_Ruby<float>().convert(rb_float_new(-1.0f)));
332
+ ASSERT_EQUAL(1.0f, detail::From_Ruby<float>().convert(rb_float_new(1.0f)));
333
+ ASSERT_EQUAL(std::numeric_limits<float>::min(),
334
+ detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::min())));
335
+ ASSERT_EQUAL(std::numeric_limits<float>::max(),
336
+ detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::max())));
337
+ ASSERT(std::isnan(detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::quiet_NaN()))));
338
+ ASSERT(std::isnan(detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::signaling_NaN()))));
339
+ ASSERT_EQUAL(std::numeric_limits<float>::epsilon(),
340
+ detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::epsilon())));
341
+
342
+ ASSERT_EXCEPTION_CHECK(
343
+ Exception,
344
+ detail::From_Ruby<float>().convert(rb_str_new2("bad value")),
345
+ ASSERT_EQUAL("no implicit conversion to float from string", ex.what())
346
+ );
347
+ }
348
+
349
+ TESTCASE(float_pointer_array)
350
+ {
351
+ Module m = define_module("Testing");
352
+
353
+ m.define_singleton_function("float_pointer", &toString<float>);
354
+
355
+ std::string code = R"(arr = [4.3, 3.2, 2.1, 1.1]
356
+ float_pointer(arr, arr.size))";
357
+ Object result = m.module_eval(code);
358
+ ASSERT_EQUAL("[4.3, 3.2, 2.1, 1.1]", detail::From_Ruby<std::string>().convert(result.value()));
359
+
360
+ code = R"(arr = [4, 3, 2.8, 1]
361
+ float_pointer(arr, arr.size))";
362
+ result = m.module_eval(code);
363
+ ASSERT_EQUAL("[4, 3, 2.8, 1]", detail::From_Ruby<std::string>().convert(result.value()));
364
+
365
+ code = R"(arr = [4, "bad", 2, 1]
366
+ float_pointer(arr, arr.size))";
367
+
368
+ ASSERT_EXCEPTION_CHECK(
369
+ Exception,
370
+ m.module_eval(code),
371
+ ASSERT_EQUAL("can't convert String into Float", ex.what())
372
+ );
373
+ }
374
+
375
+ TESTCASE(int)
376
+ {
377
+ ASSERT_EQUAL(0, detail::From_Ruby<int>().convert(INT2NUM(0)));
378
+ ASSERT_EQUAL(-1, detail::From_Ruby<int>().convert(INT2NUM(-1)));
379
+ ASSERT_EQUAL(1, detail::From_Ruby<int>().convert(INT2NUM(1)));
380
+ ASSERT_EQUAL(std::numeric_limits<int>::min(),
381
+ detail::From_Ruby<int>().convert(INT2NUM(std::numeric_limits<int>::min())));
382
+ ASSERT_EQUAL(std::numeric_limits<int>::max(),
383
+ detail::From_Ruby<int>().convert(INT2NUM(std::numeric_limits<int>::max())));
384
+
385
+ ASSERT_EXCEPTION_CHECK(
386
+ Exception,
387
+ detail::From_Ruby<int>().convert(rb_str_new2("bad value")),
388
+ ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
389
+ );
390
+ }
391
+
392
+ TESTCASE(int_pointer_array)
393
+ {
394
+ Module m = define_module("Testing");
395
+ m.define_singleton_function("int_pointer", &toString<int>);
396
+
397
+ std::string code = R"(arr = [4, 3, 2, 1]
398
+ int_pointer(arr, arr.size))";
399
+ Object result = m.module_eval(code);
400
+ ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
401
+
402
+ code = R"(arr = [4.2, 3.8, 2.0, 1]
403
+ int_pointer(arr, arr.size))";
404
+ result = m.module_eval(code);
405
+ ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
406
+ }
407
+
408
+ TESTCASE(unsigned_int)
409
+ {
410
+ ASSERT_EQUAL(0u, detail::From_Ruby<unsigned int>().convert(UINT2NUM(0)));
411
+ ASSERT_EQUAL(1u, detail::From_Ruby<unsigned int>().convert(UINT2NUM(1)));
412
+ ASSERT_EQUAL(std::numeric_limits<unsigned int>::min(),
413
+ detail::From_Ruby<unsigned int>().convert(UINT2NUM(std::numeric_limits<unsigned int>::min())));
414
+ ASSERT_EQUAL(std::numeric_limits<unsigned int>::max(),
415
+ detail::From_Ruby<unsigned int>().convert(UINT2NUM(std::numeric_limits<unsigned int>::max())));
416
+
417
+ ASSERT_EXCEPTION_CHECK(
418
+ Exception,
419
+ detail::From_Ruby<unsigned int>().convert(rb_str_new2("bad value")),
420
+ ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
421
+ );
422
+ }
423
+
424
+ TESTCASE(long)
425
+ {
426
+ ASSERT_EQUAL(0, detail::From_Ruby<long>().convert(LONG2NUM(0)));
427
+ ASSERT_EQUAL(-1, detail::From_Ruby<long>().convert(LONG2NUM(-1)));
428
+ ASSERT_EQUAL(1, detail::From_Ruby<long>().convert(LONG2NUM(1)));
429
+ ASSERT_EQUAL(FIXNUM_MIN, detail::From_Ruby<long>().convert(LONG2NUM(FIXNUM_MIN)));
430
+ ASSERT_EQUAL(FIXNUM_MAX, detail::From_Ruby<long>().convert(LONG2NUM(FIXNUM_MAX)));
431
+ ASSERT_EQUAL(std::numeric_limits<long>::min(), detail::From_Ruby<long>().convert(LONG2NUM(std::numeric_limits<long>::min())));
432
+ ASSERT_EQUAL(std::numeric_limits<long>::max(), detail::From_Ruby<long>().convert(LONG2NUM(std::numeric_limits<long>::max())));
433
+
434
+ ASSERT_EXCEPTION_CHECK(
435
+ Exception,
436
+ detail::From_Ruby<long>().convert(rb_str_new2("bad value")),
437
+ ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
438
+ );
439
+ }
440
+
441
+ TESTCASE(unsigned_long)
442
+ {
443
+ ASSERT_EQUAL(0u, detail::From_Ruby<unsigned long>().convert(ULONG2NUM(0)));
444
+ ASSERT_EQUAL(1u, detail::From_Ruby<unsigned long>().convert(ULONG2NUM(1)));
445
+ ASSERT_EQUAL(static_cast<unsigned long>(FIXNUM_MIN),
446
+ detail::From_Ruby<unsigned long>().convert(ULONG2NUM(FIXNUM_MIN)));
447
+ ASSERT_EQUAL(std::numeric_limits<unsigned long>::min(),
448
+ detail::From_Ruby<unsigned long>().convert(ULONG2NUM(std::numeric_limits<unsigned long>::min())));
449
+ ASSERT_EQUAL(std::numeric_limits<unsigned long>::max(),
450
+ detail::From_Ruby<unsigned long>().convert(ULONG2NUM(std::numeric_limits<unsigned long>::max())));
451
+
452
+ ASSERT_EXCEPTION_CHECK(
453
+ Exception,
454
+ detail::From_Ruby<unsigned long>().convert(rb_str_new2("bad value")),
455
+ ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
456
+ );
457
+ }
458
+
459
+ TESTCASE(long_long)
460
+ {
461
+ ASSERT_EQUAL(0, detail::From_Ruby<long long>().convert(LL2NUM(0)));
462
+ ASSERT_EQUAL(-1, detail::From_Ruby<long long>().convert(LL2NUM(-1)));
463
+ ASSERT_EQUAL(1, detail::From_Ruby<long long>().convert(LL2NUM(1)));
464
+ ASSERT_EQUAL(std::numeric_limits<long long>::min(),
465
+ detail::From_Ruby<long long>().convert(LL2NUM(std::numeric_limits<long long>::min())));
466
+ ASSERT_EQUAL(std::numeric_limits<long long>::max(),
467
+ detail::From_Ruby<long long>().convert(LL2NUM(std::numeric_limits<long long>::max())));
468
+
469
+ ASSERT_EXCEPTION_CHECK(
470
+ Exception,
471
+ detail::From_Ruby<long long>().convert(rb_str_new2("bad value")),
472
+ ASSERT_EQUAL("no implicit conversion from string", ex.what())
473
+ );
474
+ }
475
+
476
+ TESTCASE(unsigned_long_long)
477
+ {
478
+ ASSERT_EQUAL(0u, detail::From_Ruby<unsigned long>().convert(ULL2NUM(0)));
479
+ ASSERT_EQUAL(1u, detail::From_Ruby<unsigned long>().convert(ULL2NUM(1)));
480
+ ASSERT_EQUAL(std::numeric_limits<unsigned long long>::min(),
481
+ detail::From_Ruby<unsigned long long>().convert(ULL2NUM(std::numeric_limits<unsigned long long>::min())));
482
+ ASSERT_EQUAL(std::numeric_limits<unsigned long long>::max(),
483
+ detail::From_Ruby<unsigned long long>().convert(ULL2NUM(std::numeric_limits<unsigned long long>::max())));
484
+
485
+ ASSERT_EXCEPTION_CHECK(
486
+ Exception,
487
+ detail::From_Ruby<unsigned long long>().convert(rb_str_new2("bad value")),
488
+ ASSERT(std::string(ex.what()).find("no implicit conversion") == 0)
489
+ );
490
+ }
491
+
492
+ TESTCASE(object)
493
+ {
494
+ Object o(rb_str_new2("foo"));
495
+ ASSERT_EQUAL(o, detail::From_Ruby<Object>().convert(o));
496
+ }
497
+
498
+ TESTCASE(short)
499
+ {
500
+ ASSERT_EQUAL(0, detail::From_Ruby<short>().convert(INT2NUM(0)));
501
+ ASSERT_EQUAL(-1, detail::From_Ruby<short>().convert(INT2NUM(-1)));
502
+ ASSERT_EQUAL(1, detail::From_Ruby<short>().convert(INT2NUM(1)));
503
+ ASSERT_EQUAL(std::numeric_limits<short>::min(),
504
+ detail::From_Ruby<short>().convert(INT2NUM(std::numeric_limits<short>::min())));
505
+ ASSERT_EQUAL(std::numeric_limits<short>::max(),
506
+ detail::From_Ruby<short>().convert(INT2NUM(std::numeric_limits<short>::max())));
507
+
508
+ ASSERT_EXCEPTION_CHECK(
509
+ Exception,
510
+ detail::From_Ruby<short>().convert(rb_str_new2("bad value")),
511
+ ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
512
+ );
513
+ }
514
+
515
+ TESTCASE(unsigned_short)
516
+ {
517
+ ASSERT_EQUAL(0u, detail::From_Ruby<unsigned short>().convert(UINT2NUM(0)));
518
+ ASSERT_EQUAL(1u, detail::From_Ruby<unsigned short>().convert(UINT2NUM(1)));
519
+ ASSERT_EQUAL(std::numeric_limits<unsigned short>::min(),
520
+ detail::From_Ruby<unsigned short>().convert(UINT2NUM(std::numeric_limits<unsigned short>::min())));
521
+ ASSERT_EQUAL(std::numeric_limits<unsigned short>::max(),
522
+ detail::From_Ruby<unsigned short>().convert(UINT2NUM(std::numeric_limits<unsigned short>::max())));
523
+
524
+ ASSERT_EXCEPTION_CHECK(
525
+ Exception,
526
+ detail::From_Ruby<unsigned short>().convert(rb_str_new2("bad value")),
527
+ ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
528
+ );
529
+ }
530
+
531
+ TESTCASE(void_pointer_array)
532
+ {
533
+ Module m = define_module("Testing");
534
+ m.define_singleton_function("void_pointer", &voidToString<int>);
535
+
536
+ std::string code = R"(arr = [4, 3, 2, 1]
537
+ buffer = arr.pack("i*")
538
+ void_pointer(buffer, buffer.size))";
539
+ Object result = m.module_eval(code);
540
+ ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
541
+ }
542
+
data/test/test_Hash.cpp CHANGED
@@ -15,6 +15,11 @@ SETUP(Hash)
15
15
  embed_ruby();
16
16
  }
17
17
 
18
+ TEARDOWN(Hash)
19
+ {
20
+ rb_gc_start();
21
+ }
22
+
18
23
  TESTCASE(default_construct)
19
24
  {
20
25
  Hash h;
@@ -11,6 +11,11 @@ SETUP(Identifier)
11
11
  embed_ruby();
12
12
  }
13
13
 
14
+ TEARDOWN(Identifier)
15
+ {
16
+ rb_gc_start();
17
+ }
18
+
14
19
  TESTCASE(construct_from_id)
15
20
  {
16
21
  ID id = rb_intern("foo");
@@ -80,6 +80,11 @@ SETUP(Inheritance)
80
80
  Data_Type<PushNotification>::unbind();
81
81
  }
82
82
 
83
+ TEARDOWN(Inheritance)
84
+ {
85
+ rb_gc_start();
86
+ }
87
+
83
88
  TESTCASE(return_base_pointer)
84
89
  {
85
90
  Class rcNotification = define_class<Notification>("Notification");
@@ -171,7 +176,7 @@ TESTCASE(module_base_pointer_method_call)
171
176
  Module m = define_module("Testing");
172
177
 
173
178
  Object message = m.module_eval(R"EOS(notification = Inheritance::EmailNotification.new
174
- notification.message)EOS");
179
+ notification.message)EOS");
175
180
  ASSERT_EQUAL("Email", detail::From_Ruby<std::string>().convert(message));
176
181
 
177
182
  message = m.module_eval(R"EOS(notification = Inheritance::PushNotification.new
@@ -11,6 +11,11 @@ SETUP(Iterator)
11
11
  embed_ruby();
12
12
  }
13
13
 
14
+ TEARDOWN(Iterator)
15
+ {
16
+ rb_gc_start();
17
+ }
18
+
14
19
  namespace
15
20
  {
16
21
  class Container
@@ -0,0 +1,22 @@
1
+ #include "unittest.hpp"
2
+ #include <rice/rice.hpp>
3
+
4
+ using namespace Rice;
5
+
6
+ TESTSUITE(Jump_Tag);
7
+
8
+ SETUP(Jump_Tag)
9
+ {
10
+ }
11
+
12
+ TEARDOWN(Jump_Tag)
13
+ {
14
+ rb_gc_start();
15
+ }
16
+
17
+ TESTCASE(construct)
18
+ {
19
+ JumpException exception(JumpException::RUBY_TAG_RETURN);
20
+ ASSERT_EQUAL(JumpException::RUBY_TAG_RETURN, exception.tag);
21
+ }
22
+
@@ -60,6 +60,11 @@ SETUP(Keep_Alive)
60
60
  embed_ruby();
61
61
  }
62
62
 
63
+ TEARDOWN(Keep_Alive)
64
+ {
65
+ rb_gc_start();
66
+ }
67
+
63
68
  TESTCASE(test_arg)
64
69
  {
65
70
  define_class<Listener>("Listener")
@@ -158,4 +163,4 @@ TESTCASE(test_return)
158
163
  rb_gc_start();
159
164
  String name = column.call("name");
160
165
  ASSERT_EQUAL("column_3", name.c_str());
161
- }
166
+ }
@@ -56,6 +56,11 @@ SETUP(Keep_Alive_No_Wrapper)
56
56
  embed_ruby();
57
57
  }
58
58
 
59
+ TEARDOWN(Keep_Alive_No_Wrapper)
60
+ {
61
+ rb_gc_start();
62
+ }
63
+
59
64
  TESTCASE(test_keep_alive_no_wrapper)
60
65
  {
61
66
  define_class<Animal>("Animal")
@@ -11,6 +11,11 @@ SETUP(Memory_Management)
11
11
  embed_ruby();
12
12
  }
13
13
 
14
+ TEARDOWN(Memory_Management)
15
+ {
16
+ rb_gc_start();
17
+ }
18
+
14
19
  namespace
15
20
  {
16
21
  class TestClass {