wurlinc-rice 1.4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/COPYING +23 -0
  2. data/Doxyfile +1253 -0
  3. data/Makefile.am +26 -0
  4. data/README +1119 -0
  5. data/README.mingw +8 -0
  6. data/Rakefile +33 -0
  7. data/bootstrap +9 -0
  8. data/configure.ac +52 -0
  9. data/doxygen.ac +314 -0
  10. data/doxygen.am +186 -0
  11. data/extconf.rb +41 -0
  12. data/post-autoconf.rb +22 -0
  13. data/post-automake.rb +28 -0
  14. data/rice/Address_Registration_Guard.hpp +7 -0
  15. data/rice/Address_Registration_Guard.ipp +34 -0
  16. data/rice/Address_Registration_Guard_defn.hpp +65 -0
  17. data/rice/Allocation_Strategies.hpp +37 -0
  18. data/rice/Arg.hpp +8 -0
  19. data/rice/Arg_impl.hpp +127 -0
  20. data/rice/Arg_operators.cpp +21 -0
  21. data/rice/Arg_operators.hpp +19 -0
  22. data/rice/Array.hpp +220 -0
  23. data/rice/Array.ipp +263 -0
  24. data/rice/Builtin_Object.hpp +8 -0
  25. data/rice/Builtin_Object.ipp +50 -0
  26. data/rice/Builtin_Object_defn.hpp +51 -0
  27. data/rice/Class.cpp +57 -0
  28. data/rice/Class.hpp +8 -0
  29. data/rice/Class.ipp +6 -0
  30. data/rice/Class_defn.hpp +83 -0
  31. data/rice/Constructor.hpp +367 -0
  32. data/rice/Critical_Guard.hpp +40 -0
  33. data/rice/Critical_Guard.ipp +26 -0
  34. data/rice/Data_Object.hpp +8 -0
  35. data/rice/Data_Object.ipp +133 -0
  36. data/rice/Data_Object_defn.hpp +132 -0
  37. data/rice/Data_Type.cpp +54 -0
  38. data/rice/Data_Type.hpp +8 -0
  39. data/rice/Data_Type.ipp +365 -0
  40. data/rice/Data_Type_defn.hpp +261 -0
  41. data/rice/Data_Type_fwd.hpp +12 -0
  42. data/rice/Director.cpp +13 -0
  43. data/rice/Director.hpp +39 -0
  44. data/rice/Enum.hpp +117 -0
  45. data/rice/Enum.ipp +246 -0
  46. data/rice/Exception.cpp +59 -0
  47. data/rice/Exception.hpp +9 -0
  48. data/rice/Exception_Base.hpp +8 -0
  49. data/rice/Exception_Base.ipp +13 -0
  50. data/rice/Exception_Base_defn.hpp +27 -0
  51. data/rice/Exception_defn.hpp +69 -0
  52. data/rice/Hash.hpp +210 -0
  53. data/rice/Hash.ipp +338 -0
  54. data/rice/Identifier.cpp +8 -0
  55. data/rice/Identifier.hpp +50 -0
  56. data/rice/Identifier.ipp +33 -0
  57. data/rice/Jump_Tag.hpp +24 -0
  58. data/rice/Makefile.am +129 -0
  59. data/rice/Module.cpp +84 -0
  60. data/rice/Module.hpp +8 -0
  61. data/rice/Module.ipp +6 -0
  62. data/rice/Module_defn.hpp +88 -0
  63. data/rice/Module_impl.hpp +281 -0
  64. data/rice/Module_impl.ipp +348 -0
  65. data/rice/Object.cpp +160 -0
  66. data/rice/Object.hpp +8 -0
  67. data/rice/Object.ipp +19 -0
  68. data/rice/Object_defn.hpp +191 -0
  69. data/rice/Require_Guard.hpp +21 -0
  70. data/rice/String.cpp +94 -0
  71. data/rice/String.hpp +89 -0
  72. data/rice/Struct.cpp +117 -0
  73. data/rice/Struct.hpp +162 -0
  74. data/rice/Struct.ipp +26 -0
  75. data/rice/Symbol.cpp +25 -0
  76. data/rice/Symbol.hpp +66 -0
  77. data/rice/Symbol.ipp +44 -0
  78. data/rice/VM.cpp +92 -0
  79. data/rice/VM.hpp +32 -0
  80. data/rice/config.hpp.in +40 -0
  81. data/rice/detail/Arguments.hpp +118 -0
  82. data/rice/detail/Auto_Function_Wrapper.hpp +829 -0
  83. data/rice/detail/Auto_Function_Wrapper.ipp +3391 -0
  84. data/rice/detail/Auto_Member_Function_Wrapper.hpp +828 -0
  85. data/rice/detail/Auto_Member_Function_Wrapper.ipp +2503 -0
  86. data/rice/detail/Caster.hpp +103 -0
  87. data/rice/detail/Exception_Handler.hpp +8 -0
  88. data/rice/detail/Exception_Handler.ipp +68 -0
  89. data/rice/detail/Exception_Handler_defn.hpp +96 -0
  90. data/rice/detail/Iterator.hpp +93 -0
  91. data/rice/detail/Not_Copyable.hpp +25 -0
  92. data/rice/detail/Wrapped_Function.hpp +33 -0
  93. data/rice/detail/cfp.hpp +24 -0
  94. data/rice/detail/cfp.ipp +51 -0
  95. data/rice/detail/check_ruby_type.cpp +27 -0
  96. data/rice/detail/check_ruby_type.hpp +23 -0
  97. data/rice/detail/creation_funcs.hpp +37 -0
  98. data/rice/detail/creation_funcs.ipp +36 -0
  99. data/rice/detail/default_allocation_func.hpp +23 -0
  100. data/rice/detail/default_allocation_func.ipp +11 -0
  101. data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
  102. data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
  103. data/rice/detail/demangle.cpp +56 -0
  104. data/rice/detail/demangle.hpp +19 -0
  105. data/rice/detail/env.hpp +19 -0
  106. data/rice/detail/from_ruby.hpp +43 -0
  107. data/rice/detail/from_ruby.ipp +60 -0
  108. data/rice/detail/method_data.cpp +159 -0
  109. data/rice/detail/method_data.hpp +21 -0
  110. data/rice/detail/mininode.cpp +1220 -0
  111. data/rice/detail/mininode.hpp +320 -0
  112. data/rice/detail/node.hpp +13 -0
  113. data/rice/detail/object_call.hpp +68 -0
  114. data/rice/detail/object_call.ipp +131 -0
  115. data/rice/detail/protect.cpp +29 -0
  116. data/rice/detail/protect.hpp +34 -0
  117. data/rice/detail/ruby.hpp +93 -0
  118. data/rice/detail/ruby_version_code.hpp.in +6 -0
  119. data/rice/detail/rubysig.hpp +19 -0
  120. data/rice/detail/st.hpp +60 -0
  121. data/rice/detail/to_ruby.hpp +22 -0
  122. data/rice/detail/to_ruby.ipp +36 -0
  123. data/rice/detail/traits.hpp +43 -0
  124. data/rice/detail/win32.hpp +16 -0
  125. data/rice/detail/wrap_function.hpp +341 -0
  126. data/rice/detail/wrap_function.ipp +514 -0
  127. data/rice/global_function.hpp +33 -0
  128. data/rice/global_function.ipp +22 -0
  129. data/rice/protect.hpp +91 -0
  130. data/rice/protect.ipp +1133 -0
  131. data/rice/ruby_mark.hpp +13 -0
  132. data/rice/ruby_try_catch.hpp +86 -0
  133. data/rice/rubypp.rb +97 -0
  134. data/rice/to_from_ruby.hpp +8 -0
  135. data/rice/to_from_ruby.ipp +297 -0
  136. data/rice/to_from_ruby_defn.hpp +71 -0
  137. data/ruby/Makefile.am +1 -0
  138. data/ruby/lib/Makefile.am +3 -0
  139. data/ruby/lib/mkmf-rice.rb.in +216 -0
  140. data/ruby/lib/version.rb +3 -0
  141. data/ruby.ac +136 -0
  142. data/sample/Makefile.am +47 -0
  143. data/sample/enum/extconf.rb +3 -0
  144. data/sample/enum/sample_enum.cpp +54 -0
  145. data/sample/enum/test.rb +8 -0
  146. data/sample/inheritance/animals.cpp +98 -0
  147. data/sample/inheritance/extconf.rb +3 -0
  148. data/sample/inheritance/test.rb +7 -0
  149. data/sample/map/extconf.rb +3 -0
  150. data/sample/map/map.cpp +81 -0
  151. data/sample/map/test.rb +7 -0
  152. data/test/Makefile.am +78 -0
  153. data/test/ext/Makefile.am +43 -0
  154. data/test/ext/t1/Foo.hpp +10 -0
  155. data/test/ext/t1/extconf.rb +2 -0
  156. data/test/ext/t1/t1.cpp +15 -0
  157. data/test/ext/t2/extconf.rb +2 -0
  158. data/test/ext/t2/t2.cpp +11 -0
  159. data/test/test_Address_Registration_Guard.cpp +43 -0
  160. data/test/test_Allocation_Strategies.cpp +77 -0
  161. data/test/test_Array.cpp +241 -0
  162. data/test/test_Builtin_Object.cpp +72 -0
  163. data/test/test_Class.cpp +498 -0
  164. data/test/test_Constructor.cpp +128 -0
  165. data/test/test_Critical_Guard.cpp +51 -0
  166. data/test/test_Data_Object.cpp +275 -0
  167. data/test/test_Data_Type.cpp +348 -0
  168. data/test/test_Director.cpp +301 -0
  169. data/test/test_Enum.cpp +195 -0
  170. data/test/test_Exception.cpp +46 -0
  171. data/test/test_Hash.cpp +195 -0
  172. data/test/test_Identifier.cpp +70 -0
  173. data/test/test_Jump_Tag.cpp +17 -0
  174. data/test/test_Memory_Management.cpp +50 -0
  175. data/test/test_Module.cpp +481 -0
  176. data/test/test_Object.cpp +148 -0
  177. data/test/test_String.cpp +94 -0
  178. data/test/test_Struct.cpp +192 -0
  179. data/test/test_Symbol.cpp +63 -0
  180. data/test/test_To_From_Ruby.cpp +263 -0
  181. data/test/test_VM.cpp +26 -0
  182. data/test/test_global_functions.cpp +114 -0
  183. data/test/test_rice.rb +43 -0
  184. data/test/unittest.cpp +136 -0
  185. data/test/unittest.hpp +292 -0
  186. metadata +276 -0
@@ -0,0 +1,192 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Struct.hpp"
3
+ #include "rice/Symbol.hpp"
4
+
5
+ using namespace Rice;
6
+
7
+ TESTSUITE(Struct);
8
+
9
+ namespace
10
+ {
11
+ Struct define_3d_point()
12
+ {
13
+ static Struct rb_cPoint = define_struct()
14
+ .define_member("x")
15
+ .define_member("y")
16
+ .define_member("z")
17
+ .initialize(rb_mKernel, "Point");
18
+ return rb_cPoint;
19
+ }
20
+ }
21
+
22
+ SETUP(Struct)
23
+ {
24
+ ruby_init();
25
+ }
26
+
27
+ TESTCASE(default_construct)
28
+ {
29
+ Struct s;
30
+ ASSERT_EQUAL(0, s.members().size());
31
+ // can't call rb_struct_s_members, because this isn't a struct yet
32
+ }
33
+
34
+ TESTCASE(initialize)
35
+ {
36
+ Struct s(define_3d_point());
37
+ Array members(rb_struct_s_members(s));
38
+ ASSERT_EQUAL(3, members.size());
39
+ ASSERT_EQUAL("x", Symbol(members[0]).c_str());
40
+ ASSERT_EQUAL("y", Symbol(members[1]).c_str());
41
+ ASSERT_EQUAL("z", Symbol(members[2]).c_str());
42
+ }
43
+
44
+ TESTCASE(copy_construct)
45
+ {
46
+ Struct s(define_3d_point());
47
+ Struct s2(s);
48
+ Array members(rb_struct_s_members(s2));
49
+ ASSERT_EQUAL(3, members.size());
50
+ ASSERT_EQUAL("x", Symbol(members[0]).c_str());
51
+ ASSERT_EQUAL("y", Symbol(members[1]).c_str());
52
+ ASSERT_EQUAL("z", Symbol(members[2]).c_str());
53
+ }
54
+
55
+ TESTCASE(offset_of)
56
+ {
57
+ Struct s(define_3d_point());
58
+ ASSERT_EQUAL(0, s.offset_of("x"));
59
+ ASSERT_EQUAL(1, s.offset_of("y"));
60
+ ASSERT_EQUAL(2, s.offset_of("z"));
61
+ }
62
+
63
+ TESTCASE(new_instance_no_args)
64
+ {
65
+ Struct s(define_3d_point());
66
+ Struct::Instance p(s.new_instance());
67
+ ASSERT_EQUAL(Rice::Nil, Object(rb_struct_getmember(p, rb_intern("x"))));
68
+ ASSERT_EQUAL(Rice::Nil, Object(rb_struct_getmember(p, rb_intern("y"))));
69
+ ASSERT_EQUAL(Rice::Nil, Object(rb_struct_getmember(p, rb_intern("z"))));
70
+ }
71
+
72
+ TESTCASE(new_instance_with_args)
73
+ {
74
+ int a[] = { 1, 2, 3 };
75
+ Array args(a);
76
+ Struct s(define_3d_point());
77
+ Struct::Instance p(s.new_instance(args));
78
+ ASSERT_EQUAL(to_ruby(1), Object(rb_struct_getmember(p, rb_intern("x"))));
79
+ ASSERT_EQUAL(to_ruby(2), Object(rb_struct_getmember(p, rb_intern("y"))));
80
+ ASSERT_EQUAL(to_ruby(3), Object(rb_struct_getmember(p, rb_intern("z"))));
81
+ }
82
+
83
+ TESTCASE(swap)
84
+ {
85
+ Struct s(define_3d_point());
86
+ Struct s2;
87
+ s2.swap(s);
88
+
89
+ try
90
+ {
91
+ Array members(rb_struct_s_members(s2));
92
+ ASSERT_EQUAL(3, members.size());
93
+ ASSERT_EQUAL("x", Symbol(members[0]).c_str());
94
+ ASSERT_EQUAL("y", Symbol(members[1]).c_str());
95
+ ASSERT_EQUAL("z", Symbol(members[2]).c_str());
96
+ }
97
+ catch(...)
98
+ {
99
+ s2.swap(s);
100
+ throw;
101
+ }
102
+
103
+ s2.swap(s);
104
+ }
105
+
106
+ TESTCASE(members)
107
+ {
108
+ Struct s(define_3d_point());
109
+ Array members(s.members());
110
+ ASSERT_EQUAL(3, members.size());
111
+ ASSERT_EQUAL("x", Symbol(members[0]).c_str());
112
+ ASSERT_EQUAL("y", Symbol(members[1]).c_str());
113
+ ASSERT_EQUAL("z", Symbol(members[2]).c_str());
114
+ }
115
+
116
+ TESTCASE(construct_instance)
117
+ {
118
+ int a[] = { 1, 2, 3 };
119
+ Array args(a);
120
+ Struct s(define_3d_point());
121
+ Struct::Instance p(s, args);
122
+ ASSERT_EQUAL(to_ruby(1), Object(rb_struct_getmember(p, rb_intern("x"))));
123
+ ASSERT_EQUAL(to_ruby(2), Object(rb_struct_getmember(p, rb_intern("y"))));
124
+ ASSERT_EQUAL(to_ruby(3), Object(rb_struct_getmember(p, rb_intern("z"))));
125
+ }
126
+
127
+ TESTCASE(wrap_instance)
128
+ {
129
+ Struct s(define_3d_point());
130
+ Object o = s.instance_eval("new(1, 2, 3)");
131
+ Struct::Instance p(s, o);
132
+ ASSERT_EQUAL(to_ruby(1), Object(rb_struct_getmember(p, rb_intern("x"))));
133
+ ASSERT_EQUAL(to_ruby(2), Object(rb_struct_getmember(p, rb_intern("y"))));
134
+ ASSERT_EQUAL(to_ruby(3), Object(rb_struct_getmember(p, rb_intern("z"))));
135
+ }
136
+
137
+ TESTCASE(instance_bracket_identifier)
138
+ {
139
+ int a[] = { 1, 2, 3 };
140
+ Array args(a);
141
+ Struct s(define_3d_point());
142
+ Struct::Instance p(s, args);
143
+ ASSERT_EQUAL(to_ruby(1), p[Identifier("x")]);
144
+ ASSERT_EQUAL(to_ruby(2), p[Identifier("y")]);
145
+ ASSERT_EQUAL(to_ruby(3), p[Identifier("z")]);
146
+ }
147
+
148
+ TESTCASE(instance_bracket_name)
149
+ {
150
+ int a[] = { 1, 2, 3 };
151
+ Array args(a);
152
+ Struct s(define_3d_point());
153
+ Struct::Instance p(s, args);
154
+ ASSERT_EQUAL(to_ruby(1), p["x"]);
155
+ ASSERT_EQUAL(to_ruby(2), p["y"]);
156
+ ASSERT_EQUAL(to_ruby(3), p["z"]);
157
+ }
158
+
159
+ TESTCASE(instance_bracket_index)
160
+ {
161
+ int a[] = { 1, 2, 3 };
162
+ Array args(a);
163
+ Struct s(define_3d_point());
164
+ Struct::Instance p(s, args);
165
+ ASSERT_EQUAL(to_ruby(1), p[0]);
166
+ ASSERT_EQUAL(to_ruby(2), p[1]);
167
+ ASSERT_EQUAL(to_ruby(3), p[2]);
168
+ }
169
+
170
+ TESTCASE(instance_swap)
171
+ {
172
+ Struct s(define_3d_point());
173
+
174
+ int a1[] = { 1, 2, 3 };
175
+ Array args1(a1);
176
+ Struct::Instance p1(s, args1);
177
+
178
+ int a2[] = { 4, 5, 6 };
179
+ Array args2(a2);
180
+ Struct::Instance p2(s, args2);
181
+
182
+ p1.swap(p2);
183
+
184
+ ASSERT_EQUAL(to_ruby(4), Object(rb_struct_getmember(p1, rb_intern("x"))));
185
+ ASSERT_EQUAL(to_ruby(5), Object(rb_struct_getmember(p1, rb_intern("y"))));
186
+ ASSERT_EQUAL(to_ruby(6), Object(rb_struct_getmember(p1, rb_intern("z"))));
187
+
188
+ ASSERT_EQUAL(to_ruby(1), Object(rb_struct_getmember(p2, rb_intern("x"))));
189
+ ASSERT_EQUAL(to_ruby(2), Object(rb_struct_getmember(p2, rb_intern("y"))));
190
+ ASSERT_EQUAL(to_ruby(3), Object(rb_struct_getmember(p2, rb_intern("z"))));
191
+ }
192
+
@@ -0,0 +1,63 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Symbol.hpp"
3
+ #include "rice/Identifier.hpp"
4
+
5
+ using namespace Rice;
6
+
7
+ TESTSUITE(Symbol);
8
+
9
+ SETUP(Symbol)
10
+ {
11
+ ruby_init();
12
+ }
13
+
14
+ TESTCASE(construct_from_symbol)
15
+ {
16
+ VALUE v = ID2SYM(rb_intern("foo"));
17
+ Symbol symbol(v);
18
+ ASSERT_EQUAL(v, symbol.value());
19
+ }
20
+
21
+ TESTCASE(construct_from_identifier)
22
+ {
23
+ Identifier identifier("FOO");
24
+ Symbol symbol(identifier);
25
+ ASSERT_EQUAL(ID2SYM(rb_intern("FOO")), symbol.value());
26
+ }
27
+
28
+ TESTCASE(construct_from_string)
29
+ {
30
+ Symbol symbol("Foo");
31
+ ASSERT_EQUAL(ID2SYM(rb_intern("Foo")), symbol.value());
32
+ }
33
+
34
+ TESTCASE(default_construct)
35
+ {
36
+ Symbol symbol;
37
+ ASSERT_EQUAL(ID2SYM(rb_intern("")), symbol.value());
38
+ }
39
+
40
+ TESTCASE(copy_construct)
41
+ {
42
+ Symbol symbol1("Foo");
43
+ Symbol symbol2(symbol1);
44
+ ASSERT_EQUAL(ID2SYM(rb_intern("Foo")), symbol2.value());
45
+ }
46
+
47
+ TESTCASE(c_str)
48
+ {
49
+ Symbol symbol("Foo");
50
+ ASSERT_EQUAL("Foo", symbol.c_str());
51
+ }
52
+
53
+ TESTCASE(str)
54
+ {
55
+ Symbol symbol("Foo");
56
+ ASSERT_EQUAL(std::string("Foo"), symbol.str());
57
+ }
58
+
59
+ TESTCASE(to_id)
60
+ {
61
+ Symbol symbol("Foo");
62
+ ASSERT_EQUAL(Identifier("Foo"), symbol.to_id());
63
+ }
@@ -0,0 +1,263 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/to_from_ruby.hpp"
3
+ #include "rice/String.hpp"
4
+ #include <limits>
5
+ #include <cmath>
6
+
7
+ using namespace Rice;
8
+
9
+ TESTSUITE(To_From_Ruby);
10
+
11
+ SETUP(To_From_Ruby)
12
+ {
13
+ ruby_init();
14
+ }
15
+
16
+ TESTCASE(object_to_ruby)
17
+ {
18
+ Object o(rb_str_new2("foo"));
19
+ ASSERT_EQUAL(o.value(), to_ruby(o).value());
20
+ }
21
+
22
+ TESTCASE(object_from_ruby)
23
+ {
24
+ Object o(rb_str_new2("foo"));
25
+ ASSERT_EQUAL(o.value(), from_ruby<Object>(o).value());
26
+ }
27
+
28
+ TESTCASE(int_to_ruby)
29
+ {
30
+ ASSERT_EQUAL(INT2NUM(0), to_ruby((int)0).value());
31
+ ASSERT_EQUAL(INT2NUM(-1), to_ruby((int)-1).value());
32
+ ASSERT_EQUAL(INT2NUM(1), to_ruby((int)1).value());
33
+ ASSERT_EQUAL(
34
+ Object(INT2NUM(std::numeric_limits<int>::min())),
35
+ to_ruby(std::numeric_limits<int>::min()));
36
+ ASSERT_EQUAL(
37
+ Object(INT2NUM(std::numeric_limits<int>::max())),
38
+ to_ruby(std::numeric_limits<int>::max()));
39
+ }
40
+
41
+ TESTCASE(int_from_ruby)
42
+ {
43
+ ASSERT_EQUAL(0, from_ruby<int>(INT2NUM(0)));
44
+ ASSERT_EQUAL(-1, from_ruby<int>(INT2NUM(-1)));
45
+ ASSERT_EQUAL(1, from_ruby<int>(INT2NUM(1)));
46
+ ASSERT_EQUAL(
47
+ std::numeric_limits<int>::min(),
48
+ from_ruby<int>(INT2NUM(std::numeric_limits<int>::min())));
49
+ ASSERT_EQUAL(
50
+ std::numeric_limits<int>::max(),
51
+ from_ruby<int>(INT2NUM(std::numeric_limits<int>::max())));
52
+ }
53
+
54
+ TESTCASE(long_to_ruby)
55
+ {
56
+ ASSERT_EQUAL(LONG2NUM(0), to_ruby((long)0).value());
57
+ ASSERT_EQUAL(LONG2NUM(-1), to_ruby((long)-1).value());
58
+ ASSERT_EQUAL(LONG2NUM(1), to_ruby((long)1).value());
59
+ ASSERT_EQUAL(
60
+ LONG2NUM(FIXNUM_MAX),
61
+ to_ruby(FIXNUM_MAX).value());
62
+ ASSERT_EQUAL(
63
+ LONG2NUM(FIXNUM_MIN),
64
+ to_ruby(FIXNUM_MIN).value());
65
+ ASSERT_EQUAL(
66
+ Object(LONG2NUM(std::numeric_limits<long>::min())),
67
+ to_ruby(std::numeric_limits<long>::min()));
68
+ ASSERT_EQUAL(
69
+ Object(LONG2NUM(std::numeric_limits<long>::max())),
70
+ to_ruby(std::numeric_limits<long>::max()));
71
+ }
72
+
73
+ TESTCASE(long_from_ruby)
74
+ {
75
+ ASSERT_EQUAL(0, from_ruby<long>(LONG2NUM(0)));
76
+ ASSERT_EQUAL(-1, from_ruby<long>(LONG2NUM(-1)));
77
+ ASSERT_EQUAL(1, from_ruby<long>(LONG2NUM(1)));
78
+ ASSERT_EQUAL(
79
+ FIXNUM_MIN,
80
+ from_ruby<long>(LONG2NUM(FIXNUM_MIN)));
81
+ ASSERT_EQUAL(
82
+ FIXNUM_MAX,
83
+ from_ruby<long>(LONG2NUM(FIXNUM_MAX)));
84
+ ASSERT_EQUAL(
85
+ std::numeric_limits<long>::min(),
86
+ from_ruby<long>(LONG2NUM(std::numeric_limits<long>::min())));
87
+ ASSERT_EQUAL(
88
+ std::numeric_limits<long>::max(),
89
+ from_ruby<long>(LONG2NUM(std::numeric_limits<long>::max())));
90
+ }
91
+
92
+ TESTCASE(unsigned_int_to_ruby)
93
+ {
94
+ ASSERT_EQUAL(UINT2NUM(0), to_ruby((unsigned int)0).value());
95
+ ASSERT_EQUAL(UINT2NUM(1), to_ruby((unsigned int)1).value());
96
+ ASSERT_EQUAL(
97
+ Object(UINT2NUM(std::numeric_limits<unsigned int>::min())),
98
+ to_ruby(std::numeric_limits<unsigned int>::min()));
99
+ ASSERT_EQUAL(
100
+ Object(UINT2NUM(std::numeric_limits<unsigned int>::max())),
101
+ to_ruby(std::numeric_limits<unsigned int>::max()));
102
+ }
103
+
104
+ TESTCASE(unsigned_int_from_ruby)
105
+ {
106
+ ASSERT_EQUAL(0u, from_ruby<unsigned int>(UINT2NUM(0)));
107
+ ASSERT_EQUAL(1u, from_ruby<unsigned int>(UINT2NUM(1)));
108
+ ASSERT_EQUAL(
109
+ std::numeric_limits<unsigned int>::min(),
110
+ from_ruby<unsigned int>(UINT2NUM(std::numeric_limits<unsigned int>::min())));
111
+ ASSERT_EQUAL(
112
+ std::numeric_limits<unsigned int>::max(),
113
+ from_ruby<unsigned int>(UINT2NUM(std::numeric_limits<unsigned int>::max())));
114
+ }
115
+
116
+ TESTCASE(unsigned_long_to_ruby)
117
+ {
118
+ ASSERT_EQUAL(ULONG2NUM(0), to_ruby((unsigned long)0).value());
119
+ ASSERT_EQUAL(ULONG2NUM(1), to_ruby((unsigned long)1).value());
120
+ ASSERT_EQUAL(
121
+ ULONG2NUM(FIXNUM_MAX),
122
+ to_ruby(FIXNUM_MAX).value());
123
+ ASSERT_EQUAL(
124
+ Object(ULONG2NUM(std::numeric_limits<unsigned long>::min())),
125
+ to_ruby(std::numeric_limits<unsigned long>::min()));
126
+ ASSERT_EQUAL(
127
+ Object(ULONG2NUM(std::numeric_limits<unsigned long>::max())),
128
+ to_ruby(std::numeric_limits<unsigned long>::max()));
129
+ }
130
+
131
+ TESTCASE(unsigned_long_from_ruby)
132
+ {
133
+ ASSERT_EQUAL(0u, from_ruby<unsigned long>(ULONG2NUM(0)));
134
+ ASSERT_EQUAL(1u, from_ruby<unsigned long>(ULONG2NUM(1)));
135
+ ASSERT_EQUAL(
136
+ static_cast<unsigned long>(FIXNUM_MIN),
137
+ from_ruby<unsigned long>(ULONG2NUM(FIXNUM_MIN)));
138
+ ASSERT_EQUAL(
139
+ std::numeric_limits<unsigned long>::min(),
140
+ from_ruby<unsigned long>(ULONG2NUM(std::numeric_limits<unsigned long>::min())));
141
+ ASSERT_EQUAL(
142
+ std::numeric_limits<unsigned long>::max(),
143
+ from_ruby<unsigned long>(ULONG2NUM(std::numeric_limits<unsigned long>::max())));
144
+ }
145
+
146
+ TESTCASE(bool_to_ruby)
147
+ {
148
+ ASSERT_EQUAL(Qfalse, to_ruby(false).value());
149
+ ASSERT_EQUAL(Qtrue, to_ruby(true).value());
150
+ }
151
+
152
+ TESTCASE(bool_from_ruby)
153
+ {
154
+ ASSERT_EQUAL(false, from_ruby<bool>(Object(Qfalse)));
155
+ ASSERT_EQUAL(true, from_ruby<bool>(Object(Qtrue)));
156
+ }
157
+
158
+ TESTCASE(float_to_ruby)
159
+ {
160
+ ASSERT_EQUAL(Object(rb_float_new(0.0f)), to_ruby(0.0f));
161
+ ASSERT_EQUAL(Object(rb_float_new(-1.0f)), to_ruby(-1.0f));
162
+ ASSERT_EQUAL(Object(rb_float_new(1.0f)), to_ruby(1.0f));
163
+ ASSERT_EQUAL(Object(rb_float_new(0.5f)), to_ruby(0.5f));
164
+ ASSERT_EQUAL(
165
+ Object(rb_float_new(std::numeric_limits<float>::min())),
166
+ to_ruby(std::numeric_limits<float>::min()));
167
+ ASSERT_EQUAL(
168
+ Object(rb_float_new(std::numeric_limits<float>::max())),
169
+ to_ruby(std::numeric_limits<float>::max()));
170
+ ASSERT(
171
+ to_ruby(std::numeric_limits<float>::quiet_NaN()).call("nan?"));
172
+ ASSERT(
173
+ to_ruby(std::numeric_limits<float>::signaling_NaN()).call("nan?"));
174
+ ASSERT_EQUAL(
175
+ Object(rb_float_new(std::numeric_limits<float>::epsilon())),
176
+ to_ruby(std::numeric_limits<float>::epsilon()));
177
+ }
178
+
179
+ TESTCASE(float_from_ruby)
180
+ {
181
+ ASSERT_EQUAL(0.0f, from_ruby<float>(rb_float_new(0.0f)));
182
+ ASSERT_EQUAL(-1.0f, from_ruby<float>(rb_float_new(-1.0f)));
183
+ ASSERT_EQUAL(1.0f, from_ruby<float>(rb_float_new(1.0f)));
184
+ ASSERT_EQUAL(
185
+ std::numeric_limits<float>::min(),
186
+ from_ruby<float>(rb_float_new(std::numeric_limits<float>::min())));
187
+ ASSERT_EQUAL(
188
+ std::numeric_limits<float>::max(),
189
+ from_ruby<float>(rb_float_new(std::numeric_limits<float>::max())));
190
+ ASSERT(
191
+ std::isnan(from_ruby<float>(rb_float_new(std::numeric_limits<float>::quiet_NaN()))));
192
+ ASSERT(
193
+ std::isnan(from_ruby<float>(rb_float_new(std::numeric_limits<float>::signaling_NaN()))));
194
+ ASSERT_EQUAL(
195
+ std::numeric_limits<float>::epsilon(),
196
+ from_ruby<float>(rb_float_new(std::numeric_limits<float>::epsilon())));
197
+ }
198
+
199
+ TESTCASE(double_to_ruby)
200
+ {
201
+ ASSERT_EQUAL(Object(rb_float_new(0.0f)), to_ruby(0.0f));
202
+ ASSERT_EQUAL(Object(rb_float_new(-1.0f)), to_ruby(-1.0f));
203
+ ASSERT_EQUAL(Object(rb_float_new(1.0f)), to_ruby(1.0f));
204
+ ASSERT_EQUAL(Object(rb_float_new(0.5f)), to_ruby(0.5f));
205
+ ASSERT_EQUAL(
206
+ Object(rb_float_new(std::numeric_limits<double>::min())),
207
+ to_ruby(std::numeric_limits<double>::min()));
208
+ ASSERT_EQUAL(
209
+ Object(rb_float_new(std::numeric_limits<double>::max())),
210
+ to_ruby(std::numeric_limits<double>::max()));
211
+ ASSERT(
212
+ to_ruby(std::numeric_limits<double>::quiet_NaN()).call("nan?"));
213
+ ASSERT(
214
+ to_ruby(std::numeric_limits<double>::signaling_NaN()).call("nan?"));
215
+ ASSERT_EQUAL(
216
+ Object(rb_float_new(std::numeric_limits<double>::epsilon())),
217
+ to_ruby(std::numeric_limits<double>::epsilon()));
218
+ }
219
+
220
+ TESTCASE(double_from_ruby)
221
+ {
222
+ ASSERT_EQUAL(0.0f, from_ruby<double>(rb_float_new(0.0f)));
223
+ ASSERT_EQUAL(-1.0f, from_ruby<double>(rb_float_new(-1.0f)));
224
+ ASSERT_EQUAL(1.0f, from_ruby<double>(rb_float_new(1.0f)));
225
+ ASSERT_EQUAL(
226
+ std::numeric_limits<double>::min(),
227
+ from_ruby<double>(rb_float_new(std::numeric_limits<double>::min())));
228
+ ASSERT_EQUAL(
229
+ std::numeric_limits<double>::max(),
230
+ from_ruby<double>(rb_float_new(std::numeric_limits<double>::max())));
231
+ ASSERT(
232
+ std::isnan(from_ruby<double>(rb_float_new(std::numeric_limits<double>::quiet_NaN()))));
233
+ ASSERT(
234
+ std::isnan(from_ruby<double>(rb_float_new(std::numeric_limits<double>::signaling_NaN()))));
235
+ ASSERT_EQUAL(
236
+ std::numeric_limits<double>::epsilon(),
237
+ from_ruby<double>(rb_float_new(std::numeric_limits<double>::epsilon())));
238
+ }
239
+
240
+ TESTCASE(char_const_ptr_to_ruby)
241
+ {
242
+ ASSERT_EQUAL(String(""), to_ruby((char const *)""));
243
+ ASSERT_EQUAL(String("foo"), to_ruby((char const *)"foo"));
244
+ }
245
+
246
+ TESTCASE(char_const_ptr_from_ruby)
247
+ {
248
+ ASSERT_EQUAL("", from_ruby<char const *>(rb_str_new2("")));
249
+ ASSERT_EQUAL("foo", from_ruby<char const *>(rb_str_new2("foo")));
250
+ }
251
+
252
+ TESTCASE(std_string_to_ruby)
253
+ {
254
+ ASSERT_EQUAL(String(""), to_ruby(std::string("")));
255
+ ASSERT_EQUAL(String("foo"), to_ruby(std::string("foo")));
256
+ }
257
+
258
+ TESTCASE(std_string_from_ruby)
259
+ {
260
+ ASSERT_EQUAL(std::string(""), from_ruby<std::string>(rb_str_new2("")));
261
+ ASSERT_EQUAL(std::string("foo"), from_ruby<std::string>(rb_str_new2("foo")));
262
+ }
263
+
data/test/test_VM.cpp ADDED
@@ -0,0 +1,26 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/VM.hpp"
3
+ #include "rice/Object.hpp"
4
+ #include <memory>
5
+
6
+ using namespace Rice;
7
+
8
+ std::auto_ptr<VM> vm;
9
+
10
+ TESTSUITE(VM);
11
+
12
+ SETUP(VM)
13
+ {
14
+ std::vector<const char *> args;
15
+ args.push_back("test_VM");
16
+ args.push_back("-e");
17
+ args.push_back("puts \"HELLO\"");
18
+ vm.reset(new VM(args));
19
+ }
20
+
21
+ TESTCASE(create_object)
22
+ {
23
+ Object o;
24
+ o.call("to_s");
25
+ }
26
+
@@ -0,0 +1,114 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/global_function.hpp"
3
+
4
+ using namespace Rice;
5
+
6
+ TESTSUITE(GlobalFunction);
7
+
8
+ SETUP(GlobalFunction)
9
+ {
10
+ ruby_init();
11
+ }
12
+
13
+ namespace {
14
+
15
+ bool method_to_wrap_called = false;
16
+ void method_to_wrap(Object self) {
17
+ method_to_wrap_called = true;
18
+ }
19
+
20
+ int method_with_args_arg0;
21
+
22
+ void method_with_args(Object self, int arg) {
23
+ method_with_args_arg0 = arg;
24
+ }
25
+
26
+ }
27
+
28
+ TESTCASE(exposes_global_functions)
29
+ {
30
+ define_global_function("method_to_wrap", &method_to_wrap);
31
+ Module m = Module(rb_mKernel);
32
+ m.call("method_to_wrap");
33
+
34
+ ASSERT(method_to_wrap_called);
35
+ }
36
+
37
+ TESTCASE(exposes_global_functions_with_arguments)
38
+ {
39
+ define_global_function("method_with_args", &method_with_args);
40
+ Module m = Module(rb_mKernel);
41
+ m.call("method_with_args", 10);
42
+
43
+ ASSERT_EQUAL(10, method_with_args_arg0);
44
+ }
45
+
46
+ namespace
47
+ {
48
+ int defaults_method_one_arg1;
49
+ int defaults_method_one_arg2;
50
+ bool defaults_method_one_arg3 = false;
51
+
52
+ void defaults_method_one(int arg1, int arg2 = 3, bool arg3 = true)
53
+ {
54
+ defaults_method_one_arg1 = arg1;
55
+ defaults_method_one_arg2 = arg2;
56
+ defaults_method_one_arg3 = arg3;
57
+ }
58
+
59
+ int defaults_returns(int arg1, int arg2 = 3)
60
+ {
61
+ return arg1 * arg2;
62
+ }
63
+ }
64
+
65
+ TESTCASE(default_arguments_for_define_global_function)
66
+ {
67
+ define_global_function("foo", &defaults_method_one, (Arg("arg1"), Arg("arg2") = (int)3, Arg("arg3") = (bool)true));
68
+ Module m(rb_mKernel);
69
+
70
+ m.call("foo", 2);
71
+
72
+ ASSERT_EQUAL(2, defaults_method_one_arg1);
73
+ ASSERT_EQUAL(3, defaults_method_one_arg2);
74
+ ASSERT(defaults_method_one_arg3);
75
+
76
+ m.call("foo", 11, 10);
77
+
78
+ ASSERT_EQUAL(11, defaults_method_one_arg1);
79
+ ASSERT_EQUAL(10, defaults_method_one_arg2);
80
+ ASSERT(defaults_method_one_arg3);
81
+
82
+ m.call("foo", 22, 33, false);
83
+
84
+ ASSERT_EQUAL(22, defaults_method_one_arg1);
85
+ ASSERT_EQUAL(33, defaults_method_one_arg2);
86
+ ASSERT(!defaults_method_one_arg3);
87
+ }
88
+
89
+ TESTCASE(default_arguments_for_define_global_function_and_returning)
90
+ {
91
+ define_global_function("foo_ret", &defaults_returns, (Arg("arg1"), Arg("arg2") = (int)3));
92
+ Module m(rb_mKernel);
93
+
94
+ Object o = m.call("foo_ret", 2);
95
+ ASSERT_EQUAL(INT2NUM(6), o.value());
96
+
97
+ o = m.call("foo_ret", 5, 10);
98
+ ASSERT_EQUAL(INT2NUM(50), o.value());
99
+ }
100
+
101
+ namespace {
102
+ int the_one_default_arg = 0;
103
+ void method_with_one_default_arg(int num = 4) {
104
+ the_one_default_arg = num;
105
+ }
106
+ }
107
+
108
+ TESTCASE(single_default_argument)
109
+ {
110
+ define_global_function("foo", &method_with_one_default_arg, (Arg("num") = (int)4));
111
+ Module m(rb_mKernel);
112
+ m.call("foo");
113
+ ASSERT_EQUAL(4, the_one_default_arg);
114
+ }
data/test/test_rice.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'test/unit'
2
+ require 'rbconfig'
3
+
4
+ class RiceTest < Test::Unit::TestCase
5
+ # TODO: probably a better way to find this out...
6
+ VERBOSE = ARGV.include?('-v')
7
+
8
+ EXEEXT = Config::CONFIG['EXEEXT']
9
+ RUBY = Config::CONFIG['RUBY_INSTALL_NAME']
10
+
11
+ def test_unittest
12
+ run_external_test("./unittest#{EXEEXT}")
13
+ end
14
+
15
+ def test_vm_unittest
16
+ run_external_test("./vm_unittest#{EXEEXT}")
17
+ end
18
+
19
+ def test_multiple_extensions
20
+ run_external_test("#{RUBY} test_multiple_extensions.rb")
21
+ end
22
+
23
+ def test_multiple_extensions_with_inheritance
24
+ run_external_test("#{RUBY} test_multiple_extensions_with_inheritance.rb")
25
+ end
26
+
27
+ def test_multiple_extensions_same_class
28
+ run_external_test("#{RUBY} test_multiple_extensions_same_class.rb")
29
+ end
30
+
31
+ def run_external_test(executable)
32
+ if VERBOSE then
33
+ system(executable)
34
+ else
35
+ result = `#{executable}`
36
+ if $? != 0 then
37
+ puts result
38
+ end
39
+ end
40
+ raise "Error: $?" if $? != 0
41
+ end
42
+ end
43
+