rice 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +23 -0
- data/Doxyfile +1253 -0
- data/Makefile.am +26 -0
- data/Makefile.in +736 -0
- data/README +881 -0
- data/README.mingw +8 -0
- data/bootstrap +8 -0
- data/config.guess +1535 -0
- data/config.sub +1644 -0
- data/configure +7310 -0
- data/configure.ac +48 -0
- data/depcomp +584 -0
- data/doxygen.ac +314 -0
- data/doxygen.am +186 -0
- data/install-sh +507 -0
- data/missing +367 -0
- data/post-autoconf.rb +22 -0
- data/post-automake.rb +28 -0
- data/rice/Address_Registration_Guard.hpp +7 -0
- data/rice/Address_Registration_Guard.ipp +34 -0
- data/rice/Address_Registration_Guard_defn.hpp +65 -0
- data/rice/Allocation_Strategies.hpp +37 -0
- data/rice/Array.hpp +220 -0
- data/rice/Array.ipp +262 -0
- data/rice/Builtin_Object.hpp +8 -0
- data/rice/Builtin_Object.ipp +50 -0
- data/rice/Builtin_Object_defn.hpp +51 -0
- data/rice/Class.cpp +57 -0
- data/rice/Class.hpp +8 -0
- data/rice/Class.ipp +4 -0
- data/rice/Class_defn.hpp +83 -0
- data/rice/Constructor.hpp +189 -0
- data/rice/Critical_Guard.hpp +34 -0
- data/rice/Critical_Guard.ipp +20 -0
- data/rice/Data_Object.hpp +127 -0
- data/rice/Data_Object.ipp +129 -0
- data/rice/Data_Type.cpp +21 -0
- data/rice/Data_Type.hpp +8 -0
- data/rice/Data_Type.ipp +227 -0
- data/rice/Data_Type_defn.hpp +219 -0
- data/rice/Data_Type_fwd.hpp +12 -0
- data/rice/Enum.hpp +118 -0
- data/rice/Enum.ipp +246 -0
- data/rice/Exception.cpp +59 -0
- data/rice/Exception.hpp +69 -0
- data/rice/Exception_Base.hpp +30 -0
- data/rice/Exception_Base.ipp +11 -0
- data/rice/Hash.hpp +206 -0
- data/rice/Hash.ipp +336 -0
- data/rice/Identifier.cpp +8 -0
- data/rice/Identifier.hpp +50 -0
- data/rice/Identifier.ipp +33 -0
- data/rice/Jump_Tag.hpp +24 -0
- data/rice/Makefile.am +112 -0
- data/rice/Makefile.in +675 -0
- data/rice/Module.cpp +75 -0
- data/rice/Module.hpp +8 -0
- data/rice/Module.ipp +6 -0
- data/rice/Module_defn.hpp +87 -0
- data/rice/Module_impl.hpp +237 -0
- data/rice/Module_impl.ipp +302 -0
- data/rice/Object.cpp +153 -0
- data/rice/Object.hpp +8 -0
- data/rice/Object.ipp +19 -0
- data/rice/Object_defn.hpp +183 -0
- data/rice/Require_Guard.hpp +21 -0
- data/rice/String.cpp +93 -0
- data/rice/String.hpp +88 -0
- data/rice/Struct.cpp +117 -0
- data/rice/Struct.hpp +162 -0
- data/rice/Struct.ipp +26 -0
- data/rice/Symbol.cpp +25 -0
- data/rice/Symbol.hpp +66 -0
- data/rice/Symbol.ipp +44 -0
- data/rice/VM.cpp +79 -0
- data/rice/VM.hpp +27 -0
- data/rice/config.hpp +23 -0
- data/rice/config.hpp.in +22 -0
- data/rice/detail/Auto_Function_Wrapper.hpp +719 -0
- data/rice/detail/Auto_Function_Wrapper.ipp +1354 -0
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +685 -0
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +1435 -0
- data/rice/detail/Caster.hpp +61 -0
- data/rice/detail/Exception_Handler.hpp +118 -0
- data/rice/detail/Iterator_Definer.hpp +98 -0
- data/rice/detail/Not_Copyable.hpp +25 -0
- data/rice/detail/Wrapped_Function.hpp +33 -0
- data/rice/detail/check_ruby_type.cpp +21 -0
- data/rice/detail/check_ruby_type.hpp +23 -0
- data/rice/detail/creation_funcs.hpp +45 -0
- data/rice/detail/creation_funcs.ipp +62 -0
- data/rice/detail/default_allocation_func.hpp +23 -0
- data/rice/detail/default_allocation_func.ipp +11 -0
- data/rice/detail/define_method_and_auto_wrap.hpp +27 -0
- data/rice/detail/define_method_and_auto_wrap.ipp +20 -0
- data/rice/detail/env.hpp +13 -0
- data/rice/detail/from_ruby.hpp +43 -0
- data/rice/detail/from_ruby.ipp +74 -0
- data/rice/detail/method_data.cpp +105 -0
- data/rice/detail/method_data.hpp +33 -0
- data/rice/detail/node.hpp +13 -0
- data/rice/detail/object_call.hpp +85 -0
- data/rice/detail/object_call.ipp +147 -0
- data/rice/detail/protect.cpp +27 -0
- data/rice/detail/protect.hpp +34 -0
- data/rice/detail/remove_const.hpp +21 -0
- data/rice/detail/ruby.hpp +85 -0
- data/rice/detail/rubysig.hpp +13 -0
- data/rice/detail/st.hpp +56 -0
- data/rice/detail/to_ruby.hpp +16 -0
- data/rice/detail/to_ruby.ipp +10 -0
- data/rice/detail/win32.hpp +16 -0
- data/rice/detail/wrap_function.hpp +288 -0
- data/rice/detail/wrap_function.ipp +473 -0
- data/rice/generate_code.rb +1092 -0
- data/rice/global_function.hpp +16 -0
- data/rice/global_function.ipp +11 -0
- data/rice/protect.hpp +91 -0
- data/rice/protect.ipp +803 -0
- data/rice/ruby_try_catch.hpp +86 -0
- data/rice/to_from_ruby.hpp +8 -0
- data/rice/to_from_ruby.ipp +299 -0
- data/rice/to_from_ruby_defn.hpp +71 -0
- data/ruby.ac +105 -0
- data/ruby/Makefile.am +1 -0
- data/ruby/Makefile.in +493 -0
- data/ruby/lib/Makefile.am +3 -0
- data/ruby/lib/Makefile.in +369 -0
- data/ruby/lib/mkmf-rice.rb.in +199 -0
- data/sample/Makefile.am +47 -0
- data/sample/Makefile.in +375 -0
- data/sample/enum/extconf.rb +3 -0
- data/sample/enum/sample_enum.cpp +54 -0
- data/sample/enum/test.rb +8 -0
- data/sample/inheritance/animals.cpp +98 -0
- data/sample/inheritance/extconf.rb +3 -0
- data/sample/inheritance/test.rb +7 -0
- data/sample/map/extconf.rb +3 -0
- data/sample/map/map.cpp +81 -0
- data/sample/map/test.rb +7 -0
- data/test/Makefile.am +44 -0
- data/test/Makefile.in +575 -0
- data/test/test_Address_Registration_Guard.cpp +43 -0
- data/test/test_Allocation_Strategies.cpp +77 -0
- data/test/test_Array.cpp +241 -0
- data/test/test_Builtin_Object.cpp +72 -0
- data/test/test_Class.cpp +350 -0
- data/test/test_Constructor.cpp +30 -0
- data/test/test_Critical_Guard.cpp +47 -0
- data/test/test_Data_Object.cpp +235 -0
- data/test/test_Enum.cpp +162 -0
- data/test/test_Exception.cpp +46 -0
- data/test/test_Hash.cpp +195 -0
- data/test/test_Identifier.cpp +70 -0
- data/test/test_Jump_Tag.cpp +17 -0
- data/test/test_Module.cpp +253 -0
- data/test/test_Object.cpp +148 -0
- data/test/test_String.cpp +94 -0
- data/test/test_Struct.cpp +192 -0
- data/test/test_Symbol.cpp +63 -0
- data/test/test_To_From_Ruby.cpp +281 -0
- data/test/test_VM.cpp +26 -0
- data/test/test_rice.rb +30 -0
- data/test/unittest.cpp +136 -0
- data/test/unittest.hpp +292 -0
- metadata +209 -0
@@ -0,0 +1,281 @@
|
|
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
|
+
INT2NUM(FIXNUM_MAX),
|
35
|
+
to_ruby(FIXNUM_MAX).value());
|
36
|
+
ASSERT_EQUAL(
|
37
|
+
INT2NUM(FIXNUM_MIN),
|
38
|
+
to_ruby(FIXNUM_MIN).value());
|
39
|
+
ASSERT_EQUAL(
|
40
|
+
Object(INT2NUM(std::numeric_limits<int>::min())),
|
41
|
+
to_ruby(std::numeric_limits<int>::min()));
|
42
|
+
ASSERT_EQUAL(
|
43
|
+
Object(INT2NUM(std::numeric_limits<int>::max())),
|
44
|
+
to_ruby(std::numeric_limits<int>::max()));
|
45
|
+
}
|
46
|
+
|
47
|
+
TESTCASE(int_from_ruby)
|
48
|
+
{
|
49
|
+
ASSERT_EQUAL(0, from_ruby<int>(INT2NUM(0)));
|
50
|
+
ASSERT_EQUAL(-1, from_ruby<int>(INT2NUM(-1)));
|
51
|
+
ASSERT_EQUAL(1, from_ruby<int>(INT2NUM(1)));
|
52
|
+
ASSERT_EQUAL(
|
53
|
+
FIXNUM_MIN,
|
54
|
+
from_ruby<int>(INT2NUM(FIXNUM_MIN)));
|
55
|
+
ASSERT_EQUAL(
|
56
|
+
FIXNUM_MAX,
|
57
|
+
from_ruby<int>(INT2NUM(FIXNUM_MAX)));
|
58
|
+
ASSERT_EQUAL(
|
59
|
+
std::numeric_limits<int>::min(),
|
60
|
+
from_ruby<int>(INT2NUM(std::numeric_limits<int>::min())));
|
61
|
+
ASSERT_EQUAL(
|
62
|
+
std::numeric_limits<int>::max(),
|
63
|
+
from_ruby<int>(INT2NUM(std::numeric_limits<int>::max())));
|
64
|
+
}
|
65
|
+
|
66
|
+
TESTCASE(long_to_ruby)
|
67
|
+
{
|
68
|
+
ASSERT_EQUAL(LONG2NUM(0), to_ruby((long)0).value());
|
69
|
+
ASSERT_EQUAL(LONG2NUM(-1), to_ruby((long)-1).value());
|
70
|
+
ASSERT_EQUAL(LONG2NUM(1), to_ruby((long)1).value());
|
71
|
+
ASSERT_EQUAL(
|
72
|
+
LONG2NUM(FIXNUM_MAX),
|
73
|
+
to_ruby(FIXNUM_MAX).value());
|
74
|
+
ASSERT_EQUAL(
|
75
|
+
LONG2NUM(FIXNUM_MIN),
|
76
|
+
to_ruby(FIXNUM_MIN).value());
|
77
|
+
ASSERT_EQUAL(
|
78
|
+
Object(LONG2NUM(std::numeric_limits<long>::min())),
|
79
|
+
to_ruby(std::numeric_limits<long>::min()));
|
80
|
+
ASSERT_EQUAL(
|
81
|
+
Object(LONG2NUM(std::numeric_limits<long>::max())),
|
82
|
+
to_ruby(std::numeric_limits<long>::max()));
|
83
|
+
}
|
84
|
+
|
85
|
+
TESTCASE(long_from_ruby)
|
86
|
+
{
|
87
|
+
ASSERT_EQUAL(0, from_ruby<long>(LONG2NUM(0)));
|
88
|
+
ASSERT_EQUAL(-1, from_ruby<long>(LONG2NUM(-1)));
|
89
|
+
ASSERT_EQUAL(1, from_ruby<long>(LONG2NUM(1)));
|
90
|
+
ASSERT_EQUAL(
|
91
|
+
FIXNUM_MIN,
|
92
|
+
from_ruby<long>(LONG2NUM(FIXNUM_MIN)));
|
93
|
+
ASSERT_EQUAL(
|
94
|
+
FIXNUM_MAX,
|
95
|
+
from_ruby<long>(LONG2NUM(FIXNUM_MAX)));
|
96
|
+
ASSERT_EQUAL(
|
97
|
+
std::numeric_limits<long>::min(),
|
98
|
+
from_ruby<long>(LONG2NUM(std::numeric_limits<long>::min())));
|
99
|
+
ASSERT_EQUAL(
|
100
|
+
std::numeric_limits<long>::max(),
|
101
|
+
from_ruby<long>(LONG2NUM(std::numeric_limits<long>::max())));
|
102
|
+
}
|
103
|
+
|
104
|
+
TESTCASE(unsigned_int_to_ruby)
|
105
|
+
{
|
106
|
+
ASSERT_EQUAL(UINT2NUM(0), to_ruby((unsigned int)0).value());
|
107
|
+
ASSERT_EQUAL(UINT2NUM(1), to_ruby((unsigned int)1).value());
|
108
|
+
ASSERT_EQUAL(
|
109
|
+
UINT2NUM(FIXNUM_MAX),
|
110
|
+
to_ruby(FIXNUM_MAX).value());
|
111
|
+
ASSERT_EQUAL(
|
112
|
+
Object(UINT2NUM(std::numeric_limits<unsigned int>::min())),
|
113
|
+
to_ruby(std::numeric_limits<unsigned int>::min()));
|
114
|
+
ASSERT_EQUAL(
|
115
|
+
Object(UINT2NUM(std::numeric_limits<unsigned int>::max())),
|
116
|
+
to_ruby(std::numeric_limits<unsigned int>::max()));
|
117
|
+
}
|
118
|
+
|
119
|
+
TESTCASE(unsigned_int_from_ruby)
|
120
|
+
{
|
121
|
+
ASSERT_EQUAL(0u, from_ruby<unsigned int>(UINT2NUM(0)));
|
122
|
+
ASSERT_EQUAL(1u, from_ruby<unsigned int>(UINT2NUM(1)));
|
123
|
+
ASSERT_EQUAL(
|
124
|
+
static_cast<unsigned int>(FIXNUM_MIN),
|
125
|
+
from_ruby<unsigned int>(UINT2NUM(FIXNUM_MIN)));
|
126
|
+
ASSERT_EQUAL(
|
127
|
+
std::numeric_limits<unsigned int>::min(),
|
128
|
+
from_ruby<unsigned int>(UINT2NUM(std::numeric_limits<unsigned int>::min())));
|
129
|
+
ASSERT_EQUAL(
|
130
|
+
std::numeric_limits<unsigned int>::max(),
|
131
|
+
from_ruby<unsigned int>(UINT2NUM(std::numeric_limits<unsigned int>::max())));
|
132
|
+
}
|
133
|
+
|
134
|
+
TESTCASE(unsigned_long_to_ruby)
|
135
|
+
{
|
136
|
+
ASSERT_EQUAL(ULONG2NUM(0), to_ruby((unsigned long)0).value());
|
137
|
+
ASSERT_EQUAL(ULONG2NUM(1), to_ruby((unsigned long)1).value());
|
138
|
+
ASSERT_EQUAL(
|
139
|
+
ULONG2NUM(FIXNUM_MAX),
|
140
|
+
to_ruby(FIXNUM_MAX).value());
|
141
|
+
ASSERT_EQUAL(
|
142
|
+
Object(ULONG2NUM(std::numeric_limits<unsigned long>::min())),
|
143
|
+
to_ruby(std::numeric_limits<unsigned long>::min()));
|
144
|
+
ASSERT_EQUAL(
|
145
|
+
Object(ULONG2NUM(std::numeric_limits<unsigned long>::max())),
|
146
|
+
to_ruby(std::numeric_limits<unsigned long>::max()));
|
147
|
+
}
|
148
|
+
|
149
|
+
TESTCASE(unsigned_long_from_ruby)
|
150
|
+
{
|
151
|
+
ASSERT_EQUAL(0u, from_ruby<unsigned long>(ULONG2NUM(0)));
|
152
|
+
ASSERT_EQUAL(1u, from_ruby<unsigned long>(ULONG2NUM(1)));
|
153
|
+
ASSERT_EQUAL(
|
154
|
+
static_cast<unsigned long>(FIXNUM_MIN),
|
155
|
+
from_ruby<unsigned long>(ULONG2NUM(FIXNUM_MIN)));
|
156
|
+
ASSERT_EQUAL(
|
157
|
+
std::numeric_limits<unsigned long>::min(),
|
158
|
+
from_ruby<unsigned long>(ULONG2NUM(std::numeric_limits<unsigned long>::min())));
|
159
|
+
ASSERT_EQUAL(
|
160
|
+
std::numeric_limits<unsigned long>::max(),
|
161
|
+
from_ruby<unsigned long>(ULONG2NUM(std::numeric_limits<unsigned long>::max())));
|
162
|
+
}
|
163
|
+
|
164
|
+
TESTCASE(bool_to_ruby)
|
165
|
+
{
|
166
|
+
ASSERT_EQUAL(Qfalse, to_ruby(false).value());
|
167
|
+
ASSERT_EQUAL(Qtrue, to_ruby(true).value());
|
168
|
+
}
|
169
|
+
|
170
|
+
TESTCASE(bool_from_ruby)
|
171
|
+
{
|
172
|
+
ASSERT_EQUAL(false, from_ruby<bool>(Object(Qfalse)));
|
173
|
+
ASSERT_EQUAL(true, from_ruby<bool>(Object(Qtrue)));
|
174
|
+
}
|
175
|
+
|
176
|
+
TESTCASE(float_to_ruby)
|
177
|
+
{
|
178
|
+
ASSERT_EQUAL(Object(rb_float_new(0.0f)), to_ruby(0.0f));
|
179
|
+
ASSERT_EQUAL(Object(rb_float_new(-1.0f)), to_ruby(-1.0f));
|
180
|
+
ASSERT_EQUAL(Object(rb_float_new(1.0f)), to_ruby(1.0f));
|
181
|
+
ASSERT_EQUAL(Object(rb_float_new(0.5f)), to_ruby(0.5f));
|
182
|
+
ASSERT_EQUAL(
|
183
|
+
Object(rb_float_new(std::numeric_limits<float>::min())),
|
184
|
+
to_ruby(std::numeric_limits<float>::min()));
|
185
|
+
ASSERT_EQUAL(
|
186
|
+
Object(rb_float_new(std::numeric_limits<float>::max())),
|
187
|
+
to_ruby(std::numeric_limits<float>::max()));
|
188
|
+
ASSERT(
|
189
|
+
to_ruby(std::numeric_limits<float>::quiet_NaN()).call("nan?"));
|
190
|
+
ASSERT(
|
191
|
+
to_ruby(std::numeric_limits<float>::signaling_NaN()).call("nan?"));
|
192
|
+
ASSERT_EQUAL(
|
193
|
+
Object(rb_float_new(std::numeric_limits<float>::epsilon())),
|
194
|
+
to_ruby(std::numeric_limits<float>::epsilon()));
|
195
|
+
}
|
196
|
+
|
197
|
+
TESTCASE(float_from_ruby)
|
198
|
+
{
|
199
|
+
ASSERT_EQUAL(0.0f, from_ruby<float>(rb_float_new(0.0f)));
|
200
|
+
ASSERT_EQUAL(-1.0f, from_ruby<float>(rb_float_new(-1.0f)));
|
201
|
+
ASSERT_EQUAL(1.0f, from_ruby<float>(rb_float_new(1.0f)));
|
202
|
+
ASSERT_EQUAL(
|
203
|
+
std::numeric_limits<float>::min(),
|
204
|
+
from_ruby<float>(rb_float_new(std::numeric_limits<float>::min())));
|
205
|
+
ASSERT_EQUAL(
|
206
|
+
std::numeric_limits<float>::max(),
|
207
|
+
from_ruby<float>(rb_float_new(std::numeric_limits<float>::max())));
|
208
|
+
ASSERT(
|
209
|
+
isnan(from_ruby<float>(rb_float_new(std::numeric_limits<float>::quiet_NaN()))));
|
210
|
+
ASSERT(
|
211
|
+
isnan(from_ruby<float>(rb_float_new(std::numeric_limits<float>::signaling_NaN()))));
|
212
|
+
ASSERT_EQUAL(
|
213
|
+
std::numeric_limits<float>::epsilon(),
|
214
|
+
from_ruby<float>(rb_float_new(std::numeric_limits<float>::epsilon())));
|
215
|
+
}
|
216
|
+
|
217
|
+
TESTCASE(double_to_ruby)
|
218
|
+
{
|
219
|
+
ASSERT_EQUAL(Object(rb_float_new(0.0f)), to_ruby(0.0f));
|
220
|
+
ASSERT_EQUAL(Object(rb_float_new(-1.0f)), to_ruby(-1.0f));
|
221
|
+
ASSERT_EQUAL(Object(rb_float_new(1.0f)), to_ruby(1.0f));
|
222
|
+
ASSERT_EQUAL(Object(rb_float_new(0.5f)), to_ruby(0.5f));
|
223
|
+
ASSERT_EQUAL(
|
224
|
+
Object(rb_float_new(std::numeric_limits<double>::min())),
|
225
|
+
to_ruby(std::numeric_limits<double>::min()));
|
226
|
+
ASSERT_EQUAL(
|
227
|
+
Object(rb_float_new(std::numeric_limits<double>::max())),
|
228
|
+
to_ruby(std::numeric_limits<double>::max()));
|
229
|
+
ASSERT(
|
230
|
+
to_ruby(std::numeric_limits<double>::quiet_NaN()).call("nan?"));
|
231
|
+
ASSERT(
|
232
|
+
to_ruby(std::numeric_limits<double>::signaling_NaN()).call("nan?"));
|
233
|
+
ASSERT_EQUAL(
|
234
|
+
Object(rb_float_new(std::numeric_limits<double>::epsilon())),
|
235
|
+
to_ruby(std::numeric_limits<double>::epsilon()));
|
236
|
+
}
|
237
|
+
|
238
|
+
TESTCASE(double_from_ruby)
|
239
|
+
{
|
240
|
+
ASSERT_EQUAL(0.0f, from_ruby<double>(rb_float_new(0.0f)));
|
241
|
+
ASSERT_EQUAL(-1.0f, from_ruby<double>(rb_float_new(-1.0f)));
|
242
|
+
ASSERT_EQUAL(1.0f, from_ruby<double>(rb_float_new(1.0f)));
|
243
|
+
ASSERT_EQUAL(
|
244
|
+
std::numeric_limits<double>::min(),
|
245
|
+
from_ruby<double>(rb_float_new(std::numeric_limits<double>::min())));
|
246
|
+
ASSERT_EQUAL(
|
247
|
+
std::numeric_limits<double>::max(),
|
248
|
+
from_ruby<double>(rb_float_new(std::numeric_limits<double>::max())));
|
249
|
+
ASSERT(
|
250
|
+
isnan(from_ruby<double>(rb_float_new(std::numeric_limits<double>::quiet_NaN()))));
|
251
|
+
ASSERT(
|
252
|
+
isnan(from_ruby<double>(rb_float_new(std::numeric_limits<double>::signaling_NaN()))));
|
253
|
+
ASSERT_EQUAL(
|
254
|
+
std::numeric_limits<double>::epsilon(),
|
255
|
+
from_ruby<double>(rb_float_new(std::numeric_limits<double>::epsilon())));
|
256
|
+
}
|
257
|
+
|
258
|
+
TESTCASE(char_const_ptr_to_ruby)
|
259
|
+
{
|
260
|
+
ASSERT_EQUAL(String(""), to_ruby((char const *)""));
|
261
|
+
ASSERT_EQUAL(String("foo"), to_ruby((char const *)"foo"));
|
262
|
+
}
|
263
|
+
|
264
|
+
TESTCASE(char_const_ptr_from_ruby)
|
265
|
+
{
|
266
|
+
ASSERT_EQUAL("", from_ruby<char const *>(rb_str_new2("")));
|
267
|
+
ASSERT_EQUAL("foo", from_ruby<char const *>(rb_str_new2("foo")));
|
268
|
+
}
|
269
|
+
|
270
|
+
TESTCASE(std_string_to_ruby)
|
271
|
+
{
|
272
|
+
ASSERT_EQUAL(String(""), to_ruby(std::string("")));
|
273
|
+
ASSERT_EQUAL(String("foo"), to_ruby(std::string("foo")));
|
274
|
+
}
|
275
|
+
|
276
|
+
TESTCASE(std_string_from_ruby)
|
277
|
+
{
|
278
|
+
ASSERT_EQUAL(std::string(""), from_ruby<std::string>(rb_str_new2("")));
|
279
|
+
ASSERT_EQUAL(std::string("foo"), from_ruby<std::string>(rb_str_new2("foo")));
|
280
|
+
}
|
281
|
+
|
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<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
|
+
|
data/test/test_rice.rb
ADDED
@@ -0,0 +1,30 @@
|
|
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
|
+
|
10
|
+
def test_unittest
|
11
|
+
run_external_test("./unittest#{EXEEXT}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_vm_unittest
|
15
|
+
run_external_test("./vm_unittest#{EXEEXT}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def run_external_test(executable)
|
19
|
+
if VERBOSE then
|
20
|
+
system(executable)
|
21
|
+
else
|
22
|
+
result = `#{executable}`
|
23
|
+
if $? != 0 then
|
24
|
+
puts result
|
25
|
+
end
|
26
|
+
end
|
27
|
+
raise "Error: $?" if $? != 0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
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
|
+
|