rice 4.6.0 → 4.6.1
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 +10 -0
- data/include/rice/rice.hpp +408 -153
- data/include/rice/stl.hpp +49 -50
- data/lib/rice/version.rb +1 -1
- data/rice/Buffer.hpp +57 -12
- data/rice/Buffer.ipp +273 -84
- data/rice/Data_Type.hpp +3 -0
- data/rice/Data_Type.ipp +39 -28
- data/rice/detail/NativeAttributeGet.ipp +12 -1
- data/rice/detail/NativeAttributeSet.ipp +3 -21
- data/rice/detail/NativeCallbackFFI.ipp +1 -0
- data/rice/detail/NativeFunction.ipp +1 -0
- data/rice/detail/RubyFunction.ipp +1 -0
- data/rice/detail/Type.ipp +0 -1
- data/rice/stl/vector.ipp +49 -50
- data/rice/traits/attribute_traits.hpp +6 -6
- data/rice/traits/rice_traits.hpp +12 -0
- data/test/test_Attribute.cpp +57 -8
- data/test/test_Buffer.cpp +56 -1
- data/test/test_Data_Object.cpp +1 -1
- data/test/test_From_Ruby.cpp +6 -6
- metadata +1 -1
data/rice/Data_Type.ipp
CHANGED
@@ -61,7 +61,7 @@ namespace Rice
|
|
61
61
|
|
62
62
|
auto instances = unbound_instances();
|
63
63
|
for (auto instance: instances)
|
64
|
-
{
|
64
|
+
{
|
65
65
|
instance->set_value(klass);
|
66
66
|
}
|
67
67
|
instances.clear();
|
@@ -240,7 +240,7 @@ namespace Rice
|
|
240
240
|
return false;
|
241
241
|
}
|
242
242
|
}
|
243
|
-
|
243
|
+
|
244
244
|
template<typename Base_T>
|
245
245
|
inline Class get_superklass()
|
246
246
|
{
|
@@ -280,7 +280,7 @@ namespace Rice
|
|
280
280
|
Class superKlass = get_superklass<Base_T>();
|
281
281
|
return define_class_under<T, Base_T>(parent, id, superKlass);
|
282
282
|
}
|
283
|
-
|
283
|
+
|
284
284
|
template<typename T, typename Base_T>
|
285
285
|
inline Data_Type<T> define_class(char const* name)
|
286
286
|
{
|
@@ -314,42 +314,53 @@ namespace Rice
|
|
314
314
|
template <typename Attribute_T>
|
315
315
|
inline Data_Type<T>& Data_Type<T>::define_attr(std::string name, Attribute_T attribute, AttrAccess access)
|
316
316
|
{
|
317
|
-
|
318
|
-
detail::verifyType<typename detail::attribute_traits<Attribute_T>::attr_type>();
|
319
|
-
|
320
|
-
// Define native attribute getter
|
321
|
-
if (access == AttrAccess::ReadWrite || access == AttrAccess::Read)
|
322
|
-
detail::NativeAttributeGet<Attribute_T>::define(klass_, name, std::forward<Attribute_T>(attribute));
|
323
|
-
|
324
|
-
using Attr_T = typename detail::NativeAttributeSet<Attribute_T>::Attr_T;
|
325
|
-
if constexpr (!std::is_const_v<Attr_T> &&
|
326
|
-
(std::is_fundamental_v<Attr_T> || std::is_assignable_v<Attr_T, Attr_T>))
|
327
|
-
{
|
328
|
-
// Define native attribute setter
|
329
|
-
if (access == AttrAccess::ReadWrite || access == AttrAccess::Write)
|
330
|
-
detail::NativeAttributeSet<Attribute_T>::define(klass_, name, std::forward<Attribute_T>(attribute));
|
331
|
-
}
|
332
|
-
|
333
|
-
return *this;
|
317
|
+
return this->define_attr_internal<Attribute_T>(this->klass_, name, std::forward<Attribute_T>(attribute), access);
|
334
318
|
}
|
335
319
|
|
336
320
|
template <typename T>
|
337
321
|
template <typename Attribute_T>
|
338
322
|
inline Data_Type<T>& Data_Type<T>::define_singleton_attr(std::string name, Attribute_T attribute, AttrAccess access)
|
339
323
|
{
|
340
|
-
// Make sure the Attribute type has been previously seen by Rice
|
341
|
-
detail::verifyType<typename detail::attribute_traits<Attribute_T>::attr_type>();
|
342
|
-
|
343
|
-
// Define native attribute
|
344
324
|
VALUE singleton = detail::protect(rb_singleton_class, this->value());
|
325
|
+
return this->define_attr_internal<Attribute_T>(singleton, name, std::forward<Attribute_T>(attribute), access);
|
326
|
+
}
|
327
|
+
|
328
|
+
template <typename T>
|
329
|
+
template <typename Attribute_T>
|
330
|
+
inline Data_Type<T>& Data_Type<T>::define_attr_internal(VALUE klass, std::string name, Attribute_T attribute, AttrAccess access)
|
331
|
+
{
|
332
|
+
using Attr_T = typename detail::attribute_traits<Attribute_T>::attr_type;
|
345
333
|
|
346
|
-
//
|
334
|
+
// Make sure the Attribute type has been previously seen by Rice
|
335
|
+
detail::verifyType<Attr_T>();
|
336
|
+
|
337
|
+
// Define attribute getter
|
347
338
|
if (access == AttrAccess::ReadWrite || access == AttrAccess::Read)
|
348
|
-
|
339
|
+
{
|
340
|
+
detail::NativeAttributeGet<Attribute_T>::define(klass, name, std::forward<Attribute_T>(attribute));
|
341
|
+
}
|
349
342
|
|
350
|
-
// Define
|
343
|
+
// Define attribute setter
|
351
344
|
if (access == AttrAccess::ReadWrite || access == AttrAccess::Write)
|
352
|
-
|
345
|
+
{
|
346
|
+
if constexpr (std::is_const_v<Attr_T>)
|
347
|
+
{
|
348
|
+
throw std::runtime_error("Cannot define attribute writer for a const attribute: " + name);
|
349
|
+
}
|
350
|
+
else if constexpr (!std::is_fundamental_v<Attr_T> && !std::is_assignable_v<Attr_T, Attr_T>)
|
351
|
+
{
|
352
|
+
throw std::runtime_error("Cannot define attribute writer for a non assignable attribute: " + name);
|
353
|
+
}
|
354
|
+
else if constexpr (!std::is_fundamental_v<Attr_T> && !std::is_copy_constructible_v<Attr_T>)
|
355
|
+
{
|
356
|
+
throw std::runtime_error("Cannot define attribute writer for a non copy constructible attribute: " + name);
|
357
|
+
}
|
358
|
+
else
|
359
|
+
{
|
360
|
+
// Define native attribute setter
|
361
|
+
detail::NativeAttributeSet<Attribute_T>::define(klass, name, std::forward<Attribute_T>(attribute));
|
362
|
+
}
|
363
|
+
}
|
353
364
|
|
354
365
|
return *this;
|
355
366
|
}
|
@@ -41,7 +41,18 @@ namespace Rice::detail
|
|
41
41
|
if constexpr (std::is_member_object_pointer_v<Attribute_T>)
|
42
42
|
{
|
43
43
|
Receiver_T* nativeSelf = From_Ruby<Receiver_T*>().convert(self);
|
44
|
-
|
44
|
+
|
45
|
+
if constexpr (std::is_fundamental_v<detail::intrinsic_type<To_Ruby_T>> ||
|
46
|
+
(std::is_array_v<To_Ruby_T> && std::is_fundamental_v<std::remove_extent_t<To_Ruby_T>>))
|
47
|
+
{
|
48
|
+
return To_Ruby<To_Ruby_T>().convert(nativeSelf->*attribute_);
|
49
|
+
}
|
50
|
+
else
|
51
|
+
{
|
52
|
+
// If the attribute is an object return a reference to avoid a copy (and avoid issues with
|
53
|
+
// attributes that are not assignable, copy constructible or move constructible)
|
54
|
+
return To_Ruby<To_Ruby_T&>().convert(nativeSelf->*attribute_);
|
55
|
+
}
|
45
56
|
}
|
46
57
|
else
|
47
58
|
{
|
@@ -42,39 +42,21 @@ namespace Rice::detail
|
|
42
42
|
template<typename Attribute_T>
|
43
43
|
inline VALUE NativeAttributeSet<Attribute_T>::operator()(size_t argc, const VALUE* argv, VALUE self)
|
44
44
|
{
|
45
|
-
if constexpr (std::is_fundamental_v<intrinsic_type<Attr_T>> && std::is_pointer_v<Attr_T>)
|
46
|
-
{
|
47
|
-
static_assert(true, "An fundamental value, such as an integer, cannot be assigned to an attribute that is a pointer.");
|
48
|
-
}
|
49
|
-
else if constexpr (std::is_same_v<intrinsic_type<Attr_T>, std::string> && std::is_pointer_v<Attr_T>)
|
50
|
-
{
|
51
|
-
static_assert(true, "An string cannot be assigned to an attribute that is a pointer.");
|
52
|
-
}
|
53
|
-
|
54
45
|
if (argc != 1)
|
55
46
|
{
|
56
47
|
throw std::runtime_error("Incorrect number of parameters for setting attribute. Attribute: " + this->name_);
|
57
48
|
}
|
58
49
|
|
59
50
|
VALUE value = argv[0];
|
60
|
-
|
61
|
-
if constexpr (!std::is_null_pointer_v<Receiver_T>
|
62
|
-
!std::is_const_v<Attr_T> &&
|
63
|
-
(std::is_fundamental_v<Attr_T> || std::is_assignable_v<Attr_T, Attr_T>))
|
51
|
+
|
52
|
+
if constexpr (!std::is_null_pointer_v<Receiver_T>)
|
64
53
|
{
|
65
54
|
Receiver_T* nativeSelf = From_Ruby<Receiver_T*>().convert(self);
|
66
55
|
nativeSelf->*attribute_ = From_Ruby<T_Unqualified>().convert(value);
|
67
56
|
}
|
68
|
-
else if constexpr (std::is_null_pointer_v<Receiver_T> &&
|
69
|
-
!std::is_const_v<Attr_T> &&
|
70
|
-
(std::is_fundamental_v<Attr_T> || std::is_assignable_v<Attr_T, Attr_T>))
|
71
|
-
{
|
72
|
-
*attribute_ = From_Ruby<T_Unqualified>().convert(value);
|
73
|
-
}
|
74
57
|
else
|
75
58
|
{
|
76
|
-
|
77
|
-
throw std::invalid_argument("Could not set attribute. Attribute: " + this->name_);
|
59
|
+
*attribute_ = From_Ruby<T_Unqualified>().convert(value);
|
78
60
|
}
|
79
61
|
|
80
62
|
return value;
|
data/rice/detail/Type.ipp
CHANGED
data/rice/stl/vector.ipp
CHANGED
@@ -133,68 +133,67 @@ namespace Rice
|
|
133
133
|
}
|
134
134
|
})
|
135
135
|
.define_method("last", [](const T& vector) -> std::optional<Value_T>
|
136
|
+
{
|
137
|
+
if (vector.size() > 0)
|
136
138
|
{
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
}
|
145
|
-
})
|
139
|
+
return vector.back();
|
140
|
+
}
|
141
|
+
else
|
142
|
+
{
|
143
|
+
return std::nullopt;
|
144
|
+
}
|
145
|
+
})
|
146
146
|
.define_method("[]", [this](const T& vector, Difference_T index) -> std::optional<Value_T>
|
147
|
+
{
|
148
|
+
index = normalizeIndex(vector.size(), index);
|
149
|
+
if (index < 0 || index >= (Difference_T)vector.size())
|
147
150
|
{
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
return vector[index];
|
156
|
-
}
|
157
|
-
})
|
151
|
+
return std::nullopt;
|
152
|
+
}
|
153
|
+
else
|
154
|
+
{
|
155
|
+
return vector[index];
|
156
|
+
}
|
157
|
+
})
|
158
158
|
.define_method("[]", [this](const T& vector, Difference_T start, Difference_T length) -> VALUE
|
159
|
+
{
|
160
|
+
start = normalizeIndex(vector.size(), start);
|
161
|
+
if (start < 0 || start >= (Difference_T)vector.size())
|
162
|
+
{
|
163
|
+
return rb_ary_new();
|
164
|
+
}
|
165
|
+
else
|
159
166
|
{
|
160
|
-
|
161
|
-
|
167
|
+
auto begin = vector.begin() + start;
|
168
|
+
|
169
|
+
// Ruby does not throw an exception when the length is too long
|
170
|
+
Difference_T size = (Difference_T)vector.size();
|
171
|
+
if (start + length > size)
|
162
172
|
{
|
163
|
-
|
173
|
+
length = size - start;
|
164
174
|
}
|
165
|
-
else
|
166
|
-
{
|
167
|
-
auto begin = vector.begin() + start;
|
168
|
-
|
169
|
-
// Ruby does not throw an exception when the length is too long
|
170
|
-
Difference_T size = (Difference_T)vector.size();
|
171
|
-
if (start + length > size)
|
172
|
-
{
|
173
|
-
length = size - start;
|
174
|
-
}
|
175
175
|
|
176
|
-
|
177
|
-
|
176
|
+
auto finish = vector.begin() + start + length;
|
177
|
+
T slice(begin, finish);
|
178
178
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
return result;
|
187
|
-
}
|
188
|
-
}, Return().setValue());
|
179
|
+
VALUE result = rb_ary_new();
|
180
|
+
std::for_each(slice.begin(), slice.end(), [&result](const Reference_T element)
|
181
|
+
{
|
182
|
+
VALUE value = detail::To_Ruby<Parameter_T>().convert(element);
|
183
|
+
rb_ary_push(result, value);
|
184
|
+
});
|
189
185
|
|
190
|
-
|
191
|
-
{
|
192
|
-
define_buffer<Value_T>();
|
193
|
-
define_buffer<Value_T*>();
|
194
|
-
klass_.template define_method<Value_T*(T::*)()>("data", &T::data);
|
186
|
+
return result;
|
195
187
|
}
|
188
|
+
}, Return().setValue());
|
189
|
+
|
190
|
+
if constexpr (!std::is_same_v<Value_T, bool>)
|
191
|
+
{
|
192
|
+
define_buffer<Value_T>();
|
193
|
+
klass_.template define_method<Value_T*(T::*)()>("data", &T::data);
|
194
|
+
}
|
196
195
|
|
197
|
-
|
196
|
+
rb_define_alias(klass_, "at", "[]");
|
198
197
|
}
|
199
198
|
|
200
199
|
// Methods that require Value_T to support operator==
|
@@ -9,17 +9,17 @@ namespace Rice::detail
|
|
9
9
|
template<typename Attribute_T>
|
10
10
|
struct attribute_traits;
|
11
11
|
|
12
|
-
template<typename
|
13
|
-
struct attribute_traits<
|
12
|
+
template<typename Attribute_T>
|
13
|
+
struct attribute_traits<Attribute_T*>
|
14
14
|
{
|
15
|
-
using attr_type =
|
15
|
+
using attr_type = Attribute_T;
|
16
16
|
using class_type = std::nullptr_t;
|
17
17
|
};
|
18
18
|
|
19
|
-
template<typename
|
20
|
-
struct attribute_traits<
|
19
|
+
template<typename Attribute_T, typename Class_T>
|
20
|
+
struct attribute_traits<Attribute_T(Class_T::*)>
|
21
21
|
{
|
22
|
-
using attr_type =
|
22
|
+
using attr_type = Attribute_T;
|
23
23
|
using class_type = Class_T;
|
24
24
|
};
|
25
25
|
}
|
data/rice/traits/rice_traits.hpp
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#define Rice__detail__traits__hpp_
|
3
3
|
|
4
4
|
#include <ostream>
|
5
|
+
#include <tuple>
|
5
6
|
#include <type_traits>
|
6
7
|
#include <variant>
|
7
8
|
#include <vector>
|
@@ -154,6 +155,17 @@ namespace Rice
|
|
154
155
|
(callable(std::forward<decltype(args)>(args)), ...);
|
155
156
|
}, std::forward<Tuple_T>(tuple));
|
156
157
|
}
|
158
|
+
|
159
|
+
template<typename T, typename = void>
|
160
|
+
struct is_wrapped : std::true_type {};
|
161
|
+
|
162
|
+
template<typename T>
|
163
|
+
struct is_wrapped<T, std::enable_if_t<std::is_fundamental_v<detail::intrinsic_type<T>> ||
|
164
|
+
std::is_same_v<detail::intrinsic_type<T>, std::string>>
|
165
|
+
>: std::false_type {};
|
166
|
+
|
167
|
+
template<typename T>
|
168
|
+
constexpr bool is_wrapped_v = is_wrapped<T>::value;
|
157
169
|
} // detail
|
158
170
|
} // Rice
|
159
171
|
|
data/test/test_Attribute.cpp
CHANGED
@@ -31,6 +31,13 @@ namespace
|
|
31
31
|
NotAssignable& operator=(const NotAssignable&) = delete;
|
32
32
|
};
|
33
33
|
|
34
|
+
class NotCopyable
|
35
|
+
{
|
36
|
+
public:
|
37
|
+
NotCopyable() = default;
|
38
|
+
NotCopyable(const NotCopyable& other) = delete;
|
39
|
+
};
|
40
|
+
|
34
41
|
struct DataStruct
|
35
42
|
{
|
36
43
|
static inline float staticFloat = 1.0;
|
@@ -43,6 +50,7 @@ namespace
|
|
43
50
|
const int constInt = 5;
|
44
51
|
SomeClass someClass;
|
45
52
|
NotAssignable notAssignable;
|
53
|
+
NotCopyable notCopyable;
|
46
54
|
|
47
55
|
std::string inspect()
|
48
56
|
{
|
@@ -138,12 +146,18 @@ TESTCASE(vector)
|
|
138
146
|
|
139
147
|
TESTCASE(const_attribute)
|
140
148
|
{
|
141
|
-
|
142
|
-
.define_constructor(Constructor<DataStruct>())
|
143
|
-
.define_attr("const_int", &DataStruct::constInt);
|
149
|
+
Data_Type<DataStruct> c = define_class<DataStruct>("DataStruct")
|
150
|
+
.define_constructor(Constructor<DataStruct>());
|
144
151
|
|
145
|
-
|
152
|
+
ASSERT_EXCEPTION_CHECK(
|
153
|
+
std::exception,
|
154
|
+
c.define_attr("const_int", &DataStruct::constInt),
|
155
|
+
ASSERT_EQUAL(ex.what(), "Cannot define attribute writer for a const attribute: const_int")
|
156
|
+
);
|
146
157
|
|
158
|
+
c.define_attr("const_int", &DataStruct::constInt, AttrAccess::Read);
|
159
|
+
Data_Object<DataStruct> o = c.call("new");
|
160
|
+
|
147
161
|
if constexpr (!oldRuby)
|
148
162
|
{
|
149
163
|
ASSERT_EXCEPTION_CHECK(
|
@@ -154,15 +168,21 @@ TESTCASE(const_attribute)
|
|
154
168
|
}
|
155
169
|
}
|
156
170
|
|
157
|
-
TESTCASE(
|
171
|
+
TESTCASE(not_assignable)
|
158
172
|
{
|
159
173
|
Class notAssignableClass = define_class<NotAssignable>("NotAssignable")
|
160
174
|
.define_constructor(Constructor<NotAssignable>());
|
161
175
|
|
162
|
-
|
163
|
-
.define_constructor(Constructor<DataStruct>())
|
164
|
-
.define_attr("not_assignable", &DataStruct::notAssignable);
|
176
|
+
Data_Type<DataStruct> c = define_class<DataStruct>("DataStruct")
|
177
|
+
.define_constructor(Constructor<DataStruct>());
|
165
178
|
|
179
|
+
ASSERT_EXCEPTION_CHECK(
|
180
|
+
std::exception,
|
181
|
+
c.define_attr("not_assignable", &DataStruct::notAssignable),
|
182
|
+
ASSERT_EQUAL(ex.what(), "Cannot define attribute writer for a non assignable attribute: not_assignable")
|
183
|
+
);
|
184
|
+
|
185
|
+
c.define_attr("not_assignable", &DataStruct::notAssignable, AttrAccess::Read);
|
166
186
|
Data_Object<NotAssignable> notAssignable = notAssignableClass.call("new");
|
167
187
|
|
168
188
|
Data_Object<DataStruct> o = c.call("new");
|
@@ -177,6 +197,35 @@ TESTCASE(not_copyable_attribute)
|
|
177
197
|
}
|
178
198
|
}
|
179
199
|
|
200
|
+
TESTCASE(not_copyable)
|
201
|
+
{
|
202
|
+
Class notCopyableClass = define_class<NotCopyable>("NotCopyable")
|
203
|
+
.define_constructor(Constructor<NotCopyable>());
|
204
|
+
|
205
|
+
Data_Type<DataStruct> c = define_class<DataStruct>("DataStruct")
|
206
|
+
.define_constructor(Constructor<DataStruct>());
|
207
|
+
|
208
|
+
ASSERT_EXCEPTION_CHECK(
|
209
|
+
std::exception,
|
210
|
+
c.define_attr("not_copyable", &DataStruct::notCopyable),
|
211
|
+
ASSERT_EQUAL(ex.what(), "Cannot define attribute writer for a non copy constructible attribute: not_copyable")
|
212
|
+
);
|
213
|
+
|
214
|
+
c.define_attr("not_copyable", &DataStruct::notCopyable, AttrAccess::Read);
|
215
|
+
Data_Object<NotCopyable> notCopyable = notCopyableClass.call("new");
|
216
|
+
|
217
|
+
Data_Object<DataStruct> o = c.call("new");
|
218
|
+
|
219
|
+
if constexpr (!oldRuby)
|
220
|
+
{
|
221
|
+
ASSERT_EXCEPTION_CHECK(
|
222
|
+
Exception,
|
223
|
+
o.call("not_assignable=", notCopyable),
|
224
|
+
ASSERT(std::string(ex.what()).find("undefined method `not_copyable='") == 0)
|
225
|
+
);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
180
229
|
TESTCASE(static_attributes)
|
181
230
|
{
|
182
231
|
Class c = define_class<DataStruct>("DataStruct")
|
data/test/test_Buffer.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#include "unittest.hpp"
|
2
2
|
#include "embed_ruby.hpp"
|
3
3
|
#include <rice/rice.hpp>
|
4
4
|
|
@@ -283,3 +283,58 @@ TESTCASE(update_buffer)
|
|
283
283
|
ASSERT_EQUAL("index 1 outside of bounds: 0..1", ex.what())
|
284
284
|
);
|
285
285
|
}
|
286
|
+
|
287
|
+
TESTCASE(to_s)
|
288
|
+
{
|
289
|
+
define_buffer<unsigned char>();
|
290
|
+
Module m = define_module("Testing");
|
291
|
+
|
292
|
+
std::string code = R"(buffer = Rice::Buffer≺unsigned char≻.new([0, 127, 128, 255, 256, -128, -129, -255])
|
293
|
+
buffer.to_s)";
|
294
|
+
String result = m.instance_eval(code);
|
295
|
+
ASSERT_EQUAL("Buffer<type: unsigned char*, size: 8>", result.c_str());
|
296
|
+
|
297
|
+
Buffer<unsigned char> buffer(nullptr);
|
298
|
+
result = buffer.toString();
|
299
|
+
ASSERT_EQUAL("Buffer<type: unsigned char*, size: 0>", result.c_str());
|
300
|
+
}
|
301
|
+
|
302
|
+
namespace
|
303
|
+
{
|
304
|
+
class MyClass
|
305
|
+
{
|
306
|
+
public:
|
307
|
+
MyClass(int id) : id(id)
|
308
|
+
{
|
309
|
+
}
|
310
|
+
|
311
|
+
MyClass& operator=(const MyClass&) = delete;
|
312
|
+
|
313
|
+
int id;
|
314
|
+
};
|
315
|
+
}
|
316
|
+
|
317
|
+
TESTCASE(array_of_objects)
|
318
|
+
{
|
319
|
+
define_buffer<MyClass*>();
|
320
|
+
|
321
|
+
define_class<MyClass>("MyClass").
|
322
|
+
define_constructor(Constructor<MyClass, int>()).
|
323
|
+
define_attr("id", &MyClass::id);
|
324
|
+
|
325
|
+
std::string code = R"(array = [MyClass.new(0), MyClass.new(1)]
|
326
|
+
buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClass∗≻.new(array)
|
327
|
+
buffer[1].id)";
|
328
|
+
|
329
|
+
Module m = define_module("Testing");
|
330
|
+
Object result = m.module_eval(code);
|
331
|
+
ASSERT_EQUAL(1, detail::From_Ruby<int>().convert(result));
|
332
|
+
|
333
|
+
code = R"(array = [MyClass.new(0), MyClass.new(1)]
|
334
|
+
buffer = Rice::Buffer≺AnonymousNamespace꞉꞉MyClass∗≻.new(array)
|
335
|
+
buffer[1] = MyClass.new(2)
|
336
|
+
buffer[1].id)";
|
337
|
+
|
338
|
+
result = m.module_eval(code);
|
339
|
+
ASSERT_EQUAL(2, detail::From_Ruby<int>().convert(result));
|
340
|
+
}
|
data/test/test_Data_Object.cpp
CHANGED
@@ -244,7 +244,7 @@ TESTCASE(data_object_update_buffer)
|
|
244
244
|
Object result = m.module_eval(code);
|
245
245
|
Data_Object<Buffer<MyDataType>> dataObject(result);
|
246
246
|
Buffer<MyDataType>* buffer = dataObject.get();
|
247
|
-
MyDataType myDataType = buffer->
|
247
|
+
MyDataType myDataType = buffer->operator[](2);
|
248
248
|
ASSERT_EQUAL(100, myDataType.x);
|
249
249
|
}
|
250
250
|
|
data/test/test_From_Ruby.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#include "unittest.hpp"
|
2
2
|
#include "embed_ruby.hpp"
|
3
3
|
#include <rice/rice.hpp>
|
4
4
|
#include <rice/stl.hpp>
|
@@ -160,7 +160,7 @@ TESTCASE(char_pointer)
|
|
160
160
|
ASSERT_EXCEPTION_CHECK(
|
161
161
|
Exception,
|
162
162
|
fromRuby.convert(rb_float_new(11.11)),
|
163
|
-
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char≻)", ex.what())
|
163
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char‚ void≻)", ex.what())
|
164
164
|
);
|
165
165
|
}
|
166
166
|
|
@@ -195,7 +195,7 @@ TESTCASE(signed_char_pointer)
|
|
195
195
|
ASSERT_EXCEPTION_CHECK(
|
196
196
|
Exception,
|
197
197
|
fromRuby.convert(rb_float_new(11.11)),
|
198
|
-
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺signed char≻)", ex.what())
|
198
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺signed char‚ void≻)", ex.what())
|
199
199
|
);
|
200
200
|
}
|
201
201
|
|
@@ -218,7 +218,7 @@ TESTCASE(char_pointer_const)
|
|
218
218
|
ASSERT_EXCEPTION_CHECK(
|
219
219
|
Exception,
|
220
220
|
detail::From_Ruby<char const*>().convert(rb_float_new(32.3)),
|
221
|
-
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char≻)", ex.what())
|
221
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char‚ void≻)", ex.what())
|
222
222
|
);
|
223
223
|
}
|
224
224
|
|
@@ -272,7 +272,7 @@ TESTCASE(unsigned_char_pointer)
|
|
272
272
|
ASSERT_EXCEPTION_CHECK(
|
273
273
|
Exception,
|
274
274
|
detail::From_Ruby<const char*>().convert(rb_float_new(11.11)),
|
275
|
-
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char≻)", ex.what())
|
275
|
+
ASSERT_EQUAL("wrong argument type Float (expected Buffer≺char‚ void≻)", ex.what())
|
276
276
|
);
|
277
277
|
}
|
278
278
|
|
@@ -434,7 +434,7 @@ TESTCASE(float_array_array)
|
|
434
434
|
ASSERT_EXCEPTION_CHECK(
|
435
435
|
Exception,
|
436
436
|
m.module_eval(code),
|
437
|
-
ASSERT_EQUAL("wrong argument type Array (expected Buffer≺float
|
437
|
+
ASSERT_EQUAL("wrong argument type Array (expected Buffer≺float∗‚ void≻)", ex.what())
|
438
438
|
);
|
439
439
|
}
|
440
440
|
|