rice 2.1.1 → 4.0.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 +5 -5
- data/CHANGELOG.md +121 -0
- data/CONTRIBUTORS.md +19 -0
- data/COPYING +2 -2
- data/Gemfile +3 -0
- data/README.md +69 -0
- data/Rakefile +95 -12
- data/include/rice/rice.hpp +7766 -0
- data/lib/mkmf-rice.rb +127 -0
- data/lib/version.rb +3 -0
- data/rice/Address_Registration_Guard.ipp +75 -32
- data/rice/Address_Registration_Guard_defn.hpp +60 -56
- data/rice/Arg.hpp +80 -4
- data/rice/Arg.ipp +51 -0
- data/rice/Constructor.hpp +30 -376
- data/rice/Data_Object.ipp +234 -107
- data/rice/Data_Object_defn.hpp +77 -117
- data/rice/Data_Type.hpp +1 -2
- data/rice/Data_Type.ipp +251 -295
- data/rice/Data_Type_defn.hpp +175 -243
- data/rice/Director.hpp +14 -9
- data/rice/Enum.hpp +54 -104
- data/rice/Enum.ipp +104 -230
- data/rice/Exception.hpp +2 -8
- data/rice/Exception.ipp +65 -0
- data/rice/Exception_defn.hpp +46 -47
- data/rice/Identifier.hpp +28 -28
- data/rice/Identifier.ipp +23 -27
- data/rice/Return.hpp +39 -0
- data/rice/Return.ipp +33 -0
- data/rice/detail/Exception_Handler.ipp +22 -62
- data/rice/detail/Exception_Handler_defn.hpp +76 -91
- data/rice/detail/Iterator.hpp +18 -88
- data/rice/detail/Iterator.ipp +47 -0
- data/rice/detail/Jump_Tag.hpp +21 -0
- data/rice/detail/MethodInfo.hpp +44 -0
- data/rice/detail/MethodInfo.ipp +78 -0
- data/rice/detail/NativeAttribute.hpp +53 -0
- data/rice/detail/NativeAttribute.ipp +83 -0
- data/rice/detail/NativeFunction.hpp +69 -0
- data/rice/detail/NativeFunction.ipp +248 -0
- data/rice/detail/RubyFunction.hpp +39 -0
- data/rice/detail/RubyFunction.ipp +92 -0
- data/rice/detail/Type.hpp +29 -0
- data/rice/detail/Type.ipp +138 -0
- data/rice/detail/TypeRegistry.hpp +50 -0
- data/rice/detail/TypeRegistry.ipp +106 -0
- data/rice/detail/Wrapper.hpp +51 -0
- data/rice/detail/Wrapper.ipp +151 -0
- data/rice/detail/default_allocation_func.hpp +8 -19
- data/rice/detail/default_allocation_func.ipp +9 -8
- data/rice/detail/from_ruby.hpp +2 -37
- data/rice/detail/from_ruby.ipp +1020 -46
- data/rice/detail/from_ruby_defn.hpp +38 -0
- data/rice/detail/function_traits.hpp +124 -0
- data/rice/detail/method_data.hpp +23 -15
- data/rice/detail/method_data.ipp +53 -0
- data/rice/detail/rice_traits.hpp +116 -0
- data/rice/detail/ruby.hpp +9 -49
- data/rice/detail/to_ruby.hpp +3 -17
- data/rice/detail/to_ruby.ipp +409 -31
- data/rice/detail/to_ruby_defn.hpp +48 -0
- data/rice/forward_declares.ipp +82 -0
- data/rice/global_function.hpp +16 -20
- data/rice/global_function.ipp +8 -17
- data/rice/rice.hpp +59 -0
- data/rice/ruby_mark.hpp +5 -3
- data/rice/ruby_try_catch.hpp +4 -4
- data/rice/stl.hpp +11 -0
- data/sample/callbacks/extconf.rb +6 -0
- data/sample/callbacks/sample_callbacks.cpp +35 -0
- data/sample/callbacks/test.rb +28 -0
- data/sample/enum/extconf.rb +3 -0
- data/sample/enum/sample_enum.cpp +3 -17
- data/sample/enum/test.rb +2 -2
- data/sample/inheritance/animals.cpp +8 -24
- data/sample/inheritance/extconf.rb +3 -0
- data/sample/inheritance/test.rb +1 -1
- data/sample/map/extconf.rb +3 -0
- data/sample/map/map.cpp +10 -18
- data/sample/map/test.rb +1 -1
- data/test/embed_ruby.cpp +34 -0
- data/test/embed_ruby.hpp +4 -0
- data/test/ext/t1/extconf.rb +3 -0
- data/test/ext/t1/t1.cpp +1 -3
- data/test/ext/t2/extconf.rb +3 -0
- data/test/ext/t2/t2.cpp +1 -1
- data/test/extconf.rb +23 -0
- data/test/ruby/test_callbacks_sample.rb +28 -0
- data/test/ruby/test_multiple_extensions.rb +18 -0
- data/test/ruby/test_multiple_extensions_same_class.rb +14 -0
- data/test/ruby/test_multiple_extensions_with_inheritance.rb +20 -0
- data/test/test_Address_Registration_Guard.cpp +25 -11
- data/test/test_Array.cpp +131 -74
- data/test/test_Attribute.cpp +147 -0
- data/test/test_Builtin_Object.cpp +36 -15
- data/test/test_Class.cpp +151 -274
- data/test/test_Constructor.cpp +10 -9
- data/test/test_Data_Object.cpp +135 -193
- data/test/test_Data_Type.cpp +323 -252
- data/test/test_Director.cpp +56 -42
- data/test/test_Enum.cpp +230 -104
- data/test/test_Exception.cpp +7 -7
- data/test/test_Hash.cpp +33 -31
- data/test/test_Identifier.cpp +6 -6
- data/test/test_Inheritance.cpp +221 -0
- data/test/test_Iterator.cpp +161 -0
- data/test/test_Jump_Tag.cpp +1 -1
- data/test/test_Keep_Alive.cpp +161 -0
- data/test/test_Memory_Management.cpp +4 -5
- data/test/test_Module.cpp +169 -111
- data/test/test_Object.cpp +51 -19
- data/test/test_Ownership.cpp +275 -0
- data/test/test_Self.cpp +205 -0
- data/test/test_Stl_Optional.cpp +90 -0
- data/test/test_Stl_Pair.cpp +144 -0
- data/test/test_Stl_SmartPointer.cpp +200 -0
- data/test/test_Stl_String.cpp +74 -0
- data/test/test_Stl_Vector.cpp +652 -0
- data/test/test_String.cpp +3 -3
- data/test/test_Struct.cpp +31 -40
- data/test/test_Symbol.cpp +3 -3
- data/test/test_To_From_Ruby.cpp +283 -218
- data/test/test_global_functions.cpp +41 -20
- data/test/unittest.cpp +34 -8
- data/test/unittest.hpp +0 -4
- metadata +117 -137
- data/Doxyfile +0 -2280
- data/Makefile.am +0 -26
- data/Makefile.in +0 -920
- data/README +0 -1055
- data/README.mingw +0 -8
- data/aclocal.m4 +0 -1088
- data/bootstrap +0 -8
- data/check_stdcxx_11.ac +0 -142
- data/config.guess +0 -1421
- data/config.sub +0 -1807
- data/configure +0 -7481
- data/configure.ac +0 -55
- data/depcomp +0 -791
- data/doxygen.ac +0 -314
- data/doxygen.am +0 -186
- data/extconf.rb +0 -69
- data/install-sh +0 -501
- data/missing +0 -215
- data/post-autoconf.rb +0 -22
- data/post-automake.rb +0 -28
- data/rice/Address_Registration_Guard.cpp +0 -22
- data/rice/Arg_impl.hpp +0 -129
- data/rice/Arg_operators.cpp +0 -21
- data/rice/Arg_operators.hpp +0 -19
- data/rice/Array.hpp +0 -214
- data/rice/Array.ipp +0 -256
- data/rice/Builtin_Object.hpp +0 -8
- data/rice/Builtin_Object.ipp +0 -50
- data/rice/Builtin_Object_defn.hpp +0 -50
- data/rice/Class.cpp +0 -57
- data/rice/Class.hpp +0 -8
- data/rice/Class.ipp +0 -6
- data/rice/Class_defn.hpp +0 -83
- data/rice/Data_Type.cpp +0 -54
- data/rice/Data_Type_fwd.hpp +0 -12
- data/rice/Director.cpp +0 -13
- data/rice/Exception.cpp +0 -59
- data/rice/Exception_Base.hpp +0 -8
- data/rice/Exception_Base.ipp +0 -13
- data/rice/Exception_Base_defn.hpp +0 -27
- data/rice/Hash.hpp +0 -227
- data/rice/Hash.ipp +0 -329
- data/rice/Identifier.cpp +0 -8
- data/rice/Jump_Tag.hpp +0 -24
- data/rice/Makefile.am +0 -124
- data/rice/Makefile.in +0 -839
- data/rice/Module.cpp +0 -84
- data/rice/Module.hpp +0 -8
- data/rice/Module.ipp +0 -6
- data/rice/Module_defn.hpp +0 -88
- data/rice/Module_impl.hpp +0 -281
- data/rice/Module_impl.ipp +0 -345
- data/rice/Object.cpp +0 -169
- data/rice/Object.hpp +0 -8
- data/rice/Object.ipp +0 -19
- data/rice/Object_defn.hpp +0 -191
- data/rice/Require_Guard.hpp +0 -21
- data/rice/String.cpp +0 -94
- data/rice/String.hpp +0 -91
- data/rice/Struct.cpp +0 -117
- data/rice/Struct.hpp +0 -162
- data/rice/Struct.ipp +0 -26
- data/rice/Symbol.cpp +0 -25
- data/rice/Symbol.hpp +0 -66
- data/rice/Symbol.ipp +0 -44
- data/rice/config.hpp +0 -47
- data/rice/config.hpp.in +0 -46
- data/rice/detail/Arguments.hpp +0 -118
- data/rice/detail/Auto_Function_Wrapper.hpp +0 -898
- data/rice/detail/Auto_Function_Wrapper.ipp +0 -3694
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +0 -897
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +0 -2774
- data/rice/detail/Caster.hpp +0 -103
- data/rice/detail/Not_Copyable.hpp +0 -25
- data/rice/detail/Wrapped_Function.hpp +0 -33
- data/rice/detail/cfp.hpp +0 -24
- data/rice/detail/cfp.ipp +0 -51
- data/rice/detail/check_ruby_type.cpp +0 -27
- data/rice/detail/check_ruby_type.hpp +0 -23
- data/rice/detail/creation_funcs.hpp +0 -37
- data/rice/detail/creation_funcs.ipp +0 -36
- data/rice/detail/define_method_and_auto_wrap.hpp +0 -31
- data/rice/detail/define_method_and_auto_wrap.ipp +0 -30
- data/rice/detail/demangle.cpp +0 -56
- data/rice/detail/demangle.hpp +0 -19
- data/rice/detail/env.hpp +0 -11
- data/rice/detail/method_data.cpp +0 -86
- data/rice/detail/node.hpp +0 -13
- data/rice/detail/object_call.hpp +0 -69
- data/rice/detail/object_call.ipp +0 -131
- data/rice/detail/protect.cpp +0 -29
- data/rice/detail/protect.hpp +0 -34
- data/rice/detail/ruby_version_code.hpp +0 -6
- data/rice/detail/ruby_version_code.hpp.in +0 -6
- data/rice/detail/st.hpp +0 -22
- data/rice/detail/traits.hpp +0 -43
- data/rice/detail/win32.hpp +0 -16
- data/rice/detail/wrap_function.hpp +0 -341
- data/rice/detail/wrap_function.ipp +0 -514
- data/rice/protect.hpp +0 -92
- data/rice/protect.ipp +0 -1134
- data/rice/rubypp.rb +0 -97
- data/rice/to_from_ruby.hpp +0 -8
- data/rice/to_from_ruby.ipp +0 -294
- data/rice/to_from_ruby_defn.hpp +0 -70
- data/ruby.ac +0 -135
- data/ruby/Makefile.am +0 -1
- data/ruby/Makefile.in +0 -625
- data/ruby/lib/Makefile.am +0 -3
- data/ruby/lib/Makefile.in +0 -503
- data/ruby/lib/mkmf-rice.rb.in +0 -217
- data/ruby/lib/version.rb +0 -3
- data/sample/Makefile.am +0 -47
- data/sample/Makefile.in +0 -486
- data/test/Makefile.am +0 -72
- data/test/Makefile.in +0 -1150
- data/test/ext/Makefile.am +0 -41
- data/test/ext/Makefile.in +0 -480
- data/test/test_rice.rb +0 -41
data/test/test_Jump_Tag.cpp
CHANGED
@@ -0,0 +1,161 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "embed_ruby.hpp"
|
3
|
+
#include <rice/rice.hpp>
|
4
|
+
#include <rice/stl.hpp>
|
5
|
+
|
6
|
+
using namespace Rice;
|
7
|
+
|
8
|
+
TESTSUITE(Keep_Alive);
|
9
|
+
|
10
|
+
namespace
|
11
|
+
{
|
12
|
+
class Listener {
|
13
|
+
public:
|
14
|
+
virtual ~Listener() = default;
|
15
|
+
virtual int getValue() { return 4; }
|
16
|
+
};
|
17
|
+
|
18
|
+
/**
|
19
|
+
* This class will recieve a new Listener instance
|
20
|
+
* from Ruby
|
21
|
+
*/
|
22
|
+
class ListenerContainer
|
23
|
+
{
|
24
|
+
public:
|
25
|
+
void addListener(Listener* listener)
|
26
|
+
{
|
27
|
+
mListeners.push_back(listener);
|
28
|
+
}
|
29
|
+
|
30
|
+
void removeListener(Listener* listener)
|
31
|
+
{
|
32
|
+
auto iter = std::find(mListeners.begin(), mListeners.end(), listener);
|
33
|
+
mListeners.erase(iter);
|
34
|
+
}
|
35
|
+
|
36
|
+
int process()
|
37
|
+
{
|
38
|
+
std::vector<Listener*>::iterator i = mListeners.begin();
|
39
|
+
int accum = 0;
|
40
|
+
for(; i != mListeners.end(); i++)
|
41
|
+
{
|
42
|
+
accum += (*i)->getValue();
|
43
|
+
}
|
44
|
+
|
45
|
+
return accum;
|
46
|
+
}
|
47
|
+
|
48
|
+
size_t listenerCount()
|
49
|
+
{
|
50
|
+
return mListeners.size();
|
51
|
+
}
|
52
|
+
|
53
|
+
private:
|
54
|
+
std::vector<Listener*> mListeners;
|
55
|
+
};
|
56
|
+
}
|
57
|
+
|
58
|
+
SETUP(Keep_Alive)
|
59
|
+
{
|
60
|
+
embed_ruby();
|
61
|
+
}
|
62
|
+
|
63
|
+
TESTCASE(test_arg)
|
64
|
+
{
|
65
|
+
define_class<Listener>("Listener")
|
66
|
+
.define_constructor(Constructor<Listener>())
|
67
|
+
.define_method("get_value", &Listener::getValue);
|
68
|
+
|
69
|
+
define_class<ListenerContainer>("ListenerContainer")
|
70
|
+
.define_constructor(Constructor<ListenerContainer>())
|
71
|
+
.define_method("add_listener", &ListenerContainer::addListener, Arg("listener").keepAlive())
|
72
|
+
.define_method("process", &ListenerContainer::process)
|
73
|
+
.define_method("listener_count", &ListenerContainer::listenerCount);
|
74
|
+
|
75
|
+
Module m = define_module("TestingModule");
|
76
|
+
Object handler = m.instance_eval("@handler = ListenerContainer.new");
|
77
|
+
|
78
|
+
ASSERT_EQUAL(INT2NUM(0), handler.call("listener_count").value());
|
79
|
+
|
80
|
+
m.instance_eval(R"EOS(class MyListener < Listener
|
81
|
+
end)EOS");
|
82
|
+
|
83
|
+
m.instance_eval("@handler.add_listener(MyListener.new)");
|
84
|
+
|
85
|
+
// Without keep alive, this GC will crash the program because MyListener is no longer in scope
|
86
|
+
rb_gc_start();
|
87
|
+
|
88
|
+
ASSERT_EQUAL(INT2NUM(1), handler.call("listener_count").value());
|
89
|
+
ASSERT_EQUAL(INT2NUM(4), handler.call("process").value());
|
90
|
+
|
91
|
+
// Without keep alive, this GC will crash the program because MyListener is no longer in scope
|
92
|
+
rb_gc_start();
|
93
|
+
m.instance_eval("@handler.add_listener(Listener.new)");
|
94
|
+
|
95
|
+
ASSERT_EQUAL(INT2NUM(2), handler.call("listener_count").value());
|
96
|
+
ASSERT_EQUAL(INT2NUM(8), handler.call("process").value());
|
97
|
+
}
|
98
|
+
|
99
|
+
namespace
|
100
|
+
{
|
101
|
+
class Connection;
|
102
|
+
|
103
|
+
class Column
|
104
|
+
{
|
105
|
+
public:
|
106
|
+
Column(Connection& connection, uint32_t index) : connection_(connection), index_(index)
|
107
|
+
{
|
108
|
+
}
|
109
|
+
|
110
|
+
std::string name();
|
111
|
+
|
112
|
+
private:
|
113
|
+
Connection& connection_;
|
114
|
+
uint32_t index_;
|
115
|
+
};
|
116
|
+
|
117
|
+
class Connection
|
118
|
+
{
|
119
|
+
public:
|
120
|
+
Column getColumn(uint32_t index)
|
121
|
+
{
|
122
|
+
return Column(*this, index);
|
123
|
+
}
|
124
|
+
|
125
|
+
std::string getName(uint32_t index)
|
126
|
+
{
|
127
|
+
return this->prefix_ + std::to_string(index);
|
128
|
+
}
|
129
|
+
|
130
|
+
private:
|
131
|
+
std::string prefix_ = "column_";
|
132
|
+
};
|
133
|
+
|
134
|
+
std::string Column::name()
|
135
|
+
{
|
136
|
+
return this->connection_.getName(this->index_);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
Object getColumn(Module& m, uint32_t index)
|
141
|
+
{
|
142
|
+
Object connection = m.instance_eval("Connection.new");
|
143
|
+
return connection.call("getColumn", 3);
|
144
|
+
}
|
145
|
+
|
146
|
+
TESTCASE(test_return)
|
147
|
+
{
|
148
|
+
define_class<Column>("Column")
|
149
|
+
.define_method("name", &Column::name);
|
150
|
+
|
151
|
+
define_class<Connection>("Connection")
|
152
|
+
.define_constructor(Constructor<Connection>())
|
153
|
+
.define_method("getColumn", &Connection::getColumn, Return().keepAlive());
|
154
|
+
|
155
|
+
Module m = define_module("TestingModule");
|
156
|
+
|
157
|
+
Object column = getColumn(m, 3);
|
158
|
+
rb_gc_start();
|
159
|
+
String name = column.call("name");
|
160
|
+
ASSERT_EQUAL("column_3", name.c_str());
|
161
|
+
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
#include "unittest.hpp"
|
2
|
-
#include "
|
3
|
-
#include
|
4
|
-
#include "rice/global_function.hpp"
|
2
|
+
#include "embed_ruby.hpp"
|
3
|
+
#include <rice/rice.hpp>
|
5
4
|
|
6
5
|
using namespace Rice;
|
7
6
|
|
@@ -9,7 +8,7 @@ TESTSUITE(Memory_Management);
|
|
9
8
|
|
10
9
|
SETUP(Memory_Management)
|
11
10
|
{
|
12
|
-
|
11
|
+
embed_ruby();
|
13
12
|
}
|
14
13
|
|
15
14
|
namespace
|
@@ -46,5 +45,5 @@ TESTCASE(allows_copy_contructors_to_work)
|
|
46
45
|
Module m = define_module("TestingModule");
|
47
46
|
|
48
47
|
Object result = m.instance_eval("return_test_class.tmp");
|
49
|
-
ASSERT_EQUAL(8.0,
|
48
|
+
ASSERT_EQUAL(8.0, detail::From_Ruby<double>().convert(result.value()));
|
50
49
|
}
|
data/test/test_Module.cpp
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
#include "unittest.hpp"
|
2
|
-
#include "
|
3
|
-
|
4
|
-
#include
|
5
|
-
#include
|
6
|
-
#include "rice/global_function.hpp"
|
7
|
-
#include "rice/Constructor.hpp"
|
2
|
+
#include "embed_ruby.hpp"
|
3
|
+
|
4
|
+
#include <rice/rice.hpp>
|
5
|
+
#include <rice/stl.hpp>
|
8
6
|
|
9
7
|
using namespace Rice;
|
10
8
|
|
@@ -12,7 +10,7 @@ TESTSUITE(Module);
|
|
12
10
|
|
13
11
|
SETUP(Object)
|
14
12
|
{
|
15
|
-
|
13
|
+
embed_ruby();
|
16
14
|
}
|
17
15
|
|
18
16
|
TESTCASE(construct_from_value)
|
@@ -49,55 +47,73 @@ TESTCASE(add_handler)
|
|
49
47
|
Object exc = m.instance_eval("begin; foo; rescue Exception; $!; end");
|
50
48
|
ASSERT_EQUAL(rb_eRuntimeError, CLASS_OF(exc));
|
51
49
|
Exception ex(exc);
|
52
|
-
ASSERT_EQUAL(String("SILLY"), String(ex.
|
50
|
+
ASSERT_EQUAL(String("SILLY"), String(ex.what()));
|
53
51
|
}
|
54
52
|
|
55
53
|
namespace
|
56
54
|
{
|
57
55
|
|
58
|
-
bool
|
56
|
+
bool some_function()
|
57
|
+
{
|
58
|
+
return true;
|
59
|
+
}
|
60
|
+
|
61
|
+
Object some_method(Object o)
|
62
|
+
{
|
63
|
+
return o;
|
64
|
+
}
|
65
|
+
|
66
|
+
int function_int(int i)
|
67
|
+
{
|
68
|
+
return i;
|
69
|
+
}
|
59
70
|
|
60
|
-
|
71
|
+
int method_int(Object object, int i)
|
61
72
|
{
|
62
|
-
|
73
|
+
return i;
|
63
74
|
}
|
64
75
|
|
65
76
|
} // namespace
|
66
77
|
|
67
|
-
TESTCASE(
|
78
|
+
TESTCASE(define_method)
|
68
79
|
{
|
69
80
|
Module m(anonymous_module());
|
70
|
-
m.define_method("
|
71
|
-
|
72
|
-
Object o = m.instance_eval("o = Object.new
|
73
|
-
|
81
|
+
m.define_method("some_method", some_method);
|
82
|
+
|
83
|
+
Object o = m.instance_eval("$o = Object.new");
|
84
|
+
Object result = m.instance_eval(R"EOS($o.extend(self)
|
85
|
+
$o.some_method)EOS");
|
86
|
+
ASSERT_EQUAL(o, result);
|
74
87
|
}
|
75
88
|
|
76
|
-
TESTCASE(
|
89
|
+
TESTCASE(define_singleton_method)
|
77
90
|
{
|
78
91
|
Module m(anonymous_module());
|
79
|
-
m.define_singleton_method("
|
80
|
-
|
81
|
-
|
82
|
-
ASSERT(define_method_simple_ok);
|
92
|
+
m.define_singleton_method("some_method", some_method);
|
93
|
+
Object result = m.call("some_method");
|
94
|
+
ASSERT_EQUAL(m, result);
|
83
95
|
}
|
84
96
|
|
85
|
-
TESTCASE(
|
97
|
+
TESTCASE(define_module_function)
|
86
98
|
{
|
87
99
|
Module m(anonymous_module());
|
88
|
-
m.define_module_function("
|
89
|
-
|
90
|
-
m.instance_eval("o = Object.new
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
100
|
+
m.define_module_function("some_function", some_function);
|
101
|
+
|
102
|
+
Object result = m.instance_eval(R"EOS(o = Object.new
|
103
|
+
o.extend(self)
|
104
|
+
o.instance_eval do
|
105
|
+
some_function
|
106
|
+
end)EOS");
|
107
|
+
|
108
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
109
|
+
result = m.call("some_function");
|
110
|
+
ASSERT_EQUAL(Qtrue, result.value());
|
95
111
|
}
|
96
112
|
|
97
113
|
TESTCASE(define_module_does_not_leak_method_to_Object)
|
98
114
|
{
|
99
115
|
Module m = define_module("TestModule");
|
100
|
-
m.define_module_function("test_module_function", &
|
116
|
+
m.define_module_function("test_module_function", &some_method);
|
101
117
|
|
102
118
|
Module runner(anonymous_module());
|
103
119
|
ASSERT_EXCEPTION_CHECK(
|
@@ -110,52 +126,53 @@ TESTCASE(define_module_does_not_leak_method_to_Object)
|
|
110
126
|
);
|
111
127
|
}
|
112
128
|
|
113
|
-
|
114
|
-
{
|
115
|
-
|
116
|
-
int define_method_int_result;
|
117
|
-
|
118
|
-
void define_method_int_helper(Object o, int i)
|
129
|
+
TESTCASE(define_function_int)
|
119
130
|
{
|
120
|
-
|
131
|
+
Module m(anonymous_module());
|
132
|
+
m.define_function("foo", function_int);
|
133
|
+
Object result = m.instance_eval("o = Object.new; o.extend(self); o.foo(42)");
|
134
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(result));
|
121
135
|
}
|
122
136
|
|
123
|
-
} // namespace
|
124
|
-
|
125
137
|
TESTCASE(define_method_int)
|
126
138
|
{
|
127
139
|
Module m(anonymous_module());
|
128
|
-
m.define_method("foo",
|
129
|
-
|
130
|
-
|
131
|
-
ASSERT_EQUAL(42, define_method_int_result);
|
140
|
+
m.define_method("foo", method_int);
|
141
|
+
Object result = m.instance_eval("o = Object.new; o.extend(self); o.foo(42)");
|
142
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(result));
|
132
143
|
}
|
133
144
|
|
134
145
|
TESTCASE(define_singleton_method_int)
|
135
146
|
{
|
136
147
|
Module m(anonymous_module());
|
137
|
-
m.define_singleton_method("foo",
|
138
|
-
|
139
|
-
|
140
|
-
|
148
|
+
m.define_singleton_method("foo", method_int);
|
149
|
+
Object result = m.call("foo", 42);
|
150
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(result));
|
151
|
+
}
|
152
|
+
|
153
|
+
TESTCASE(define_singleton_function_int)
|
154
|
+
{
|
155
|
+
Module m(anonymous_module());
|
156
|
+
m.define_singleton_function("foo", function_int);
|
157
|
+
Object result = m.call("foo", 42);
|
158
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(result));
|
141
159
|
}
|
142
160
|
|
143
161
|
TESTCASE(define_module_function_int)
|
144
162
|
{
|
145
163
|
Module m(anonymous_module());
|
146
|
-
m.define_module_function("foo",
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
ASSERT_EQUAL(42, define_method_int_result);
|
164
|
+
m.define_module_function("foo", function_int);
|
165
|
+
Object result = m.instance_eval("o = Object.new; o.extend(self); o.instance_eval { foo(42) }");
|
166
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(result));
|
167
|
+
|
168
|
+
result = m.call("foo", 42);
|
169
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(result));
|
153
170
|
}
|
154
171
|
|
155
|
-
TESTCASE(
|
172
|
+
TESTCASE(method_int_passed_no_args)
|
156
173
|
{
|
157
174
|
Module m(anonymous_module());
|
158
|
-
m.define_method("foo",
|
175
|
+
m.define_method("foo", method_int);
|
159
176
|
ASSERT_EXCEPTION_CHECK(
|
160
177
|
Exception,
|
161
178
|
m.instance_eval("o = Object.new; o.extend(self); o.foo"),
|
@@ -166,47 +183,14 @@ TESTCASE(define_method_int_passed_no_args)
|
|
166
183
|
);
|
167
184
|
}
|
168
185
|
|
169
|
-
namespace
|
170
|
-
{
|
171
|
-
|
172
|
-
struct Foo
|
173
|
-
{
|
174
|
-
int x;
|
175
|
-
};
|
176
|
-
|
177
|
-
int define_method_int_foo_result_i;
|
178
|
-
Foo * define_method_int_foo_result_x;
|
179
|
-
|
180
|
-
void define_method_int_foo_helper(Object o, int i, Foo * x)
|
181
|
-
{
|
182
|
-
define_method_int_foo_result_i = i;
|
183
|
-
define_method_int_foo_result_x = x;
|
184
|
-
}
|
185
|
-
|
186
|
-
} // namespace
|
187
|
-
|
188
|
-
template<>
|
189
|
-
Foo * from_ruby<Foo *>(Object x)
|
190
|
-
{
|
191
|
-
Foo * retval;
|
192
|
-
Data_Get_Struct(x.value(), Foo, retval);
|
193
|
-
return retval;
|
194
|
-
}
|
195
|
-
|
196
186
|
TESTCASE(define_singleton_method_int_foo)
|
197
187
|
{
|
198
188
|
Module m(anonymous_module());
|
199
|
-
m.define_singleton_method("
|
200
|
-
define_method_int_result = 0;
|
201
|
-
Foo * foo = new Foo;
|
202
|
-
foo->x = 1024;
|
203
|
-
VALUE f = Data_Wrap_Struct(rb_cObject, 0, Default_Free_Function<Foo>::free, foo);
|
204
|
-
m.call("int_and_foo", 42, Object(f));
|
205
|
-
ASSERT_EQUAL(42, define_method_int_foo_result_i);
|
206
|
-
ASSERT_EQUAL(foo, define_method_int_foo_result_x);
|
207
|
-
}
|
189
|
+
m.define_singleton_method("method_int", method_int);
|
208
190
|
|
209
|
-
|
191
|
+
Object result = m.call("method_int", 42);
|
192
|
+
ASSERT_EQUAL(42, detail::From_Ruby<int>().convert(result));
|
193
|
+
}
|
210
194
|
|
211
195
|
TESTCASE(include_module)
|
212
196
|
{
|
@@ -223,7 +207,7 @@ TESTCASE(include_module)
|
|
223
207
|
TESTCASE(const_set_get_by_id)
|
224
208
|
{
|
225
209
|
Module m(anonymous_module());
|
226
|
-
Object v = to_ruby(42);
|
210
|
+
Object v = detail::to_ruby(42);
|
227
211
|
Module & m2(m.const_set(rb_intern("FOO"), v));
|
228
212
|
ASSERT_EQUAL(&m, &m2);
|
229
213
|
ASSERT_EQUAL(v, m.const_get(rb_intern("FOO")));
|
@@ -232,7 +216,7 @@ TESTCASE(const_set_get_by_id)
|
|
232
216
|
TESTCASE(const_set_get_by_identifier)
|
233
217
|
{
|
234
218
|
Module m(anonymous_module());
|
235
|
-
Object v = to_ruby(42);
|
219
|
+
Object v = detail::to_ruby(42);
|
236
220
|
Module & m2(m.const_set(Identifier("FOO"), v));
|
237
221
|
ASSERT_EQUAL(&m, &m2);
|
238
222
|
ASSERT_EQUAL(v, m.const_get(Identifier("FOO")));
|
@@ -241,7 +225,7 @@ TESTCASE(const_set_get_by_identifier)
|
|
241
225
|
TESTCASE(const_set_get_by_string)
|
242
226
|
{
|
243
227
|
Module m(anonymous_module());
|
244
|
-
Object v = to_ruby(42);
|
228
|
+
Object v = detail::to_ruby(42);
|
245
229
|
Module & m2(m.const_set("FOO", v));
|
246
230
|
ASSERT_EQUAL(&m, &m2);
|
247
231
|
ASSERT_EQUAL(v, m.const_get("FOO"));
|
@@ -250,7 +234,7 @@ TESTCASE(const_set_get_by_string)
|
|
250
234
|
TESTCASE(remove_const)
|
251
235
|
{
|
252
236
|
Module m(anonymous_module());
|
253
|
-
Object v = to_ruby(42);
|
237
|
+
Object v = detail::to_ruby(42);
|
254
238
|
m.const_set("FOO", v);
|
255
239
|
ASSERT_EQUAL(v, m.const_get("FOO"));
|
256
240
|
m.remove_const("FOO");
|
@@ -270,9 +254,7 @@ TESTCASE(mod_name_anonymous)
|
|
270
254
|
ASSERT_EQUAL(String(""), m.name());
|
271
255
|
}
|
272
256
|
|
273
|
-
|
274
|
-
* Tests for default arguments
|
275
|
-
*/
|
257
|
+
// Tests for default arguments
|
276
258
|
namespace
|
277
259
|
{
|
278
260
|
int defaults_method_one_arg1;
|
@@ -290,7 +272,7 @@ namespace
|
|
290
272
|
TESTCASE(define_method_default_arguments)
|
291
273
|
{
|
292
274
|
Module m(anonymous_module());
|
293
|
-
m.
|
275
|
+
m.define_function("foo", &defaults_method_one, Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true);
|
294
276
|
|
295
277
|
Object o = m.instance_eval("o = Object.new; o.extend(self); o");
|
296
278
|
o.call("foo", 2);
|
@@ -315,7 +297,7 @@ TESTCASE(define_method_default_arguments)
|
|
315
297
|
TESTCASE(default_arguments_still_throws_argument_error)
|
316
298
|
{
|
317
299
|
Module m(anonymous_module());
|
318
|
-
m.
|
300
|
+
m.define_function("foo", &defaults_method_one, Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true);
|
319
301
|
|
320
302
|
ASSERT_EXCEPTION_CHECK(
|
321
303
|
Exception,
|
@@ -347,7 +329,7 @@ TESTCASE(defining_methods_with_single_default_argument)
|
|
347
329
|
{
|
348
330
|
// define_method
|
349
331
|
Module m(anonymous_module());
|
350
|
-
m.
|
332
|
+
m.define_function("foo", &method_with_one_default_arg, (Arg("num") = 4));
|
351
333
|
m.instance_eval("o = Object.new; o.extend(self); o.foo()");
|
352
334
|
ASSERT_EQUAL(4, the_one_default_arg);
|
353
335
|
|
@@ -355,7 +337,7 @@ TESTCASE(defining_methods_with_single_default_argument)
|
|
355
337
|
|
356
338
|
// define_singleton_method
|
357
339
|
Class c(anonymous_class());
|
358
|
-
c.
|
340
|
+
c.define_singleton_function("foo", &method_with_one_default_arg, (Arg("num") = 4));
|
359
341
|
c.call("foo");
|
360
342
|
ASSERT_EQUAL(4, the_one_default_arg);
|
361
343
|
|
@@ -371,7 +353,7 @@ TESTCASE(defining_methods_with_single_default_argument)
|
|
371
353
|
TESTCASE(default_arguments_for_define_singleton_method)
|
372
354
|
{
|
373
355
|
Class c(anonymous_class());
|
374
|
-
c.
|
356
|
+
c.define_singleton_function("foo", &defaults_method_one, Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true);
|
375
357
|
|
376
358
|
c.call("foo", 2);
|
377
359
|
|
@@ -395,7 +377,7 @@ TESTCASE(default_arguments_for_define_singleton_method)
|
|
395
377
|
TESTCASE(default_arguments_for_define_module_function)
|
396
378
|
{
|
397
379
|
Module m(anonymous_module());
|
398
|
-
m.define_module_function("foo", &defaults_method_one,
|
380
|
+
m.define_module_function("foo", &defaults_method_one, Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true);
|
399
381
|
|
400
382
|
m.call("foo", 2);
|
401
383
|
|
@@ -431,7 +413,7 @@ TESTCASE(define_method_works_with_reference_arguments)
|
|
431
413
|
{
|
432
414
|
Module m(anonymous_module());
|
433
415
|
m.define_module_function("foo", &with_defaults_and_references,
|
434
|
-
|
416
|
+
Arg("x"), Arg("doIt") = false);
|
435
417
|
|
436
418
|
m.call("foo", "test");
|
437
419
|
|
@@ -471,8 +453,8 @@ TESTCASE(define_method_works_with_const_reference_return)
|
|
471
453
|
ASSERT_EQUAL("ReturnTest", result.class_of().name().c_str());
|
472
454
|
}
|
473
455
|
|
474
|
-
|
475
|
-
|
456
|
+
namespace
|
457
|
+
{
|
476
458
|
float with_reference_defaults_x;
|
477
459
|
std::string with_reference_defaults_str;
|
478
460
|
|
@@ -487,11 +469,87 @@ TESTCASE(define_method_works_with_reference_const_default_values)
|
|
487
469
|
{
|
488
470
|
Module m(anonymous_module());
|
489
471
|
m.define_module_function("bar", &with_reference_defaults,
|
490
|
-
|
472
|
+
Arg("x"), Arg("str") = std::string("testing"));
|
491
473
|
|
492
474
|
m.call("bar", 3);
|
493
475
|
|
494
476
|
ASSERT_EQUAL(3, with_reference_defaults_x);
|
495
477
|
ASSERT_EQUAL("testing", with_reference_defaults_str);
|
496
478
|
}
|
497
|
-
|
479
|
+
|
480
|
+
namespace
|
481
|
+
{
|
482
|
+
int with_pointers_x;
|
483
|
+
std::string with_pointers_str;
|
484
|
+
|
485
|
+
void with_pointers(int* x, std::string const* str)
|
486
|
+
{
|
487
|
+
with_pointers_x = *x;
|
488
|
+
with_pointers_str = *str;
|
489
|
+
}
|
490
|
+
}
|
491
|
+
|
492
|
+
TESTCASE(define_method_works_with_pointers)
|
493
|
+
{
|
494
|
+
Module m(anonymous_module());
|
495
|
+
m.define_module_function("bar", &with_pointers);
|
496
|
+
|
497
|
+
m.call("bar", 3, "testing");
|
498
|
+
|
499
|
+
ASSERT_EQUAL(3, with_pointers_x);
|
500
|
+
ASSERT_EQUAL("testing", with_pointers_str);
|
501
|
+
}
|
502
|
+
|
503
|
+
namespace
|
504
|
+
{
|
505
|
+
int intValue;
|
506
|
+
bool boolValue;
|
507
|
+
float floatValue;
|
508
|
+
double doubleValue;
|
509
|
+
|
510
|
+
void withPointers(const int* anInt, const bool* aBool, const float* aFloat, const double* aDouble)
|
511
|
+
{
|
512
|
+
intValue = *anInt;
|
513
|
+
boolValue = *aBool;
|
514
|
+
floatValue = *aFloat;
|
515
|
+
doubleValue = *aDouble;
|
516
|
+
}
|
517
|
+
|
518
|
+
void withReferences(const int& anInt, const bool& aBool, const float& aFloat, const double& aDouble)
|
519
|
+
{
|
520
|
+
intValue = anInt;
|
521
|
+
boolValue = aBool;
|
522
|
+
floatValue = aFloat;
|
523
|
+
doubleValue = aDouble;
|
524
|
+
}
|
525
|
+
}
|
526
|
+
|
527
|
+
TESTCASE(pointers)
|
528
|
+
{
|
529
|
+
define_global_function("with_pointers", &withPointers);
|
530
|
+
|
531
|
+
Module m = define_module("TestingModule");
|
532
|
+
|
533
|
+
std::string code = "with_pointers(32, true, 33.0, 34.0)";
|
534
|
+
m.instance_eval(code);
|
535
|
+
|
536
|
+
ASSERT_EQUAL(intValue, 32);
|
537
|
+
ASSERT_EQUAL(boolValue, true);
|
538
|
+
ASSERT_EQUAL(floatValue, 33.0);
|
539
|
+
ASSERT_EQUAL(doubleValue, 34.0);
|
540
|
+
}
|
541
|
+
|
542
|
+
TESTCASE(references)
|
543
|
+
{
|
544
|
+
define_global_function("with_references", &withReferences);
|
545
|
+
|
546
|
+
Module m = define_module("TestingModule");
|
547
|
+
|
548
|
+
std::string code = "with_references(42, true, 43.0, 44.0)";
|
549
|
+
m.instance_eval(code);
|
550
|
+
|
551
|
+
ASSERT_EQUAL(intValue, 42);
|
552
|
+
ASSERT_EQUAL(boolValue, true);
|
553
|
+
ASSERT_EQUAL(floatValue, 43.0);
|
554
|
+
ASSERT_EQUAL(doubleValue, 44.0);
|
555
|
+
}
|