rice2 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +23 -0
- data/Doxyfile +2268 -0
- data/Makefile.am +26 -0
- data/Makefile.in +929 -0
- data/README.md +1054 -0
- data/README.mingw +8 -0
- data/Rakefile +24 -0
- data/aclocal.m4 +1090 -0
- data/bootstrap +8 -0
- data/config.guess +1667 -0
- data/config.sub +1793 -0
- data/configure +8209 -0
- data/configure.ac +55 -0
- data/depcomp +791 -0
- data/doxygen.ac +314 -0
- data/doxygen.am +186 -0
- data/extconf.rb +66 -0
- data/install-sh +529 -0
- data/missing +215 -0
- data/post-autoconf.rb +22 -0
- data/post-automake.rb +28 -0
- data/rice/Address_Registration_Guard.cpp +22 -0
- data/rice/Address_Registration_Guard.hpp +7 -0
- data/rice/Address_Registration_Guard.ipp +37 -0
- data/rice/Address_Registration_Guard_defn.hpp +75 -0
- data/rice/Arg.hpp +8 -0
- data/rice/Arg_impl.hpp +129 -0
- data/rice/Arg_operators.cpp +21 -0
- data/rice/Arg_operators.hpp +19 -0
- data/rice/Array.hpp +214 -0
- data/rice/Array.ipp +256 -0
- data/rice/Builtin_Object.hpp +8 -0
- data/rice/Builtin_Object.ipp +50 -0
- data/rice/Builtin_Object_defn.hpp +50 -0
- data/rice/Class.cpp +57 -0
- data/rice/Class.hpp +8 -0
- data/rice/Class.ipp +6 -0
- data/rice/Class_defn.hpp +83 -0
- data/rice/Constructor.hpp +47 -0
- data/rice/Data_Object.hpp +8 -0
- data/rice/Data_Object.ipp +133 -0
- data/rice/Data_Object_defn.hpp +138 -0
- data/rice/Data_Type.cpp +54 -0
- data/rice/Data_Type.hpp +8 -0
- data/rice/Data_Type.ipp +365 -0
- data/rice/Data_Type_defn.hpp +261 -0
- data/rice/Data_Type_fwd.hpp +12 -0
- data/rice/Director.cpp +13 -0
- data/rice/Director.hpp +39 -0
- data/rice/Enum.hpp +117 -0
- data/rice/Enum.ipp +246 -0
- data/rice/Exception.cpp +59 -0
- data/rice/Exception.hpp +13 -0
- data/rice/Exception_Base.hpp +8 -0
- data/rice/Exception_Base.ipp +13 -0
- data/rice/Exception_Base_defn.hpp +27 -0
- data/rice/Exception_defn.hpp +69 -0
- data/rice/Hash.hpp +227 -0
- data/rice/Hash.ipp +329 -0
- data/rice/Identifier.cpp +8 -0
- data/rice/Identifier.hpp +50 -0
- data/rice/Identifier.ipp +33 -0
- data/rice/Jump_Tag.hpp +24 -0
- data/rice/Makefile.am +122 -0
- data/rice/Makefile.in +885 -0
- data/rice/Module.cpp +84 -0
- data/rice/Module.hpp +8 -0
- data/rice/Module.ipp +6 -0
- data/rice/Module_defn.hpp +88 -0
- data/rice/Module_impl.hpp +281 -0
- data/rice/Module_impl.ipp +345 -0
- data/rice/Object.cpp +169 -0
- data/rice/Object.hpp +8 -0
- data/rice/Object.ipp +33 -0
- data/rice/Object_defn.hpp +214 -0
- data/rice/Require_Guard.hpp +21 -0
- data/rice/String.cpp +94 -0
- data/rice/String.hpp +91 -0
- data/rice/Struct.cpp +117 -0
- data/rice/Struct.hpp +162 -0
- data/rice/Struct.ipp +26 -0
- data/rice/Symbol.cpp +25 -0
- data/rice/Symbol.hpp +66 -0
- data/rice/Symbol.ipp +44 -0
- data/rice/config.hpp +47 -0
- data/rice/config.hpp.in +46 -0
- data/rice/detail/Arguments.hpp +118 -0
- data/rice/detail/Auto_Function_Wrapper.hpp +898 -0
- data/rice/detail/Auto_Function_Wrapper.ipp +3694 -0
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +897 -0
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +2774 -0
- data/rice/detail/Caster.hpp +103 -0
- data/rice/detail/Exception_Handler.hpp +8 -0
- data/rice/detail/Exception_Handler.ipp +68 -0
- data/rice/detail/Exception_Handler_defn.hpp +96 -0
- data/rice/detail/Iterator.hpp +93 -0
- data/rice/detail/Not_Copyable.hpp +25 -0
- data/rice/detail/Wrapped_Function.hpp +33 -0
- data/rice/detail/cfp.hpp +24 -0
- data/rice/detail/cfp.ipp +51 -0
- data/rice/detail/check_ruby_type.cpp +27 -0
- data/rice/detail/check_ruby_type.hpp +23 -0
- data/rice/detail/creation_funcs.hpp +37 -0
- data/rice/detail/creation_funcs.ipp +36 -0
- data/rice/detail/default_allocation_func.hpp +23 -0
- data/rice/detail/default_allocation_func.ipp +11 -0
- data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
- data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
- data/rice/detail/demangle.cpp +56 -0
- data/rice/detail/demangle.hpp +19 -0
- data/rice/detail/env.hpp +11 -0
- data/rice/detail/from_ruby.hpp +43 -0
- data/rice/detail/from_ruby.ipp +60 -0
- data/rice/detail/method_data.cpp +92 -0
- data/rice/detail/method_data.hpp +21 -0
- data/rice/detail/node.hpp +13 -0
- data/rice/detail/protect.cpp +29 -0
- data/rice/detail/protect.hpp +34 -0
- data/rice/detail/ruby.hpp +74 -0
- data/rice/detail/ruby_version_code.hpp +6 -0
- data/rice/detail/ruby_version_code.hpp.in +6 -0
- data/rice/detail/st.hpp +22 -0
- data/rice/detail/to_ruby.hpp +22 -0
- data/rice/detail/to_ruby.ipp +36 -0
- data/rice/detail/traits.hpp +43 -0
- data/rice/detail/win32.hpp +16 -0
- data/rice/detail/wrap_function.hpp +66 -0
- data/rice/global_function.hpp +33 -0
- data/rice/global_function.ipp +22 -0
- data/rice/protect.hpp +38 -0
- data/rice/protect.ipp +1134 -0
- data/rice/ruby_mark.hpp +13 -0
- data/rice/ruby_try_catch.hpp +86 -0
- data/rice/rubypp.rb +97 -0
- data/rice/to_from_ruby.hpp +8 -0
- data/rice/to_from_ruby.ipp +418 -0
- data/rice/to_from_ruby_defn.hpp +70 -0
- data/ruby.ac +135 -0
- data/ruby/Makefile.am +1 -0
- data/ruby/Makefile.in +628 -0
- data/ruby/lib/Makefile.am +3 -0
- data/ruby/lib/Makefile.in +506 -0
- data/ruby/lib/mkmf-rice.rb.in +217 -0
- data/ruby/lib/version.rb +3 -0
- data/sample/Makefile.am +47 -0
- data/sample/Makefile.in +489 -0
- data/sample/enum/extconf.rb +3 -0
- data/sample/enum/sample_enum.cpp +54 -0
- data/sample/enum/test.rb +8 -0
- data/sample/inheritance/animals.cpp +98 -0
- data/sample/inheritance/extconf.rb +3 -0
- data/sample/inheritance/test.rb +7 -0
- data/sample/map/extconf.rb +3 -0
- data/sample/map/map.cpp +81 -0
- data/sample/map/test.rb +7 -0
- data/test/Makefile.am +72 -0
- data/test/Makefile.in +1213 -0
- data/test/ext/Makefile.am +41 -0
- data/test/ext/Makefile.in +483 -0
- data/test/ext/t1/Foo.hpp +10 -0
- data/test/ext/t1/extconf.rb +2 -0
- data/test/ext/t1/t1.cpp +15 -0
- data/test/ext/t2/extconf.rb +2 -0
- data/test/ext/t2/t2.cpp +11 -0
- data/test/test_Address_Registration_Guard.cpp +43 -0
- data/test/test_Array.cpp +248 -0
- data/test/test_Builtin_Object.cpp +71 -0
- data/test/test_Class.cpp +496 -0
- data/test/test_Constructor.cpp +128 -0
- data/test/test_Data_Object.cpp +275 -0
- data/test/test_Data_Type.cpp +348 -0
- data/test/test_Director.cpp +308 -0
- data/test/test_Enum.cpp +215 -0
- data/test/test_Exception.cpp +47 -0
- data/test/test_Hash.cpp +212 -0
- data/test/test_Identifier.cpp +70 -0
- data/test/test_Jump_Tag.cpp +17 -0
- data/test/test_Memory_Management.cpp +50 -0
- data/test/test_Module.cpp +497 -0
- data/test/test_Object.cpp +159 -0
- data/test/test_String.cpp +107 -0
- data/test/test_Struct.cpp +205 -0
- data/test/test_Symbol.cpp +63 -0
- data/test/test_To_From_Ruby.cpp +428 -0
- data/test/test_global_functions.cpp +114 -0
- data/test/test_rice.rb +41 -0
- data/test/unittest.cpp +136 -0
- data/test/unittest.hpp +294 -0
- metadata +297 -0
@@ -0,0 +1,159 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/Object.hpp"
|
3
|
+
#include "rice/Class.hpp"
|
4
|
+
#include "rice/String.hpp"
|
5
|
+
#include "rice/Array.hpp"
|
6
|
+
|
7
|
+
using namespace Rice;
|
8
|
+
|
9
|
+
TESTSUITE(Object);
|
10
|
+
|
11
|
+
SETUP(Object)
|
12
|
+
{
|
13
|
+
ruby_init();
|
14
|
+
}
|
15
|
+
|
16
|
+
TESTCASE(default_construct)
|
17
|
+
{
|
18
|
+
Object o;
|
19
|
+
ASSERT_EQUAL(Qnil, o.value());
|
20
|
+
}
|
21
|
+
|
22
|
+
TESTCASE(construct_with_value)
|
23
|
+
{
|
24
|
+
Object o(INT2NUM(42));
|
25
|
+
ASSERT_EQUAL(INT2NUM(42), o.value());
|
26
|
+
}
|
27
|
+
|
28
|
+
TESTCASE(copy_construct)
|
29
|
+
{
|
30
|
+
Object o(INT2NUM(42));
|
31
|
+
Object o2(o);
|
32
|
+
ASSERT_EQUAL(INT2NUM(42), o2.value());
|
33
|
+
}
|
34
|
+
|
35
|
+
TESTCASE(test)
|
36
|
+
{
|
37
|
+
ASSERT_EQUAL(true, Object(Qtrue).test());
|
38
|
+
ASSERT_EQUAL(true, Object(INT2NUM(42)).test());
|
39
|
+
ASSERT_EQUAL(false, Object(Qfalse).test());
|
40
|
+
ASSERT_EQUAL(false, Object(Qnil).test());
|
41
|
+
ASSERT_EQUAL(true, Object(Qundef).test());
|
42
|
+
}
|
43
|
+
|
44
|
+
TESTCASE(explicit_conversion_to_bool)
|
45
|
+
{
|
46
|
+
// g++ 3.3.3 can't handle constructor-style inside the assert, which
|
47
|
+
// is why we use cast-style here.
|
48
|
+
ASSERT_EQUAL(true, (bool)Object(Qtrue));
|
49
|
+
ASSERT_EQUAL(true, (bool)Object(INT2NUM(42)));
|
50
|
+
ASSERT_EQUAL(false, (bool)Object(Qfalse));
|
51
|
+
ASSERT_EQUAL(false, (bool)Object(Qnil));
|
52
|
+
ASSERT_EQUAL(true, (bool)Object(Qundef));
|
53
|
+
}
|
54
|
+
|
55
|
+
TESTCASE(is_nil)
|
56
|
+
{
|
57
|
+
ASSERT_EQUAL(false, Object(Qtrue).is_nil());
|
58
|
+
ASSERT_EQUAL(false, Object(INT2NUM(42)).is_nil());
|
59
|
+
ASSERT_EQUAL(false, Object(Qfalse).is_nil());
|
60
|
+
ASSERT_EQUAL(true, Object(Qnil).is_nil());
|
61
|
+
ASSERT_EQUAL(false, Object(Qundef).is_nil());
|
62
|
+
}
|
63
|
+
|
64
|
+
TESTCASE(implicit_conversion_to_value)
|
65
|
+
{
|
66
|
+
// g++ 3.3.3 can't handle constructor-style inside the assert, which
|
67
|
+
// is why we use cast-style here.
|
68
|
+
ASSERT_EQUAL(Qtrue, (VALUE)Object(Qtrue));
|
69
|
+
ASSERT_EQUAL(INT2NUM(42), (VALUE)Object(INT2NUM(42)));
|
70
|
+
ASSERT_EQUAL(Qfalse, (VALUE)Object(Qfalse));
|
71
|
+
ASSERT_EQUAL(Qnil, (VALUE)Object(Qnil));
|
72
|
+
ASSERT_EQUAL(Qundef, (VALUE)Object(Qundef));
|
73
|
+
}
|
74
|
+
|
75
|
+
TESTCASE(explicit_conversion_to_value)
|
76
|
+
{
|
77
|
+
ASSERT_EQUAL(Qtrue, Object(Qtrue).value());
|
78
|
+
ASSERT_EQUAL(INT2NUM(42), Object(INT2NUM(42)).value());
|
79
|
+
ASSERT_EQUAL(Qfalse, Object(Qfalse).value());
|
80
|
+
ASSERT_EQUAL(Qnil, Object(Qnil).value());
|
81
|
+
ASSERT_EQUAL(Qundef, Object(Qundef).value());
|
82
|
+
}
|
83
|
+
|
84
|
+
TESTCASE(class_of)
|
85
|
+
{
|
86
|
+
ASSERT_EQUAL(Class(rb_cObject), Class(rb_cObject).call("new").class_of());
|
87
|
+
ASSERT_EQUAL(Class(rb_cFloat), Object(rb_float_new(42.0)).class_of());
|
88
|
+
}
|
89
|
+
|
90
|
+
TESTCASE(compare)
|
91
|
+
{
|
92
|
+
ASSERT_EQUAL(0, Object(INT2NUM(42)).compare(Object(INT2NUM(42))));
|
93
|
+
ASSERT_EQUAL(-1, Object(INT2NUM(42)).compare(Object(INT2NUM(43))));
|
94
|
+
ASSERT_EQUAL(1, Object(INT2NUM(42)).compare(Object(INT2NUM(41))));
|
95
|
+
}
|
96
|
+
|
97
|
+
TESTCASE(to_s)
|
98
|
+
{
|
99
|
+
ASSERT_EQUAL(String("42"), Object(INT2NUM(42)).to_s());
|
100
|
+
}
|
101
|
+
|
102
|
+
TESTCASE(inspect)
|
103
|
+
{
|
104
|
+
ASSERT_EQUAL(String("42"), Object(INT2NUM(42)).inspect());
|
105
|
+
ASSERT_EQUAL(String("\"foo\""), Object(rb_str_new2("foo")).inspect());
|
106
|
+
}
|
107
|
+
|
108
|
+
TESTCASE(freeze)
|
109
|
+
{
|
110
|
+
Object o(Class(rb_cObject).call("new"));
|
111
|
+
ASSERT(!OBJ_FROZEN(o.value()));
|
112
|
+
o.freeze();
|
113
|
+
ASSERT(OBJ_FROZEN(o.value()));
|
114
|
+
}
|
115
|
+
|
116
|
+
TESTCASE(is_frozen)
|
117
|
+
{
|
118
|
+
Object o(Class(rb_cObject).call("new"));
|
119
|
+
ASSERT(!o.is_frozen());
|
120
|
+
rb_obj_freeze(o);
|
121
|
+
ASSERT(o.is_frozen());
|
122
|
+
}
|
123
|
+
|
124
|
+
TESTCASE(swap)
|
125
|
+
{
|
126
|
+
Object o1(INT2NUM(42));
|
127
|
+
Object o2(rb_ary_new());
|
128
|
+
o1.swap(o2);
|
129
|
+
ASSERT_EQUAL(to_ruby(42), o2);
|
130
|
+
ASSERT_EQUAL(Class(rb_cArray), o1.class_of());
|
131
|
+
}
|
132
|
+
|
133
|
+
TESTCASE(instance_eval)
|
134
|
+
{
|
135
|
+
Object o(Class(rb_cObject).call("new"));
|
136
|
+
o.iv_set("@foo", 42);
|
137
|
+
ASSERT_EQUAL(to_ruby(42), o.instance_eval("@foo"));
|
138
|
+
}
|
139
|
+
|
140
|
+
TESTCASE(rb_type)
|
141
|
+
{
|
142
|
+
ASSERT_EQUAL(T_TRUE, Object(Qtrue).rb_type());
|
143
|
+
ASSERT_EQUAL(T_FIXNUM, Object(INT2NUM(42)).rb_type());
|
144
|
+
ASSERT_EQUAL(T_FALSE, Object(Qfalse).rb_type());
|
145
|
+
ASSERT_EQUAL(T_NIL, Object(Qnil).rb_type());
|
146
|
+
ASSERT_EQUAL(T_UNDEF, Object(Qundef).rb_type());
|
147
|
+
}
|
148
|
+
|
149
|
+
TESTCASE(call_no_arguments)
|
150
|
+
{
|
151
|
+
Object three = to_ruby(3).call("to_s");
|
152
|
+
ASSERT_EQUAL(String("3"), three);
|
153
|
+
}
|
154
|
+
|
155
|
+
TESTCASE(call_return_rice_object)
|
156
|
+
{
|
157
|
+
Object three = to_ruby(1).call("+", 2);
|
158
|
+
ASSERT_EQUAL(to_ruby(3), three);
|
159
|
+
}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/String.hpp"
|
3
|
+
#include "rice/global_function.hpp"
|
4
|
+
|
5
|
+
using namespace Rice;
|
6
|
+
|
7
|
+
TESTSUITE(String);
|
8
|
+
|
9
|
+
SETUP(String)
|
10
|
+
{
|
11
|
+
ruby_init();
|
12
|
+
}
|
13
|
+
|
14
|
+
TESTCASE(default_construct)
|
15
|
+
{
|
16
|
+
String s;
|
17
|
+
ASSERT_EQUAL(T_STRING, rb_type(s));
|
18
|
+
ASSERT_EQUAL("", RSTRING_PTR(s.value()));
|
19
|
+
}
|
20
|
+
|
21
|
+
TESTCASE(construct_from_value)
|
22
|
+
{
|
23
|
+
String s(rb_str_new2("foo"));
|
24
|
+
ASSERT_EQUAL(T_STRING, rb_type(s));
|
25
|
+
ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
|
26
|
+
}
|
27
|
+
|
28
|
+
TESTCASE(construct_from_object)
|
29
|
+
{
|
30
|
+
Object o(rb_str_new2("foo"));
|
31
|
+
String s(o);
|
32
|
+
ASSERT_EQUAL(T_STRING, rb_type(s));
|
33
|
+
ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
|
34
|
+
}
|
35
|
+
|
36
|
+
TESTCASE(construct_from_identifier)
|
37
|
+
{
|
38
|
+
String s(Identifier("foo"));
|
39
|
+
ASSERT_EQUAL(T_STRING, rb_type(s));
|
40
|
+
ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
|
41
|
+
}
|
42
|
+
|
43
|
+
TESTCASE(construct_from_c_string)
|
44
|
+
{
|
45
|
+
String s("foo");
|
46
|
+
ASSERT_EQUAL(T_STRING, rb_type(s));
|
47
|
+
ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
|
48
|
+
}
|
49
|
+
|
50
|
+
TESTCASE(construct_from_std_string)
|
51
|
+
{
|
52
|
+
String s(std::string("foo"));
|
53
|
+
ASSERT_EQUAL(T_STRING, rb_type(s));
|
54
|
+
ASSERT_EQUAL("foo", RSTRING_PTR(s.value()));
|
55
|
+
}
|
56
|
+
|
57
|
+
TESTCASE(format)
|
58
|
+
{
|
59
|
+
String s(String::format("%s %d", "foo", 42));
|
60
|
+
ASSERT_EQUAL(T_STRING, rb_type(s));
|
61
|
+
ASSERT_EQUAL("foo 42", RSTRING_PTR(s.value()));
|
62
|
+
}
|
63
|
+
|
64
|
+
TESTCASE(length)
|
65
|
+
{
|
66
|
+
String s("foo");
|
67
|
+
ASSERT_EQUAL(3u, s.length());
|
68
|
+
}
|
69
|
+
|
70
|
+
TESTCASE(bracket)
|
71
|
+
{
|
72
|
+
String s("foo");
|
73
|
+
ASSERT_EQUAL('f', s[0]);
|
74
|
+
ASSERT_EQUAL('o', s[1]);
|
75
|
+
ASSERT_EQUAL('o', s[2]);
|
76
|
+
}
|
77
|
+
|
78
|
+
TESTCASE(c_str)
|
79
|
+
{
|
80
|
+
String s("foo");
|
81
|
+
ASSERT_EQUAL(RSTRING_PTR(s.value()), s.c_str());
|
82
|
+
}
|
83
|
+
|
84
|
+
TESTCASE(str)
|
85
|
+
{
|
86
|
+
String s("foo");
|
87
|
+
ASSERT_EQUAL(std::string("foo"), s.str());
|
88
|
+
}
|
89
|
+
|
90
|
+
TESTCASE(intern)
|
91
|
+
{
|
92
|
+
String s("foo");
|
93
|
+
ASSERT_EQUAL(Identifier("foo"), s.intern());
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Issue 59 - Copy constructor compilation problem.
|
98
|
+
*/
|
99
|
+
|
100
|
+
namespace {
|
101
|
+
void testStringArg(Object self, String string) {
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
TESTCASE(use_string_in_wrapped_function) {
|
106
|
+
define_global_function("test_string_arg", &testStringArg);
|
107
|
+
}
|
@@ -0,0 +1,205 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/Struct.hpp"
|
3
|
+
#include "rice/Symbol.hpp"
|
4
|
+
#include "rice/global_function.hpp"
|
5
|
+
|
6
|
+
using namespace Rice;
|
7
|
+
|
8
|
+
TESTSUITE(Struct);
|
9
|
+
|
10
|
+
namespace
|
11
|
+
{
|
12
|
+
Struct define_3d_point()
|
13
|
+
{
|
14
|
+
static Struct rb_cPoint = define_struct()
|
15
|
+
.define_member("x")
|
16
|
+
.define_member("y")
|
17
|
+
.define_member("z")
|
18
|
+
.initialize(rb_mKernel, "Point");
|
19
|
+
return rb_cPoint;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
SETUP(Struct)
|
24
|
+
{
|
25
|
+
ruby_init();
|
26
|
+
}
|
27
|
+
|
28
|
+
TESTCASE(default_construct)
|
29
|
+
{
|
30
|
+
Struct s;
|
31
|
+
ASSERT_EQUAL(0, s.members().size());
|
32
|
+
// can't call rb_struct_s_members, because this isn't a struct yet
|
33
|
+
}
|
34
|
+
|
35
|
+
TESTCASE(initialize)
|
36
|
+
{
|
37
|
+
Struct s(define_3d_point());
|
38
|
+
Array members(rb_struct_s_members(s));
|
39
|
+
ASSERT_EQUAL(3, members.size());
|
40
|
+
ASSERT_EQUAL("x", Symbol(members[0]).c_str());
|
41
|
+
ASSERT_EQUAL("y", Symbol(members[1]).c_str());
|
42
|
+
ASSERT_EQUAL("z", Symbol(members[2]).c_str());
|
43
|
+
}
|
44
|
+
|
45
|
+
TESTCASE(copy_construct)
|
46
|
+
{
|
47
|
+
Struct s(define_3d_point());
|
48
|
+
Struct s2(s);
|
49
|
+
Array members(rb_struct_s_members(s2));
|
50
|
+
ASSERT_EQUAL(3, members.size());
|
51
|
+
ASSERT_EQUAL("x", Symbol(members[0]).c_str());
|
52
|
+
ASSERT_EQUAL("y", Symbol(members[1]).c_str());
|
53
|
+
ASSERT_EQUAL("z", Symbol(members[2]).c_str());
|
54
|
+
}
|
55
|
+
|
56
|
+
TESTCASE(offset_of)
|
57
|
+
{
|
58
|
+
Struct s(define_3d_point());
|
59
|
+
ASSERT_EQUAL(0, s.offset_of("x"));
|
60
|
+
ASSERT_EQUAL(1, s.offset_of("y"));
|
61
|
+
ASSERT_EQUAL(2, s.offset_of("z"));
|
62
|
+
}
|
63
|
+
|
64
|
+
TESTCASE(new_instance_no_args)
|
65
|
+
{
|
66
|
+
Struct s(define_3d_point());
|
67
|
+
Struct::Instance p(s.new_instance());
|
68
|
+
ASSERT_EQUAL(Rice::Nil, Object(rb_struct_getmember(p, rb_intern("x"))));
|
69
|
+
ASSERT_EQUAL(Rice::Nil, Object(rb_struct_getmember(p, rb_intern("y"))));
|
70
|
+
ASSERT_EQUAL(Rice::Nil, Object(rb_struct_getmember(p, rb_intern("z"))));
|
71
|
+
}
|
72
|
+
|
73
|
+
TESTCASE(new_instance_with_args)
|
74
|
+
{
|
75
|
+
int a[] = { 1, 2, 3 };
|
76
|
+
Array args(a);
|
77
|
+
Struct s(define_3d_point());
|
78
|
+
Struct::Instance p(s.new_instance(args));
|
79
|
+
ASSERT_EQUAL(to_ruby(1), Object(rb_struct_getmember(p, rb_intern("x"))));
|
80
|
+
ASSERT_EQUAL(to_ruby(2), Object(rb_struct_getmember(p, rb_intern("y"))));
|
81
|
+
ASSERT_EQUAL(to_ruby(3), Object(rb_struct_getmember(p, rb_intern("z"))));
|
82
|
+
}
|
83
|
+
|
84
|
+
TESTCASE(swap)
|
85
|
+
{
|
86
|
+
Struct s(define_3d_point());
|
87
|
+
Struct s2;
|
88
|
+
s2.swap(s);
|
89
|
+
|
90
|
+
try
|
91
|
+
{
|
92
|
+
Array members(rb_struct_s_members(s2));
|
93
|
+
ASSERT_EQUAL(3, members.size());
|
94
|
+
ASSERT_EQUAL("x", Symbol(members[0]).c_str());
|
95
|
+
ASSERT_EQUAL("y", Symbol(members[1]).c_str());
|
96
|
+
ASSERT_EQUAL("z", Symbol(members[2]).c_str());
|
97
|
+
}
|
98
|
+
catch(...)
|
99
|
+
{
|
100
|
+
s2.swap(s);
|
101
|
+
throw;
|
102
|
+
}
|
103
|
+
|
104
|
+
s2.swap(s);
|
105
|
+
}
|
106
|
+
|
107
|
+
TESTCASE(members)
|
108
|
+
{
|
109
|
+
Struct s(define_3d_point());
|
110
|
+
Array members(s.members());
|
111
|
+
ASSERT_EQUAL(3, members.size());
|
112
|
+
ASSERT_EQUAL("x", Symbol(members[0]).c_str());
|
113
|
+
ASSERT_EQUAL("y", Symbol(members[1]).c_str());
|
114
|
+
ASSERT_EQUAL("z", Symbol(members[2]).c_str());
|
115
|
+
}
|
116
|
+
|
117
|
+
TESTCASE(construct_instance)
|
118
|
+
{
|
119
|
+
int a[] = { 1, 2, 3 };
|
120
|
+
Array args(a);
|
121
|
+
Struct s(define_3d_point());
|
122
|
+
Struct::Instance p(s, args);
|
123
|
+
ASSERT_EQUAL(to_ruby(1), Object(rb_struct_getmember(p, rb_intern("x"))));
|
124
|
+
ASSERT_EQUAL(to_ruby(2), Object(rb_struct_getmember(p, rb_intern("y"))));
|
125
|
+
ASSERT_EQUAL(to_ruby(3), Object(rb_struct_getmember(p, rb_intern("z"))));
|
126
|
+
}
|
127
|
+
|
128
|
+
TESTCASE(wrap_instance)
|
129
|
+
{
|
130
|
+
Struct s(define_3d_point());
|
131
|
+
Object o = s.instance_eval("new(1, 2, 3)");
|
132
|
+
Struct::Instance p(s, o);
|
133
|
+
ASSERT_EQUAL(to_ruby(1), Object(rb_struct_getmember(p, rb_intern("x"))));
|
134
|
+
ASSERT_EQUAL(to_ruby(2), Object(rb_struct_getmember(p, rb_intern("y"))));
|
135
|
+
ASSERT_EQUAL(to_ruby(3), Object(rb_struct_getmember(p, rb_intern("z"))));
|
136
|
+
}
|
137
|
+
|
138
|
+
TESTCASE(instance_bracket_identifier)
|
139
|
+
{
|
140
|
+
int a[] = { 1, 2, 3 };
|
141
|
+
Array args(a);
|
142
|
+
Struct s(define_3d_point());
|
143
|
+
Struct::Instance p(s, args);
|
144
|
+
ASSERT_EQUAL(to_ruby(1), p[Identifier("x")]);
|
145
|
+
ASSERT_EQUAL(to_ruby(2), p[Identifier("y")]);
|
146
|
+
ASSERT_EQUAL(to_ruby(3), p[Identifier("z")]);
|
147
|
+
}
|
148
|
+
|
149
|
+
TESTCASE(instance_bracket_name)
|
150
|
+
{
|
151
|
+
int a[] = { 1, 2, 3 };
|
152
|
+
Array args(a);
|
153
|
+
Struct s(define_3d_point());
|
154
|
+
Struct::Instance p(s, args);
|
155
|
+
ASSERT_EQUAL(to_ruby(1), p["x"]);
|
156
|
+
ASSERT_EQUAL(to_ruby(2), p["y"]);
|
157
|
+
ASSERT_EQUAL(to_ruby(3), p["z"]);
|
158
|
+
}
|
159
|
+
|
160
|
+
TESTCASE(instance_bracket_index)
|
161
|
+
{
|
162
|
+
int a[] = { 1, 2, 3 };
|
163
|
+
Array args(a);
|
164
|
+
Struct s(define_3d_point());
|
165
|
+
Struct::Instance p(s, args);
|
166
|
+
ASSERT_EQUAL(to_ruby(1), p[0]);
|
167
|
+
ASSERT_EQUAL(to_ruby(2), p[1]);
|
168
|
+
ASSERT_EQUAL(to_ruby(3), p[2]);
|
169
|
+
}
|
170
|
+
|
171
|
+
TESTCASE(instance_swap)
|
172
|
+
{
|
173
|
+
Struct s(define_3d_point());
|
174
|
+
|
175
|
+
int a1[] = { 1, 2, 3 };
|
176
|
+
Array args1(a1);
|
177
|
+
Struct::Instance p1(s, args1);
|
178
|
+
|
179
|
+
int a2[] = { 4, 5, 6 };
|
180
|
+
Array args2(a2);
|
181
|
+
Struct::Instance p2(s, args2);
|
182
|
+
|
183
|
+
p1.swap(p2);
|
184
|
+
|
185
|
+
ASSERT_EQUAL(to_ruby(4), Object(rb_struct_getmember(p1, rb_intern("x"))));
|
186
|
+
ASSERT_EQUAL(to_ruby(5), Object(rb_struct_getmember(p1, rb_intern("y"))));
|
187
|
+
ASSERT_EQUAL(to_ruby(6), Object(rb_struct_getmember(p1, rb_intern("z"))));
|
188
|
+
|
189
|
+
ASSERT_EQUAL(to_ruby(1), Object(rb_struct_getmember(p2, rb_intern("x"))));
|
190
|
+
ASSERT_EQUAL(to_ruby(2), Object(rb_struct_getmember(p2, rb_intern("y"))));
|
191
|
+
ASSERT_EQUAL(to_ruby(3), Object(rb_struct_getmember(p2, rb_intern("z"))));
|
192
|
+
}
|
193
|
+
|
194
|
+
/**
|
195
|
+
* Issue 59 - Copy constructor compilation problem.
|
196
|
+
*/
|
197
|
+
|
198
|
+
namespace {
|
199
|
+
void testStructArg(Object self, Struct string) {
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
TESTCASE(use_struct_in_wrapped_function) {
|
204
|
+
define_global_function("test_struct_arg", &testStructArg);
|
205
|
+
}
|