rice 4.3.3 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +86 -26
- data/CMakeLists.txt +31 -0
- data/CMakePresets.json +75 -0
- data/COPYING +3 -2
- data/FindRuby.cmake +437 -0
- data/README.md +7 -2
- data/Rakefile +12 -5
- data/include/rice/rice.hpp +9522 -4426
- data/include/rice/stl.hpp +2831 -1198
- data/lib/make_rice_headers.rb +79 -0
- data/lib/mkmf-rice.rb +40 -94
- data/lib/rice/version.rb +3 -0
- data/lib/rice.rb +1 -0
- data/lib/rubygems/builder.rb +11 -0
- data/lib/rubygems/cmake_builder.rb +113 -0
- data/lib/rubygems_plugin.rb +9 -0
- data/rice/Address_Registration_Guard.hpp +72 -3
- data/rice/Arg.hpp +26 -6
- data/rice/Arg.ipp +35 -2
- data/rice/Buffer.hpp +123 -0
- data/rice/Buffer.ipp +599 -0
- data/rice/Callback.hpp +21 -0
- data/rice/Callback.ipp +13 -0
- data/rice/Constructor.hpp +4 -27
- data/rice/Constructor.ipp +79 -0
- data/rice/Data_Object.hpp +73 -3
- data/rice/Data_Object.ipp +388 -96
- data/rice/Data_Type.hpp +214 -3
- data/rice/Data_Type.ipp +144 -67
- data/rice/Director.hpp +0 -2
- data/rice/Enum.hpp +4 -7
- data/rice/Enum.ipp +102 -55
- data/rice/Exception.hpp +62 -2
- data/rice/Exception.ipp +7 -12
- data/rice/Init.hpp +8 -0
- data/rice/Init.ipp +8 -0
- data/rice/JumpException.hpp +44 -0
- data/rice/JumpException.ipp +48 -0
- data/rice/MemoryView.hpp +11 -0
- data/rice/MemoryView.ipp +3 -0
- data/rice/Return.hpp +7 -27
- data/rice/Return.ipp +13 -13
- data/rice/cpp_api/Array.hpp +209 -0
- data/rice/cpp_api/Array.ipp +304 -0
- data/rice/cpp_api/Builtin_Object.hpp +31 -0
- data/rice/cpp_api/Builtin_Object.ipp +37 -0
- data/rice/cpp_api/Class.hpp +70 -0
- data/rice/cpp_api/Class.ipp +97 -0
- data/rice/cpp_api/Encoding.hpp +32 -0
- data/rice/cpp_api/Encoding.ipp +59 -0
- data/rice/cpp_api/Hash.hpp +194 -0
- data/rice/cpp_api/Hash.ipp +257 -0
- data/rice/{Identifier.hpp → cpp_api/Identifier.hpp} +2 -6
- data/rice/{Identifier.ipp → cpp_api/Identifier.ipp} +4 -2
- data/rice/cpp_api/Module.hpp +72 -0
- data/rice/cpp_api/Module.ipp +101 -0
- data/rice/cpp_api/Object.hpp +272 -0
- data/rice/cpp_api/Object.ipp +235 -0
- data/rice/cpp_api/String.hpp +74 -0
- data/rice/cpp_api/String.ipp +120 -0
- data/rice/cpp_api/Struct.hpp +113 -0
- data/rice/cpp_api/Struct.ipp +92 -0
- data/rice/cpp_api/Symbol.hpp +46 -0
- data/rice/cpp_api/Symbol.ipp +93 -0
- data/rice/cpp_api/shared_methods.hpp +134 -0
- data/rice/detail/DefaultHandler.hpp +12 -0
- data/rice/detail/DefaultHandler.ipp +8 -0
- data/rice/detail/HandlerRegistry.hpp +5 -35
- data/rice/detail/HandlerRegistry.ipp +7 -11
- data/rice/detail/InstanceRegistry.hpp +1 -4
- data/rice/detail/MethodInfo.hpp +12 -10
- data/rice/detail/MethodInfo.ipp +26 -21
- data/rice/detail/Native.hpp +33 -0
- data/rice/detail/Native.ipp +157 -0
- data/rice/detail/NativeAttributeGet.hpp +52 -0
- data/rice/detail/NativeAttributeGet.ipp +57 -0
- data/rice/detail/NativeAttributeSet.hpp +44 -0
- data/rice/detail/NativeAttributeSet.ipp +88 -0
- data/rice/detail/NativeCallbackFFI.hpp +55 -0
- data/rice/detail/NativeCallbackFFI.ipp +151 -0
- data/rice/detail/NativeCallbackSimple.hpp +30 -0
- data/rice/detail/NativeCallbackSimple.ipp +29 -0
- data/rice/detail/NativeFunction.hpp +33 -23
- data/rice/detail/NativeFunction.ipp +309 -70
- data/rice/detail/NativeIterator.hpp +9 -11
- data/rice/detail/NativeIterator.ipp +33 -31
- data/rice/detail/NativeRegistry.hpp +24 -15
- data/rice/detail/NativeRegistry.ipp +23 -48
- data/rice/detail/Proc.hpp +4 -0
- data/rice/detail/Proc.ipp +85 -0
- data/rice/detail/Registries.hpp +0 -7
- data/rice/detail/Registries.ipp +0 -18
- data/rice/detail/RubyFunction.hpp +0 -3
- data/rice/detail/RubyFunction.ipp +4 -8
- data/rice/detail/RubyType.hpp +16 -0
- data/rice/detail/RubyType.ipp +232 -0
- data/rice/detail/Type.hpp +7 -6
- data/rice/detail/Type.ipp +192 -45
- data/rice/detail/TypeRegistry.hpp +15 -7
- data/rice/detail/TypeRegistry.ipp +105 -12
- data/rice/detail/Wrapper.hpp +68 -32
- data/rice/detail/Wrapper.ipp +121 -109
- data/rice/detail/cpp_protect.hpp +5 -6
- data/rice/detail/default_allocation_func.ipp +0 -2
- data/rice/detail/from_ruby.hpp +38 -3
- data/rice/detail/from_ruby.ipp +1321 -492
- data/rice/detail/ruby.hpp +18 -0
- data/rice/detail/to_ruby.hpp +41 -3
- data/rice/detail/to_ruby.ipp +1424 -194
- data/rice/global_function.hpp +0 -4
- data/rice/global_function.ipp +0 -1
- data/rice/libc/file.hpp +11 -0
- data/rice/libc/file.ipp +32 -0
- data/rice/rice.hpp +116 -26
- data/rice/ruby_mark.hpp +4 -3
- data/rice/stl/complex.hpp +6 -0
- data/rice/stl/complex.ipp +93 -0
- data/rice/stl/exception.hpp +11 -0
- data/rice/stl/exception.ipp +29 -0
- data/rice/stl/exception_ptr.hpp +6 -0
- data/rice/stl/exception_ptr.ipp +27 -0
- data/rice/stl/map.hpp +12 -0
- data/rice/stl/map.ipp +469 -0
- data/rice/stl/monostate.hpp +6 -0
- data/rice/stl/monostate.ipp +80 -0
- data/rice/stl/multimap.hpp +14 -0
- data/rice/stl/multimap.ipp +448 -0
- data/rice/stl/optional.hpp +6 -0
- data/rice/stl/optional.ipp +118 -0
- data/rice/stl/pair.hpp +13 -0
- data/rice/stl/pair.ipp +155 -0
- data/rice/stl/reference_wrapper.hpp +6 -0
- data/rice/stl/reference_wrapper.ipp +41 -0
- data/rice/stl/set.hpp +12 -0
- data/rice/stl/set.ipp +495 -0
- data/rice/stl/shared_ptr.hpp +28 -0
- data/rice/stl/shared_ptr.ipp +224 -0
- data/rice/stl/string.hpp +6 -0
- data/rice/stl/string.ipp +158 -0
- data/rice/stl/string_view.hpp +6 -0
- data/rice/stl/string_view.ipp +65 -0
- data/rice/stl/tuple.hpp +6 -0
- data/rice/stl/tuple.ipp +128 -0
- data/rice/stl/type_index.hpp +6 -0
- data/rice/stl/type_index.ipp +30 -0
- data/rice/stl/type_info.hpp +6 -0
- data/rice/stl/type_info.ipp +29 -0
- data/rice/stl/unique_ptr.hpp +22 -0
- data/rice/stl/unique_ptr.ipp +139 -0
- data/rice/stl/unordered_map.hpp +12 -0
- data/rice/stl/unordered_map.ipp +469 -0
- data/rice/stl/variant.hpp +6 -0
- data/rice/stl/variant.ipp +242 -0
- data/rice/stl/vector.hpp +12 -0
- data/rice/stl/vector.ipp +590 -0
- data/rice/stl.hpp +11 -3
- data/rice/traits/attribute_traits.hpp +26 -0
- data/rice/traits/function_traits.hpp +95 -0
- data/rice/traits/method_traits.hpp +47 -0
- data/rice/traits/rice_traits.hpp +160 -0
- data/rice.gemspec +85 -0
- data/test/embed_ruby.cpp +7 -1
- data/test/extconf.rb +2 -0
- data/test/test_Address_Registration_Guard.cpp +5 -0
- data/test/test_Array.cpp +18 -4
- data/test/test_Attribute.cpp +136 -21
- data/test/test_Buffer.cpp +285 -0
- data/test/test_Builtin_Object.cpp +5 -0
- data/test/test_Callback.cpp +230 -0
- data/test/test_Class.cpp +5 -31
- data/test/test_Constructor.cpp +69 -6
- data/test/test_Data_Object.cpp +97 -38
- data/test/test_Data_Type.cpp +470 -65
- data/test/test_Director.cpp +17 -8
- data/test/test_Enum.cpp +155 -40
- data/test/test_Exception.cpp +235 -0
- data/test/test_File.cpp +70 -0
- data/test/test_From_Ruby.cpp +609 -0
- data/test/test_Hash.cpp +5 -0
- data/test/test_Identifier.cpp +5 -0
- data/test/test_Inheritance.cpp +6 -1
- data/test/test_Iterator.cpp +6 -1
- data/test/test_Jump_Exception.cpp +23 -0
- data/test/test_Keep_Alive.cpp +13 -19
- data/test/test_Keep_Alive_No_Wrapper.cpp +5 -1
- data/test/test_Memory_Management.cpp +5 -0
- data/test/test_Module.cpp +128 -67
- data/test/test_Native_Registry.cpp +2 -34
- data/test/test_Object.cpp +5 -0
- data/test/test_Overloads.cpp +806 -0
- data/test/test_Ownership.cpp +160 -54
- data/test/test_Proc.cpp +44 -0
- data/test/test_Self.cpp +9 -4
- data/test/test_Stl_Exception.cpp +109 -0
- data/test/test_Stl_Map.cpp +54 -42
- data/test/test_Stl_Multimap.cpp +693 -0
- data/test/test_Stl_Optional.cpp +5 -0
- data/test/test_Stl_Pair.cpp +14 -9
- data/test/test_Stl_Reference_Wrapper.cpp +9 -2
- data/test/test_Stl_Set.cpp +790 -0
- data/test/test_Stl_SharedPtr.cpp +458 -0
- data/test/test_Stl_String.cpp +5 -0
- data/test/test_Stl_String_View.cpp +5 -0
- data/test/test_Stl_Tuple.cpp +116 -0
- data/test/test_Stl_Type.cpp +147 -0
- data/test/test_Stl_UniquePtr.cpp +202 -0
- data/test/test_Stl_Unordered_Map.cpp +43 -38
- data/test/test_Stl_Variant.cpp +217 -84
- data/test/test_Stl_Vector.cpp +306 -58
- data/test/test_String.cpp +5 -0
- data/test/test_Struct.cpp +5 -0
- data/test/test_Symbol.cpp +5 -0
- data/test/test_Template.cpp +192 -0
- data/test/test_To_Ruby.cpp +524 -0
- data/test/test_Tracking.cpp +1 -0
- data/test/test_Type.cpp +171 -0
- data/test/test_global_functions.cpp +67 -7
- data/test/unittest.cpp +8 -0
- metadata +127 -26
- data/lib/version.rb +0 -3
- data/rice/Address_Registration_Guard_defn.hpp +0 -79
- data/rice/Data_Object_defn.hpp +0 -84
- data/rice/Data_Type_defn.hpp +0 -190
- data/rice/Exception_defn.hpp +0 -68
- data/rice/HandlerRegistration.hpp +0 -15
- data/rice/detail/ExceptionHandler.hpp +0 -8
- data/rice/detail/ExceptionHandler.ipp +0 -28
- data/rice/detail/ExceptionHandler_defn.hpp +0 -77
- data/rice/detail/Jump_Tag.hpp +0 -21
- data/rice/detail/NativeAttribute.hpp +0 -64
- data/rice/detail/NativeAttribute.ipp +0 -112
- data/rice/detail/from_ruby_defn.hpp +0 -38
- data/rice/detail/to_ruby_defn.hpp +0 -48
- data/test/test_Jump_Tag.cpp +0 -17
- data/test/test_Stl_SmartPointer.cpp +0 -283
- data/test/test_To_From_Ruby.cpp +0 -399
@@ -0,0 +1,609 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "embed_ruby.hpp"
|
3
|
+
#include <rice/rice.hpp>
|
4
|
+
#include <rice/stl.hpp>
|
5
|
+
|
6
|
+
#include <limits>
|
7
|
+
#include <cmath>
|
8
|
+
|
9
|
+
using namespace Rice;
|
10
|
+
|
11
|
+
TESTSUITE(FromRuby);
|
12
|
+
|
13
|
+
SETUP(FromRuby)
|
14
|
+
{
|
15
|
+
embed_ruby();
|
16
|
+
define_fundamental_buffer_types();
|
17
|
+
}
|
18
|
+
|
19
|
+
TEARDOWN(FromRuby)
|
20
|
+
{
|
21
|
+
rb_gc_start();
|
22
|
+
}
|
23
|
+
|
24
|
+
namespace
|
25
|
+
{
|
26
|
+
template<typename T>
|
27
|
+
std::string arrayToString(T* buffer, int size)
|
28
|
+
{
|
29
|
+
std::ostringstream result;
|
30
|
+
result << "[";
|
31
|
+
|
32
|
+
for (int i = 0; i < size; i++)
|
33
|
+
{
|
34
|
+
T item = buffer[i];
|
35
|
+
result << item;
|
36
|
+
if (i < size - 1)
|
37
|
+
{
|
38
|
+
result << ", ";
|
39
|
+
}
|
40
|
+
}
|
41
|
+
result << "]";
|
42
|
+
return result.str();
|
43
|
+
}
|
44
|
+
|
45
|
+
template<typename T>
|
46
|
+
std::string voidToString(void* buffer, int size)
|
47
|
+
{
|
48
|
+
return arrayToString<T>((T*)buffer, size/sizeof(T));
|
49
|
+
}
|
50
|
+
|
51
|
+
template<typename T>
|
52
|
+
std::string arrayofArraysToString(T** buffer, int outerSize, int innerSize)
|
53
|
+
{
|
54
|
+
std::ostringstream result;
|
55
|
+
result << "[";
|
56
|
+
|
57
|
+
for (int i = 0; i < outerSize; i++)
|
58
|
+
{
|
59
|
+
T* outer = buffer[i];
|
60
|
+
|
61
|
+
result << "[";
|
62
|
+
for (int j = 0; j < innerSize; j++)
|
63
|
+
{
|
64
|
+
T item = outer[j];
|
65
|
+
result << item;
|
66
|
+
if (j < innerSize - 1)
|
67
|
+
{
|
68
|
+
result << ", ";
|
69
|
+
}
|
70
|
+
}
|
71
|
+
result << "]";
|
72
|
+
if (i < outerSize - 1)
|
73
|
+
{
|
74
|
+
result << ", ";
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
result << "]";
|
79
|
+
return result.str();
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
TESTCASE(bool)
|
84
|
+
{
|
85
|
+
ASSERT_EQUAL(detail::Convertible::Exact, detail::From_Ruby<bool>().is_convertible(Qfalse));
|
86
|
+
ASSERT_EQUAL(detail::Convertible::Exact, detail::From_Ruby<bool>().is_convertible(Qtrue));
|
87
|
+
ASSERT_EQUAL(detail::Convertible::Cast, detail::From_Ruby<bool>().is_convertible(Qnil));
|
88
|
+
ASSERT_EQUAL(detail::Convertible::None, detail::From_Ruby<bool>().is_convertible(INT2NUM(3)));
|
89
|
+
ASSERT_EQUAL(detail::Convertible::None, detail::From_Ruby<bool>().is_convertible(rb_float_new(3.33)));
|
90
|
+
ASSERT_EQUAL(detail::Convertible::None, detail::From_Ruby<bool>().is_convertible(rb_str_new2("some string")));
|
91
|
+
|
92
|
+
ASSERT_EQUAL(false, detail::From_Ruby<bool>().convert(Qfalse));
|
93
|
+
ASSERT_EQUAL(false, detail::From_Ruby<bool>().convert(Qnil));
|
94
|
+
ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(Qtrue));
|
95
|
+
ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(INT2NUM(3)));
|
96
|
+
ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(INT2NUM(0)));
|
97
|
+
ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_float_new(3.33)));
|
98
|
+
ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_float_new(0.0)));
|
99
|
+
ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_str_new2("some string")));
|
100
|
+
ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_str_new2("true")));
|
101
|
+
ASSERT_EQUAL(true, detail::From_Ruby<bool>().convert(rb_str_new2("false")));
|
102
|
+
}
|
103
|
+
|
104
|
+
TESTCASE(char)
|
105
|
+
{
|
106
|
+
unsigned char expected = 10;
|
107
|
+
ASSERT_EQUAL(expected, detail::From_Ruby<signed char>().convert(INT2NUM(10)));
|
108
|
+
}
|
109
|
+
|
110
|
+
TESTCASE(char_single_character_string)
|
111
|
+
{
|
112
|
+
ASSERT_EQUAL('x', detail::From_Ruby<char>().convert(rb_str_new2("x")));
|
113
|
+
}
|
114
|
+
|
115
|
+
TESTCASE(char_longer_string)
|
116
|
+
{
|
117
|
+
ASSERT_EQUAL('x', detail::From_Ruby<char>().convert(rb_str_new2("xy")));
|
118
|
+
}
|
119
|
+
|
120
|
+
TESTCASE(char_float)
|
121
|
+
{
|
122
|
+
// '/' is 47
|
123
|
+
ASSERT_EQUAL('/', detail::From_Ruby<char>().convert(rb_float_new(47.2)));
|
124
|
+
}
|
125
|
+
|
126
|
+
TESTCASE(char_fixnum)
|
127
|
+
{
|
128
|
+
// '1' is 49
|
129
|
+
ASSERT_EQUAL('1', detail::From_Ruby<char>().convert(INT2NUM(49)));
|
130
|
+
}
|
131
|
+
|
132
|
+
TESTCASE(char_pointer)
|
133
|
+
{
|
134
|
+
Module m = define_module("Testing");
|
135
|
+
detail::From_Ruby<char*> fromRuby;
|
136
|
+
|
137
|
+
char* expected = nullptr;
|
138
|
+
char* data = fromRuby.convert(Qnil);
|
139
|
+
ASSERT_EQUAL(expected, data);
|
140
|
+
|
141
|
+
std::string code = R"(Rice::Buffer≺char≻.new("my string"))";
|
142
|
+
Object result = m.instance_eval(code);
|
143
|
+
data = fromRuby.convert(result.value());
|
144
|
+
//expected = "my string";
|
145
|
+
// ASSERT_EQUAL(*expected, *data);
|
146
|
+
|
147
|
+
code = R"(Rice::Buffer≺char≻.new([0, 127, 128, 255, 256, -128, -129, -255]))";
|
148
|
+
result = m.instance_eval(code);
|
149
|
+
data = fromRuby.convert(result.value());
|
150
|
+
|
151
|
+
ASSERT_EQUAL(data[0], 0);
|
152
|
+
ASSERT_EQUAL(data[1], 127);
|
153
|
+
ASSERT_EQUAL(data[2], -128);
|
154
|
+
ASSERT_EQUAL(data[3], -1);
|
155
|
+
ASSERT_EQUAL(data[4], 0);
|
156
|
+
ASSERT_EQUAL(data[5], -128);
|
157
|
+
ASSERT_EQUAL(data[6], 127);
|
158
|
+
ASSERT_EQUAL(data[7], 1);
|
159
|
+
|
160
|
+
ASSERT_EXCEPTION_CHECK(
|
161
|
+
Exception,
|
162
|
+
fromRuby.convert(rb_float_new(11.11)),
|
163
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char≻)", ex.what())
|
164
|
+
);
|
165
|
+
}
|
166
|
+
|
167
|
+
TESTCASE(signed_char_pointer)
|
168
|
+
{
|
169
|
+
Module m = define_module("Testing");
|
170
|
+
detail::From_Ruby<signed char*> fromRuby;
|
171
|
+
|
172
|
+
signed char* expected = nullptr;
|
173
|
+
signed char* data = fromRuby.convert(Qnil);
|
174
|
+
ASSERT_EQUAL(expected, data);
|
175
|
+
|
176
|
+
std::string code = R"(Rice::Buffer≺signed char≻.new("my string"))";
|
177
|
+
Object result = m.instance_eval(code);
|
178
|
+
data = fromRuby.convert(result.value());
|
179
|
+
expected = (signed char*)"my string";
|
180
|
+
ASSERT_EQUAL(*expected, *data);
|
181
|
+
|
182
|
+
code = R"(Rice::Buffer≺signed char≻.new([0, 127, 128, 255, 256, -128, -129, -255]))";
|
183
|
+
result = m.instance_eval(code);
|
184
|
+
data = fromRuby.convert(result.value());
|
185
|
+
|
186
|
+
ASSERT_EQUAL(data[0], 0);
|
187
|
+
ASSERT_EQUAL(data[1], 127);
|
188
|
+
ASSERT_EQUAL(data[2], -128);
|
189
|
+
ASSERT_EQUAL(data[3], -1);
|
190
|
+
ASSERT_EQUAL(data[4], 0);
|
191
|
+
ASSERT_EQUAL(data[5], -128);
|
192
|
+
ASSERT_EQUAL(data[6], 127);
|
193
|
+
ASSERT_EQUAL(data[7], 1);
|
194
|
+
|
195
|
+
ASSERT_EXCEPTION_CHECK(
|
196
|
+
Exception,
|
197
|
+
fromRuby.convert(rb_float_new(11.11)),
|
198
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺signed char≻)", ex.what())
|
199
|
+
);
|
200
|
+
}
|
201
|
+
|
202
|
+
TESTCASE(char_pointer_const)
|
203
|
+
{
|
204
|
+
Module m = define_module("Testing");
|
205
|
+
|
206
|
+
std::string code = R"(Rice::Buffer≺char≻.new("my string"))";
|
207
|
+
Object result = m.instance_eval(code);
|
208
|
+
const char* expected = "my string";
|
209
|
+
const char* data = detail::From_Ruby<const char*>().convert(result.value());
|
210
|
+
ASSERT_EQUAL(expected, data);
|
211
|
+
|
212
|
+
code = R"(Rice::Buffer≺char≻.new(""))";
|
213
|
+
result = m.instance_eval(code);
|
214
|
+
expected = "";
|
215
|
+
data = detail::From_Ruby<const char*>().convert(result.value());
|
216
|
+
ASSERT_EQUAL(expected, data);
|
217
|
+
|
218
|
+
ASSERT_EXCEPTION_CHECK(
|
219
|
+
Exception,
|
220
|
+
detail::From_Ruby<char const*>().convert(rb_float_new(32.3)),
|
221
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char≻)", ex.what())
|
222
|
+
);
|
223
|
+
}
|
224
|
+
|
225
|
+
TESTCASE(unsigned_char)
|
226
|
+
{
|
227
|
+
unsigned char expected = -1;
|
228
|
+
ASSERT_EQUAL(expected, detail::From_Ruby<unsigned char>().convert(INT2NUM(-1)));
|
229
|
+
|
230
|
+
expected = 1;
|
231
|
+
ASSERT_EQUAL(expected, detail::From_Ruby<unsigned char>().convert(rb_float_new(1.3)));
|
232
|
+
}
|
233
|
+
|
234
|
+
TESTCASE(unsigned_char_pointer)
|
235
|
+
{
|
236
|
+
Module m = define_module("Testing");
|
237
|
+
|
238
|
+
detail::From_Ruby<unsigned char*> fromRuby;
|
239
|
+
|
240
|
+
unsigned char* expected = nullptr;
|
241
|
+
unsigned char* data = fromRuby.convert(Qnil);
|
242
|
+
ASSERT_EQUAL(expected, data);
|
243
|
+
|
244
|
+
std::string code = R"(Rice::Buffer≺unsigned char≻.new([0, 127, 128, 255, 256, -128, -129, -255]))";
|
245
|
+
Object result = m.instance_eval(code);
|
246
|
+
data = fromRuby.convert(result.value());
|
247
|
+
|
248
|
+
ASSERT_EQUAL(data[0], 0x0);
|
249
|
+
ASSERT_EQUAL(data[1], 0x7F);
|
250
|
+
ASSERT_EQUAL(data[2], 0x80);
|
251
|
+
ASSERT_EQUAL(data[3], 0xFF);
|
252
|
+
ASSERT_EQUAL(data[4], 0x00);
|
253
|
+
ASSERT_EQUAL(data[5], 0x80);
|
254
|
+
ASSERT_EQUAL(data[6], 0x7F);
|
255
|
+
ASSERT_EQUAL(data[7], 0x01);
|
256
|
+
|
257
|
+
code = R"(array = [0, 127, 128, 255, 256, -128, -129, -255]
|
258
|
+
packed = array.pack("C*")
|
259
|
+
Rice::Buffer≺unsigned char≻.new(packed))";
|
260
|
+
result = m.instance_eval(code);
|
261
|
+
data = fromRuby.convert(result.value());
|
262
|
+
|
263
|
+
ASSERT_EQUAL(data[0], 0x0);
|
264
|
+
ASSERT_EQUAL(data[1], 0x7F);
|
265
|
+
ASSERT_EQUAL(data[2], 0x80);
|
266
|
+
ASSERT_EQUAL(data[3], 0xFF);
|
267
|
+
ASSERT_EQUAL(data[4], 0x00);
|
268
|
+
ASSERT_EQUAL(data[5], 0x80);
|
269
|
+
ASSERT_EQUAL(data[6], 0x7F);
|
270
|
+
ASSERT_EQUAL(data[7], 0x01);
|
271
|
+
|
272
|
+
ASSERT_EXCEPTION_CHECK(
|
273
|
+
Exception,
|
274
|
+
detail::From_Ruby<const char*>().convert(rb_float_new(11.11)),
|
275
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char≻)", ex.what())
|
276
|
+
);
|
277
|
+
}
|
278
|
+
|
279
|
+
TESTCASE(unsigned_char_pointer_array)
|
280
|
+
{
|
281
|
+
Module m = define_module("Testing");
|
282
|
+
|
283
|
+
m.define_singleton_function("unsigned_char_pointer", &arrayToString<unsigned char>);
|
284
|
+
|
285
|
+
std::string code = R"(arr = ["A", "B"]
|
286
|
+
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
287
|
+
unsigned_char_pointer(buffer, buffer.size))";
|
288
|
+
|
289
|
+
ASSERT_EXCEPTION_CHECK(
|
290
|
+
Exception,
|
291
|
+
Object result = m.module_eval(code),
|
292
|
+
ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
|
293
|
+
);
|
294
|
+
|
295
|
+
code = R"(arr = ["A", "B"].map do |char|
|
296
|
+
char.ord
|
297
|
+
end
|
298
|
+
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
299
|
+
unsigned_char_pointer(buffer, buffer.size))";
|
300
|
+
|
301
|
+
Object result = m.module_eval(code);
|
302
|
+
ASSERT_EQUAL("[A, B]", detail::From_Ruby<std::string>().convert(result.value()));
|
303
|
+
|
304
|
+
code = R"(arr = [65, 66]
|
305
|
+
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
306
|
+
unsigned_char_pointer(buffer, buffer.size))";
|
307
|
+
result = m.module_eval(code);
|
308
|
+
ASSERT_EQUAL("[A, B]", detail::From_Ruby<std::string>().convert(result.value()));
|
309
|
+
|
310
|
+
code = R"(arr = [true]
|
311
|
+
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
312
|
+
unsigned_char_pointer(buffer, buffer.size))";
|
313
|
+
|
314
|
+
ASSERT_EXCEPTION_CHECK(
|
315
|
+
Exception,
|
316
|
+
m.module_eval(code),
|
317
|
+
ASSERT_EQUAL("no implicit conversion of true into Integer", ex.what())
|
318
|
+
);
|
319
|
+
}
|
320
|
+
|
321
|
+
TESTCASE(double)
|
322
|
+
{
|
323
|
+
ASSERT_EQUAL(0.0, detail::From_Ruby<double>().convert(rb_float_new(0.0)));
|
324
|
+
ASSERT_EQUAL(-1.0, detail::From_Ruby<double>().convert(rb_float_new(-1.0)));
|
325
|
+
ASSERT_EQUAL(1.0, detail::From_Ruby<double>().convert(rb_float_new(1.0)));
|
326
|
+
ASSERT_EQUAL(std::numeric_limits<double>::min(),
|
327
|
+
detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::min())));
|
328
|
+
ASSERT_EQUAL(std::numeric_limits<double>::max(),
|
329
|
+
detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::max())));
|
330
|
+
ASSERT(std::isnan(detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::quiet_NaN()))));
|
331
|
+
ASSERT(std::isnan(detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::signaling_NaN()))));
|
332
|
+
ASSERT_EQUAL(std::numeric_limits<double>::epsilon(),
|
333
|
+
detail::From_Ruby<double>().convert(rb_float_new(std::numeric_limits<double>::epsilon())));
|
334
|
+
|
335
|
+
ASSERT_EXCEPTION_CHECK(
|
336
|
+
Exception,
|
337
|
+
detail::From_Ruby<double>().convert(rb_str_new2("bad value")),
|
338
|
+
ASSERT_EQUAL("no implicit conversion to float from string", ex.what())
|
339
|
+
);
|
340
|
+
}
|
341
|
+
|
342
|
+
TESTCASE(double_pointer_array)
|
343
|
+
{
|
344
|
+
Module m = define_module("Testing");
|
345
|
+
m.define_singleton_function("double_pointer", &arrayToString<double>);
|
346
|
+
|
347
|
+
std::string code = R"(arr = [1.1, 2.2, 3.3, 4.4]
|
348
|
+
buffer = Rice::Buffer≺double≻.new(arr)
|
349
|
+
double_pointer(buffer, buffer.size))";
|
350
|
+
|
351
|
+
Object result = m.module_eval(code);
|
352
|
+
|
353
|
+
ASSERT_EQUAL("[1.1, 2.2, 3.3, 4.4]", detail::From_Ruby<std::string>().convert(result.value()));
|
354
|
+
}
|
355
|
+
|
356
|
+
TESTCASE(float)
|
357
|
+
{
|
358
|
+
ASSERT_EQUAL(0.0f, detail::From_Ruby<float>().convert(rb_float_new(0.0f)));
|
359
|
+
ASSERT_EQUAL(-1.0f, detail::From_Ruby<float>().convert(rb_float_new(-1.0f)));
|
360
|
+
ASSERT_EQUAL(1.0f, detail::From_Ruby<float>().convert(rb_float_new(1.0f)));
|
361
|
+
ASSERT_EQUAL(std::numeric_limits<float>::min(),
|
362
|
+
detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::min())));
|
363
|
+
ASSERT_EQUAL(std::numeric_limits<float>::max(),
|
364
|
+
detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::max())));
|
365
|
+
ASSERT(std::isnan(detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::quiet_NaN()))));
|
366
|
+
ASSERT(std::isnan(detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::signaling_NaN()))));
|
367
|
+
ASSERT_EQUAL(std::numeric_limits<float>::epsilon(),
|
368
|
+
detail::From_Ruby<float>().convert(rb_float_new(std::numeric_limits<float>::epsilon())));
|
369
|
+
|
370
|
+
ASSERT_EXCEPTION_CHECK(
|
371
|
+
Exception,
|
372
|
+
detail::From_Ruby<float>().convert(rb_str_new2("bad value")),
|
373
|
+
ASSERT_EQUAL("no implicit conversion to float from string", ex.what())
|
374
|
+
);
|
375
|
+
}
|
376
|
+
|
377
|
+
TESTCASE(float_pointer_array)
|
378
|
+
{
|
379
|
+
Module m = define_module("Testing");
|
380
|
+
|
381
|
+
m.define_singleton_function("float_pointer", &arrayToString<float>);
|
382
|
+
|
383
|
+
std::string code = R"(arr = [4.3, 3.2, 2.1, 1.1]
|
384
|
+
buffer = Rice::Buffer≺float≻.new(arr)
|
385
|
+
float_pointer(buffer, buffer.size))";
|
386
|
+
Object result = m.module_eval(code);
|
387
|
+
ASSERT_EQUAL("[4.3, 3.2, 2.1, 1.1]", detail::From_Ruby<std::string>().convert(result.value()));
|
388
|
+
|
389
|
+
code = R"(arr = [4, 3, 2.8, 1]
|
390
|
+
buffer = Rice::Buffer≺float≻.new(arr)
|
391
|
+
float_pointer(buffer, buffer.size))";
|
392
|
+
result = m.module_eval(code);
|
393
|
+
ASSERT_EQUAL("[4, 3, 2.8, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
394
|
+
|
395
|
+
code = R"(arr = [4, "bad", 2, 1]
|
396
|
+
buffer = Rice::Buffer≺float≻.new(arr)
|
397
|
+
float_pointer(buffer, buffer.size))";
|
398
|
+
|
399
|
+
ASSERT_EXCEPTION_CHECK(
|
400
|
+
Exception,
|
401
|
+
m.module_eval(code),
|
402
|
+
ASSERT_EQUAL("can't convert String into Float", ex.what())
|
403
|
+
);
|
404
|
+
}
|
405
|
+
|
406
|
+
TESTCASE(float_array_array)
|
407
|
+
{
|
408
|
+
Module m = define_module("Testing");
|
409
|
+
|
410
|
+
m.define_singleton_function("array_array_to_string", &arrayofArraysToString<float>);
|
411
|
+
|
412
|
+
std::string code = R"(buffer = Rice::Buffer≺float∗≻.new([[1.1, 2.2], [3.3, 4.4], [5.5, 6.6]])
|
413
|
+
array_array_to_string(buffer, buffer.size, 2))";
|
414
|
+
Object result = m.module_eval(code);
|
415
|
+
ASSERT_EQUAL("[[1.1, 2.2], [3.3, 4.4], [5.5, 6.6]]", detail::From_Ruby<std::string>().convert(result.value()));
|
416
|
+
|
417
|
+
code = R"(buffer = Rice::Buffer≺float∗≻.new([[4, 3], [2.8, 1]])
|
418
|
+
array_array_to_string(buffer, buffer.size, 2))";
|
419
|
+
result = m.module_eval(code);
|
420
|
+
ASSERT_EQUAL("[[4, 3], [2.8, 1]]", detail::From_Ruby<std::string>().convert(result.value()));
|
421
|
+
|
422
|
+
code = R"(buffer = Rice::Buffer≺float∗≻.new([[4, "bad"], [2, 1]])
|
423
|
+
array_array_to_string(buffer, buffer.size, 2))";
|
424
|
+
|
425
|
+
ASSERT_EXCEPTION_CHECK(
|
426
|
+
Exception,
|
427
|
+
m.module_eval(code),
|
428
|
+
ASSERT_EQUAL("can't convert String into Float", ex.what())
|
429
|
+
);
|
430
|
+
|
431
|
+
code = R"(array = [[4, "bad"], [2, 1]]
|
432
|
+
array_array_to_string(array, array.size, 2))";
|
433
|
+
|
434
|
+
ASSERT_EXCEPTION_CHECK(
|
435
|
+
Exception,
|
436
|
+
m.module_eval(code),
|
437
|
+
ASSERT_EQUAL("wrong argument type Array (expected Buffer≺float∗≻)", ex.what())
|
438
|
+
);
|
439
|
+
}
|
440
|
+
|
441
|
+
TESTCASE(int)
|
442
|
+
{
|
443
|
+
ASSERT_EQUAL(0, detail::From_Ruby<int>().convert(INT2NUM(0)));
|
444
|
+
ASSERT_EQUAL(-1, detail::From_Ruby<int>().convert(INT2NUM(-1)));
|
445
|
+
ASSERT_EQUAL(1, detail::From_Ruby<int>().convert(INT2NUM(1)));
|
446
|
+
ASSERT_EQUAL(std::numeric_limits<int>::min(),
|
447
|
+
detail::From_Ruby<int>().convert(INT2NUM(std::numeric_limits<int>::min())));
|
448
|
+
ASSERT_EQUAL(std::numeric_limits<int>::max(),
|
449
|
+
detail::From_Ruby<int>().convert(INT2NUM(std::numeric_limits<int>::max())));
|
450
|
+
|
451
|
+
ASSERT_EXCEPTION_CHECK(
|
452
|
+
Exception,
|
453
|
+
detail::From_Ruby<int>().convert(rb_str_new2("bad value")),
|
454
|
+
ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
|
455
|
+
);
|
456
|
+
}
|
457
|
+
|
458
|
+
TESTCASE(int_pointer_array)
|
459
|
+
{
|
460
|
+
Module m = define_module("Testing");
|
461
|
+
m.define_singleton_function("int_pointer", &arrayToString<int>);
|
462
|
+
|
463
|
+
std::string code = R"(arr = [4, 3, 2, 1]
|
464
|
+
buffer = Rice::Buffer≺int≻.new(arr)
|
465
|
+
int_pointer(buffer, buffer.size))";
|
466
|
+
Object result = m.module_eval(code);
|
467
|
+
ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
468
|
+
|
469
|
+
code = R"(arr = [4.2, 3.8, 2.0, 1]
|
470
|
+
buffer = Rice::Buffer≺int≻.new(arr)
|
471
|
+
int_pointer(buffer, buffer.size))";
|
472
|
+
result = m.module_eval(code);
|
473
|
+
ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
474
|
+
}
|
475
|
+
|
476
|
+
TESTCASE(unsigned_int)
|
477
|
+
{
|
478
|
+
ASSERT_EQUAL(0u, detail::From_Ruby<unsigned int>().convert(UINT2NUM(0)));
|
479
|
+
ASSERT_EQUAL(1u, detail::From_Ruby<unsigned int>().convert(UINT2NUM(1)));
|
480
|
+
ASSERT_EQUAL(std::numeric_limits<unsigned int>::min(),
|
481
|
+
detail::From_Ruby<unsigned int>().convert(UINT2NUM(std::numeric_limits<unsigned int>::min())));
|
482
|
+
ASSERT_EQUAL(std::numeric_limits<unsigned int>::max(),
|
483
|
+
detail::From_Ruby<unsigned int>().convert(UINT2NUM(std::numeric_limits<unsigned int>::max())));
|
484
|
+
|
485
|
+
ASSERT_EXCEPTION_CHECK(
|
486
|
+
Exception,
|
487
|
+
detail::From_Ruby<unsigned int>().convert(rb_str_new2("bad value")),
|
488
|
+
ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
|
489
|
+
);
|
490
|
+
}
|
491
|
+
|
492
|
+
TESTCASE(long)
|
493
|
+
{
|
494
|
+
ASSERT_EQUAL(0, detail::From_Ruby<long>().convert(LONG2NUM(0)));
|
495
|
+
ASSERT_EQUAL(-1, detail::From_Ruby<long>().convert(LONG2NUM(-1)));
|
496
|
+
ASSERT_EQUAL(1, detail::From_Ruby<long>().convert(LONG2NUM(1)));
|
497
|
+
ASSERT_EQUAL(FIXNUM_MIN, detail::From_Ruby<long>().convert(LONG2NUM(FIXNUM_MIN)));
|
498
|
+
ASSERT_EQUAL(FIXNUM_MAX, detail::From_Ruby<long>().convert(LONG2NUM(FIXNUM_MAX)));
|
499
|
+
ASSERT_EQUAL(std::numeric_limits<long>::min(), detail::From_Ruby<long>().convert(LONG2NUM(std::numeric_limits<long>::min())));
|
500
|
+
ASSERT_EQUAL(std::numeric_limits<long>::max(), detail::From_Ruby<long>().convert(LONG2NUM(std::numeric_limits<long>::max())));
|
501
|
+
|
502
|
+
ASSERT_EXCEPTION_CHECK(
|
503
|
+
Exception,
|
504
|
+
detail::From_Ruby<long>().convert(rb_str_new2("bad value")),
|
505
|
+
ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
|
506
|
+
);
|
507
|
+
}
|
508
|
+
|
509
|
+
TESTCASE(unsigned_long)
|
510
|
+
{
|
511
|
+
ASSERT_EQUAL(0u, detail::From_Ruby<unsigned long>().convert(ULONG2NUM(0)));
|
512
|
+
ASSERT_EQUAL(1u, detail::From_Ruby<unsigned long>().convert(ULONG2NUM(1)));
|
513
|
+
ASSERT_EQUAL(static_cast<unsigned long>(FIXNUM_MIN),
|
514
|
+
detail::From_Ruby<unsigned long>().convert(ULONG2NUM(FIXNUM_MIN)));
|
515
|
+
ASSERT_EQUAL(std::numeric_limits<unsigned long>::min(),
|
516
|
+
detail::From_Ruby<unsigned long>().convert(ULONG2NUM(std::numeric_limits<unsigned long>::min())));
|
517
|
+
ASSERT_EQUAL(std::numeric_limits<unsigned long>::max(),
|
518
|
+
detail::From_Ruby<unsigned long>().convert(ULONG2NUM(std::numeric_limits<unsigned long>::max())));
|
519
|
+
|
520
|
+
ASSERT_EXCEPTION_CHECK(
|
521
|
+
Exception,
|
522
|
+
detail::From_Ruby<unsigned long>().convert(rb_str_new2("bad value")),
|
523
|
+
ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
|
524
|
+
);
|
525
|
+
}
|
526
|
+
|
527
|
+
TESTCASE(long_long)
|
528
|
+
{
|
529
|
+
ASSERT_EQUAL(0, detail::From_Ruby<long long>().convert(LL2NUM(0)));
|
530
|
+
ASSERT_EQUAL(-1, detail::From_Ruby<long long>().convert(LL2NUM(-1)));
|
531
|
+
ASSERT_EQUAL(1, detail::From_Ruby<long long>().convert(LL2NUM(1)));
|
532
|
+
ASSERT_EQUAL(std::numeric_limits<long long>::min(),
|
533
|
+
detail::From_Ruby<long long>().convert(LL2NUM(std::numeric_limits<long long>::min())));
|
534
|
+
ASSERT_EQUAL(std::numeric_limits<long long>::max(),
|
535
|
+
detail::From_Ruby<long long>().convert(LL2NUM(std::numeric_limits<long long>::max())));
|
536
|
+
|
537
|
+
ASSERT_EXCEPTION_CHECK(
|
538
|
+
Exception,
|
539
|
+
detail::From_Ruby<long long>().convert(rb_str_new2("bad value")),
|
540
|
+
ASSERT_EQUAL("no implicit conversion from string", ex.what())
|
541
|
+
);
|
542
|
+
}
|
543
|
+
|
544
|
+
TESTCASE(unsigned_long_long)
|
545
|
+
{
|
546
|
+
ASSERT_EQUAL(0u, detail::From_Ruby<unsigned long>().convert(ULL2NUM(0)));
|
547
|
+
ASSERT_EQUAL(1u, detail::From_Ruby<unsigned long>().convert(ULL2NUM(1)));
|
548
|
+
ASSERT_EQUAL(std::numeric_limits<unsigned long long>::min(),
|
549
|
+
detail::From_Ruby<unsigned long long>().convert(ULL2NUM(std::numeric_limits<unsigned long long>::min())));
|
550
|
+
ASSERT_EQUAL(std::numeric_limits<unsigned long long>::max(),
|
551
|
+
detail::From_Ruby<unsigned long long>().convert(ULL2NUM(std::numeric_limits<unsigned long long>::max())));
|
552
|
+
|
553
|
+
ASSERT_EXCEPTION_CHECK(
|
554
|
+
Exception,
|
555
|
+
detail::From_Ruby<unsigned long long>().convert(rb_str_new2("bad value")),
|
556
|
+
ASSERT(std::string(ex.what()).find("no implicit conversion") == 0)
|
557
|
+
);
|
558
|
+
}
|
559
|
+
|
560
|
+
TESTCASE(object)
|
561
|
+
{
|
562
|
+
Object o(rb_str_new2("foo"));
|
563
|
+
ASSERT_EQUAL(o, detail::From_Ruby<Object>().convert(o));
|
564
|
+
}
|
565
|
+
|
566
|
+
TESTCASE(short)
|
567
|
+
{
|
568
|
+
ASSERT_EQUAL(0, detail::From_Ruby<short>().convert(INT2NUM(0)));
|
569
|
+
ASSERT_EQUAL(-1, detail::From_Ruby<short>().convert(INT2NUM(-1)));
|
570
|
+
ASSERT_EQUAL(1, detail::From_Ruby<short>().convert(INT2NUM(1)));
|
571
|
+
ASSERT_EQUAL(std::numeric_limits<short>::min(),
|
572
|
+
detail::From_Ruby<short>().convert(INT2NUM(std::numeric_limits<short>::min())));
|
573
|
+
ASSERT_EQUAL(std::numeric_limits<short>::max(),
|
574
|
+
detail::From_Ruby<short>().convert(INT2NUM(std::numeric_limits<short>::max())));
|
575
|
+
|
576
|
+
ASSERT_EXCEPTION_CHECK(
|
577
|
+
Exception,
|
578
|
+
detail::From_Ruby<short>().convert(rb_str_new2("bad value")),
|
579
|
+
ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
|
580
|
+
);
|
581
|
+
}
|
582
|
+
|
583
|
+
TESTCASE(unsigned_short)
|
584
|
+
{
|
585
|
+
ASSERT_EQUAL(0u, detail::From_Ruby<unsigned short>().convert(UINT2NUM(0)));
|
586
|
+
ASSERT_EQUAL(1u, detail::From_Ruby<unsigned short>().convert(UINT2NUM(1)));
|
587
|
+
ASSERT_EQUAL(std::numeric_limits<unsigned short>::min(),
|
588
|
+
detail::From_Ruby<unsigned short>().convert(UINT2NUM(std::numeric_limits<unsigned short>::min())));
|
589
|
+
ASSERT_EQUAL(std::numeric_limits<unsigned short>::max(),
|
590
|
+
detail::From_Ruby<unsigned short>().convert(UINT2NUM(std::numeric_limits<unsigned short>::max())));
|
591
|
+
|
592
|
+
ASSERT_EXCEPTION_CHECK(
|
593
|
+
Exception,
|
594
|
+
detail::From_Ruby<unsigned short>().convert(rb_str_new2("bad value")),
|
595
|
+
ASSERT_EQUAL("no implicit conversion of String into Integer", ex.what())
|
596
|
+
);
|
597
|
+
}
|
598
|
+
|
599
|
+
TESTCASE(void_pointer_array)
|
600
|
+
{
|
601
|
+
Module m = define_module("Testing");
|
602
|
+
m.define_singleton_function("void_pointer", &voidToString<int>);
|
603
|
+
|
604
|
+
std::string code = R"(arr = [4, 3, 2, 1]
|
605
|
+
buffer = arr.pack("i*")
|
606
|
+
void_pointer(buffer, buffer.size))";
|
607
|
+
Object result = m.module_eval(code);
|
608
|
+
ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
609
|
+
}
|
data/test/test_Hash.cpp
CHANGED
data/test/test_Identifier.cpp
CHANGED
data/test/test_Inheritance.cpp
CHANGED
@@ -80,6 +80,11 @@ SETUP(Inheritance)
|
|
80
80
|
Data_Type<PushNotification>::unbind();
|
81
81
|
}
|
82
82
|
|
83
|
+
TEARDOWN(Inheritance)
|
84
|
+
{
|
85
|
+
rb_gc_start();
|
86
|
+
}
|
87
|
+
|
83
88
|
TESTCASE(return_base_pointer)
|
84
89
|
{
|
85
90
|
Class rcNotification = define_class<Notification>("Notification");
|
@@ -171,7 +176,7 @@ TESTCASE(module_base_pointer_method_call)
|
|
171
176
|
Module m = define_module("Testing");
|
172
177
|
|
173
178
|
Object message = m.module_eval(R"EOS(notification = Inheritance::EmailNotification.new
|
174
|
-
|
179
|
+
notification.message)EOS");
|
175
180
|
ASSERT_EQUAL("Email", detail::From_Ruby<std::string>().convert(message));
|
176
181
|
|
177
182
|
message = m.module_eval(R"EOS(notification = Inheritance::PushNotification.new
|
data/test/test_Iterator.cpp
CHANGED
@@ -11,6 +11,11 @@ SETUP(Iterator)
|
|
11
11
|
embed_ruby();
|
12
12
|
}
|
13
13
|
|
14
|
+
TEARDOWN(Iterator)
|
15
|
+
{
|
16
|
+
rb_gc_start();
|
17
|
+
}
|
18
|
+
|
14
19
|
namespace
|
15
20
|
{
|
16
21
|
class Container
|
@@ -347,7 +352,7 @@ TESTCASE(IterateNoCopy)
|
|
347
352
|
|
348
353
|
ASSERT_EQUAL(container.data_.size(), a.size());
|
349
354
|
|
350
|
-
for (
|
355
|
+
for (size_t i = 0; i < container.data_.size(); i++)
|
351
356
|
{
|
352
357
|
Data& expected = container.data_[i];
|
353
358
|
Data_Object<Data> actual(a[i]);
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "embed_ruby.hpp"
|
3
|
+
#include <rice/rice.hpp>
|
4
|
+
|
5
|
+
using namespace Rice;
|
6
|
+
|
7
|
+
TESTSUITE(Jump_Tag);
|
8
|
+
|
9
|
+
SETUP(Jump_Tag)
|
10
|
+
{
|
11
|
+
}
|
12
|
+
|
13
|
+
TEARDOWN(Jump_Tag)
|
14
|
+
{
|
15
|
+
rb_gc_start();
|
16
|
+
}
|
17
|
+
|
18
|
+
TESTCASE(construct)
|
19
|
+
{
|
20
|
+
JumpException exception(JumpException::RUBY_TAG_RETURN);
|
21
|
+
ASSERT_EQUAL(JumpException::RUBY_TAG_RETURN, exception.tag);
|
22
|
+
}
|
23
|
+
|