rice2 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +23 -0
  3. data/Doxyfile +2268 -0
  4. data/Makefile.am +26 -0
  5. data/Makefile.in +929 -0
  6. data/README.md +1054 -0
  7. data/README.mingw +8 -0
  8. data/Rakefile +24 -0
  9. data/aclocal.m4 +1090 -0
  10. data/bootstrap +8 -0
  11. data/config.guess +1667 -0
  12. data/config.sub +1793 -0
  13. data/configure +8209 -0
  14. data/configure.ac +55 -0
  15. data/depcomp +791 -0
  16. data/doxygen.ac +314 -0
  17. data/doxygen.am +186 -0
  18. data/extconf.rb +66 -0
  19. data/install-sh +529 -0
  20. data/missing +215 -0
  21. data/post-autoconf.rb +22 -0
  22. data/post-automake.rb +28 -0
  23. data/rice/Address_Registration_Guard.cpp +22 -0
  24. data/rice/Address_Registration_Guard.hpp +7 -0
  25. data/rice/Address_Registration_Guard.ipp +37 -0
  26. data/rice/Address_Registration_Guard_defn.hpp +75 -0
  27. data/rice/Arg.hpp +8 -0
  28. data/rice/Arg_impl.hpp +129 -0
  29. data/rice/Arg_operators.cpp +21 -0
  30. data/rice/Arg_operators.hpp +19 -0
  31. data/rice/Array.hpp +214 -0
  32. data/rice/Array.ipp +256 -0
  33. data/rice/Builtin_Object.hpp +8 -0
  34. data/rice/Builtin_Object.ipp +50 -0
  35. data/rice/Builtin_Object_defn.hpp +50 -0
  36. data/rice/Class.cpp +57 -0
  37. data/rice/Class.hpp +8 -0
  38. data/rice/Class.ipp +6 -0
  39. data/rice/Class_defn.hpp +83 -0
  40. data/rice/Constructor.hpp +47 -0
  41. data/rice/Data_Object.hpp +8 -0
  42. data/rice/Data_Object.ipp +133 -0
  43. data/rice/Data_Object_defn.hpp +138 -0
  44. data/rice/Data_Type.cpp +54 -0
  45. data/rice/Data_Type.hpp +8 -0
  46. data/rice/Data_Type.ipp +365 -0
  47. data/rice/Data_Type_defn.hpp +261 -0
  48. data/rice/Data_Type_fwd.hpp +12 -0
  49. data/rice/Director.cpp +13 -0
  50. data/rice/Director.hpp +39 -0
  51. data/rice/Enum.hpp +117 -0
  52. data/rice/Enum.ipp +246 -0
  53. data/rice/Exception.cpp +59 -0
  54. data/rice/Exception.hpp +13 -0
  55. data/rice/Exception_Base.hpp +8 -0
  56. data/rice/Exception_Base.ipp +13 -0
  57. data/rice/Exception_Base_defn.hpp +27 -0
  58. data/rice/Exception_defn.hpp +69 -0
  59. data/rice/Hash.hpp +227 -0
  60. data/rice/Hash.ipp +329 -0
  61. data/rice/Identifier.cpp +8 -0
  62. data/rice/Identifier.hpp +50 -0
  63. data/rice/Identifier.ipp +33 -0
  64. data/rice/Jump_Tag.hpp +24 -0
  65. data/rice/Makefile.am +122 -0
  66. data/rice/Makefile.in +885 -0
  67. data/rice/Module.cpp +84 -0
  68. data/rice/Module.hpp +8 -0
  69. data/rice/Module.ipp +6 -0
  70. data/rice/Module_defn.hpp +88 -0
  71. data/rice/Module_impl.hpp +281 -0
  72. data/rice/Module_impl.ipp +345 -0
  73. data/rice/Object.cpp +169 -0
  74. data/rice/Object.hpp +8 -0
  75. data/rice/Object.ipp +33 -0
  76. data/rice/Object_defn.hpp +214 -0
  77. data/rice/Require_Guard.hpp +21 -0
  78. data/rice/String.cpp +94 -0
  79. data/rice/String.hpp +91 -0
  80. data/rice/Struct.cpp +117 -0
  81. data/rice/Struct.hpp +162 -0
  82. data/rice/Struct.ipp +26 -0
  83. data/rice/Symbol.cpp +25 -0
  84. data/rice/Symbol.hpp +66 -0
  85. data/rice/Symbol.ipp +44 -0
  86. data/rice/config.hpp +47 -0
  87. data/rice/config.hpp.in +46 -0
  88. data/rice/detail/Arguments.hpp +118 -0
  89. data/rice/detail/Auto_Function_Wrapper.hpp +898 -0
  90. data/rice/detail/Auto_Function_Wrapper.ipp +3694 -0
  91. data/rice/detail/Auto_Member_Function_Wrapper.hpp +897 -0
  92. data/rice/detail/Auto_Member_Function_Wrapper.ipp +2774 -0
  93. data/rice/detail/Caster.hpp +103 -0
  94. data/rice/detail/Exception_Handler.hpp +8 -0
  95. data/rice/detail/Exception_Handler.ipp +68 -0
  96. data/rice/detail/Exception_Handler_defn.hpp +96 -0
  97. data/rice/detail/Iterator.hpp +93 -0
  98. data/rice/detail/Not_Copyable.hpp +25 -0
  99. data/rice/detail/Wrapped_Function.hpp +33 -0
  100. data/rice/detail/cfp.hpp +24 -0
  101. data/rice/detail/cfp.ipp +51 -0
  102. data/rice/detail/check_ruby_type.cpp +27 -0
  103. data/rice/detail/check_ruby_type.hpp +23 -0
  104. data/rice/detail/creation_funcs.hpp +37 -0
  105. data/rice/detail/creation_funcs.ipp +36 -0
  106. data/rice/detail/default_allocation_func.hpp +23 -0
  107. data/rice/detail/default_allocation_func.ipp +11 -0
  108. data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
  109. data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
  110. data/rice/detail/demangle.cpp +56 -0
  111. data/rice/detail/demangle.hpp +19 -0
  112. data/rice/detail/env.hpp +11 -0
  113. data/rice/detail/from_ruby.hpp +43 -0
  114. data/rice/detail/from_ruby.ipp +60 -0
  115. data/rice/detail/method_data.cpp +92 -0
  116. data/rice/detail/method_data.hpp +21 -0
  117. data/rice/detail/node.hpp +13 -0
  118. data/rice/detail/protect.cpp +29 -0
  119. data/rice/detail/protect.hpp +34 -0
  120. data/rice/detail/ruby.hpp +74 -0
  121. data/rice/detail/ruby_version_code.hpp +6 -0
  122. data/rice/detail/ruby_version_code.hpp.in +6 -0
  123. data/rice/detail/st.hpp +22 -0
  124. data/rice/detail/to_ruby.hpp +22 -0
  125. data/rice/detail/to_ruby.ipp +36 -0
  126. data/rice/detail/traits.hpp +43 -0
  127. data/rice/detail/win32.hpp +16 -0
  128. data/rice/detail/wrap_function.hpp +66 -0
  129. data/rice/global_function.hpp +33 -0
  130. data/rice/global_function.ipp +22 -0
  131. data/rice/protect.hpp +38 -0
  132. data/rice/protect.ipp +1134 -0
  133. data/rice/ruby_mark.hpp +13 -0
  134. data/rice/ruby_try_catch.hpp +86 -0
  135. data/rice/rubypp.rb +97 -0
  136. data/rice/to_from_ruby.hpp +8 -0
  137. data/rice/to_from_ruby.ipp +418 -0
  138. data/rice/to_from_ruby_defn.hpp +70 -0
  139. data/ruby.ac +135 -0
  140. data/ruby/Makefile.am +1 -0
  141. data/ruby/Makefile.in +628 -0
  142. data/ruby/lib/Makefile.am +3 -0
  143. data/ruby/lib/Makefile.in +506 -0
  144. data/ruby/lib/mkmf-rice.rb.in +217 -0
  145. data/ruby/lib/version.rb +3 -0
  146. data/sample/Makefile.am +47 -0
  147. data/sample/Makefile.in +489 -0
  148. data/sample/enum/extconf.rb +3 -0
  149. data/sample/enum/sample_enum.cpp +54 -0
  150. data/sample/enum/test.rb +8 -0
  151. data/sample/inheritance/animals.cpp +98 -0
  152. data/sample/inheritance/extconf.rb +3 -0
  153. data/sample/inheritance/test.rb +7 -0
  154. data/sample/map/extconf.rb +3 -0
  155. data/sample/map/map.cpp +81 -0
  156. data/sample/map/test.rb +7 -0
  157. data/test/Makefile.am +72 -0
  158. data/test/Makefile.in +1213 -0
  159. data/test/ext/Makefile.am +41 -0
  160. data/test/ext/Makefile.in +483 -0
  161. data/test/ext/t1/Foo.hpp +10 -0
  162. data/test/ext/t1/extconf.rb +2 -0
  163. data/test/ext/t1/t1.cpp +15 -0
  164. data/test/ext/t2/extconf.rb +2 -0
  165. data/test/ext/t2/t2.cpp +11 -0
  166. data/test/test_Address_Registration_Guard.cpp +43 -0
  167. data/test/test_Array.cpp +248 -0
  168. data/test/test_Builtin_Object.cpp +71 -0
  169. data/test/test_Class.cpp +496 -0
  170. data/test/test_Constructor.cpp +128 -0
  171. data/test/test_Data_Object.cpp +275 -0
  172. data/test/test_Data_Type.cpp +348 -0
  173. data/test/test_Director.cpp +308 -0
  174. data/test/test_Enum.cpp +215 -0
  175. data/test/test_Exception.cpp +47 -0
  176. data/test/test_Hash.cpp +212 -0
  177. data/test/test_Identifier.cpp +70 -0
  178. data/test/test_Jump_Tag.cpp +17 -0
  179. data/test/test_Memory_Management.cpp +50 -0
  180. data/test/test_Module.cpp +497 -0
  181. data/test/test_Object.cpp +159 -0
  182. data/test/test_String.cpp +107 -0
  183. data/test/test_Struct.cpp +205 -0
  184. data/test/test_Symbol.cpp +63 -0
  185. data/test/test_To_From_Ruby.cpp +428 -0
  186. data/test/test_global_functions.cpp +114 -0
  187. data/test/test_rice.rb +41 -0
  188. data/test/unittest.cpp +136 -0
  189. data/test/unittest.hpp +294 -0
  190. metadata +297 -0
@@ -0,0 +1,63 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Symbol.hpp"
3
+ #include "rice/Identifier.hpp"
4
+
5
+ using namespace Rice;
6
+
7
+ TESTSUITE(Symbol);
8
+
9
+ SETUP(Symbol)
10
+ {
11
+ ruby_init();
12
+ }
13
+
14
+ TESTCASE(construct_from_symbol)
15
+ {
16
+ VALUE v = ID2SYM(rb_intern("foo"));
17
+ Symbol symbol(v);
18
+ ASSERT_EQUAL(v, symbol.value());
19
+ }
20
+
21
+ TESTCASE(construct_from_identifier)
22
+ {
23
+ Identifier identifier("FOO");
24
+ Symbol symbol(identifier);
25
+ ASSERT_EQUAL(ID2SYM(rb_intern("FOO")), symbol.value());
26
+ }
27
+
28
+ TESTCASE(construct_from_string)
29
+ {
30
+ Symbol symbol("Foo");
31
+ ASSERT_EQUAL(ID2SYM(rb_intern("Foo")), symbol.value());
32
+ }
33
+
34
+ TESTCASE(default_construct)
35
+ {
36
+ Symbol symbol;
37
+ ASSERT_EQUAL(ID2SYM(rb_intern("")), symbol.value());
38
+ }
39
+
40
+ TESTCASE(copy_construct)
41
+ {
42
+ Symbol symbol1("Foo");
43
+ Symbol symbol2(symbol1);
44
+ ASSERT_EQUAL(ID2SYM(rb_intern("Foo")), symbol2.value());
45
+ }
46
+
47
+ TESTCASE(c_str)
48
+ {
49
+ Symbol symbol("Foo");
50
+ ASSERT_EQUAL("Foo", symbol.c_str());
51
+ }
52
+
53
+ TESTCASE(str)
54
+ {
55
+ Symbol symbol("Foo");
56
+ ASSERT_EQUAL(std::string("Foo"), symbol.str());
57
+ }
58
+
59
+ TESTCASE(to_id)
60
+ {
61
+ Symbol symbol("Foo");
62
+ ASSERT_EQUAL(Identifier("Foo"), symbol.to_id());
63
+ }
@@ -0,0 +1,428 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/to_from_ruby.hpp"
3
+ #include "rice/String.hpp"
4
+ #include "rice/Array.hpp"
5
+ #include "rice/Hash.hpp"
6
+ #include <limits>
7
+ #include <cmath>
8
+
9
+ using namespace Rice;
10
+
11
+ TESTSUITE(To_From_Ruby);
12
+
13
+ SETUP(To_From_Ruby)
14
+ {
15
+ ruby_init();
16
+ }
17
+
18
+ TESTCASE(object_to_ruby)
19
+ {
20
+ Object o(rb_str_new2("foo"));
21
+ ASSERT_EQUAL(o.value(), to_ruby(o).value());
22
+ }
23
+
24
+ TESTCASE(object_from_ruby)
25
+ {
26
+ Object o(rb_str_new2("foo"));
27
+ ASSERT_EQUAL(o.value(), from_ruby<Object>(o).value());
28
+ }
29
+
30
+ TESTCASE(short_to_ruby)
31
+ {
32
+ ASSERT_EQUAL(INT2NUM(0), to_ruby((short)0).value());
33
+ ASSERT_EQUAL(INT2NUM(-1), to_ruby((short)-1).value());
34
+ ASSERT_EQUAL(INT2NUM(1), to_ruby((short)1).value());
35
+ ASSERT_EQUAL(
36
+ Object(INT2NUM(std::numeric_limits<short>::min())),
37
+ to_ruby(std::numeric_limits<short>::min()));
38
+ ASSERT_EQUAL(
39
+ Object(INT2NUM(std::numeric_limits<short>::max())),
40
+ to_ruby(std::numeric_limits<short>::max()));
41
+ }
42
+
43
+ TESTCASE(short_from_ruby)
44
+ {
45
+ ASSERT_EQUAL(0, from_ruby<short>(INT2NUM(0)));
46
+ ASSERT_EQUAL(-1, from_ruby<short>(INT2NUM(-1)));
47
+ ASSERT_EQUAL(1, from_ruby<short>(INT2NUM(1)));
48
+ ASSERT_EQUAL(
49
+ std::numeric_limits<short>::min(),
50
+ from_ruby<short>(INT2NUM(std::numeric_limits<short>::min())));
51
+ ASSERT_EQUAL(
52
+ std::numeric_limits<short>::max(),
53
+ from_ruby<short>(INT2NUM(std::numeric_limits<short>::max())));
54
+ }
55
+
56
+ TESTCASE(int_to_ruby)
57
+ {
58
+ ASSERT_EQUAL(INT2NUM(0), to_ruby((int)0).value());
59
+ ASSERT_EQUAL(INT2NUM(-1), to_ruby((int)-1).value());
60
+ ASSERT_EQUAL(INT2NUM(1), to_ruby((int)1).value());
61
+ ASSERT_EQUAL(
62
+ Object(INT2NUM(std::numeric_limits<int>::min())),
63
+ to_ruby(std::numeric_limits<int>::min()));
64
+ ASSERT_EQUAL(
65
+ Object(INT2NUM(std::numeric_limits<int>::max())),
66
+ to_ruby(std::numeric_limits<int>::max()));
67
+ }
68
+
69
+ TESTCASE(int_from_ruby)
70
+ {
71
+ ASSERT_EQUAL(0, from_ruby<int>(INT2NUM(0)));
72
+ ASSERT_EQUAL(-1, from_ruby<int>(INT2NUM(-1)));
73
+ ASSERT_EQUAL(1, from_ruby<int>(INT2NUM(1)));
74
+ ASSERT_EQUAL(
75
+ std::numeric_limits<int>::min(),
76
+ from_ruby<int>(INT2NUM(std::numeric_limits<int>::min())));
77
+ ASSERT_EQUAL(
78
+ std::numeric_limits<int>::max(),
79
+ from_ruby<int>(INT2NUM(std::numeric_limits<int>::max())));
80
+ }
81
+
82
+ TESTCASE(long_to_ruby)
83
+ {
84
+ ASSERT_EQUAL(LONG2NUM(0), to_ruby((long)0).value());
85
+ ASSERT_EQUAL(LONG2NUM(-1), to_ruby((long)-1).value());
86
+ ASSERT_EQUAL(LONG2NUM(1), to_ruby((long)1).value());
87
+ ASSERT_EQUAL(
88
+ LONG2NUM(FIXNUM_MAX),
89
+ to_ruby(FIXNUM_MAX).value());
90
+ ASSERT_EQUAL(
91
+ LONG2NUM(FIXNUM_MIN),
92
+ to_ruby(FIXNUM_MIN).value());
93
+ ASSERT_EQUAL(
94
+ Object(LONG2NUM(std::numeric_limits<long>::min())),
95
+ to_ruby(std::numeric_limits<long>::min()));
96
+ ASSERT_EQUAL(
97
+ Object(LONG2NUM(std::numeric_limits<long>::max())),
98
+ to_ruby(std::numeric_limits<long>::max()));
99
+ }
100
+
101
+ TESTCASE(long_from_ruby)
102
+ {
103
+ ASSERT_EQUAL(0, from_ruby<long>(LONG2NUM(0)));
104
+ ASSERT_EQUAL(-1, from_ruby<long>(LONG2NUM(-1)));
105
+ ASSERT_EQUAL(1, from_ruby<long>(LONG2NUM(1)));
106
+ ASSERT_EQUAL(
107
+ FIXNUM_MIN,
108
+ from_ruby<long>(LONG2NUM(FIXNUM_MIN)));
109
+ ASSERT_EQUAL(
110
+ FIXNUM_MAX,
111
+ from_ruby<long>(LONG2NUM(FIXNUM_MAX)));
112
+ ASSERT_EQUAL(
113
+ std::numeric_limits<long>::min(),
114
+ from_ruby<long>(LONG2NUM(std::numeric_limits<long>::min())));
115
+ ASSERT_EQUAL(
116
+ std::numeric_limits<long>::max(),
117
+ from_ruby<long>(LONG2NUM(std::numeric_limits<long>::max())));
118
+ }
119
+
120
+ TESTCASE(long_long_to_ruby)
121
+ {
122
+ ASSERT_EQUAL(LL2NUM(0), to_ruby((long long)0).value());
123
+ ASSERT_EQUAL(LL2NUM(-1), to_ruby((long long)-1).value());
124
+ ASSERT_EQUAL(LL2NUM(1), to_ruby((long long)1).value());
125
+ ASSERT_EQUAL(
126
+ Object(LL2NUM(std::numeric_limits<long long>::min())),
127
+ to_ruby(std::numeric_limits<long long>::min()));
128
+ ASSERT_EQUAL(
129
+ Object(LL2NUM(std::numeric_limits<long long>::max())),
130
+ to_ruby(std::numeric_limits<long long>::max()));
131
+ }
132
+
133
+ TESTCASE(long_long_from_ruby)
134
+ {
135
+ ASSERT_EQUAL(0, from_ruby<long long>(LL2NUM(0)));
136
+ ASSERT_EQUAL(-1, from_ruby<long long>(LL2NUM(-1)));
137
+ ASSERT_EQUAL(1, from_ruby<long long>(LL2NUM(1)));
138
+ ASSERT_EQUAL(
139
+ std::numeric_limits<long long>::min(),
140
+ from_ruby<long long>(LL2NUM(std::numeric_limits<long long>::min())));
141
+ ASSERT_EQUAL(
142
+ std::numeric_limits<long long>::max(),
143
+ from_ruby<long long>(LL2NUM(std::numeric_limits<long long>::max())));
144
+ }
145
+
146
+ TESTCASE(unsigned_short_to_ruby)
147
+ {
148
+ ASSERT_EQUAL(UINT2NUM(0), to_ruby((unsigned short)0).value());
149
+ ASSERT_EQUAL(UINT2NUM(1), to_ruby((unsigned short)1).value());
150
+ ASSERT_EQUAL(
151
+ Object(UINT2NUM(std::numeric_limits<unsigned short>::min())),
152
+ to_ruby(std::numeric_limits<unsigned short>::min()));
153
+ ASSERT_EQUAL(
154
+ Object(UINT2NUM(std::numeric_limits<unsigned short>::max())),
155
+ to_ruby(std::numeric_limits<unsigned short>::max()));
156
+ }
157
+
158
+ TESTCASE(unsigned_short_from_ruby)
159
+ {
160
+ ASSERT_EQUAL(0u, from_ruby<unsigned short>(UINT2NUM(0)));
161
+ ASSERT_EQUAL(1u, from_ruby<unsigned short>(UINT2NUM(1)));
162
+ ASSERT_EQUAL(
163
+ std::numeric_limits<unsigned short>::min(),
164
+ from_ruby<unsigned short>(UINT2NUM(std::numeric_limits<unsigned short>::min())));
165
+ ASSERT_EQUAL(
166
+ std::numeric_limits<unsigned short>::max(),
167
+ from_ruby<unsigned short>(UINT2NUM(std::numeric_limits<unsigned short>::max())));
168
+ }
169
+
170
+ TESTCASE(unsigned_int_to_ruby)
171
+ {
172
+ ASSERT_EQUAL(UINT2NUM(0), to_ruby((unsigned int)0).value());
173
+ ASSERT_EQUAL(UINT2NUM(1), to_ruby((unsigned int)1).value());
174
+ ASSERT_EQUAL(
175
+ Object(UINT2NUM(std::numeric_limits<unsigned int>::min())),
176
+ to_ruby(std::numeric_limits<unsigned int>::min()));
177
+ ASSERT_EQUAL(
178
+ Object(UINT2NUM(std::numeric_limits<unsigned int>::max())),
179
+ to_ruby(std::numeric_limits<unsigned int>::max()));
180
+ }
181
+
182
+ TESTCASE(unsigned_int_from_ruby)
183
+ {
184
+ ASSERT_EQUAL(0u, from_ruby<unsigned int>(UINT2NUM(0)));
185
+ ASSERT_EQUAL(1u, from_ruby<unsigned int>(UINT2NUM(1)));
186
+ ASSERT_EQUAL(
187
+ std::numeric_limits<unsigned int>::min(),
188
+ from_ruby<unsigned int>(UINT2NUM(std::numeric_limits<unsigned int>::min())));
189
+ ASSERT_EQUAL(
190
+ std::numeric_limits<unsigned int>::max(),
191
+ from_ruby<unsigned int>(UINT2NUM(std::numeric_limits<unsigned int>::max())));
192
+ }
193
+
194
+ TESTCASE(unsigned_long_to_ruby)
195
+ {
196
+ ASSERT_EQUAL(ULONG2NUM(0), to_ruby((unsigned long)0).value());
197
+ ASSERT_EQUAL(ULONG2NUM(1), to_ruby((unsigned long)1).value());
198
+ ASSERT_EQUAL(
199
+ ULONG2NUM(FIXNUM_MAX),
200
+ to_ruby(FIXNUM_MAX).value());
201
+ ASSERT_EQUAL(
202
+ Object(ULONG2NUM(std::numeric_limits<unsigned long>::min())),
203
+ to_ruby(std::numeric_limits<unsigned long>::min()));
204
+ ASSERT_EQUAL(
205
+ Object(ULONG2NUM(std::numeric_limits<unsigned long>::max())),
206
+ to_ruby(std::numeric_limits<unsigned long>::max()));
207
+ }
208
+
209
+ TESTCASE(unsigned_long_from_ruby)
210
+ {
211
+ ASSERT_EQUAL(0u, from_ruby<unsigned long>(ULONG2NUM(0)));
212
+ ASSERT_EQUAL(1u, from_ruby<unsigned long>(ULONG2NUM(1)));
213
+ ASSERT_EQUAL(
214
+ static_cast<unsigned long>(FIXNUM_MIN),
215
+ from_ruby<unsigned long>(ULONG2NUM(FIXNUM_MIN)));
216
+ ASSERT_EQUAL(
217
+ std::numeric_limits<unsigned long>::min(),
218
+ from_ruby<unsigned long>(ULONG2NUM(std::numeric_limits<unsigned long>::min())));
219
+ ASSERT_EQUAL(
220
+ std::numeric_limits<unsigned long>::max(),
221
+ from_ruby<unsigned long>(ULONG2NUM(std::numeric_limits<unsigned long>::max())));
222
+ }
223
+
224
+ TESTCASE(unsigned_long_long_to_ruby)
225
+ {
226
+ ASSERT_EQUAL(ULL2NUM(0), to_ruby((unsigned long long)0).value());
227
+ ASSERT_EQUAL(ULL2NUM(1), to_ruby((unsigned long long)1).value());
228
+ ASSERT_EQUAL(
229
+ Object(ULL2NUM(std::numeric_limits<unsigned long long>::min())),
230
+ to_ruby(std::numeric_limits<unsigned long long>::min()));
231
+ ASSERT_EQUAL(
232
+ Object(ULL2NUM(std::numeric_limits<unsigned long long>::max())),
233
+ to_ruby(std::numeric_limits<unsigned long long>::max()));
234
+ }
235
+
236
+ TESTCASE(unsigned_long_long_from_ruby)
237
+ {
238
+ ASSERT_EQUAL(0u, from_ruby<unsigned long>(ULL2NUM(0)));
239
+ ASSERT_EQUAL(1u, from_ruby<unsigned long>(ULL2NUM(1)));
240
+ ASSERT_EQUAL(
241
+ std::numeric_limits<unsigned long long>::min(),
242
+ from_ruby<unsigned long long>(ULL2NUM(std::numeric_limits<unsigned long long>::min())));
243
+ ASSERT_EQUAL(
244
+ std::numeric_limits<unsigned long long>::max(),
245
+ from_ruby<unsigned long long>(ULL2NUM(std::numeric_limits<unsigned long long>::max())));
246
+ }
247
+
248
+ TESTCASE(bool_to_ruby)
249
+ {
250
+ ASSERT_EQUAL(Qfalse, to_ruby(false).value());
251
+ ASSERT_EQUAL(Qtrue, to_ruby(true).value());
252
+ }
253
+
254
+ TESTCASE(bool_from_ruby)
255
+ {
256
+ ASSERT_EQUAL(false, from_ruby<bool>(Object(Qfalse)));
257
+ ASSERT_EQUAL(true, from_ruby<bool>(Object(Qtrue)));
258
+ }
259
+
260
+ TESTCASE(float_to_ruby)
261
+ {
262
+ ASSERT_EQUAL(Object(rb_float_new(0.0f)), to_ruby(0.0f));
263
+ ASSERT_EQUAL(Object(rb_float_new(-1.0f)), to_ruby(-1.0f));
264
+ ASSERT_EQUAL(Object(rb_float_new(1.0f)), to_ruby(1.0f));
265
+ ASSERT_EQUAL(Object(rb_float_new(0.5f)), to_ruby(0.5f));
266
+ ASSERT_EQUAL(
267
+ Object(rb_float_new(std::numeric_limits<float>::min())),
268
+ to_ruby(std::numeric_limits<float>::min()));
269
+ ASSERT_EQUAL(
270
+ Object(rb_float_new(std::numeric_limits<float>::max())),
271
+ to_ruby(std::numeric_limits<float>::max()));
272
+ ASSERT(
273
+ to_ruby(std::numeric_limits<float>::quiet_NaN()).call("nan?"));
274
+ ASSERT(
275
+ to_ruby(std::numeric_limits<float>::signaling_NaN()).call("nan?"));
276
+ ASSERT_EQUAL(
277
+ Object(rb_float_new(std::numeric_limits<float>::epsilon())),
278
+ to_ruby(std::numeric_limits<float>::epsilon()));
279
+ }
280
+
281
+ TESTCASE(float_from_ruby)
282
+ {
283
+ ASSERT_EQUAL(0.0f, from_ruby<float>(rb_float_new(0.0f)));
284
+ ASSERT_EQUAL(-1.0f, from_ruby<float>(rb_float_new(-1.0f)));
285
+ ASSERT_EQUAL(1.0f, from_ruby<float>(rb_float_new(1.0f)));
286
+ ASSERT_EQUAL(
287
+ std::numeric_limits<float>::min(),
288
+ from_ruby<float>(rb_float_new(std::numeric_limits<float>::min())));
289
+ ASSERT_EQUAL(
290
+ std::numeric_limits<float>::max(),
291
+ from_ruby<float>(rb_float_new(std::numeric_limits<float>::max())));
292
+ ASSERT(
293
+ std::isnan(from_ruby<float>(rb_float_new(std::numeric_limits<float>::quiet_NaN()))));
294
+ ASSERT(
295
+ std::isnan(from_ruby<float>(rb_float_new(std::numeric_limits<float>::signaling_NaN()))));
296
+ ASSERT_EQUAL(
297
+ std::numeric_limits<float>::epsilon(),
298
+ from_ruby<float>(rb_float_new(std::numeric_limits<float>::epsilon())));
299
+ }
300
+
301
+ TESTCASE(double_to_ruby)
302
+ {
303
+ ASSERT_EQUAL(Object(rb_float_new(0.0f)), to_ruby(0.0f));
304
+ ASSERT_EQUAL(Object(rb_float_new(-1.0f)), to_ruby(-1.0f));
305
+ ASSERT_EQUAL(Object(rb_float_new(1.0f)), to_ruby(1.0f));
306
+ ASSERT_EQUAL(Object(rb_float_new(0.5f)), to_ruby(0.5f));
307
+ ASSERT_EQUAL(
308
+ Object(rb_float_new(std::numeric_limits<double>::min())),
309
+ to_ruby(std::numeric_limits<double>::min()));
310
+ ASSERT_EQUAL(
311
+ Object(rb_float_new(std::numeric_limits<double>::max())),
312
+ to_ruby(std::numeric_limits<double>::max()));
313
+ ASSERT(
314
+ to_ruby(std::numeric_limits<double>::quiet_NaN()).call("nan?"));
315
+ ASSERT(
316
+ to_ruby(std::numeric_limits<double>::signaling_NaN()).call("nan?"));
317
+ ASSERT_EQUAL(
318
+ Object(rb_float_new(std::numeric_limits<double>::epsilon())),
319
+ to_ruby(std::numeric_limits<double>::epsilon()));
320
+ }
321
+
322
+ TESTCASE(double_from_ruby)
323
+ {
324
+ ASSERT_EQUAL(0.0f, from_ruby<double>(rb_float_new(0.0f)));
325
+ ASSERT_EQUAL(-1.0f, from_ruby<double>(rb_float_new(-1.0f)));
326
+ ASSERT_EQUAL(1.0f, from_ruby<double>(rb_float_new(1.0f)));
327
+ ASSERT_EQUAL(
328
+ std::numeric_limits<double>::min(),
329
+ from_ruby<double>(rb_float_new(std::numeric_limits<double>::min())));
330
+ ASSERT_EQUAL(
331
+ std::numeric_limits<double>::max(),
332
+ from_ruby<double>(rb_float_new(std::numeric_limits<double>::max())));
333
+ ASSERT(
334
+ std::isnan(from_ruby<double>(rb_float_new(std::numeric_limits<double>::quiet_NaN()))));
335
+ ASSERT(
336
+ std::isnan(from_ruby<double>(rb_float_new(std::numeric_limits<double>::signaling_NaN()))));
337
+ ASSERT_EQUAL(
338
+ std::numeric_limits<double>::epsilon(),
339
+ from_ruby<double>(rb_float_new(std::numeric_limits<double>::epsilon())));
340
+ }
341
+
342
+ TESTCASE(char_const_ptr_to_ruby)
343
+ {
344
+ ASSERT_EQUAL(String(""), to_ruby((char const *)""));
345
+ ASSERT_EQUAL(String("foo"), to_ruby((char const *)"foo"));
346
+ }
347
+
348
+ TESTCASE(char_const_ptr_from_ruby)
349
+ {
350
+ char const* foo = "foo";
351
+ ASSERT_EQUAL("", from_ruby<char const *>(rb_str_new2("")));
352
+ ASSERT_EQUAL(foo, from_ruby<char const *>(rb_str_new2("foo")));
353
+ }
354
+
355
+ TESTCASE(char_from_ruby_single_character_string)
356
+ {
357
+ ASSERT_EQUAL('x', from_ruby<char>(rb_str_new2("x")));
358
+ }
359
+
360
+ TESTCASE(char_from_ruby_longer_string)
361
+ {
362
+ ASSERT_EXCEPTION(
363
+ std::invalid_argument,
364
+ from_ruby<char>(rb_str_new2("xy"))
365
+ );
366
+ }
367
+
368
+ TESTCASE(char_from_ruby_fixnum)
369
+ {
370
+ ASSERT_EQUAL('1', from_ruby<char>(INT2NUM(49)));
371
+ }
372
+
373
+ TESTCASE(char_star_from_ruby)
374
+ {
375
+ const char* expected = "my string";
376
+ ASSERT_EQUAL(expected, from_ruby<const char*>(rb_str_new2("my string")));
377
+ }
378
+
379
+ TESTCASE(std_string_to_ruby)
380
+ {
381
+ ASSERT_EQUAL(String(""), to_ruby(std::string("")));
382
+ ASSERT_EQUAL(String("foo"), to_ruby(std::string("foo")));
383
+ }
384
+
385
+ TESTCASE(std_string_from_ruby)
386
+ {
387
+ ASSERT_EQUAL(std::string(""), from_ruby<std::string>(rb_str_new2("")));
388
+ ASSERT_EQUAL(std::string("foo"), from_ruby<std::string>(rb_str_new2("foo")));
389
+ }
390
+
391
+ TESTCASE(std_string_to_ruby_with_binary)
392
+ {
393
+ Rice::String got = to_ruby(std::string("\000test", 5));
394
+
395
+ ASSERT_EQUAL(String(std::string("\000test", 5)), got);
396
+ ASSERT_EQUAL(5, got.length());
397
+ }
398
+
399
+ TESTCASE(std_string_from_ruby_with_binary)
400
+ {
401
+ std::string got = from_ruby<std::string>(rb_str_new("\000test", 5));
402
+ ASSERT_EQUAL(5, got.length());
403
+ ASSERT_EQUAL(std::string("\000test", 5), got);
404
+ }
405
+
406
+ TESTCASE(array_to_ruby)
407
+ {
408
+ Array a(rb_ary_new());
409
+ ASSERT_EQUAL(a.value(), to_ruby(a).value());
410
+ }
411
+
412
+ TESTCASE(array_from_ruby)
413
+ {
414
+ Array a(rb_ary_new());
415
+ ASSERT_EQUAL(a.value(), from_ruby<Array>(a).value());
416
+ }
417
+
418
+ TESTCASE(hash_to_ruby)
419
+ {
420
+ Hash h(rb_hash_new());
421
+ ASSERT_EQUAL(h.value(), to_ruby(h).value());
422
+ }
423
+
424
+ TESTCASE(hash_from_ruby)
425
+ {
426
+ Hash h(rb_hash_new());
427
+ ASSERT_EQUAL(h.value(), from_ruby<Hash>(h).value());
428
+ }