rice 4.5.0 → 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 +23 -0
- data/CMakeLists.txt +31 -0
- data/CMakePresets.json +75 -0
- data/COPYING +3 -2
- data/FindRuby.cmake +437 -0
- data/Rakefile +5 -4
- data/include/rice/rice.hpp +5436 -3201
- data/include/rice/stl.hpp +2355 -1269
- data/lib/make_rice_headers.rb +79 -0
- data/lib/mkmf-rice.rb +4 -0
- 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/Arg.hpp +7 -1
- data/rice/Arg.ipp +11 -2
- data/rice/Buffer.hpp +123 -0
- data/rice/Buffer.ipp +599 -0
- data/rice/Constructor.ipp +3 -3
- data/rice/Data_Object.hpp +2 -3
- data/rice/Data_Object.ipp +188 -188
- data/rice/Data_Type.hpp +4 -5
- data/rice/Data_Type.ipp +42 -26
- data/rice/Enum.hpp +0 -1
- data/rice/Enum.ipp +26 -23
- data/rice/Init.hpp +8 -0
- data/rice/Init.ipp +8 -0
- data/rice/MemoryView.ipp +1 -41
- data/rice/Return.hpp +1 -1
- data/rice/Return.ipp +6 -0
- 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/cpp_api/Identifier.hpp +46 -0
- data/rice/cpp_api/Identifier.ipp +31 -0
- 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/MethodInfo.hpp +1 -9
- data/rice/detail/MethodInfo.ipp +5 -72
- data/rice/detail/Native.hpp +3 -2
- data/rice/detail/Native.ipp +32 -4
- data/rice/detail/NativeAttributeGet.hpp +3 -2
- data/rice/detail/NativeAttributeGet.ipp +8 -2
- data/rice/detail/NativeAttributeSet.hpp +3 -2
- data/rice/detail/NativeAttributeSet.ipp +8 -2
- data/rice/detail/NativeCallbackFFI.ipp +1 -1
- data/rice/detail/NativeFunction.hpp +17 -6
- data/rice/detail/NativeFunction.ipp +168 -64
- data/rice/detail/NativeIterator.hpp +3 -2
- data/rice/detail/NativeIterator.ipp +8 -2
- data/rice/detail/RubyType.hpp +2 -5
- data/rice/detail/RubyType.ipp +50 -5
- data/rice/detail/Type.hpp +3 -1
- data/rice/detail/Type.ipp +61 -31
- data/rice/detail/Wrapper.hpp +68 -33
- data/rice/detail/Wrapper.ipp +103 -113
- data/rice/detail/from_ruby.hpp +5 -4
- data/rice/detail/from_ruby.ipp +737 -365
- data/rice/detail/to_ruby.ipp +1092 -186
- data/rice/global_function.ipp +1 -1
- data/rice/libc/file.hpp +11 -0
- data/rice/libc/file.ipp +32 -0
- data/rice/rice.hpp +23 -16
- 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 +7 -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 +3 -0
- data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
- data/test/test_Array.cpp +6 -3
- data/test/test_Attribute.cpp +34 -1
- data/test/test_Buffer.cpp +285 -0
- data/test/test_Callback.cpp +2 -3
- data/test/test_Data_Object.cpp +88 -34
- data/test/test_Data_Type.cpp +106 -65
- data/test/test_Director.cpp +7 -3
- data/test/test_Enum.cpp +5 -2
- data/test/test_File.cpp +1 -1
- data/test/test_From_Ruby.cpp +181 -114
- data/test/test_Iterator.cpp +1 -1
- data/test/{test_JumpException.cpp → test_Jump_Exception.cpp} +1 -0
- data/test/test_Keep_Alive.cpp +7 -18
- data/test/test_Keep_Alive_No_Wrapper.cpp +0 -1
- data/test/test_Module.cpp +13 -6
- data/test/test_Native_Registry.cpp +0 -1
- data/test/test_Overloads.cpp +180 -5
- data/test/test_Ownership.cpp +100 -57
- data/test/test_Proc.cpp +0 -1
- data/test/test_Self.cpp +4 -4
- data/test/test_Stl_Map.cpp +37 -39
- data/test/test_Stl_Multimap.cpp +693 -0
- data/test/test_Stl_Pair.cpp +8 -8
- data/test/test_Stl_Reference_Wrapper.cpp +4 -2
- data/test/test_Stl_Set.cpp +790 -0
- data/test/{test_Stl_SmartPointer.cpp → test_Stl_SharedPtr.cpp} +97 -127
- data/test/test_Stl_Tuple.cpp +116 -0
- data/test/test_Stl_Type.cpp +1 -1
- data/test/test_Stl_UniquePtr.cpp +202 -0
- data/test/test_Stl_Unordered_Map.cpp +28 -34
- data/test/test_Stl_Variant.cpp +217 -89
- data/test/test_Stl_Vector.cpp +209 -83
- data/test/test_To_Ruby.cpp +373 -1
- data/test/test_Type.cpp +85 -14
- data/test/test_global_functions.cpp +17 -4
- metadata +94 -10
- data/rice/detail/TupleIterator.hpp +0 -14
data/test/test_From_Ruby.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "unittest.hpp"
|
1
|
+
#include "unittest.hpp"
|
2
2
|
#include "embed_ruby.hpp"
|
3
3
|
#include <rice/rice.hpp>
|
4
4
|
#include <rice/stl.hpp>
|
@@ -13,6 +13,7 @@ TESTSUITE(FromRuby);
|
|
13
13
|
SETUP(FromRuby)
|
14
14
|
{
|
15
15
|
embed_ruby();
|
16
|
+
define_fundamental_buffer_types();
|
16
17
|
}
|
17
18
|
|
18
19
|
TEARDOWN(FromRuby)
|
@@ -23,7 +24,7 @@ TEARDOWN(FromRuby)
|
|
23
24
|
namespace
|
24
25
|
{
|
25
26
|
template<typename T>
|
26
|
-
std::string
|
27
|
+
std::string arrayToString(T* buffer, int size)
|
27
28
|
{
|
28
29
|
std::ostringstream result;
|
29
30
|
result << "[";
|
@@ -44,7 +45,38 @@ namespace
|
|
44
45
|
template<typename T>
|
45
46
|
std::string voidToString(void* buffer, int size)
|
46
47
|
{
|
47
|
-
return
|
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();
|
48
80
|
}
|
49
81
|
}
|
50
82
|
|
@@ -103,43 +135,32 @@ TESTCASE(char_pointer)
|
|
103
135
|
detail::From_Ruby<char*> fromRuby;
|
104
136
|
|
105
137
|
char* expected = nullptr;
|
106
|
-
char*
|
107
|
-
ASSERT_EQUAL(expected,
|
108
|
-
|
109
|
-
|
110
|
-
result =
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
ASSERT_EQUAL(
|
120
|
-
ASSERT_EQUAL(
|
121
|
-
ASSERT_EQUAL(
|
122
|
-
ASSERT_EQUAL(
|
123
|
-
ASSERT_EQUAL(
|
124
|
-
ASSERT_EQUAL(
|
125
|
-
|
126
|
-
|
127
|
-
String packed = array.call("pack", format);
|
128
|
-
result = fromRuby.convert(packed.value());
|
129
|
-
|
130
|
-
ASSERT_EQUAL(result[0], 0);
|
131
|
-
ASSERT_EQUAL(result[1], 127);
|
132
|
-
ASSERT_EQUAL(result[2], -128);
|
133
|
-
ASSERT_EQUAL(result[3], -1);
|
134
|
-
ASSERT_EQUAL(result[4], 0);
|
135
|
-
ASSERT_EQUAL(result[5], -128);
|
136
|
-
ASSERT_EQUAL(result[6], 127);
|
137
|
-
ASSERT_EQUAL(result[7], 1);
|
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);
|
138
159
|
|
139
160
|
ASSERT_EXCEPTION_CHECK(
|
140
161
|
Exception,
|
141
162
|
fromRuby.convert(rb_float_new(11.11)),
|
142
|
-
ASSERT_EQUAL("wrong argument type Float (expected char
|
163
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char≻)", ex.what())
|
143
164
|
);
|
144
165
|
}
|
145
166
|
|
@@ -149,56 +170,55 @@ TESTCASE(signed_char_pointer)
|
|
149
170
|
detail::From_Ruby<signed char*> fromRuby;
|
150
171
|
|
151
172
|
signed char* expected = nullptr;
|
152
|
-
signed char*
|
153
|
-
ASSERT_EQUAL(expected,
|
173
|
+
signed char* data = fromRuby.convert(Qnil);
|
174
|
+
ASSERT_EQUAL(expected, data);
|
154
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());
|
155
179
|
expected = (signed char*)"my string";
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
ASSERT_EQUAL(
|
164
|
-
ASSERT_EQUAL(
|
165
|
-
ASSERT_EQUAL(
|
166
|
-
ASSERT_EQUAL(
|
167
|
-
ASSERT_EQUAL(
|
168
|
-
ASSERT_EQUAL(
|
169
|
-
ASSERT_EQUAL(
|
170
|
-
ASSERT_EQUAL(result[7], 1);
|
171
|
-
|
172
|
-
std::string format = CHAR_MIN < 0 ? "c*" : "C*";
|
173
|
-
String packed = array.call("pack", format);
|
174
|
-
result = fromRuby.convert(packed.value());
|
175
|
-
|
176
|
-
ASSERT_EQUAL(result[0], 0);
|
177
|
-
ASSERT_EQUAL(result[1], 127);
|
178
|
-
ASSERT_EQUAL(result[2], -128);
|
179
|
-
ASSERT_EQUAL(result[3], -1);
|
180
|
-
ASSERT_EQUAL(result[4], 0);
|
181
|
-
ASSERT_EQUAL(result[5], -128);
|
182
|
-
ASSERT_EQUAL(result[6], 127);
|
183
|
-
ASSERT_EQUAL(result[7], 1);
|
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);
|
184
194
|
|
185
195
|
ASSERT_EXCEPTION_CHECK(
|
186
196
|
Exception,
|
187
197
|
fromRuby.convert(rb_float_new(11.11)),
|
188
|
-
ASSERT_EQUAL("wrong argument type Float (expected signed
|
198
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺signed char≻)", ex.what())
|
189
199
|
);
|
190
200
|
}
|
191
201
|
|
192
202
|
TESTCASE(char_pointer_const)
|
193
203
|
{
|
194
|
-
|
195
|
-
|
196
|
-
|
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);
|
197
217
|
|
198
218
|
ASSERT_EXCEPTION_CHECK(
|
199
219
|
Exception,
|
200
220
|
detail::From_Ruby<char const*>().convert(rb_float_new(32.3)),
|
201
|
-
ASSERT_EQUAL("wrong argument type Float (expected char
|
221
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char≻)", ex.what())
|
202
222
|
);
|
203
223
|
}
|
204
224
|
|
@@ -218,38 +238,41 @@ TESTCASE(unsigned_char_pointer)
|
|
218
238
|
detail::From_Ruby<unsigned char*> fromRuby;
|
219
239
|
|
220
240
|
unsigned char* expected = nullptr;
|
221
|
-
unsigned char*
|
222
|
-
ASSERT_EQUAL(expected,
|
223
|
-
|
224
|
-
std::string code = R"(
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
ASSERT_EQUAL(
|
229
|
-
ASSERT_EQUAL(
|
230
|
-
ASSERT_EQUAL(
|
231
|
-
ASSERT_EQUAL(
|
232
|
-
ASSERT_EQUAL(
|
233
|
-
ASSERT_EQUAL(
|
234
|
-
ASSERT_EQUAL(
|
235
|
-
ASSERT_EQUAL(
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
ASSERT_EQUAL(
|
244
|
-
ASSERT_EQUAL(
|
245
|
-
ASSERT_EQUAL(
|
246
|
-
ASSERT_EQUAL(
|
247
|
-
ASSERT_EQUAL(
|
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);
|
248
271
|
|
249
272
|
ASSERT_EXCEPTION_CHECK(
|
250
273
|
Exception,
|
251
274
|
detail::From_Ruby<const char*>().convert(rb_float_new(11.11)),
|
252
|
-
ASSERT_EQUAL("wrong argument type Float (expected char
|
275
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char≻)", ex.what())
|
253
276
|
);
|
254
277
|
}
|
255
278
|
|
@@ -257,10 +280,11 @@ TESTCASE(unsigned_char_pointer_array)
|
|
257
280
|
{
|
258
281
|
Module m = define_module("Testing");
|
259
282
|
|
260
|
-
m.define_singleton_function("unsigned_char_pointer", &
|
283
|
+
m.define_singleton_function("unsigned_char_pointer", &arrayToString<unsigned char>);
|
261
284
|
|
262
285
|
std::string code = R"(arr = ["A", "B"]
|
263
|
-
|
286
|
+
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
287
|
+
unsigned_char_pointer(buffer, buffer.size))";
|
264
288
|
|
265
289
|
ASSERT_EXCEPTION_CHECK(
|
266
290
|
Exception,
|
@@ -271,18 +295,21 @@ TESTCASE(unsigned_char_pointer_array)
|
|
271
295
|
code = R"(arr = ["A", "B"].map do |char|
|
272
296
|
char.ord
|
273
297
|
end
|
274
|
-
|
298
|
+
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
299
|
+
unsigned_char_pointer(buffer, buffer.size))";
|
275
300
|
|
276
301
|
Object result = m.module_eval(code);
|
277
302
|
ASSERT_EQUAL("[A, B]", detail::From_Ruby<std::string>().convert(result.value()));
|
278
303
|
|
279
304
|
code = R"(arr = [65, 66]
|
280
|
-
|
305
|
+
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
306
|
+
unsigned_char_pointer(buffer, buffer.size))";
|
281
307
|
result = m.module_eval(code);
|
282
308
|
ASSERT_EQUAL("[A, B]", detail::From_Ruby<std::string>().convert(result.value()));
|
283
309
|
|
284
310
|
code = R"(arr = [true]
|
285
|
-
|
311
|
+
buffer = Rice::Buffer≺unsigned char≻.new(arr)
|
312
|
+
unsigned_char_pointer(buffer, buffer.size))";
|
286
313
|
|
287
314
|
ASSERT_EXCEPTION_CHECK(
|
288
315
|
Exception,
|
@@ -315,10 +342,11 @@ TESTCASE(double)
|
|
315
342
|
TESTCASE(double_pointer_array)
|
316
343
|
{
|
317
344
|
Module m = define_module("Testing");
|
318
|
-
m.define_singleton_function("double_pointer", &
|
345
|
+
m.define_singleton_function("double_pointer", &arrayToString<double>);
|
319
346
|
|
320
347
|
std::string code = R"(arr = [1.1, 2.2, 3.3, 4.4]
|
321
|
-
|
348
|
+
buffer = Rice::Buffer≺double≻.new(arr)
|
349
|
+
double_pointer(buffer, buffer.size))";
|
322
350
|
|
323
351
|
Object result = m.module_eval(code);
|
324
352
|
|
@@ -350,20 +378,23 @@ TESTCASE(float_pointer_array)
|
|
350
378
|
{
|
351
379
|
Module m = define_module("Testing");
|
352
380
|
|
353
|
-
m.define_singleton_function("float_pointer", &
|
381
|
+
m.define_singleton_function("float_pointer", &arrayToString<float>);
|
354
382
|
|
355
383
|
std::string code = R"(arr = [4.3, 3.2, 2.1, 1.1]
|
356
|
-
|
384
|
+
buffer = Rice::Buffer≺float≻.new(arr)
|
385
|
+
float_pointer(buffer, buffer.size))";
|
357
386
|
Object result = m.module_eval(code);
|
358
387
|
ASSERT_EQUAL("[4.3, 3.2, 2.1, 1.1]", detail::From_Ruby<std::string>().convert(result.value()));
|
359
388
|
|
360
389
|
code = R"(arr = [4, 3, 2.8, 1]
|
361
|
-
|
390
|
+
buffer = Rice::Buffer≺float≻.new(arr)
|
391
|
+
float_pointer(buffer, buffer.size))";
|
362
392
|
result = m.module_eval(code);
|
363
393
|
ASSERT_EQUAL("[4, 3, 2.8, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
364
394
|
|
365
395
|
code = R"(arr = [4, "bad", 2, 1]
|
366
|
-
|
396
|
+
buffer = Rice::Buffer≺float≻.new(arr)
|
397
|
+
float_pointer(buffer, buffer.size))";
|
367
398
|
|
368
399
|
ASSERT_EXCEPTION_CHECK(
|
369
400
|
Exception,
|
@@ -372,6 +403,41 @@ TESTCASE(float_pointer_array)
|
|
372
403
|
);
|
373
404
|
}
|
374
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
|
+
|
375
441
|
TESTCASE(int)
|
376
442
|
{
|
377
443
|
ASSERT_EQUAL(0, detail::From_Ruby<int>().convert(INT2NUM(0)));
|
@@ -392,15 +458,17 @@ TESTCASE(int)
|
|
392
458
|
TESTCASE(int_pointer_array)
|
393
459
|
{
|
394
460
|
Module m = define_module("Testing");
|
395
|
-
m.define_singleton_function("int_pointer", &
|
461
|
+
m.define_singleton_function("int_pointer", &arrayToString<int>);
|
396
462
|
|
397
463
|
std::string code = R"(arr = [4, 3, 2, 1]
|
398
|
-
|
464
|
+
buffer = Rice::Buffer≺int≻.new(arr)
|
465
|
+
int_pointer(buffer, buffer.size))";
|
399
466
|
Object result = m.module_eval(code);
|
400
467
|
ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
401
468
|
|
402
469
|
code = R"(arr = [4.2, 3.8, 2.0, 1]
|
403
|
-
|
470
|
+
buffer = Rice::Buffer≺int≻.new(arr)
|
471
|
+
int_pointer(buffer, buffer.size))";
|
404
472
|
result = m.module_eval(code);
|
405
473
|
ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
406
474
|
}
|
@@ -539,4 +607,3 @@ TESTCASE(void_pointer_array)
|
|
539
607
|
Object result = m.module_eval(code);
|
540
608
|
ASSERT_EQUAL("[4, 3, 2, 1]", detail::From_Ruby<std::string>().convert(result.value()));
|
541
609
|
}
|
542
|
-
|
data/test/test_Iterator.cpp
CHANGED
@@ -352,7 +352,7 @@ TESTCASE(IterateNoCopy)
|
|
352
352
|
|
353
353
|
ASSERT_EQUAL(container.data_.size(), a.size());
|
354
354
|
|
355
|
-
for (
|
355
|
+
for (size_t i = 0; i < container.data_.size(); i++)
|
356
356
|
{
|
357
357
|
Data& expected = container.data_[i];
|
358
358
|
Data_Object<Data> actual(a[i]);
|
data/test/test_Keep_Alive.cpp
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
#include "unittest.hpp"
|
2
2
|
#include "embed_ruby.hpp"
|
3
3
|
#include <rice/rice.hpp>
|
4
|
-
#include <rice/stl.hpp>
|
5
4
|
|
6
5
|
using namespace Rice;
|
7
6
|
|
@@ -112,7 +111,10 @@ namespace
|
|
112
111
|
{
|
113
112
|
}
|
114
113
|
|
115
|
-
|
114
|
+
uint32_t index()
|
115
|
+
{
|
116
|
+
return this->index_;
|
117
|
+
}
|
116
118
|
|
117
119
|
private:
|
118
120
|
Connection& connection_;
|
@@ -126,20 +128,7 @@ namespace
|
|
126
128
|
{
|
127
129
|
return Column(*this, index);
|
128
130
|
}
|
129
|
-
|
130
|
-
std::string getName(uint32_t index)
|
131
|
-
{
|
132
|
-
return this->prefix_ + std::to_string(index);
|
133
|
-
}
|
134
|
-
|
135
|
-
private:
|
136
|
-
std::string prefix_ = "column_";
|
137
131
|
};
|
138
|
-
|
139
|
-
std::string Column::name()
|
140
|
-
{
|
141
|
-
return this->connection_.getName(this->index_);
|
142
|
-
}
|
143
132
|
}
|
144
133
|
|
145
134
|
Object getColumn(Module& m, uint32_t index)
|
@@ -151,7 +140,7 @@ Object getColumn(Module& m, uint32_t index)
|
|
151
140
|
TESTCASE(test_return)
|
152
141
|
{
|
153
142
|
define_class<Column>("Column")
|
154
|
-
.define_method("
|
143
|
+
.define_method("index", &Column::index);
|
155
144
|
|
156
145
|
define_class<Connection>("Connection")
|
157
146
|
.define_constructor(Constructor<Connection>())
|
@@ -161,6 +150,6 @@ TESTCASE(test_return)
|
|
161
150
|
|
162
151
|
Object column = getColumn(m, 3);
|
163
152
|
rb_gc_start();
|
164
|
-
|
165
|
-
ASSERT_EQUAL(
|
153
|
+
Object index = column.call("index");
|
154
|
+
ASSERT_EQUAL(3, detail::From_Ruby<int>().convert(index));
|
166
155
|
}
|
data/test/test_Module.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "unittest.hpp"
|
1
|
+
#include "unittest.hpp"
|
2
2
|
#include "embed_ruby.hpp"
|
3
3
|
|
4
4
|
#include <rice/rice.hpp>
|
@@ -11,6 +11,7 @@ TESTSUITE(Module);
|
|
11
11
|
SETUP(Module)
|
12
12
|
{
|
13
13
|
embed_ruby();
|
14
|
+
define_fundamental_buffer_types();
|
14
15
|
}
|
15
16
|
|
16
17
|
TEARDOWN(Module)
|
@@ -187,7 +188,7 @@ TESTCASE(method_int_passed_no_args)
|
|
187
188
|
ASSERT_EXCEPTION_CHECK(
|
188
189
|
Exception,
|
189
190
|
m.module_eval("o = Object.new; o.extend(self); o.foo"),
|
190
|
-
ASSERT_EQUAL("
|
191
|
+
ASSERT_EQUAL("Missing argument. Name: arg_0. Index: 0.", ex.what())
|
191
192
|
);
|
192
193
|
}
|
193
194
|
|
@@ -272,7 +273,7 @@ TESTCASE(default_arguments_still_throws_argument_error)
|
|
272
273
|
ASSERT_EXCEPTION_CHECK(
|
273
274
|
Exception,
|
274
275
|
m.module_eval("o = Object.new; o.extend(self); o.foo()"),
|
275
|
-
ASSERT_EQUAL("
|
276
|
+
ASSERT_EQUAL("Missing argument. Name: arg1. Index: 0.", ex.what())
|
276
277
|
);
|
277
278
|
|
278
279
|
ASSERT_EXCEPTION_CHECK(
|
@@ -284,7 +285,7 @@ TESTCASE(default_arguments_still_throws_argument_error)
|
|
284
285
|
ASSERT_EXCEPTION_CHECK(
|
285
286
|
Exception,
|
286
287
|
m.module_eval("o = Object.new; o.extend(self); o.foo(3, 4, false, 17)"),
|
287
|
-
ASSERT_EQUAL("wrong number of arguments (given 4, expected
|
288
|
+
ASSERT_EQUAL("wrong number of arguments (given 4, expected 3)", ex.what())
|
288
289
|
);
|
289
290
|
}
|
290
291
|
|
@@ -464,7 +465,9 @@ TESTCASE(define_method_works_with_pointers)
|
|
464
465
|
Module m(anonymous_module());
|
465
466
|
m.define_module_function("bar", &with_pointers);
|
466
467
|
|
467
|
-
|
468
|
+
int anInt = 3;
|
469
|
+
Buffer<int> buffer(&anInt, 1);
|
470
|
+
m.call("bar", std::move(buffer), "testing");
|
468
471
|
|
469
472
|
ASSERT_EQUAL(3, with_pointers_x);
|
470
473
|
ASSERT_EQUAL("testing", with_pointers_str);
|
@@ -499,8 +502,12 @@ TESTCASE(pointers)
|
|
499
502
|
define_global_function("with_pointers", &withPointers);
|
500
503
|
|
501
504
|
Module m = define_module("TestingModule");
|
505
|
+
std::string code = R"(int_buffer = Rice::Buffer≺int≻.new(32)
|
506
|
+
bool_buffer = Rice::Buffer≺bool≻.new(true)
|
507
|
+
double_buffer = Rice::Buffer≺float≻.new(33.0)
|
508
|
+
float_buffer = Rice::Buffer≺double≻.new(34.0)
|
509
|
+
with_pointers(int_buffer, bool_buffer, double_buffer, float_buffer))";
|
502
510
|
|
503
|
-
std::string code = "with_pointers(32, true, 33.0, 34.0)";
|
504
511
|
m.module_eval(code);
|
505
512
|
|
506
513
|
ASSERT_EQUAL(intValue, 32);
|