wurlinc-rice 1.4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +23 -0
- data/Doxyfile +1253 -0
- data/Makefile.am +26 -0
- data/README +1119 -0
- data/README.mingw +8 -0
- data/Rakefile +33 -0
- data/bootstrap +9 -0
- data/configure.ac +52 -0
- data/doxygen.ac +314 -0
- data/doxygen.am +186 -0
- data/extconf.rb +41 -0
- data/post-autoconf.rb +22 -0
- data/post-automake.rb +28 -0
- data/rice/Address_Registration_Guard.hpp +7 -0
- data/rice/Address_Registration_Guard.ipp +34 -0
- data/rice/Address_Registration_Guard_defn.hpp +65 -0
- data/rice/Allocation_Strategies.hpp +37 -0
- data/rice/Arg.hpp +8 -0
- data/rice/Arg_impl.hpp +127 -0
- data/rice/Arg_operators.cpp +21 -0
- data/rice/Arg_operators.hpp +19 -0
- data/rice/Array.hpp +220 -0
- data/rice/Array.ipp +263 -0
- data/rice/Builtin_Object.hpp +8 -0
- data/rice/Builtin_Object.ipp +50 -0
- data/rice/Builtin_Object_defn.hpp +51 -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 +367 -0
- data/rice/Critical_Guard.hpp +40 -0
- data/rice/Critical_Guard.ipp +26 -0
- data/rice/Data_Object.hpp +8 -0
- data/rice/Data_Object.ipp +133 -0
- data/rice/Data_Object_defn.hpp +132 -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 +9 -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 +210 -0
- data/rice/Hash.ipp +338 -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 +129 -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 +348 -0
- data/rice/Object.cpp +160 -0
- data/rice/Object.hpp +8 -0
- data/rice/Object.ipp +19 -0
- data/rice/Object_defn.hpp +191 -0
- data/rice/Require_Guard.hpp +21 -0
- data/rice/String.cpp +94 -0
- data/rice/String.hpp +89 -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/VM.cpp +92 -0
- data/rice/VM.hpp +32 -0
- data/rice/config.hpp.in +40 -0
- data/rice/detail/Arguments.hpp +118 -0
- data/rice/detail/Auto_Function_Wrapper.hpp +829 -0
- data/rice/detail/Auto_Function_Wrapper.ipp +3391 -0
- data/rice/detail/Auto_Member_Function_Wrapper.hpp +828 -0
- data/rice/detail/Auto_Member_Function_Wrapper.ipp +2503 -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 +19 -0
- data/rice/detail/from_ruby.hpp +43 -0
- data/rice/detail/from_ruby.ipp +60 -0
- data/rice/detail/method_data.cpp +159 -0
- data/rice/detail/method_data.hpp +21 -0
- data/rice/detail/mininode.cpp +1220 -0
- data/rice/detail/mininode.hpp +320 -0
- data/rice/detail/node.hpp +13 -0
- data/rice/detail/object_call.hpp +68 -0
- data/rice/detail/object_call.ipp +131 -0
- data/rice/detail/protect.cpp +29 -0
- data/rice/detail/protect.hpp +34 -0
- data/rice/detail/ruby.hpp +93 -0
- data/rice/detail/ruby_version_code.hpp.in +6 -0
- data/rice/detail/rubysig.hpp +19 -0
- data/rice/detail/st.hpp +60 -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 +341 -0
- data/rice/detail/wrap_function.ipp +514 -0
- data/rice/global_function.hpp +33 -0
- data/rice/global_function.ipp +22 -0
- data/rice/protect.hpp +91 -0
- data/rice/protect.ipp +1133 -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 +297 -0
- data/rice/to_from_ruby_defn.hpp +71 -0
- data/ruby/Makefile.am +1 -0
- data/ruby/lib/Makefile.am +3 -0
- data/ruby/lib/mkmf-rice.rb.in +216 -0
- data/ruby/lib/version.rb +3 -0
- data/ruby.ac +136 -0
- data/sample/Makefile.am +47 -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 +78 -0
- data/test/ext/Makefile.am +43 -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_Allocation_Strategies.cpp +77 -0
- data/test/test_Array.cpp +241 -0
- data/test/test_Builtin_Object.cpp +72 -0
- data/test/test_Class.cpp +498 -0
- data/test/test_Constructor.cpp +128 -0
- data/test/test_Critical_Guard.cpp +51 -0
- data/test/test_Data_Object.cpp +275 -0
- data/test/test_Data_Type.cpp +348 -0
- data/test/test_Director.cpp +301 -0
- data/test/test_Enum.cpp +195 -0
- data/test/test_Exception.cpp +46 -0
- data/test/test_Hash.cpp +195 -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 +481 -0
- data/test/test_Object.cpp +148 -0
- data/test/test_String.cpp +94 -0
- data/test/test_Struct.cpp +192 -0
- data/test/test_Symbol.cpp +63 -0
- data/test/test_To_From_Ruby.cpp +263 -0
- data/test/test_VM.cpp +26 -0
- data/test/test_global_functions.cpp +114 -0
- data/test/test_rice.rb +43 -0
- data/test/unittest.cpp +136 -0
- data/test/unittest.hpp +292 -0
- metadata +276 -0
data/test/Makefile.am
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
noinst_PROGRAMS = unittest vm_unittest
|
2
|
+
|
3
|
+
SUBDIRS = ext
|
4
|
+
|
5
|
+
TESTS = unittest vm_unittest
|
6
|
+
|
7
|
+
|
8
|
+
check: run_multiple_extensions_test
|
9
|
+
|
10
|
+
.PHONY: run_multiple_extensions_test
|
11
|
+
|
12
|
+
run_multiple_extensions_test:
|
13
|
+
$(RUBY) test_multiple_extensions.rb
|
14
|
+
|
15
|
+
|
16
|
+
check: run_multiple_extensions_with_inheritance_test
|
17
|
+
|
18
|
+
.PHONY: run_multiple_extensions_with_inheritance_test
|
19
|
+
|
20
|
+
run_multiple_extensions_with_inheritance_test:
|
21
|
+
$(RUBY) test_multiple_extensions_with_inheritance.rb
|
22
|
+
|
23
|
+
|
24
|
+
check: run_multiple_extensions_same_class_test
|
25
|
+
|
26
|
+
.PHONY: run_multiple_extensions_same_class_test
|
27
|
+
|
28
|
+
run_multiple_extensions_same_class_test:
|
29
|
+
$(RUBY) test_multiple_extensions_same_class.rb
|
30
|
+
|
31
|
+
|
32
|
+
unittest_SOURCES = \
|
33
|
+
unittest.cpp \
|
34
|
+
test_Address_Registration_Guard.cpp \
|
35
|
+
test_Allocation_Strategies.cpp \
|
36
|
+
test_Array.cpp \
|
37
|
+
test_Builtin_Object.cpp \
|
38
|
+
test_Class.cpp \
|
39
|
+
test_Constructor.cpp \
|
40
|
+
test_Critical_Guard.cpp \
|
41
|
+
test_Data_Object.cpp \
|
42
|
+
test_Data_Type.cpp \
|
43
|
+
test_Director.cpp \
|
44
|
+
test_Enum.cpp \
|
45
|
+
test_Exception.cpp \
|
46
|
+
test_Hash.cpp \
|
47
|
+
test_Identifier.cpp \
|
48
|
+
test_Jump_Tag.cpp \
|
49
|
+
test_Memory_Management.cpp \
|
50
|
+
test_Module.cpp \
|
51
|
+
test_Object.cpp \
|
52
|
+
test_String.cpp \
|
53
|
+
test_Struct.cpp \
|
54
|
+
test_Symbol.cpp \
|
55
|
+
test_To_From_Ruby.cpp \
|
56
|
+
test_global_functions.cpp
|
57
|
+
|
58
|
+
vm_unittest_SOURCES = \
|
59
|
+
unittest.cpp \
|
60
|
+
test_VM.cpp
|
61
|
+
|
62
|
+
AM_CPPFLAGS = \
|
63
|
+
-I.. \
|
64
|
+
$(RUBY_CFLAGS)
|
65
|
+
$(RUBY_CPPFLAGS)
|
66
|
+
|
67
|
+
AM_CXXLAGS = \
|
68
|
+
$(RUBY_CXXFLAGS)
|
69
|
+
|
70
|
+
AM_LDFLAGS = \
|
71
|
+
$(RUBY_LDFLAGS) \
|
72
|
+
-L../rice
|
73
|
+
|
74
|
+
LIBS = \
|
75
|
+
-lrice \
|
76
|
+
$(RUBY_LIBS) \
|
77
|
+
$(RUBY_LIBRUBYARG)
|
78
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
RUBY_EXTCONF_OPTIONS = -I@RICE_ROOT@/ruby/lib
|
2
|
+
EXTCONF_OPTIONS = --with-cppflags="-I@RICE_ROOT@" --with-libpath="@RICE_ROOT@/rice"
|
3
|
+
|
4
|
+
EXTRA_DIST = \
|
5
|
+
t1/extconf.rb \
|
6
|
+
t1/t1.cpp \
|
7
|
+
t2/extconf.rb \
|
8
|
+
t2/t2.cpp
|
9
|
+
|
10
|
+
all:
|
11
|
+
|
12
|
+
t1/Makefile: t1/extconf.rb ../../config.status ../../ruby/lib/mkmf-rice.rb
|
13
|
+
@RUBY@ $(RUBY_EXTCONF_OPTIONS) -C t1 extconf.rb $(EXTCONF_OPTIONS)
|
14
|
+
|
15
|
+
t2/Makefile: t2/extconf.rb ../../config.status ../../ruby/lib/mkmf-rice.rb
|
16
|
+
@RUBY@ $(RUBY_EXTCONF_OPTIONS) -C t2 extconf.rb $(EXTCONF_OPTIONS)
|
17
|
+
|
18
|
+
all clean distclean: t1/Makefile t2/Makefile
|
19
|
+
|
20
|
+
all: t1_all t2_all
|
21
|
+
|
22
|
+
t1_all:
|
23
|
+
make -C t1 all
|
24
|
+
|
25
|
+
t2_all:
|
26
|
+
make -C t2 all
|
27
|
+
|
28
|
+
clean: t1_clean t2_clean
|
29
|
+
|
30
|
+
t1_clean:
|
31
|
+
make -C t1 clean
|
32
|
+
|
33
|
+
t2_clean:
|
34
|
+
make -C t2 clean
|
35
|
+
|
36
|
+
distclean: t1_distclean t2_distclean
|
37
|
+
|
38
|
+
t1_distclean:
|
39
|
+
make -C t1 distclean
|
40
|
+
|
41
|
+
t2_distclean:
|
42
|
+
make -C t2 distclean
|
43
|
+
|
data/test/ext/t1/Foo.hpp
ADDED
data/test/ext/t1/t1.cpp
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#include "Foo.hpp"
|
2
|
+
|
3
|
+
#include "rice/Data_Type.hpp"
|
4
|
+
#include "rice/Constructor.hpp"
|
5
|
+
|
6
|
+
using namespace Rice;
|
7
|
+
|
8
|
+
extern "C"
|
9
|
+
void Init_t1()
|
10
|
+
{
|
11
|
+
define_class<Foo>("Foo")
|
12
|
+
.define_constructor(Constructor<Foo>())
|
13
|
+
.define_method("foo", &Foo::foo);
|
14
|
+
}
|
15
|
+
|
data/test/ext/t2/t2.cpp
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/Address_Registration_Guard.hpp"
|
3
|
+
|
4
|
+
using namespace Rice;
|
5
|
+
|
6
|
+
TESTSUITE(Address_Registration_Guard);
|
7
|
+
|
8
|
+
SETUP(Address_Registration_Guard)
|
9
|
+
{
|
10
|
+
ruby_init();
|
11
|
+
}
|
12
|
+
|
13
|
+
TESTCASE(register_address)
|
14
|
+
{
|
15
|
+
VALUE v = Qnil;
|
16
|
+
Address_Registration_Guard g(&v);
|
17
|
+
}
|
18
|
+
|
19
|
+
TESTCASE(register_object)
|
20
|
+
{
|
21
|
+
Object o;
|
22
|
+
Address_Registration_Guard g(&o);
|
23
|
+
}
|
24
|
+
|
25
|
+
TESTCASE(get_address)
|
26
|
+
{
|
27
|
+
VALUE v = Qnil;
|
28
|
+
Address_Registration_Guard g(&v);
|
29
|
+
ASSERT_EQUAL(&v, g.address());
|
30
|
+
}
|
31
|
+
|
32
|
+
TESTCASE(swap)
|
33
|
+
{
|
34
|
+
VALUE v = Qnil;
|
35
|
+
VALUE v2 = Qnil;
|
36
|
+
Address_Registration_Guard g(&v);
|
37
|
+
Address_Registration_Guard g2(&v2);
|
38
|
+
g.swap(g2);
|
39
|
+
ASSERT_EQUAL(&v, g2.address());
|
40
|
+
ASSERT_EQUAL(&v2, g.address());
|
41
|
+
// TODO: ensure addresses are still registered
|
42
|
+
}
|
43
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/Allocation_Strategies.hpp"
|
3
|
+
|
4
|
+
using namespace Rice;
|
5
|
+
|
6
|
+
namespace
|
7
|
+
{
|
8
|
+
|
9
|
+
bool constructor_called = false;
|
10
|
+
bool destructor_called = false;
|
11
|
+
|
12
|
+
class Foo
|
13
|
+
{
|
14
|
+
public:
|
15
|
+
Foo()
|
16
|
+
{
|
17
|
+
constructor_called = true;
|
18
|
+
}
|
19
|
+
|
20
|
+
~Foo()
|
21
|
+
{
|
22
|
+
destructor_called = true;
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
} // namespace
|
27
|
+
|
28
|
+
TESTSUITE(Allocation_Strategies);
|
29
|
+
|
30
|
+
SETUP(Allocation_Strategies)
|
31
|
+
{
|
32
|
+
ruby_init();
|
33
|
+
constructor_called = false;
|
34
|
+
destructor_called = false;
|
35
|
+
}
|
36
|
+
|
37
|
+
TESTCASE(default_allocation_strategy_allocate)
|
38
|
+
{
|
39
|
+
Foo * t = Default_Allocation_Strategy<Foo>::allocate();
|
40
|
+
ASSERT(constructor_called);
|
41
|
+
ASSERT(!destructor_called);
|
42
|
+
delete t;
|
43
|
+
ASSERT(constructor_called);
|
44
|
+
ASSERT(destructor_called);
|
45
|
+
}
|
46
|
+
|
47
|
+
TESTCASE(default_allocation_strategy_free)
|
48
|
+
{
|
49
|
+
Foo * t = new Foo;
|
50
|
+
ASSERT(constructor_called);
|
51
|
+
ASSERT(!destructor_called);
|
52
|
+
Default_Allocation_Strategy<Foo>::free(t);
|
53
|
+
ASSERT(constructor_called);
|
54
|
+
ASSERT(destructor_called);
|
55
|
+
}
|
56
|
+
|
57
|
+
TESTCASE(xmalloc_allocation_strategy_allocate)
|
58
|
+
{
|
59
|
+
Foo * t = Xmalloc_Allocation_Strategy<Foo>::allocate();
|
60
|
+
ASSERT(constructor_called);
|
61
|
+
ASSERT(!destructor_called);
|
62
|
+
t->~Foo();
|
63
|
+
xfree(t);
|
64
|
+
ASSERT(constructor_called);
|
65
|
+
ASSERT(destructor_called);
|
66
|
+
}
|
67
|
+
|
68
|
+
TESTCASE(xmalloc_allocation_strategy_free)
|
69
|
+
{
|
70
|
+
Foo * t = Xmalloc_Allocation_Strategy<Foo>::allocate();
|
71
|
+
ASSERT(constructor_called);
|
72
|
+
ASSERT(!destructor_called);
|
73
|
+
Xmalloc_Allocation_Strategy<Foo>::free(t);
|
74
|
+
ASSERT(constructor_called);
|
75
|
+
ASSERT(destructor_called);
|
76
|
+
}
|
77
|
+
|
data/test/test_Array.cpp
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/Array.hpp"
|
3
|
+
#include "rice/String.hpp"
|
4
|
+
|
5
|
+
using namespace Rice;
|
6
|
+
|
7
|
+
TESTSUITE(Array);
|
8
|
+
|
9
|
+
SETUP(Array)
|
10
|
+
{
|
11
|
+
ruby_init();
|
12
|
+
}
|
13
|
+
|
14
|
+
TESTCASE(default_construct)
|
15
|
+
{
|
16
|
+
Array a;
|
17
|
+
ASSERT_EQUAL(T_ARRAY, rb_type(a));
|
18
|
+
ASSERT_EQUAL(0, RARRAY_LEN(a.value()));
|
19
|
+
}
|
20
|
+
|
21
|
+
TESTCASE(construct_from_vector_of_int)
|
22
|
+
{
|
23
|
+
std::vector<int> v;
|
24
|
+
v.push_back(10);
|
25
|
+
v.push_back(6);
|
26
|
+
v.push_back(42);
|
27
|
+
Array a(v.begin(), v.end());
|
28
|
+
ASSERT_EQUAL(3u, a.size());
|
29
|
+
ASSERT_EQUAL(to_ruby(10), a[0]);
|
30
|
+
ASSERT_EQUAL(to_ruby(6), a[1]);
|
31
|
+
ASSERT_EQUAL(to_ruby(42), a[2]);
|
32
|
+
}
|
33
|
+
|
34
|
+
TESTCASE(construct_from_c_array)
|
35
|
+
{
|
36
|
+
int arr[] = { 10, 6, 42 };
|
37
|
+
Array a(arr);
|
38
|
+
ASSERT_EQUAL(3u, a.size());
|
39
|
+
ASSERT_EQUAL(to_ruby(10), a[0]);
|
40
|
+
ASSERT_EQUAL(to_ruby(6), a[1]);
|
41
|
+
ASSERT_EQUAL(to_ruby(42), a[2]);
|
42
|
+
}
|
43
|
+
|
44
|
+
|
45
|
+
TESTCASE(push_no_items)
|
46
|
+
{
|
47
|
+
Array a;
|
48
|
+
ASSERT_EQUAL(0u, a.size());
|
49
|
+
}
|
50
|
+
|
51
|
+
TESTCASE(push_one_item)
|
52
|
+
{
|
53
|
+
Array a;
|
54
|
+
a.push(Rice::True);
|
55
|
+
ASSERT_EQUAL(1u, a.size());
|
56
|
+
ASSERT_EQUAL(Qtrue, a[0]);
|
57
|
+
}
|
58
|
+
|
59
|
+
TESTCASE(push_two_items)
|
60
|
+
{
|
61
|
+
Array a;
|
62
|
+
a.push(to_ruby(42));
|
63
|
+
a.push(to_ruby(43));
|
64
|
+
ASSERT_EQUAL(2u, a.size());
|
65
|
+
ASSERT_EQUAL(42, from_ruby<int>(a[0]));
|
66
|
+
ASSERT_EQUAL(43, from_ruby<int>(a[1]));
|
67
|
+
}
|
68
|
+
|
69
|
+
TESTCASE(push_three_items)
|
70
|
+
{
|
71
|
+
Array a;
|
72
|
+
a.push(to_ruby(42));
|
73
|
+
a.push(to_ruby(43));
|
74
|
+
a.push(to_ruby(44));
|
75
|
+
ASSERT_EQUAL(3u, a.size());
|
76
|
+
ASSERT_EQUAL(42, from_ruby<int>(a[0]));
|
77
|
+
ASSERT_EQUAL(43, from_ruby<int>(a[1]));
|
78
|
+
ASSERT_EQUAL(44, from_ruby<int>(a[2]));
|
79
|
+
}
|
80
|
+
|
81
|
+
TESTCASE(push_int)
|
82
|
+
{
|
83
|
+
Array a;
|
84
|
+
a.push(42);
|
85
|
+
ASSERT_EQUAL(1u, a.size());
|
86
|
+
ASSERT_EQUAL(to_ruby(42), a[0]);
|
87
|
+
}
|
88
|
+
|
89
|
+
TESTCASE(bracket_equals)
|
90
|
+
{
|
91
|
+
Array a;
|
92
|
+
a.push(to_ruby(42));
|
93
|
+
a.push(to_ruby(43));
|
94
|
+
a.push(to_ruby(44));
|
95
|
+
a[1] = to_ruby(10);
|
96
|
+
ASSERT_EQUAL(10, from_ruby<int>(a[1]));
|
97
|
+
}
|
98
|
+
|
99
|
+
TESTCASE(to_s)
|
100
|
+
{
|
101
|
+
Array a;
|
102
|
+
a.push(to_ruby(42));
|
103
|
+
a.push(to_ruby(43));
|
104
|
+
a.push(to_ruby(44));
|
105
|
+
String s1(a.call("to_s"));
|
106
|
+
String s2(a.to_s());
|
107
|
+
ASSERT_EQUAL(s1.str(), s2.str());
|
108
|
+
}
|
109
|
+
|
110
|
+
TESTCASE(pop)
|
111
|
+
{
|
112
|
+
Array a;
|
113
|
+
a.push(to_ruby(42));
|
114
|
+
a.push(to_ruby(43));
|
115
|
+
a.push(to_ruby(44));
|
116
|
+
VALUE result = a.pop();
|
117
|
+
ASSERT_EQUAL(2u, a.size());
|
118
|
+
ASSERT_EQUAL(42, from_ruby<int>(a[0]));
|
119
|
+
ASSERT_EQUAL(43, from_ruby<int>(a[1]));
|
120
|
+
ASSERT_EQUAL(44, from_ruby<int>(result));
|
121
|
+
}
|
122
|
+
|
123
|
+
TESTCASE(unshift)
|
124
|
+
{
|
125
|
+
Array a;
|
126
|
+
a.push(to_ruby(42));
|
127
|
+
a.push(to_ruby(43));
|
128
|
+
a.push(to_ruby(44));
|
129
|
+
a.unshift(to_ruby(10));
|
130
|
+
ASSERT_EQUAL(4u, a.size());
|
131
|
+
ASSERT_EQUAL(10, from_ruby<int>(a[0]));
|
132
|
+
ASSERT_EQUAL(42, from_ruby<int>(a[1]));
|
133
|
+
ASSERT_EQUAL(43, from_ruby<int>(a[2]));
|
134
|
+
ASSERT_EQUAL(44, from_ruby<int>(a[3]));
|
135
|
+
}
|
136
|
+
|
137
|
+
TESTCASE(unshift_int)
|
138
|
+
{
|
139
|
+
Array a;
|
140
|
+
a.unshift(42);
|
141
|
+
ASSERT_EQUAL(1u, a.size());
|
142
|
+
ASSERT_EQUAL(to_ruby(42), a[0]);
|
143
|
+
}
|
144
|
+
|
145
|
+
TESTCASE(shift)
|
146
|
+
{
|
147
|
+
Array a;
|
148
|
+
a.push(to_ruby(42));
|
149
|
+
a.push(to_ruby(43));
|
150
|
+
a.push(to_ruby(44));
|
151
|
+
VALUE result = a.shift();
|
152
|
+
ASSERT_EQUAL(2u, a.size());
|
153
|
+
ASSERT_EQUAL(42, from_ruby<int>(result));
|
154
|
+
ASSERT_EQUAL(43, from_ruby<int>(a[0]));
|
155
|
+
ASSERT_EQUAL(44, from_ruby<int>(a[1]));
|
156
|
+
}
|
157
|
+
|
158
|
+
TESTCASE(to_c_array)
|
159
|
+
{
|
160
|
+
Array a;
|
161
|
+
ASSERT_EQUAL(RARRAY_PTR(a.value()), a.to_c_array());
|
162
|
+
}
|
163
|
+
|
164
|
+
TESTCASE(iterate)
|
165
|
+
{
|
166
|
+
Array a;
|
167
|
+
a.push(to_ruby(42));
|
168
|
+
a.push(to_ruby(43));
|
169
|
+
a.push(to_ruby(44));
|
170
|
+
int ca[] = { 42, 43, 44 };
|
171
|
+
Array::iterator it = a.begin();
|
172
|
+
Array::iterator end = a.end();
|
173
|
+
for(int j = 0; it != end; ++j, ++it)
|
174
|
+
{
|
175
|
+
ASSERT_EQUAL(ca[j], from_ruby<int>(*it));
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
TESTCASE(const_iterate)
|
180
|
+
{
|
181
|
+
Array a;
|
182
|
+
a.push(to_ruby(42));
|
183
|
+
a.push(to_ruby(43));
|
184
|
+
a.push(to_ruby(44));
|
185
|
+
int ca[] = { 42, 43, 44 };
|
186
|
+
Array::const_iterator it = a.begin();
|
187
|
+
Array::const_iterator end = a.end();
|
188
|
+
for(int j = 0; it != end; ++j, ++it)
|
189
|
+
{
|
190
|
+
ASSERT_EQUAL(ca[j], from_ruby<int>(*it));
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
TESTCASE(iterate_and_change)
|
195
|
+
{
|
196
|
+
Array a;
|
197
|
+
a.push(to_ruby(42));
|
198
|
+
a.push(to_ruby(43));
|
199
|
+
a.push(to_ruby(44));
|
200
|
+
Array::iterator it = a.begin();
|
201
|
+
Array::iterator end = a.end();
|
202
|
+
for(int j = 0; it != end; ++j, ++it)
|
203
|
+
{
|
204
|
+
int value = from_ruby<int>(*it);
|
205
|
+
*it = to_ruby(value + j);
|
206
|
+
}
|
207
|
+
ASSERT_EQUAL(42, from_ruby<int>(a[0]));
|
208
|
+
ASSERT_EQUAL(44, from_ruby<int>(a[1]));
|
209
|
+
ASSERT_EQUAL(46, from_ruby<int>(a[2]));
|
210
|
+
}
|
211
|
+
|
212
|
+
TESTCASE(iterate_and_call_member)
|
213
|
+
{
|
214
|
+
Array a;
|
215
|
+
a.push(to_ruby(42));
|
216
|
+
a.push(to_ruby(43));
|
217
|
+
a.push(to_ruby(44));
|
218
|
+
Array::iterator it = a.begin();
|
219
|
+
Array::iterator end = a.end();
|
220
|
+
std::vector<Object> v;
|
221
|
+
for(int j = 0; it != end; ++j, ++it)
|
222
|
+
{
|
223
|
+
v.push_back(it->to_s());
|
224
|
+
}
|
225
|
+
ASSERT_EQUAL(42, from_ruby<int>(a[0]));
|
226
|
+
ASSERT_EQUAL(43, from_ruby<int>(a[1]));
|
227
|
+
ASSERT_EQUAL(44, from_ruby<int>(a[2]));
|
228
|
+
ASSERT_EQUAL(3u, v.size());
|
229
|
+
ASSERT_EQUAL(Object(a[0]).to_s(), v[0]);
|
230
|
+
ASSERT_EQUAL(Object(a[1]).to_s(), v[1]);
|
231
|
+
ASSERT_EQUAL(Object(a[2]).to_s(), v[2]);
|
232
|
+
}
|
233
|
+
|
234
|
+
TESTCASE(assign_int)
|
235
|
+
{
|
236
|
+
Array a;
|
237
|
+
a.push(42);
|
238
|
+
a[0] = 10;
|
239
|
+
ASSERT_EQUAL(10, from_ruby<int>(a[0]));
|
240
|
+
}
|
241
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#include "unittest.hpp"
|
2
|
+
#include "rice/Builtin_Object.hpp"
|
3
|
+
#include "rice/Class.hpp"
|
4
|
+
|
5
|
+
using namespace Rice;
|
6
|
+
|
7
|
+
TESTSUITE(Builtin_Object);
|
8
|
+
|
9
|
+
SETUP(Builtin_Object)
|
10
|
+
{
|
11
|
+
ruby_init();
|
12
|
+
}
|
13
|
+
|
14
|
+
TESTCASE(construct_with_object)
|
15
|
+
{
|
16
|
+
Class c(rb_cObject);
|
17
|
+
Object o(c.call("new"));
|
18
|
+
Builtin_Object<RObject, T_OBJECT> b(o);
|
19
|
+
ASSERT_EQUAL(o.value(), b.value());
|
20
|
+
ASSERT_EQUAL(T_OBJECT, rb_type(b.value()));
|
21
|
+
ASSERT_EQUAL(rb_cObject, b.class_of().value());
|
22
|
+
ASSERT_EQUAL(rb_cObject, CLASS_OF(b.value()));
|
23
|
+
}
|
24
|
+
|
25
|
+
TESTCASE(copy_construct)
|
26
|
+
{
|
27
|
+
Class c(rb_cObject);
|
28
|
+
Object o(c.call("new"));
|
29
|
+
Builtin_Object<RObject, T_OBJECT> b(o);
|
30
|
+
Builtin_Object<RObject, T_OBJECT> b2(b);
|
31
|
+
ASSERT_EQUAL(o.value(), b2.value());
|
32
|
+
ASSERT_EQUAL(T_OBJECT, rb_type(b2.value()));
|
33
|
+
ASSERT_EQUAL(rb_cObject, b2.class_of().value());
|
34
|
+
ASSERT_EQUAL(rb_cObject, CLASS_OF(b2.value()));
|
35
|
+
}
|
36
|
+
|
37
|
+
TESTCASE(dereference)
|
38
|
+
{
|
39
|
+
Class c(rb_cObject);
|
40
|
+
Object o(c.call("new"));
|
41
|
+
Builtin_Object<RObject, T_OBJECT> b(o);
|
42
|
+
ASSERT_EQUAL(ROBJECT(o.value()), &*b);
|
43
|
+
}
|
44
|
+
|
45
|
+
TESTCASE(arrow)
|
46
|
+
{
|
47
|
+
Class c(rb_cObject);
|
48
|
+
Object o(c.call("new"));
|
49
|
+
Builtin_Object<RObject, T_OBJECT> b(o);
|
50
|
+
ASSERT_EQUAL(rb_cObject, b->basic.klass);
|
51
|
+
}
|
52
|
+
|
53
|
+
TESTCASE(get)
|
54
|
+
{
|
55
|
+
Class c(rb_cObject);
|
56
|
+
Object o(c.call("new"));
|
57
|
+
Builtin_Object<RObject, T_OBJECT> b(o);
|
58
|
+
ASSERT_EQUAL(ROBJECT(o.value()), b.get());
|
59
|
+
}
|
60
|
+
|
61
|
+
TESTCASE(swap)
|
62
|
+
{
|
63
|
+
Class c(rb_cObject);
|
64
|
+
Object o1(c.call("new"));
|
65
|
+
Builtin_Object<RObject, T_OBJECT> b1(o1);
|
66
|
+
Object o2(c.call("new"));
|
67
|
+
Builtin_Object<RObject, T_OBJECT> b2(o2);
|
68
|
+
b1.swap(b2);
|
69
|
+
ASSERT_EQUAL(b1.value(), o2.value());
|
70
|
+
ASSERT_EQUAL(b2.value(), o1.value());
|
71
|
+
}
|
72
|
+
|