jameskilton-rice 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. data/COPYING +23 -0
  2. data/Doxyfile +1253 -0
  3. data/Makefile.am +26 -0
  4. data/Makefile.in +749 -0
  5. data/README +879 -0
  6. data/README.mingw +8 -0
  7. data/Rakefile +72 -0
  8. data/aclocal.m4 +891 -0
  9. data/bootstrap +8 -0
  10. data/config.guess +1526 -0
  11. data/config.sub +1658 -0
  12. data/configure +7668 -0
  13. data/configure.ac +52 -0
  14. data/depcomp +589 -0
  15. data/doxygen.ac +314 -0
  16. data/doxygen.am +186 -0
  17. data/extconf.rb +22 -0
  18. data/install-sh +519 -0
  19. data/missing +367 -0
  20. data/post-autoconf.rb +22 -0
  21. data/post-automake.rb +28 -0
  22. data/rice/Address_Registration_Guard.hpp +7 -0
  23. data/rice/Address_Registration_Guard.ipp +34 -0
  24. data/rice/Address_Registration_Guard_defn.hpp +65 -0
  25. data/rice/Allocation_Strategies.hpp +37 -0
  26. data/rice/Arg.hpp +8 -0
  27. data/rice/Arg_impl.hpp +116 -0
  28. data/rice/Arg_operators.cpp +21 -0
  29. data/rice/Arg_operators.hpp +18 -0
  30. data/rice/Array.hpp +220 -0
  31. data/rice/Array.ipp +263 -0
  32. data/rice/Builtin_Object.hpp +8 -0
  33. data/rice/Builtin_Object.ipp +50 -0
  34. data/rice/Builtin_Object_defn.hpp +51 -0
  35. data/rice/Class.cpp +57 -0
  36. data/rice/Class.hpp +8 -0
  37. data/rice/Class.ipp +6 -0
  38. data/rice/Class_defn.hpp +83 -0
  39. data/rice/Constructor.hpp +339 -0
  40. data/rice/Critical_Guard.hpp +40 -0
  41. data/rice/Critical_Guard.ipp +26 -0
  42. data/rice/Data_Object.hpp +8 -0
  43. data/rice/Data_Object.ipp +133 -0
  44. data/rice/Data_Object_defn.hpp +132 -0
  45. data/rice/Data_Type.cpp +21 -0
  46. data/rice/Data_Type.hpp +8 -0
  47. data/rice/Data_Type.ipp +306 -0
  48. data/rice/Data_Type_defn.hpp +219 -0
  49. data/rice/Data_Type_fwd.hpp +12 -0
  50. data/rice/Director.cpp +19 -0
  51. data/rice/Director.hpp +47 -0
  52. data/rice/Enum.hpp +118 -0
  53. data/rice/Enum.ipp +246 -0
  54. data/rice/Exception.cpp +59 -0
  55. data/rice/Exception.hpp +9 -0
  56. data/rice/Exception_Base.hpp +8 -0
  57. data/rice/Exception_Base.ipp +13 -0
  58. data/rice/Exception_Base_defn.hpp +27 -0
  59. data/rice/Exception_defn.hpp +69 -0
  60. data/rice/Hash.hpp +210 -0
  61. data/rice/Hash.ipp +338 -0
  62. data/rice/Identifier.cpp +8 -0
  63. data/rice/Identifier.hpp +50 -0
  64. data/rice/Identifier.ipp +33 -0
  65. data/rice/Jump_Tag.hpp +24 -0
  66. data/rice/Makefile.am +140 -0
  67. data/rice/Makefile.in +740 -0
  68. data/rice/Module.cpp +84 -0
  69. data/rice/Module.hpp +8 -0
  70. data/rice/Module.ipp +6 -0
  71. data/rice/Module_defn.hpp +88 -0
  72. data/rice/Module_impl.hpp +281 -0
  73. data/rice/Module_impl.ipp +348 -0
  74. data/rice/Object.cpp +153 -0
  75. data/rice/Object.hpp +8 -0
  76. data/rice/Object.ipp +19 -0
  77. data/rice/Object_defn.hpp +183 -0
  78. data/rice/Require_Guard.hpp +21 -0
  79. data/rice/String.cpp +94 -0
  80. data/rice/String.hpp +89 -0
  81. data/rice/Struct.cpp +117 -0
  82. data/rice/Struct.hpp +162 -0
  83. data/rice/Struct.ipp +26 -0
  84. data/rice/Symbol.cpp +25 -0
  85. data/rice/Symbol.hpp +66 -0
  86. data/rice/Symbol.ipp +44 -0
  87. data/rice/VM.cpp +92 -0
  88. data/rice/VM.hpp +32 -0
  89. data/rice/config.hpp +44 -0
  90. data/rice/config.hpp.in +43 -0
  91. data/rice/detail/Arguments.hpp +126 -0
  92. data/rice/detail/Auto_Function_Wrapper.hpp +861 -0
  93. data/rice/detail/Auto_Function_Wrapper.ipp +2929 -0
  94. data/rice/detail/Auto_Member_Function_Wrapper.hpp +828 -0
  95. data/rice/detail/Auto_Member_Function_Wrapper.ipp +2326 -0
  96. data/rice/detail/Caster.hpp +63 -0
  97. data/rice/detail/Exception_Handler.hpp +8 -0
  98. data/rice/detail/Exception_Handler.ipp +68 -0
  99. data/rice/detail/Exception_Handler_defn.hpp +96 -0
  100. data/rice/detail/Iterator.hpp +93 -0
  101. data/rice/detail/Not_Copyable.hpp +25 -0
  102. data/rice/detail/Wrapped_Function.hpp +33 -0
  103. data/rice/detail/check_ruby_type.cpp +27 -0
  104. data/rice/detail/check_ruby_type.hpp +23 -0
  105. data/rice/detail/creation_funcs.hpp +37 -0
  106. data/rice/detail/creation_funcs.ipp +36 -0
  107. data/rice/detail/default_allocation_func.hpp +23 -0
  108. data/rice/detail/default_allocation_func.ipp +11 -0
  109. data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
  110. data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
  111. data/rice/detail/demangle.cpp +56 -0
  112. data/rice/detail/demangle.hpp +19 -0
  113. data/rice/detail/env.hpp +19 -0
  114. data/rice/detail/from_ruby.hpp +43 -0
  115. data/rice/detail/from_ruby.ipp +60 -0
  116. data/rice/detail/method_data.cpp +392 -0
  117. data/rice/detail/method_data.cpp.rpp +301 -0
  118. data/rice/detail/method_data.hpp +21 -0
  119. data/rice/detail/mininode.cpp +1220 -0
  120. data/rice/detail/mininode.cpp.rpp +62 -0
  121. data/rice/detail/mininode.hpp +320 -0
  122. data/rice/detail/mininode.hpp.rpp +119 -0
  123. data/rice/detail/node.hpp +13 -0
  124. data/rice/detail/object_call.hpp +85 -0
  125. data/rice/detail/object_call.ipp +147 -0
  126. data/rice/detail/protect.cpp +29 -0
  127. data/rice/detail/protect.hpp +34 -0
  128. data/rice/detail/remove_const.hpp +21 -0
  129. data/rice/detail/ruby.hpp +89 -0
  130. data/rice/detail/ruby_version_code.hpp +6 -0
  131. data/rice/detail/ruby_version_code.hpp.in +6 -0
  132. data/rice/detail/rubysig.hpp +19 -0
  133. data/rice/detail/st.hpp +60 -0
  134. data/rice/detail/to_ruby.hpp +22 -0
  135. data/rice/detail/to_ruby.ipp +37 -0
  136. data/rice/detail/win32.hpp +16 -0
  137. data/rice/detail/wrap_function.hpp +345 -0
  138. data/rice/detail/wrap_function.ipp +531 -0
  139. data/rice/generate_code.rb +1311 -0
  140. data/rice/global_function.hpp +33 -0
  141. data/rice/global_function.ipp +22 -0
  142. data/rice/protect.hpp +91 -0
  143. data/rice/protect.ipp +803 -0
  144. data/rice/ruby_mark.hpp +13 -0
  145. data/rice/ruby_try_catch.hpp +86 -0
  146. data/rice/rubypp.rb +97 -0
  147. data/rice/to_from_ruby.hpp +8 -0
  148. data/rice/to_from_ruby.ipp +299 -0
  149. data/rice/to_from_ruby_defn.hpp +71 -0
  150. data/ruby.ac +150 -0
  151. data/ruby/Makefile.am +1 -0
  152. data/ruby/Makefile.in +497 -0
  153. data/ruby/lib/Makefile.am +3 -0
  154. data/ruby/lib/Makefile.in +374 -0
  155. data/ruby/lib/mkmf-rice.rb.in +209 -0
  156. data/ruby/lib/version.rb +3 -0
  157. data/sample/Makefile.am +47 -0
  158. data/sample/Makefile.in +380 -0
  159. data/sample/enum/extconf.rb +3 -0
  160. data/sample/enum/sample_enum.cpp +54 -0
  161. data/sample/enum/test.rb +8 -0
  162. data/sample/inheritance/animals.cpp +98 -0
  163. data/sample/inheritance/extconf.rb +3 -0
  164. data/sample/inheritance/test.rb +7 -0
  165. data/sample/map/extconf.rb +3 -0
  166. data/sample/map/map.cpp +81 -0
  167. data/sample/map/test.rb +7 -0
  168. data/test/Makefile.am +49 -0
  169. data/test/Makefile.in +603 -0
  170. data/test/test_Address_Registration_Guard.cpp +43 -0
  171. data/test/test_Allocation_Strategies.cpp +77 -0
  172. data/test/test_Array.cpp +241 -0
  173. data/test/test_Builtin_Object.cpp +72 -0
  174. data/test/test_Class.cpp +398 -0
  175. data/test/test_Constructor.cpp +238 -0
  176. data/test/test_Critical_Guard.cpp +51 -0
  177. data/test/test_Data_Object.cpp +275 -0
  178. data/test/test_Data_Type.cpp +121 -0
  179. data/test/test_Director.cpp +225 -0
  180. data/test/test_Enum.cpp +162 -0
  181. data/test/test_Exception.cpp +46 -0
  182. data/test/test_Hash.cpp +195 -0
  183. data/test/test_Identifier.cpp +70 -0
  184. data/test/test_Jump_Tag.cpp +17 -0
  185. data/test/test_Module.cpp +428 -0
  186. data/test/test_Object.cpp +148 -0
  187. data/test/test_String.cpp +94 -0
  188. data/test/test_Struct.cpp +192 -0
  189. data/test/test_Symbol.cpp +63 -0
  190. data/test/test_To_From_Ruby.cpp +263 -0
  191. data/test/test_VM.cpp +26 -0
  192. data/test/test_global_functions.cpp +97 -0
  193. data/test/test_rice.rb +35 -0
  194. data/test/unittest.cpp +136 -0
  195. data/test/unittest.hpp +292 -0
  196. metadata +247 -0
@@ -0,0 +1,263 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/to_from_ruby.hpp"
3
+ #include "rice/String.hpp"
4
+ #include <limits>
5
+ #include <cmath>
6
+
7
+ using namespace Rice;
8
+
9
+ TESTSUITE(To_From_Ruby);
10
+
11
+ SETUP(To_From_Ruby)
12
+ {
13
+ ruby_init();
14
+ }
15
+
16
+ TESTCASE(object_to_ruby)
17
+ {
18
+ Object o(rb_str_new2("foo"));
19
+ ASSERT_EQUAL(o.value(), to_ruby(o).value());
20
+ }
21
+
22
+ TESTCASE(object_from_ruby)
23
+ {
24
+ Object o(rb_str_new2("foo"));
25
+ ASSERT_EQUAL(o.value(), from_ruby<Object>(o).value());
26
+ }
27
+
28
+ TESTCASE(int_to_ruby)
29
+ {
30
+ ASSERT_EQUAL(INT2NUM(0), to_ruby((int)0).value());
31
+ ASSERT_EQUAL(INT2NUM(-1), to_ruby((int)-1).value());
32
+ ASSERT_EQUAL(INT2NUM(1), to_ruby((int)1).value());
33
+ ASSERT_EQUAL(
34
+ Object(INT2NUM(std::numeric_limits<int>::min())),
35
+ to_ruby(std::numeric_limits<int>::min()));
36
+ ASSERT_EQUAL(
37
+ Object(INT2NUM(std::numeric_limits<int>::max())),
38
+ to_ruby(std::numeric_limits<int>::max()));
39
+ }
40
+
41
+ TESTCASE(int_from_ruby)
42
+ {
43
+ ASSERT_EQUAL(0, from_ruby<int>(INT2NUM(0)));
44
+ ASSERT_EQUAL(-1, from_ruby<int>(INT2NUM(-1)));
45
+ ASSERT_EQUAL(1, from_ruby<int>(INT2NUM(1)));
46
+ ASSERT_EQUAL(
47
+ std::numeric_limits<int>::min(),
48
+ from_ruby<int>(INT2NUM(std::numeric_limits<int>::min())));
49
+ ASSERT_EQUAL(
50
+ std::numeric_limits<int>::max(),
51
+ from_ruby<int>(INT2NUM(std::numeric_limits<int>::max())));
52
+ }
53
+
54
+ TESTCASE(long_to_ruby)
55
+ {
56
+ ASSERT_EQUAL(LONG2NUM(0), to_ruby((long)0).value());
57
+ ASSERT_EQUAL(LONG2NUM(-1), to_ruby((long)-1).value());
58
+ ASSERT_EQUAL(LONG2NUM(1), to_ruby((long)1).value());
59
+ ASSERT_EQUAL(
60
+ LONG2NUM(FIXNUM_MAX),
61
+ to_ruby(FIXNUM_MAX).value());
62
+ ASSERT_EQUAL(
63
+ LONG2NUM(FIXNUM_MIN),
64
+ to_ruby(FIXNUM_MIN).value());
65
+ ASSERT_EQUAL(
66
+ Object(LONG2NUM(std::numeric_limits<long>::min())),
67
+ to_ruby(std::numeric_limits<long>::min()));
68
+ ASSERT_EQUAL(
69
+ Object(LONG2NUM(std::numeric_limits<long>::max())),
70
+ to_ruby(std::numeric_limits<long>::max()));
71
+ }
72
+
73
+ TESTCASE(long_from_ruby)
74
+ {
75
+ ASSERT_EQUAL(0, from_ruby<long>(LONG2NUM(0)));
76
+ ASSERT_EQUAL(-1, from_ruby<long>(LONG2NUM(-1)));
77
+ ASSERT_EQUAL(1, from_ruby<long>(LONG2NUM(1)));
78
+ ASSERT_EQUAL(
79
+ FIXNUM_MIN,
80
+ from_ruby<long>(LONG2NUM(FIXNUM_MIN)));
81
+ ASSERT_EQUAL(
82
+ FIXNUM_MAX,
83
+ from_ruby<long>(LONG2NUM(FIXNUM_MAX)));
84
+ ASSERT_EQUAL(
85
+ std::numeric_limits<long>::min(),
86
+ from_ruby<long>(LONG2NUM(std::numeric_limits<long>::min())));
87
+ ASSERT_EQUAL(
88
+ std::numeric_limits<long>::max(),
89
+ from_ruby<long>(LONG2NUM(std::numeric_limits<long>::max())));
90
+ }
91
+
92
+ TESTCASE(unsigned_int_to_ruby)
93
+ {
94
+ ASSERT_EQUAL(UINT2NUM(0), to_ruby((unsigned int)0).value());
95
+ ASSERT_EQUAL(UINT2NUM(1), to_ruby((unsigned int)1).value());
96
+ ASSERT_EQUAL(
97
+ Object(UINT2NUM(std::numeric_limits<unsigned int>::min())),
98
+ to_ruby(std::numeric_limits<unsigned int>::min()));
99
+ ASSERT_EQUAL(
100
+ Object(UINT2NUM(std::numeric_limits<unsigned int>::max())),
101
+ to_ruby(std::numeric_limits<unsigned int>::max()));
102
+ }
103
+
104
+ TESTCASE(unsigned_int_from_ruby)
105
+ {
106
+ ASSERT_EQUAL(0u, from_ruby<unsigned int>(UINT2NUM(0)));
107
+ ASSERT_EQUAL(1u, from_ruby<unsigned int>(UINT2NUM(1)));
108
+ ASSERT_EQUAL(
109
+ std::numeric_limits<unsigned int>::min(),
110
+ from_ruby<unsigned int>(UINT2NUM(std::numeric_limits<unsigned int>::min())));
111
+ ASSERT_EQUAL(
112
+ std::numeric_limits<unsigned int>::max(),
113
+ from_ruby<unsigned int>(UINT2NUM(std::numeric_limits<unsigned int>::max())));
114
+ }
115
+
116
+ TESTCASE(unsigned_long_to_ruby)
117
+ {
118
+ ASSERT_EQUAL(ULONG2NUM(0), to_ruby((unsigned long)0).value());
119
+ ASSERT_EQUAL(ULONG2NUM(1), to_ruby((unsigned long)1).value());
120
+ ASSERT_EQUAL(
121
+ ULONG2NUM(FIXNUM_MAX),
122
+ to_ruby(FIXNUM_MAX).value());
123
+ ASSERT_EQUAL(
124
+ Object(ULONG2NUM(std::numeric_limits<unsigned long>::min())),
125
+ to_ruby(std::numeric_limits<unsigned long>::min()));
126
+ ASSERT_EQUAL(
127
+ Object(ULONG2NUM(std::numeric_limits<unsigned long>::max())),
128
+ to_ruby(std::numeric_limits<unsigned long>::max()));
129
+ }
130
+
131
+ TESTCASE(unsigned_long_from_ruby)
132
+ {
133
+ ASSERT_EQUAL(0u, from_ruby<unsigned long>(ULONG2NUM(0)));
134
+ ASSERT_EQUAL(1u, from_ruby<unsigned long>(ULONG2NUM(1)));
135
+ ASSERT_EQUAL(
136
+ static_cast<unsigned long>(FIXNUM_MIN),
137
+ from_ruby<unsigned long>(ULONG2NUM(FIXNUM_MIN)));
138
+ ASSERT_EQUAL(
139
+ std::numeric_limits<unsigned long>::min(),
140
+ from_ruby<unsigned long>(ULONG2NUM(std::numeric_limits<unsigned long>::min())));
141
+ ASSERT_EQUAL(
142
+ std::numeric_limits<unsigned long>::max(),
143
+ from_ruby<unsigned long>(ULONG2NUM(std::numeric_limits<unsigned long>::max())));
144
+ }
145
+
146
+ TESTCASE(bool_to_ruby)
147
+ {
148
+ ASSERT_EQUAL(Qfalse, to_ruby(false).value());
149
+ ASSERT_EQUAL(Qtrue, to_ruby(true).value());
150
+ }
151
+
152
+ TESTCASE(bool_from_ruby)
153
+ {
154
+ ASSERT_EQUAL(false, from_ruby<bool>(Object(Qfalse)));
155
+ ASSERT_EQUAL(true, from_ruby<bool>(Object(Qtrue)));
156
+ }
157
+
158
+ TESTCASE(float_to_ruby)
159
+ {
160
+ ASSERT_EQUAL(Object(rb_float_new(0.0f)), to_ruby(0.0f));
161
+ ASSERT_EQUAL(Object(rb_float_new(-1.0f)), to_ruby(-1.0f));
162
+ ASSERT_EQUAL(Object(rb_float_new(1.0f)), to_ruby(1.0f));
163
+ ASSERT_EQUAL(Object(rb_float_new(0.5f)), to_ruby(0.5f));
164
+ ASSERT_EQUAL(
165
+ Object(rb_float_new(std::numeric_limits<float>::min())),
166
+ to_ruby(std::numeric_limits<float>::min()));
167
+ ASSERT_EQUAL(
168
+ Object(rb_float_new(std::numeric_limits<float>::max())),
169
+ to_ruby(std::numeric_limits<float>::max()));
170
+ ASSERT(
171
+ to_ruby(std::numeric_limits<float>::quiet_NaN()).call("nan?"));
172
+ ASSERT(
173
+ to_ruby(std::numeric_limits<float>::signaling_NaN()).call("nan?"));
174
+ ASSERT_EQUAL(
175
+ Object(rb_float_new(std::numeric_limits<float>::epsilon())),
176
+ to_ruby(std::numeric_limits<float>::epsilon()));
177
+ }
178
+
179
+ TESTCASE(float_from_ruby)
180
+ {
181
+ ASSERT_EQUAL(0.0f, from_ruby<float>(rb_float_new(0.0f)));
182
+ ASSERT_EQUAL(-1.0f, from_ruby<float>(rb_float_new(-1.0f)));
183
+ ASSERT_EQUAL(1.0f, from_ruby<float>(rb_float_new(1.0f)));
184
+ ASSERT_EQUAL(
185
+ std::numeric_limits<float>::min(),
186
+ from_ruby<float>(rb_float_new(std::numeric_limits<float>::min())));
187
+ ASSERT_EQUAL(
188
+ std::numeric_limits<float>::max(),
189
+ from_ruby<float>(rb_float_new(std::numeric_limits<float>::max())));
190
+ ASSERT(
191
+ isnan(from_ruby<float>(rb_float_new(std::numeric_limits<float>::quiet_NaN()))));
192
+ ASSERT(
193
+ isnan(from_ruby<float>(rb_float_new(std::numeric_limits<float>::signaling_NaN()))));
194
+ ASSERT_EQUAL(
195
+ std::numeric_limits<float>::epsilon(),
196
+ from_ruby<float>(rb_float_new(std::numeric_limits<float>::epsilon())));
197
+ }
198
+
199
+ TESTCASE(double_to_ruby)
200
+ {
201
+ ASSERT_EQUAL(Object(rb_float_new(0.0f)), to_ruby(0.0f));
202
+ ASSERT_EQUAL(Object(rb_float_new(-1.0f)), to_ruby(-1.0f));
203
+ ASSERT_EQUAL(Object(rb_float_new(1.0f)), to_ruby(1.0f));
204
+ ASSERT_EQUAL(Object(rb_float_new(0.5f)), to_ruby(0.5f));
205
+ ASSERT_EQUAL(
206
+ Object(rb_float_new(std::numeric_limits<double>::min())),
207
+ to_ruby(std::numeric_limits<double>::min()));
208
+ ASSERT_EQUAL(
209
+ Object(rb_float_new(std::numeric_limits<double>::max())),
210
+ to_ruby(std::numeric_limits<double>::max()));
211
+ ASSERT(
212
+ to_ruby(std::numeric_limits<double>::quiet_NaN()).call("nan?"));
213
+ ASSERT(
214
+ to_ruby(std::numeric_limits<double>::signaling_NaN()).call("nan?"));
215
+ ASSERT_EQUAL(
216
+ Object(rb_float_new(std::numeric_limits<double>::epsilon())),
217
+ to_ruby(std::numeric_limits<double>::epsilon()));
218
+ }
219
+
220
+ TESTCASE(double_from_ruby)
221
+ {
222
+ ASSERT_EQUAL(0.0f, from_ruby<double>(rb_float_new(0.0f)));
223
+ ASSERT_EQUAL(-1.0f, from_ruby<double>(rb_float_new(-1.0f)));
224
+ ASSERT_EQUAL(1.0f, from_ruby<double>(rb_float_new(1.0f)));
225
+ ASSERT_EQUAL(
226
+ std::numeric_limits<double>::min(),
227
+ from_ruby<double>(rb_float_new(std::numeric_limits<double>::min())));
228
+ ASSERT_EQUAL(
229
+ std::numeric_limits<double>::max(),
230
+ from_ruby<double>(rb_float_new(std::numeric_limits<double>::max())));
231
+ ASSERT(
232
+ isnan(from_ruby<double>(rb_float_new(std::numeric_limits<double>::quiet_NaN()))));
233
+ ASSERT(
234
+ isnan(from_ruby<double>(rb_float_new(std::numeric_limits<double>::signaling_NaN()))));
235
+ ASSERT_EQUAL(
236
+ std::numeric_limits<double>::epsilon(),
237
+ from_ruby<double>(rb_float_new(std::numeric_limits<double>::epsilon())));
238
+ }
239
+
240
+ TESTCASE(char_const_ptr_to_ruby)
241
+ {
242
+ ASSERT_EQUAL(String(""), to_ruby((char const *)""));
243
+ ASSERT_EQUAL(String("foo"), to_ruby((char const *)"foo"));
244
+ }
245
+
246
+ TESTCASE(char_const_ptr_from_ruby)
247
+ {
248
+ ASSERT_EQUAL("", from_ruby<char const *>(rb_str_new2("")));
249
+ ASSERT_EQUAL("foo", from_ruby<char const *>(rb_str_new2("foo")));
250
+ }
251
+
252
+ TESTCASE(std_string_to_ruby)
253
+ {
254
+ ASSERT_EQUAL(String(""), to_ruby(std::string("")));
255
+ ASSERT_EQUAL(String("foo"), to_ruby(std::string("foo")));
256
+ }
257
+
258
+ TESTCASE(std_string_from_ruby)
259
+ {
260
+ ASSERT_EQUAL(std::string(""), from_ruby<std::string>(rb_str_new2("")));
261
+ ASSERT_EQUAL(std::string("foo"), from_ruby<std::string>(rb_str_new2("foo")));
262
+ }
263
+
data/test/test_VM.cpp ADDED
@@ -0,0 +1,26 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/VM.hpp"
3
+ #include "rice/Object.hpp"
4
+ #include <memory>
5
+
6
+ using namespace Rice;
7
+
8
+ std::auto_ptr<VM> vm;
9
+
10
+ TESTSUITE(VM);
11
+
12
+ SETUP(VM)
13
+ {
14
+ std::vector<const char *> args;
15
+ args.push_back("test_VM");
16
+ args.push_back("-e");
17
+ args.push_back("puts \"HELLO\"");
18
+ vm.reset(new VM(args));
19
+ }
20
+
21
+ TESTCASE(create_object)
22
+ {
23
+ Object o;
24
+ o.call("to_s");
25
+ }
26
+
@@ -0,0 +1,97 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/global_function.hpp"
3
+
4
+ using namespace Rice;
5
+
6
+ TESTSUITE(GlobalFunction);
7
+
8
+ SETUP(GlobalFunction)
9
+ {
10
+ ruby_init();
11
+ }
12
+
13
+ namespace {
14
+
15
+ bool method_to_wrap_called = false;
16
+ void method_to_wrap(Object self) {
17
+ method_to_wrap_called = true;
18
+ }
19
+
20
+ int method_with_args_arg0;
21
+
22
+ void method_with_args(Object self, int arg) {
23
+ method_with_args_arg0 = arg;
24
+ }
25
+
26
+ }
27
+
28
+ TESTCASE(exposes_global_functions)
29
+ {
30
+ define_global_function("method_to_wrap", &method_to_wrap);
31
+ Module m = Module(rb_mKernel);
32
+ m.call("method_to_wrap");
33
+
34
+ ASSERT(method_to_wrap_called);
35
+ }
36
+
37
+ TESTCASE(exposes_global_functions_with_arguments)
38
+ {
39
+ define_global_function("method_with_args", &method_with_args);
40
+ Module m = Module(rb_mKernel);
41
+ m.call("method_with_args", 10);
42
+
43
+ ASSERT_EQUAL(10, method_with_args_arg0);
44
+ }
45
+
46
+ namespace
47
+ {
48
+ int defaults_method_one_arg1;
49
+ int defaults_method_one_arg2;
50
+ bool defaults_method_one_arg3 = false;
51
+
52
+ void defaults_method_one(int arg1, int arg2 = 3, bool arg3 = true)
53
+ {
54
+ defaults_method_one_arg1 = arg1;
55
+ defaults_method_one_arg2 = arg2;
56
+ defaults_method_one_arg3 = arg3;
57
+ }
58
+ }
59
+
60
+ TESTCASE(default_arguments_for_define_global_function)
61
+ {
62
+ define_global_function("foo", &defaults_method_one, (Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true));
63
+ Module m(rb_mKernel);
64
+
65
+ m.call("foo", 2);
66
+
67
+ ASSERT_EQUAL(2, defaults_method_one_arg1);
68
+ ASSERT_EQUAL(3, defaults_method_one_arg2);
69
+ ASSERT(defaults_method_one_arg3);
70
+
71
+ m.call("foo", 11, 10);
72
+
73
+ ASSERT_EQUAL(11, defaults_method_one_arg1);
74
+ ASSERT_EQUAL(10, defaults_method_one_arg2);
75
+ ASSERT(defaults_method_one_arg3);
76
+
77
+ m.call("foo", 22, 33, false);
78
+
79
+ ASSERT_EQUAL(22, defaults_method_one_arg1);
80
+ ASSERT_EQUAL(33, defaults_method_one_arg2);
81
+ ASSERT(!defaults_method_one_arg3);
82
+ }
83
+
84
+ namespace {
85
+ int the_one_default_arg = 0;
86
+ void method_with_one_default_arg(int num = 4) {
87
+ the_one_default_arg = num;
88
+ }
89
+ }
90
+
91
+ TESTCASE(single_default_argument)
92
+ {
93
+ define_global_function("foo", &method_with_one_default_arg, (Arg("num") = 4));
94
+ Module m(rb_mKernel);
95
+ m.call("foo");
96
+ ASSERT_EQUAL(4, the_one_default_arg);
97
+ }
data/test/test_rice.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'test/unit'
2
+ require 'rbconfig'
3
+
4
+ class RiceTest < Test::Unit::TestCase
5
+ # TODO: probably a better way to find this out...
6
+ VERBOSE = ARGV.include?('-v')
7
+
8
+ EXEEXT = Config::CONFIG['EXEEXT']
9
+ RUBY = Config::CONFIG['RUBY_INSTALL_NAME']
10
+
11
+ def test_unittest
12
+ run_external_test("./unittest#{EXEEXT}")
13
+ end
14
+
15
+ def test_vm_unittest
16
+ run_external_test("./vm_unittest#{EXEEXT}")
17
+ end
18
+
19
+ def test_vm_unittest
20
+ run_external_test("#{RUBY} test_multiple_extensions.rb")
21
+ end
22
+
23
+ def run_external_test(executable)
24
+ if VERBOSE then
25
+ system(executable)
26
+ else
27
+ result = `#{executable}`
28
+ if $? != 0 then
29
+ puts result
30
+ end
31
+ end
32
+ raise "Error: $?" if $? != 0
33
+ end
34
+ end
35
+
data/test/unittest.cpp ADDED
@@ -0,0 +1,136 @@
1
+ #include <iostream>
2
+ #include <map>
3
+ #include "unittest.hpp"
4
+
5
+ size_t assertions;
6
+
7
+ namespace
8
+ {
9
+
10
+ typedef std::map<std::string, Test_Suite> Test_Suites;
11
+ Test_Suite * last_test_suite;
12
+
13
+ Test_Suites & test_suites()
14
+ {
15
+ static Test_Suites test_suites;
16
+ return test_suites;
17
+ }
18
+
19
+ } // namespace
20
+
21
+ Test_Suite & test_suite()
22
+ {
23
+ return *last_test_suite;
24
+ }
25
+
26
+ void new_test_suite(std::string const & name)
27
+ {
28
+ test_suites()[name] = Test_Suite(name);
29
+ last_test_suite = &test_suites()[name];
30
+ }
31
+
32
+ std::ostream & operator<<(std::ostream & out, Failure const & failure)
33
+ {
34
+ out << "" << failure.test_suite_name_ << ":" << failure.test_case_name_ << ": " << failure.what_;
35
+ return out;
36
+ }
37
+
38
+ Test_Suite::
39
+ Test_Suite(std::string const & name)
40
+ : name_(name)
41
+ , setup_(0)
42
+ , teardown_(0)
43
+ {
44
+ }
45
+
46
+ void Test_Suite::
47
+ run(Test_Result & result)
48
+ {
49
+ for(Test_Cases::iterator it = test_cases_.begin(),
50
+ end = test_cases_.end();
51
+ it != end;
52
+ ++it)
53
+ {
54
+ try
55
+ {
56
+ std::cout << "" << name() << ":" << it->name() << " ";
57
+ std::cout.flush();
58
+ if(setup_)
59
+ {
60
+ setup_();
61
+ }
62
+ it->run();
63
+ std::cout << ".";
64
+ }
65
+ catch(Assertion_Failed const & ex)
66
+ {
67
+ std::cout << "F";
68
+ result.add_failure(Failure(name(), it->name(), ex.what()));
69
+ }
70
+ catch(std::exception const & ex)
71
+ {
72
+ std::cout << "E";
73
+ result.add_error(Failure(name(), it->name(), ex.what()));
74
+ }
75
+ catch(...)
76
+ {
77
+ std::cout << "E";
78
+ result.add_error(Failure(name(), it->name(), "Unknown exception"));
79
+ }
80
+ if(teardown_)
81
+ {
82
+ teardown_();
83
+ }
84
+ std::cout << std::endl;
85
+ }
86
+ }
87
+
88
+ int main()
89
+ {
90
+ Test_Result result;
91
+ size_t num_tests = 0;
92
+
93
+ for(Test_Suites::iterator it = test_suites().begin(),
94
+ end = test_suites().end();
95
+ it != end;
96
+ ++it)
97
+ {
98
+ it->second.run(result);
99
+ num_tests += it->second.size();
100
+ }
101
+
102
+ std::cout << std::endl;
103
+
104
+ std::cout << num_tests << " test(s), "
105
+ << assertions << " assertion(s), "
106
+ << result.errors().size() << " error(s), "
107
+ << result.failures().size() << " failure(s)"
108
+ << std::endl;
109
+
110
+ if(result.errors().size() > 0)
111
+ {
112
+ std::cout << std::endl << "Errors:" << std::endl;
113
+ for(std::vector<Failure>::const_iterator it = result.errors().begin(),
114
+ end = result.errors().end();
115
+ it != end;
116
+ ++it)
117
+ {
118
+ std::cout << *it << std::endl;
119
+ }
120
+ }
121
+
122
+ if(result.failures().size() > 0)
123
+ {
124
+ std::cout << std::endl << "Failures:" << std::endl;
125
+ for(std::vector<Failure>::const_iterator it = result.failures().begin(),
126
+ end = result.failures().end();
127
+ it != end;
128
+ ++it)
129
+ {
130
+ std::cout << *it << std::endl;
131
+ }
132
+ }
133
+
134
+ return result.errors().size() + result.failures().size();
135
+ }
136
+