rice-jdguyot 1.4.0.p1
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 +743 -0
- data/README +1119 -0
- data/README.mingw +8 -0
- data/Rakefile +33 -0
- data/aclocal.m4 +874 -0
- data/bootstrap +8 -0
- data/config.guess +1500 -0
- data/config.sub +1616 -0
- data/configure +7461 -0
- data/configure.ac +52 -0
- data/depcomp +584 -0
- data/doxygen.ac +314 -0
- data/doxygen.am +186 -0
- data/extconf.rb +34 -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.cpp +22 -0
- data/rice/Address_Registration_Guard.hpp +7 -0
- data/rice/Address_Registration_Guard.ipp +37 -0
- data/rice/Address_Registration_Guard_defn.hpp +75 -0
- data/rice/Allocation_Strategies.hpp +37 -0
- data/rice/Arg.hpp +8 -0
- data/rice/Arg_impl.hpp +127 -0
- data/rice/Arg_operators.cpp +21 -0
- data/rice/Arg_operators.hpp +19 -0
- data/rice/Array.hpp +220 -0
- data/rice/Array.ipp +263 -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 +6 -0
- data/rice/Class_defn.hpp +83 -0
- data/rice/Constructor.hpp +367 -0
- data/rice/Critical_Guard.hpp +40 -0
- data/rice/Critical_Guard.ipp +26 -0
- data/rice/Data_Object.hpp +8 -0
- data/rice/Data_Object.ipp +133 -0
- data/rice/Data_Object_defn.hpp +132 -0
- data/rice/Data_Type.cpp +54 -0
- data/rice/Data_Type.hpp +8 -0
- data/rice/Data_Type.ipp +365 -0
- data/rice/Data_Type_defn.hpp +261 -0
- data/rice/Data_Type_fwd.hpp +12 -0
- data/rice/Director.cpp +13 -0
- data/rice/Director.hpp +39 -0
- data/rice/Enum.hpp +117 -0
- data/rice/Enum.ipp +246 -0
- data/rice/Exception.cpp +59 -0
- data/rice/Exception.hpp +9 -0
- data/rice/Exception_Base.hpp +8 -0
- data/rice/Exception_Base.ipp +13 -0
- data/rice/Exception_Base_defn.hpp +27 -0
- data/rice/Exception_defn.hpp +69 -0
- data/rice/Hash.hpp +210 -0
- data/rice/Hash.ipp +338 -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 +130 -0
- data/rice/Makefile.in +716 -0
- data/rice/Module.cpp +84 -0
- data/rice/Module.hpp +8 -0
- data/rice/Module.ipp +6 -0
- data/rice/Module_defn.hpp +88 -0
- data/rice/Module_impl.hpp +281 -0
- data/rice/Module_impl.ipp +348 -0
- data/rice/Object.cpp +160 -0
- data/rice/Object.hpp +8 -0
- data/rice/Object.ipp +19 -0
- data/rice/Object_defn.hpp +191 -0
- data/rice/Require_Guard.hpp +21 -0
- data/rice/String.cpp +94 -0
- data/rice/String.hpp +89 -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 +92 -0
- data/rice/VM.hpp +32 -0
- data/rice/config.hpp +41 -0
- data/rice/config.hpp.in +40 -0
- data/rice/detail/Arguments.hpp +118 -0
- data/rice/detail/Auto_Function_Wrapper.hpp +829 -0
- data/rice/detail/Auto_Function_Wrapper.ipp +3391 -0
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +828 -0
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +2503 -0
- data/rice/detail/Caster.hpp +103 -0
- data/rice/detail/Exception_Handler.hpp +8 -0
- data/rice/detail/Exception_Handler.ipp +68 -0
- data/rice/detail/Exception_Handler_defn.hpp +96 -0
- data/rice/detail/Iterator.hpp +93 -0
- data/rice/detail/Not_Copyable.hpp +25 -0
- data/rice/detail/Wrapped_Function.hpp +33 -0
- data/rice/detail/cfp.hpp +24 -0
- data/rice/detail/cfp.ipp +51 -0
- data/rice/detail/check_ruby_type.cpp +27 -0
- data/rice/detail/check_ruby_type.hpp +23 -0
- data/rice/detail/creation_funcs.hpp +37 -0
- data/rice/detail/creation_funcs.ipp +36 -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 +31 -0
- data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
- data/rice/detail/demangle.cpp +56 -0
- data/rice/detail/demangle.hpp +19 -0
- data/rice/detail/env.hpp +19 -0
- data/rice/detail/from_ruby.hpp +43 -0
- data/rice/detail/from_ruby.ipp +60 -0
- data/rice/detail/method_data.cpp +159 -0
- data/rice/detail/method_data.hpp +21 -0
- data/rice/detail/mininode.cpp +1220 -0
- data/rice/detail/mininode.hpp +320 -0
- data/rice/detail/node.hpp +13 -0
- data/rice/detail/object_call.hpp +68 -0
- data/rice/detail/object_call.ipp +131 -0
- data/rice/detail/protect.cpp +29 -0
- data/rice/detail/protect.hpp +34 -0
- data/rice/detail/ruby.hpp +93 -0
- data/rice/detail/ruby_version_code.hpp +6 -0
- data/rice/detail/ruby_version_code.hpp.in +6 -0
- data/rice/detail/rubysig.hpp +19 -0
- data/rice/detail/st.hpp +60 -0
- data/rice/detail/to_ruby.hpp +22 -0
- data/rice/detail/to_ruby.ipp +36 -0
- data/rice/detail/traits.hpp +43 -0
- data/rice/detail/win32.hpp +16 -0
- data/rice/detail/wrap_function.hpp +341 -0
- data/rice/detail/wrap_function.ipp +514 -0
- data/rice/global_function.hpp +33 -0
- data/rice/global_function.ipp +22 -0
- data/rice/protect.hpp +91 -0
- data/rice/protect.ipp +1133 -0
- data/rice/ruby_mark.hpp +13 -0
- data/rice/ruby_try_catch.hpp +86 -0
- data/rice/rubypp.rb +97 -0
- data/rice/to_from_ruby.hpp +8 -0
- data/rice/to_from_ruby.ipp +294 -0
- data/rice/to_from_ruby_defn.hpp +71 -0
- data/ruby/Makefile.am +1 -0
- data/ruby/Makefile.in +497 -0
- data/ruby/lib/Makefile.am +3 -0
- data/ruby/lib/Makefile.in +373 -0
- data/ruby/lib/mkmf-rice.rb.in +216 -0
- data/ruby/lib/version.rb +3 -0
- data/ruby.ac +136 -0
- data/sample/Makefile.am +47 -0
- data/sample/Makefile.in +379 -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 +78 -0
- data/test/Makefile.in +728 -0
- data/test/ext/Makefile.am +43 -0
- data/test/ext/Makefile.in +375 -0
- data/test/ext/t1/Foo.hpp +10 -0
- data/test/ext/t1/extconf.rb +2 -0
- data/test/ext/t1/t1.cpp +15 -0
- data/test/ext/t2/extconf.rb +2 -0
- data/test/ext/t2/t2.cpp +11 -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 +498 -0
- data/test/test_Constructor.cpp +128 -0
- data/test/test_Critical_Guard.cpp +51 -0
- data/test/test_Data_Object.cpp +275 -0
- data/test/test_Data_Type.cpp +348 -0
- data/test/test_Director.cpp +301 -0
- data/test/test_Enum.cpp +195 -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_Memory_Management.cpp +50 -0
- data/test/test_Module.cpp +481 -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 +277 -0
- data/test/test_VM.cpp +26 -0
- data/test/test_global_functions.cpp +114 -0
- data/test/test_rice.rb +43 -0
- data/test/unittest.cpp +136 -0
- data/test/unittest.hpp +292 -0
- metadata +289 -0
@@ -0,0 +1,277 @@
|
|
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
|
+
std::isnan(from_ruby<float>(rb_float_new(std::numeric_limits<float>::quiet_NaN()))));
|
192
|
+
ASSERT(
|
193
|
+
std::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
|
+
std::isnan(from_ruby<double>(rb_float_new(std::numeric_limits<double>::quiet_NaN()))));
|
233
|
+
ASSERT(
|
234
|
+
std::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
|
+
|
264
|
+
TESTCASE(std_string_to_ruby_with_binary)
|
265
|
+
{
|
266
|
+
Rice::String got = to_ruby(std::string("\000test", 5));
|
267
|
+
|
268
|
+
ASSERT_EQUAL(String(std::string("\000test", 5)), got);
|
269
|
+
ASSERT_EQUAL(5, got.length());
|
270
|
+
}
|
271
|
+
|
272
|
+
TESTCASE(std_string_from_ruby_with_binary)
|
273
|
+
{
|
274
|
+
std::string got = from_ruby<std::string>(rb_str_new("\000test", 5));
|
275
|
+
ASSERT_EQUAL(5, got.length());
|
276
|
+
ASSERT_EQUAL(std::string("\000test", 5), got);
|
277
|
+
}
|
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,114 @@
|
|
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
|
+
int defaults_returns(int arg1, int arg2 = 3)
|
60
|
+
{
|
61
|
+
return arg1 * arg2;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
TESTCASE(default_arguments_for_define_global_function)
|
66
|
+
{
|
67
|
+
define_global_function("foo", &defaults_method_one, (Arg("arg1"), Arg("arg2") = (int)3, Arg("arg3") = (bool)true));
|
68
|
+
Module m(rb_mKernel);
|
69
|
+
|
70
|
+
m.call("foo", 2);
|
71
|
+
|
72
|
+
ASSERT_EQUAL(2, defaults_method_one_arg1);
|
73
|
+
ASSERT_EQUAL(3, defaults_method_one_arg2);
|
74
|
+
ASSERT(defaults_method_one_arg3);
|
75
|
+
|
76
|
+
m.call("foo", 11, 10);
|
77
|
+
|
78
|
+
ASSERT_EQUAL(11, defaults_method_one_arg1);
|
79
|
+
ASSERT_EQUAL(10, defaults_method_one_arg2);
|
80
|
+
ASSERT(defaults_method_one_arg3);
|
81
|
+
|
82
|
+
m.call("foo", 22, 33, false);
|
83
|
+
|
84
|
+
ASSERT_EQUAL(22, defaults_method_one_arg1);
|
85
|
+
ASSERT_EQUAL(33, defaults_method_one_arg2);
|
86
|
+
ASSERT(!defaults_method_one_arg3);
|
87
|
+
}
|
88
|
+
|
89
|
+
TESTCASE(default_arguments_for_define_global_function_and_returning)
|
90
|
+
{
|
91
|
+
define_global_function("foo_ret", &defaults_returns, (Arg("arg1"), Arg("arg2") = (int)3));
|
92
|
+
Module m(rb_mKernel);
|
93
|
+
|
94
|
+
Object o = m.call("foo_ret", 2);
|
95
|
+
ASSERT_EQUAL(INT2NUM(6), o.value());
|
96
|
+
|
97
|
+
o = m.call("foo_ret", 5, 10);
|
98
|
+
ASSERT_EQUAL(INT2NUM(50), o.value());
|
99
|
+
}
|
100
|
+
|
101
|
+
namespace {
|
102
|
+
int the_one_default_arg = 0;
|
103
|
+
void method_with_one_default_arg(int num = 4) {
|
104
|
+
the_one_default_arg = num;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
TESTCASE(single_default_argument)
|
109
|
+
{
|
110
|
+
define_global_function("foo", &method_with_one_default_arg, (Arg("num") = (int)4));
|
111
|
+
Module m(rb_mKernel);
|
112
|
+
m.call("foo");
|
113
|
+
ASSERT_EQUAL(4, the_one_default_arg);
|
114
|
+
}
|
data/test/test_rice.rb
ADDED
@@ -0,0 +1,43 @@
|
|
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_multiple_extensions
|
20
|
+
run_external_test("#{RUBY} test_multiple_extensions.rb")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_multiple_extensions_with_inheritance
|
24
|
+
run_external_test("#{RUBY} test_multiple_extensions_with_inheritance.rb")
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_multiple_extensions_same_class
|
28
|
+
run_external_test("#{RUBY} test_multiple_extensions_same_class.rb")
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_external_test(executable)
|
32
|
+
if VERBOSE then
|
33
|
+
system(executable)
|
34
|
+
else
|
35
|
+
result = `#{executable}`
|
36
|
+
if $? != 0 then
|
37
|
+
puts result
|
38
|
+
end
|
39
|
+
end
|
40
|
+
raise "Error: $?" if $? != 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|