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
@@ -1,399 +0,0 @@
1
- #include "unittest.hpp"
2
- #include "embed_ruby.hpp"
3
- #include <rice/rice.hpp>
4
-
5
- #include <limits>
6
- #include <cmath>
7
-
8
- using namespace Rice;
9
-
10
- TESTSUITE(To_From_Ruby);
11
-
12
- SETUP(To_From_Ruby)
13
- {
14
- embed_ruby();
15
- }
16
-
17
- TESTCASE(object_to_ruby)
18
- {
19
- Object o(rb_str_new2("foo"));
20
- ASSERT_EQUAL(o.value(), detail::to_ruby(o));
21
- }
22
-
23
- TESTCASE(object_from_ruby)
24
- {
25
- Object o(rb_str_new2("foo"));
26
- ASSERT_EQUAL(o, detail::From_Ruby<Object>().convert(o));
27
- }
28
-
29
- TESTCASE(short_to_ruby)
30
- {
31
- ASSERT_EQUAL(INT2NUM(0), detail::to_ruby((short)0));
32
- ASSERT_EQUAL(INT2NUM(-1), detail::to_ruby((short)-1));
33
- ASSERT_EQUAL(INT2NUM(1), detail::to_ruby((short)1));
34
- ASSERT_EQUAL(INT2NUM(std::numeric_limits<short>::min()),
35
- detail::to_ruby(std::numeric_limits<short>::min()));
36
- ASSERT_EQUAL(INT2NUM(std::numeric_limits<short>::max()),
37
- detail::to_ruby(std::numeric_limits<short>::max()));
38
- }
39
-
40
- TESTCASE(short_from_ruby)
41
- {
42
- ASSERT_EQUAL(0, detail::From_Ruby<short>().convert(INT2NUM(0)));
43
- ASSERT_EQUAL(-1, detail::From_Ruby<short>().convert(INT2NUM(-1)));
44
- ASSERT_EQUAL(1, detail::From_Ruby<short>().convert(INT2NUM(1)));
45
- ASSERT_EQUAL(std::numeric_limits<short>::min(),
46
- detail::From_Ruby<short>().convert(INT2NUM(std::numeric_limits<short>::min())));
47
- ASSERT_EQUAL(std::numeric_limits<short>::max(),
48
- detail::From_Ruby<short>().convert(INT2NUM(std::numeric_limits<short>::max())));
49
-
50
- ASSERT_EXCEPTION_CHECK(
51
- Exception,
52
- detail::From_Ruby<short>().convert(rb_str_new2("bad value")),
53
- ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
54
- );
55
- }
56
-
57
- TESTCASE(int_to_ruby)
58
- {
59
- ASSERT(rb_equal(INT2NUM(0), detail::to_ruby((int)0)));
60
- ASSERT(rb_equal(INT2NUM(-1), detail::to_ruby((int)-1)));
61
- ASSERT(rb_equal(INT2NUM(1), detail::to_ruby((int)1)));
62
- ASSERT(rb_equal(INT2NUM(std::numeric_limits<int>::min()), detail::to_ruby(std::numeric_limits<int>::min())));
63
- ASSERT(rb_equal(INT2NUM(std::numeric_limits<int>::max()), detail::to_ruby(std::numeric_limits<int>::max())));
64
- }
65
-
66
- TESTCASE(int_from_ruby)
67
- {
68
- ASSERT_EQUAL(0, detail::From_Ruby<int>().convert(INT2NUM(0)));
69
- ASSERT_EQUAL(-1, detail::From_Ruby<int>().convert(INT2NUM(-1)));
70
- ASSERT_EQUAL(1, detail::From_Ruby<int>().convert(INT2NUM(1)));
71
- ASSERT_EQUAL(std::numeric_limits<int>::min(),
72
- detail::From_Ruby<int>().convert(INT2NUM(std::numeric_limits<int>::min())));
73
- ASSERT_EQUAL(std::numeric_limits<int>::max(),
74
- detail::From_Ruby<int>().convert(INT2NUM(std::numeric_limits<int>::max())));
75
-
76
- ASSERT_EXCEPTION_CHECK(
77
- Exception,
78
- detail::From_Ruby<int>().convert(rb_str_new2("bad value")),
79
- ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
80
- );
81
- }
82
-
83
- TESTCASE(long_to_ruby)
84
- {
85
- ASSERT(rb_equal(LONG2NUM(0), detail::to_ruby((long)0)));
86
- ASSERT(rb_equal(LONG2NUM(-1), detail::to_ruby((long)-1)));
87
- ASSERT(rb_equal(LONG2NUM(1), detail::to_ruby((long)1)));
88
- ASSERT(rb_equal(LONG2NUM(FIXNUM_MAX), detail::to_ruby(FIXNUM_MAX)));
89
- ASSERT(rb_equal(LONG2NUM(FIXNUM_MIN), detail::to_ruby(FIXNUM_MIN)));
90
- ASSERT(rb_equal(LONG2NUM(std::numeric_limits<long>::min()), detail::to_ruby(std::numeric_limits<long>::min())));
91
- ASSERT(rb_equal(LONG2NUM(std::numeric_limits<long>::max()), detail::to_ruby(std::numeric_limits<long>::max())));
92
- }
93
-
94
- TESTCASE(long_from_ruby)
95
- {
96
- ASSERT_EQUAL(0, detail::From_Ruby<long>().convert(LONG2NUM(0)));
97
- ASSERT_EQUAL(-1, detail::From_Ruby<long>().convert(LONG2NUM(-1)));
98
- ASSERT_EQUAL(1, detail::From_Ruby<long>().convert(LONG2NUM(1)));
99
- ASSERT_EQUAL(FIXNUM_MIN, detail::From_Ruby<long>().convert(LONG2NUM(FIXNUM_MIN)));
100
- ASSERT_EQUAL(FIXNUM_MAX, detail::From_Ruby<long>().convert(LONG2NUM(FIXNUM_MAX)));
101
- ASSERT_EQUAL(std::numeric_limits<long>::min(), detail::From_Ruby<long>().convert(LONG2NUM(std::numeric_limits<long>::min())));
102
- ASSERT_EQUAL(std::numeric_limits<long>::max(), detail::From_Ruby<long>().convert(LONG2NUM(std::numeric_limits<long>::max())));
103
-
104
- ASSERT_EXCEPTION_CHECK(
105
- Exception,
106
- detail::From_Ruby<long>().convert(rb_str_new2("bad value")),
107
- ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
108
- );
109
- }
110
-
111
- TESTCASE(long_long_to_ruby)
112
- {
113
- ASSERT(rb_equal(LL2NUM(0), detail::to_ruby((long long)0)));
114
- ASSERT(rb_equal(LL2NUM(-1), detail::to_ruby((long long)-1)));
115
- ASSERT(rb_equal(LL2NUM(1), detail::to_ruby((long long)1)));
116
- ASSERT(rb_equal(LL2NUM(std::numeric_limits<long long>::min()), detail::to_ruby(std::numeric_limits<long long>::min())));
117
- ASSERT(rb_equal(LL2NUM(std::numeric_limits<long long>::max()), detail::to_ruby(std::numeric_limits<long long>::max())));
118
- }
119
-
120
- TESTCASE(long_long_from_ruby)
121
- {
122
- ASSERT_EQUAL(0, detail::From_Ruby<long long>().convert(LL2NUM(0)));
123
- ASSERT_EQUAL(-1, detail::From_Ruby<long long>().convert(LL2NUM(-1)));
124
- ASSERT_EQUAL(1, detail::From_Ruby<long long>().convert(LL2NUM(1)));
125
- ASSERT_EQUAL(std::numeric_limits<long long>::min(),
126
- detail::From_Ruby<long long>().convert(LL2NUM(std::numeric_limits<long long>::min())));
127
- ASSERT_EQUAL(std::numeric_limits<long long>::max(),
128
- detail::From_Ruby<long long>().convert(LL2NUM(std::numeric_limits<long long>::max())));
129
-
130
- ASSERT_EXCEPTION_CHECK(
131
- Exception,
132
- detail::From_Ruby<long long>().convert(rb_str_new2("bad value")),
133
- ASSERT_EQUAL("no implicit conversion from string", ex.what())
134
- );
135
- }
136
-
137
- TESTCASE(unsigned_short_to_ruby)
138
- {
139
- ASSERT(rb_equal(UINT2NUM(0), detail::to_ruby((unsigned short)0)));
140
- ASSERT(rb_equal(UINT2NUM(1), detail::to_ruby((unsigned short)1)));
141
- ASSERT(rb_equal(UINT2NUM(std::numeric_limits<unsigned short>::min()), detail::to_ruby(std::numeric_limits<unsigned short>::min())));
142
- ASSERT(rb_equal(UINT2NUM(std::numeric_limits<unsigned short>::max()), detail::to_ruby(std::numeric_limits<unsigned short>::max())));
143
- }
144
-
145
- TESTCASE(unsigned_short_from_ruby)
146
- {
147
- ASSERT_EQUAL(0u, detail::From_Ruby<unsigned short>().convert(UINT2NUM(0)));
148
- ASSERT_EQUAL(1u, detail::From_Ruby<unsigned short>().convert(UINT2NUM(1)));
149
- ASSERT_EQUAL(std::numeric_limits<unsigned short>::min(),
150
- detail::From_Ruby<unsigned short>().convert(UINT2NUM(std::numeric_limits<unsigned short>::min())));
151
- ASSERT_EQUAL(std::numeric_limits<unsigned short>::max(),
152
- detail::From_Ruby<unsigned short>().convert(UINT2NUM(std::numeric_limits<unsigned short>::max())));
153
-
154
- ASSERT_EXCEPTION_CHECK(
155
- Exception,
156
- detail::From_Ruby<unsigned short>().convert(rb_str_new2("bad value")),
157
- ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
158
- );
159
- }
160
-
161
- TESTCASE(unsigned_int_to_ruby)
162
- {
163
- ASSERT(rb_equal(UINT2NUM(0), detail::to_ruby((unsigned int)0)));
164
- ASSERT(rb_equal(UINT2NUM(1), detail::to_ruby((unsigned int)1)));
165
- ASSERT(rb_equal(UINT2NUM(std::numeric_limits<unsigned int>::min()), detail::to_ruby(std::numeric_limits<unsigned int>::min())));
166
- ASSERT(rb_equal(UINT2NUM(std::numeric_limits<unsigned int>::max()), detail::to_ruby(std::numeric_limits<unsigned int>::max())));
167
- }
168
-
169
- TESTCASE(unsigned_int_from_ruby)
170
- {
171
- ASSERT_EQUAL(0u, detail::From_Ruby<unsigned int>().convert(UINT2NUM(0)));
172
- ASSERT_EQUAL(1u, detail::From_Ruby<unsigned int>().convert(UINT2NUM(1)));
173
- ASSERT_EQUAL(std::numeric_limits<unsigned int>::min(),
174
- detail::From_Ruby<unsigned int>().convert(UINT2NUM(std::numeric_limits<unsigned int>::min())));
175
- ASSERT_EQUAL(std::numeric_limits<unsigned int>::max(),
176
- detail::From_Ruby<unsigned int>().convert(UINT2NUM(std::numeric_limits<unsigned int>::max())));
177
-
178
- ASSERT_EXCEPTION_CHECK(
179
- Exception,
180
- detail::From_Ruby<unsigned int>().convert(rb_str_new2("bad value")),
181
- ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
182
- );
183
- }
184
-
185
- TESTCASE(unsigned_long_to_ruby)
186
- {
187
- ASSERT(rb_equal(ULONG2NUM(0), detail::to_ruby((unsigned long)0)));
188
- ASSERT(rb_equal(ULONG2NUM(1), detail::to_ruby((unsigned long)1)));
189
- ASSERT(rb_equal(ULONG2NUM(FIXNUM_MAX), detail::to_ruby(FIXNUM_MAX)));
190
- ASSERT(rb_equal(ULONG2NUM(std::numeric_limits<unsigned long>::min()), detail::to_ruby(std::numeric_limits<unsigned long>::min())));
191
- ASSERT(rb_equal(ULONG2NUM(std::numeric_limits<unsigned long>::max()), detail::to_ruby(std::numeric_limits<unsigned long>::max())));
192
- }
193
-
194
- TESTCASE(unsigned_long_from_ruby)
195
- {
196
- ASSERT_EQUAL(0u, detail::From_Ruby<unsigned long>().convert(ULONG2NUM(0)));
197
- ASSERT_EQUAL(1u, detail::From_Ruby<unsigned long>().convert(ULONG2NUM(1)));
198
- ASSERT_EQUAL(static_cast<unsigned long>(FIXNUM_MIN),
199
- detail::From_Ruby<unsigned long>().convert(ULONG2NUM(FIXNUM_MIN)));
200
- ASSERT_EQUAL(std::numeric_limits<unsigned long>::min(),
201
- detail::From_Ruby<unsigned long>().convert(ULONG2NUM(std::numeric_limits<unsigned long>::min())));
202
- ASSERT_EQUAL(std::numeric_limits<unsigned long>::max(),
203
- detail::From_Ruby<unsigned long>().convert(ULONG2NUM(std::numeric_limits<unsigned long>::max())));
204
-
205
- ASSERT_EXCEPTION_CHECK(
206
- Exception,
207
- detail::From_Ruby<unsigned long>().convert(rb_str_new2("bad value")),
208
- ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
209
- );
210
- }
211
-
212
- TESTCASE(unsigned_long_long_to_ruby)
213
- {
214
- ASSERT(rb_equal(ULL2NUM(0), detail::to_ruby((unsigned long long)0)));
215
- ASSERT(rb_equal(ULL2NUM(1), detail::to_ruby((unsigned long long)1)));
216
- ASSERT(rb_equal(ULL2NUM(std::numeric_limits<unsigned long long>::min()), detail::to_ruby(std::numeric_limits<unsigned long long>::min())));
217
- ASSERT(rb_equal(ULL2NUM(std::numeric_limits<unsigned long long>::max()), detail::to_ruby(std::numeric_limits<unsigned long long>::max())));
218
- }
219
-
220
- TESTCASE(unsigned_long_long_from_ruby)
221
- {
222
- ASSERT_EQUAL(0u, detail::From_Ruby<unsigned long>().convert(ULL2NUM(0)));
223
- ASSERT_EQUAL(1u, detail::From_Ruby<unsigned long>().convert(ULL2NUM(1)));
224
- ASSERT_EQUAL(std::numeric_limits<unsigned long long>::min(),
225
- detail::From_Ruby<unsigned long long>().convert(ULL2NUM(std::numeric_limits<unsigned long long>::min())));
226
- ASSERT_EQUAL(std::numeric_limits<unsigned long long>::max(),
227
- detail::From_Ruby<unsigned long long>().convert(ULL2NUM(std::numeric_limits<unsigned long long>::max())));
228
-
229
- ASSERT_EXCEPTION_CHECK(
230
- Exception,
231
- detail::From_Ruby<unsigned long long>().convert(rb_str_new2("bad value")),
232
- ASSERT(std::string(ex.what()).find("no implicit conversion") == 0)
233
- );
234
- }
235
-
236
- TESTCASE(bool_to_ruby)
237
- {
238
- ASSERT(rb_equal(Qfalse, detail::to_ruby(false)));
239
- ASSERT(rb_equal(Qtrue, detail::to_ruby(true)));
240
- }
241
-
242
- TESTCASE(bool_from_ruby)
243
- {
244
- ASSERT_EQUAL(false, detail::From_Ruby<bool>().convert(Qfalse));
245
- ASSERT_EQUAL(false, detail::From_Ruby<bool>().convert(Qnil));
246
- ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(Qtrue));
247
- ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_str_new2("some string")));
248
- ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(INT2NUM(3)));
249
- ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_float_new(3.33)));
250
- }
251
-
252
- TESTCASE(float_to_ruby)
253
- {
254
- ASSERT(rb_equal(rb_float_new(0.0f), detail::to_ruby(0.0f)));
255
- ASSERT(rb_equal(rb_float_new(-1.0f), detail::to_ruby(-1.0f)));
256
- ASSERT(rb_equal(rb_float_new(1.0f), detail::to_ruby(1.0f)));
257
- ASSERT(rb_equal(rb_float_new(0.5f), detail::to_ruby(0.5f)));
258
- ASSERT(rb_equal(rb_float_new(std::numeric_limits<float>::min()), detail::to_ruby(std::numeric_limits<float>::min())));
259
- ASSERT(rb_equal(rb_float_new(std::numeric_limits<float>::max()), detail::to_ruby(std::numeric_limits<float>::max())));
260
- ASSERT(Object(detail::to_ruby(std::numeric_limits<float>::quiet_NaN())).call("nan?"));
261
- ASSERT(Object(detail::to_ruby(std::numeric_limits<float>::signaling_NaN())).call("nan?"));
262
- ASSERT_EQUAL(rb_float_new(std::numeric_limits<float>::epsilon()),
263
- detail::to_ruby(std::numeric_limits<float>::epsilon()));
264
- }
265
-
266
- TESTCASE(float_from_ruby)
267
- {
268
- ASSERT_EQUAL(0.0f, detail::From_Ruby<float>().convert(rb_float_new(0.0f)));
269
- ASSERT_EQUAL(-1.0f, detail::From_Ruby<float>().convert(rb_float_new(-1.0f)));
270
- ASSERT_EQUAL(1.0f, detail::From_Ruby<float>().convert(rb_float_new(1.0f)));
271
- ASSERT_EQUAL(std::numeric_limits<float>::min(),
272
- detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::min())));
273
- ASSERT_EQUAL(std::numeric_limits<float>::max(),
274
- detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::max())));
275
- ASSERT(std::isnan(detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::quiet_NaN()))));
276
- ASSERT(std::isnan(detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::signaling_NaN()))));
277
- ASSERT_EQUAL(std::numeric_limits<float>::epsilon(),
278
- detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::epsilon())));
279
-
280
- ASSERT_EXCEPTION_CHECK(
281
- Exception,
282
- detail::From_Ruby<float>().convert(rb_str_new2("bad value")),
283
- ASSERT_EQUAL("no implicit conversion to float from string", ex.what())
284
- );
285
- }
286
-
287
- TESTCASE(double_to_ruby)
288
- {
289
- ASSERT(rb_equal(rb_float_new(0.0f), detail::to_ruby(0.0f)));
290
- ASSERT(rb_equal(rb_float_new(-1.0f), detail::to_ruby(-1.0f)));
291
- ASSERT(rb_equal(rb_float_new(1.0f), detail::to_ruby(1.0f)));
292
- ASSERT(rb_equal(rb_float_new(0.5f), detail::to_ruby(0.5f)));
293
- ASSERT(rb_equal(rb_float_new(std::numeric_limits<double>::min()), detail::to_ruby(std::numeric_limits<double>::min())));
294
- ASSERT(rb_equal(rb_float_new(std::numeric_limits<double>::max()), detail::to_ruby(std::numeric_limits<double>::max())));
295
- ASSERT(Object(detail::to_ruby(std::numeric_limits<double>::quiet_NaN())).call("nan?"));
296
- ASSERT(Object(detail::to_ruby(std::numeric_limits<double>::signaling_NaN())).call("nan?"));
297
- ASSERT(rb_equal(rb_float_new(std::numeric_limits<double>::epsilon()), detail::to_ruby(std::numeric_limits<double>::epsilon())));
298
- }
299
-
300
- TESTCASE(double_from_ruby)
301
- {
302
- ASSERT_EQUAL(0.0, detail::From_Ruby<double>().convert(rb_float_new(0.0)));
303
- ASSERT_EQUAL(-1.0, detail::From_Ruby<double>().convert(rb_float_new(-1.0)));
304
- ASSERT_EQUAL(1.0, detail::From_Ruby<double>().convert(rb_float_new(1.0)));
305
- ASSERT_EQUAL(std::numeric_limits<double>::min(),
306
- detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::min())));
307
- ASSERT_EQUAL(std::numeric_limits<double>::max(),
308
- detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::max())));
309
- ASSERT(std::isnan(detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::quiet_NaN()))));
310
- ASSERT(std::isnan(detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::signaling_NaN()))));
311
- ASSERT_EQUAL(std::numeric_limits<double>::epsilon(),
312
- detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::epsilon())));
313
-
314
- ASSERT_EXCEPTION_CHECK(
315
- Exception,
316
- detail::From_Ruby<double>().convert(rb_str_new2("bad value")),
317
- ASSERT_EQUAL("no implicit conversion to float from string", ex.what())
318
- );
319
- }
320
-
321
- TESTCASE(char_const_ptr_to_ruby)
322
- {
323
- ASSERT(rb_equal(String("").value(), detail::to_ruby((char const *)"")));
324
- ASSERT(rb_equal(String("foo").value(), detail::to_ruby((char const *)"foo")));
325
- ASSERT(rb_equal(String("foo").value(), detail::to_ruby("foo")));
326
- }
327
-
328
- TESTCASE(char_const_array_to_ruby_symbol)
329
- {
330
- ASSERT(rb_equal(Symbol("foo").value(), detail::to_ruby(":foo")));
331
- }
332
-
333
- TESTCASE(char_const_ptr_from_ruby)
334
- {
335
- char const* foo = "foo";
336
- ASSERT_EQUAL(foo, detail::From_Ruby<char const *>().convert(rb_str_new2("foo")));
337
- ASSERT_EQUAL("", detail::From_Ruby<char const*>().convert(rb_str_new2("")));
338
-
339
- ASSERT_EXCEPTION_CHECK(
340
- Exception,
341
- detail::From_Ruby<char const *>().convert(rb_float_new(32.3)),
342
- ASSERT_EQUAL("wrong argument type Float (expected String)", ex.what())
343
- );
344
- }
345
-
346
- TESTCASE(char_from_ruby_single_character_string)
347
- {
348
- ASSERT_EQUAL('x', detail::From_Ruby<char>().convert(rb_str_new2("x")));
349
- }
350
-
351
- TESTCASE(char_from_ruby_longer_string)
352
- {
353
- ASSERT_EXCEPTION_CHECK(
354
- std::invalid_argument,
355
- detail::From_Ruby<char>().convert(rb_str_new2("xy")),
356
- ASSERT_EQUAL("from_ruby<char>: string must have length 1", ex.what())
357
- );
358
-
359
- ASSERT_EXCEPTION_CHECK(
360
- Exception,
361
- detail::From_Ruby<char>().convert(rb_float_new(47.2)),
362
- ASSERT_EQUAL("wrong argument type Float (expected char type)", ex.what())
363
- );
364
- }
365
-
366
- TESTCASE(char_from_ruby_fixnum)
367
- {
368
- ASSERT_EQUAL('1', detail::From_Ruby<char>().convert(INT2NUM(49)));
369
- }
370
-
371
- TESTCASE(unsigned_char_from_ruby)
372
- {
373
- unsigned char expected = -1;
374
- ASSERT_EQUAL(expected, detail::From_Ruby<unsigned char>().convert(INT2NUM(-1)));
375
-
376
- ASSERT_EXCEPTION_CHECK(
377
- Exception,
378
- detail::From_Ruby<unsigned char>().convert(rb_float_new(1.3)),
379
- ASSERT_EQUAL("wrong argument type Float (expected char type)", ex.what())
380
- );
381
- }
382
-
383
- TESTCASE(signed_char_from_ruby)
384
- {
385
- unsigned char expected = 10;
386
- ASSERT_EQUAL(expected, detail::From_Ruby<signed char>().convert(INT2NUM(10)));
387
- }
388
-
389
- TESTCASE(char_star_from_ruby)
390
- {
391
- const char* expected = "my string";
392
- ASSERT_EQUAL(expected, detail::From_Ruby<const char*>().convert(rb_str_new2("my string")));
393
-
394
- ASSERT_EXCEPTION_CHECK(
395
- Exception,
396
- detail::From_Ruby<const char*>().convert(rb_float_new(11.11)),
397
- ASSERT_EQUAL("wrong argument type Float (expected String)", ex.what())
398
- );
399
- }