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,301 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Director.hpp"
3
+ #include "rice/Constructor.hpp"
4
+ #include "rice/Data_Type.hpp"
5
+
6
+ #include <vector>
7
+ #include <iostream>
8
+
9
+ using namespace std;
10
+ using namespace Rice;
11
+
12
+ TESTSUITE(Director);
13
+
14
+ namespace {
15
+ /**
16
+ * Abstract base class
17
+ */
18
+ class Worker {
19
+ public:
20
+ virtual ~Worker() { }
21
+
22
+ int getNumber() { return 12; }
23
+
24
+ virtual int doSomething(int num) { return num * 4; }
25
+
26
+ virtual int process(int num) = 0;
27
+ };
28
+
29
+ /**
30
+ * Subclass that implements pure virtual
31
+ */
32
+ class MultiplyWorker : public Worker {
33
+ public:
34
+ virtual ~MultiplyWorker() { }
35
+
36
+ virtual int process(int num) { return num * 2; }
37
+ };
38
+
39
+ /**
40
+ * Class to handle workers
41
+ */
42
+ class Handler {
43
+ std::vector<Worker*> mWorkers;
44
+
45
+ public:
46
+
47
+ void addWorker(Worker* worker) { mWorkers.push_back(worker); }
48
+
49
+ int processWorkers(int start) {
50
+ std::vector<Worker*>::iterator i = mWorkers.begin();
51
+ int results = start;
52
+
53
+ for(; i != mWorkers.end(); i++) {
54
+ results = (*i)->process(results);
55
+ }
56
+
57
+ return results;
58
+ }
59
+ };
60
+
61
+ /**
62
+ * Our Director wrapper of Worker
63
+ */
64
+ class WorkerDirector : public Worker, public Rice::Director {
65
+ public:
66
+ WorkerDirector(Object self) : Director(self) { }
67
+
68
+ virtual int process(int num) {
69
+ return from_ruby<int>( getSelf().call("process", num) );
70
+ }
71
+
72
+ int default_process(int num) {
73
+ raisePureVirtual();
74
+ }
75
+
76
+ virtual int doSomething(int num) {
77
+ return from_ruby<int>( getSelf().call("do_something", num) );
78
+ }
79
+
80
+ int default_doSomething(int num) {
81
+ return Worker::doSomething(num);
82
+ }
83
+ };
84
+ };
85
+
86
+ SETUP(Director)
87
+ {
88
+ ruby_init();
89
+ }
90
+
91
+ TESTCASE(exposes_worker_as_instantiatable_class)
92
+ {
93
+ define_class<Worker>("Worker")
94
+ .define_director<WorkerDirector>()
95
+ .define_constructor(Constructor<WorkerDirector, Object>())
96
+ .define_method("get_number", &Worker::getNumber);
97
+
98
+ Module m = define_module("Testing");
99
+ Object result = m.instance_eval("worker = Worker.new; worker.get_number");
100
+
101
+ ASSERT_EQUAL(12, from_ruby<int>(result.value()));
102
+ }
103
+
104
+ TESTCASE(can_call_virtual_methods_on_base_class)
105
+ {
106
+ define_class<Worker>("Worker")
107
+ .define_director<WorkerDirector>()
108
+ .define_constructor(Constructor<WorkerDirector, Object>())
109
+ .define_method("get_number", &Worker::getNumber)
110
+ .define_method("do_something", &WorkerDirector::default_doSomething);
111
+
112
+ Module m = define_module("Testing");
113
+
114
+ Object result = m.instance_eval("worker = Worker.new; worker.do_something(4)");
115
+
116
+ ASSERT_EQUAL(16, from_ruby<int>(result.value()));
117
+ }
118
+
119
+ TESTCASE(super_calls_pass_execution_up_the_inheritance_chain)
120
+ {
121
+ define_class<Worker>("Worker")
122
+ .define_director<WorkerDirector>()
123
+ .define_constructor(Constructor<WorkerDirector, Object>())
124
+ .define_method("do_something", &WorkerDirector::default_doSomething);
125
+
126
+ Module m = define_module("Testing");
127
+ m.instance_eval("class RubyWorker < Worker; def do_something(num); super * num; end; end");
128
+
129
+ Object result = m.instance_eval("worker = RubyWorker.new; worker.do_something(10)");
130
+
131
+ ASSERT_EQUAL(400, from_ruby<int>(result.value()));
132
+ }
133
+
134
+ TESTCASE(super_calls_on_pure_virtual_raise_error)
135
+ {
136
+ define_class<Worker>("Worker")
137
+ .define_director<WorkerDirector>()
138
+ .define_constructor(Constructor<WorkerDirector, Object>())
139
+ .define_method("process", &WorkerDirector::default_process);
140
+
141
+ Module m = define_module("Testing");
142
+ m.instance_eval("class RubyWorker < Worker; def process(num); super; end; end");
143
+
144
+ ASSERT_EXCEPTION_CHECK(
145
+ Exception,
146
+ m.instance_eval("worker = RubyWorker.new; worker.process(10)"),
147
+ ASSERT_EQUAL(
148
+ Object(rb_eNotImpError),
149
+ Object(CLASS_OF(ex.value()))
150
+ )
151
+ );
152
+ }
153
+
154
+ TESTCASE(polymorphic_calls_head_down_the_call_chain)
155
+ {
156
+ define_class<Handler>("Handler")
157
+ .define_constructor(Constructor<Handler>())
158
+ .define_method("add_worker", &Handler::addWorker)
159
+ .define_method("process_workers", &Handler::processWorkers);
160
+
161
+ define_class<Worker>("Worker")
162
+ .define_director<WorkerDirector>()
163
+ .define_constructor(Constructor<WorkerDirector, Object>())
164
+ .define_method("process", &WorkerDirector::default_process);
165
+
166
+ Module m = define_module("Testing");
167
+
168
+ m.instance_eval(
169
+ "class EchoWorker < Worker; def process(num); num + 2; end; end;"
170
+ "class DoubleWorker < Worker; def process(num); num * 2; end; end;"
171
+ "$handler = Handler.new;"
172
+ "$handler.add_worker(EchoWorker.new);"
173
+ "$handler.add_worker(DoubleWorker.new);"
174
+ );
175
+
176
+ Object result = m.instance_eval("$handler.process_workers(5)");
177
+
178
+ // Hit's EchoWorker, so 5 + 2, then passes that to DoubleWorker, so 7 * 2 = 14
179
+ ASSERT_EQUAL(14, from_ruby<int>(result.value()));
180
+ }
181
+
182
+ namespace {
183
+
184
+ class CallsSelf {
185
+ public:
186
+ int doIt(int in) {
187
+ return doItImpl(in);
188
+ }
189
+
190
+ virtual int doItImpl(int in) = 0;
191
+ };
192
+
193
+ class CallsSelfDirector : public CallsSelf, public Director {
194
+
195
+ public:
196
+ CallsSelfDirector(Object self) : Director(self) { }
197
+
198
+ virtual int doItImpl(int in) {
199
+ return from_ruby<int>( getSelf().call("do_it_impl", in) );
200
+ }
201
+
202
+ int default_doItImpl(int in) {
203
+ raisePureVirtual();
204
+ }
205
+ };
206
+
207
+ struct MyCallsSelf : CallsSelf {
208
+ MyCallsSelf() { }
209
+
210
+ int doItImpl(int in) { return in * 12; }
211
+ };
212
+
213
+ // Abstract type return types handled properly
214
+ CallsSelf* getCallsSelf() {
215
+ return new MyCallsSelf();
216
+ }
217
+
218
+ // Abstract type Argument types handled properly
219
+ int doItOnPointer(CallsSelf* obj, int in) {
220
+ return obj->doIt(in);
221
+ }
222
+
223
+ int doItOnReference(CallsSelf& obj, int in) {
224
+ return obj.doIt(in);
225
+ }
226
+
227
+ }
228
+
229
+ TESTCASE(mix_of_polymorphic_calls_and_inheritance_dont_cause_infinite_loops)
230
+ {
231
+ define_class<CallsSelf>("CallsSelf")
232
+ .define_director<CallsSelfDirector>()
233
+ .define_constructor(Constructor<CallsSelfDirector, Rice::Object>())
234
+ .define_method("do_it_impl", &CallsSelfDirector::default_doItImpl)
235
+ .define_method("do_it", &CallsSelf::doIt);
236
+
237
+ Module m = define_module("Testing");
238
+
239
+ Object result = m.instance_eval(
240
+ "class MySelf < CallsSelf; def do_it_impl(num); num * 10; end; end;"
241
+ "c = MySelf.new; c.do_it(10)"
242
+ );
243
+
244
+ ASSERT_EQUAL(100, from_ruby<int>(result.value()));
245
+ }
246
+
247
+ TESTCASE(director_class_super_classes_get_type_bound)
248
+ {
249
+ Module m = define_module("Testing");
250
+ m.define_module_function("get_calls_self", &getCallsSelf);
251
+
252
+ define_class<CallsSelf>("CallsSelf")
253
+ .define_director<CallsSelfDirector>()
254
+ .define_constructor(Constructor<CallsSelfDirector, Rice::Object>())
255
+ .define_method("do_it_impl", &CallsSelfDirector::default_doItImpl)
256
+ .define_method("do_it", &CallsSelf::doIt);
257
+
258
+ Object result = m.instance_eval("cs = Testing::get_calls_self; cs.do_it(3);");
259
+ ASSERT_EQUAL(36, from_ruby<int>(result.value()));
260
+ }
261
+
262
+ TESTCASE(director_allows_abstract_types_used_as_parameters_pointers)
263
+ {
264
+ Module m = define_module("Testing");
265
+ m.define_module_function("do_it_on_pointer", &doItOnPointer);
266
+
267
+ define_class<CallsSelf>("CallsSelf")
268
+ .define_director<CallsSelfDirector>()
269
+ .define_constructor(Constructor<CallsSelfDirector, Rice::Object>())
270
+ .define_method("do_it_impl", &CallsSelfDirector::default_doItImpl)
271
+ .define_method("do_it", &CallsSelf::doIt);
272
+
273
+ Object result = m.instance_eval(
274
+ "class MySelf < CallsSelf; def do_it_impl(num); num * 10; end; end;"
275
+ "c = MySelf.new;"
276
+ "Testing::do_it_on_pointer(c, 5)"
277
+ );
278
+
279
+ ASSERT_EQUAL(50, from_ruby<int>(result.value()));
280
+ }
281
+ /*
282
+ TESTCASE(director_allows_abstract_types_used_as_parameters_reference)
283
+ {
284
+ Module m = define_module("Testing");
285
+ m.define_module_function("do_it_on_ref", &doItOnReference);
286
+
287
+ define_class<CallsSelf>("CallsSelf")
288
+ .define_director<CallsSelfDirector>()
289
+ .define_constructor(Constructor<CallsSelfDirector, Rice::Object>())
290
+ .define_method("do_it_impl", &CallsSelfDirector::default_doItImpl)
291
+ .define_method("do_it", &CallsSelf::doIt);
292
+
293
+ Object result = m.instance_eval(
294
+ "class MySelf < CallsSelf; def do_it_impl(num); num * 10; end; end;"
295
+ "c = MySelf.new;"
296
+ "Testing::do_it_on_ref(c, 3)"
297
+ );
298
+
299
+ ASSERT_EQUAL(30, from_ruby<int>(result.value()));
300
+ }
301
+ */
@@ -0,0 +1,195 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Enum.hpp"
3
+ #include "rice/Array.hpp"
4
+ #include "rice/String.hpp"
5
+ #include "rice/Constructor.hpp"
6
+ #include <iostream>
7
+
8
+ using namespace Rice;
9
+
10
+ TESTSUITE(Enum);
11
+
12
+ namespace
13
+ {
14
+ enum Color { RED, BLACK, GREEN };
15
+
16
+ Enum<Color> define_color_enum()
17
+ {
18
+ static Enum<Color> colors = define_enum<Color>("Color")
19
+ .define_value("RED", RED)
20
+ .define_value("BLACK", BLACK)
21
+ .define_value("GREEN", GREEN);
22
+ return colors;
23
+ }
24
+ }
25
+
26
+ SETUP(Enum)
27
+ {
28
+ ruby_init();
29
+ }
30
+
31
+ TESTCASE(copy_construct)
32
+ {
33
+ Enum<Color> rb_cColor(define_color_enum());
34
+ ASSERT_EQUAL(define_color_enum().value(), rb_cColor.value());
35
+ }
36
+
37
+ TESTCASE(assignment)
38
+ {
39
+ Enum<Color> rb_cColor;
40
+ rb_cColor = define_color_enum();
41
+ ASSERT_EQUAL(define_color_enum().value(), rb_cColor.value());
42
+ }
43
+
44
+ TESTCASE(each)
45
+ {
46
+ Enum<Color> rb_cColor = define_color_enum();
47
+ Array a = protect(rb_eval_string, "a = []; Color.each { |x| a << x }; a");
48
+ ASSERT_EQUAL(3u, a.size());
49
+ ASSERT_EQUAL(RED, from_ruby<Color>(a[0]));
50
+ ASSERT_EQUAL(BLACK, from_ruby<Color>(a[1]));
51
+ ASSERT_EQUAL(GREEN, from_ruby<Color>(a[2]));
52
+ }
53
+
54
+ TESTCASE(to_s)
55
+ {
56
+ Enum<Color> rb_cColor = define_color_enum();
57
+ ASSERT_EQUAL(String("RED"), String(protect(rb_eval_string, "Color::RED.to_s")));
58
+ ASSERT_EQUAL(String("BLACK"), String(protect(rb_eval_string, "Color::BLACK.to_s")));
59
+ ASSERT_EQUAL(String("GREEN"), String(protect(rb_eval_string, "Color::GREEN.to_s")));
60
+ }
61
+
62
+ TESTCASE(to_i)
63
+ {
64
+ Enum<Color> rb_cColor = define_color_enum();
65
+ ASSERT_EQUAL(to_ruby(int(RED)), Object(protect(rb_eval_string, "Color::RED.to_i")));
66
+ ASSERT_EQUAL(to_ruby(int(BLACK)), Object(protect(rb_eval_string, "Color::BLACK.to_i")));
67
+ ASSERT_EQUAL(to_ruby(int(GREEN)), Object(protect(rb_eval_string, "Color::GREEN.to_i")));
68
+ }
69
+
70
+ TESTCASE(inspect)
71
+ {
72
+ Enum<Color> rb_cColor = define_color_enum();
73
+ ASSERT_EQUAL(String("#<Color::RED>"), String(protect(rb_eval_string, "Color::RED.inspect")));
74
+ ASSERT_EQUAL(String("#<Color::BLACK>"), String(protect(rb_eval_string, "Color::BLACK.inspect")));
75
+ ASSERT_EQUAL(String("#<Color::GREEN>"), String(protect(rb_eval_string, "Color::GREEN.inspect")));
76
+ }
77
+
78
+ TESTCASE(compare)
79
+ {
80
+ Enum<Color> rb_cColor = define_color_enum();
81
+ ASSERT_EQUAL(to_ruby(-1), Object(protect(rb_eval_string, "Color::RED <=> Color::BLACK")));
82
+ ASSERT_EQUAL(to_ruby(1), Object(protect(rb_eval_string, "Color::GREEN <=> Color::RED")));
83
+ ASSERT_EQUAL(to_ruby(0), Object(protect(rb_eval_string, "Color::BLACK <=> Color::BLACK")));
84
+ }
85
+
86
+ TESTCASE(eql)
87
+ {
88
+ Enum<Color> rb_cColor = define_color_enum();
89
+ ASSERT_EQUAL(to_ruby(false), Object(protect(rb_eval_string, "Color::RED == Color::BLACK")));
90
+ ASSERT_EQUAL(to_ruby(true), Object(protect(rb_eval_string, "Color::GREEN == Color::GREEN")));
91
+ }
92
+
93
+ TESTCASE(invalid_to_s)
94
+ {
95
+ Enum<Color> rb_cColor = define_color_enum();
96
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
97
+ ASSERT_EQUAL(String("INVALID(42)"), invalid.to_s());
98
+ }
99
+
100
+ TESTCASE(invalid_to_i)
101
+ {
102
+ Enum<Color> rb_cColor = define_color_enum();
103
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
104
+ ASSERT_EQUAL(to_ruby(42), invalid.call("to_i"));
105
+ }
106
+
107
+ TESTCASE(invalid_inspect)
108
+ {
109
+ Enum<Color> rb_cColor = define_color_enum();
110
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
111
+ ASSERT_EQUAL(String("#<Color::INVALID(42)>"), invalid.inspect());
112
+ }
113
+
114
+ TESTCASE(invalid_compare)
115
+ {
116
+ Enum<Color> rb_cColor = define_color_enum();
117
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
118
+ Data_Object<Color> red(new Color(RED));
119
+ ASSERT_EQUAL(1, invalid.compare(red));
120
+ ASSERT_EQUAL(-1, red.compare(invalid));
121
+ ASSERT_EQUAL(0, invalid.compare(invalid));
122
+ }
123
+
124
+ TESTCASE(invalid_eql)
125
+ {
126
+ Enum<Color> rb_cColor = define_color_enum();
127
+ Data_Object<Color> invalid(new Color(static_cast<Color>(42)));
128
+ Data_Object<Color> red(new Color(RED));
129
+ ASSERT_EQUAL(false, invalid == red);
130
+ ASSERT_EQUAL(false, red == invalid);
131
+ ASSERT_EQUAL(true, invalid == invalid);
132
+ }
133
+
134
+ TESTCASE(different_objects_compare)
135
+ {
136
+ Enum<Color> rb_cColor = define_color_enum();
137
+ Data_Object<Color> red1(new Color(RED));
138
+ Data_Object<Color> red2(new Color(RED));
139
+ ASSERT_EQUAL(0, red1.compare(red2));
140
+ }
141
+
142
+ TESTCASE(different_objects_eql)
143
+ {
144
+ Enum<Color> rb_cColor = define_color_enum();
145
+ Data_Object<Color> red1(new Color(RED));
146
+ Data_Object<Color> red2(new Color(RED));
147
+ ASSERT_EQUAL(true, red1 == red2);
148
+ }
149
+
150
+ /*
151
+ TESTCASE(hash)
152
+ {
153
+ Enum<Color> rb_cColor = define_color_enum();
154
+ Data_Object<Color> red(new Color(RED));
155
+ ASSERT_EQUAL(to_ruby(int(RED)), red.call("hash"));
156
+ }
157
+ */
158
+
159
+ TESTCASE(from_int)
160
+ {
161
+ Enum<Color> rb_cColor = define_color_enum();
162
+ Data_Object<Color> color(rb_cColor.call("from_int", int(RED)));
163
+ ASSERT_EQUAL(RED, *color);
164
+ }
165
+
166
+ namespace
167
+ {
168
+ class Inner
169
+ {
170
+ public:
171
+ enum Props
172
+ {
173
+ VALUE1,
174
+ VALUE2,
175
+ VALUE3
176
+ };
177
+ };
178
+ }
179
+
180
+ TESTCASE(nested_enums)
181
+ {
182
+ {
183
+ Data_Type<Inner> inner = define_class<Inner>("Inner");
184
+ define_enum<Inner::Props>("Props", inner)
185
+ .define_value("VALUE1", Inner::VALUE1)
186
+ .define_value("VALUE2", Inner::VALUE2)
187
+ .define_value("VALUE3", Inner::VALUE3);
188
+ inner.define_constructor(Constructor<Inner>());
189
+ }
190
+
191
+ ASSERT_EQUAL(to_ruby(int(0)), Object(protect(rb_eval_string, "Inner::Props::VALUE1.to_i")));
192
+ ASSERT_EQUAL(to_ruby(int(1)), Object(protect(rb_eval_string, "Inner::Props::VALUE2.to_i")));
193
+ ASSERT_EQUAL(to_ruby(int(2)), Object(protect(rb_eval_string, "Inner::Props::VALUE3.to_i")));
194
+ }
195
+
@@ -0,0 +1,46 @@
1
+ #include "unittest.hpp"
2
+ #include "rice/Exception.hpp"
3
+ #include "rice/String.hpp"
4
+
5
+ using namespace Rice;
6
+
7
+ TESTSUITE(Exception);
8
+
9
+ SETUP(Exception)
10
+ {
11
+ ruby_init();
12
+ }
13
+
14
+ TESTCASE(construct_from_exception_object)
15
+ {
16
+ VALUE v = protect(rb_exc_new2, rb_eRuntimeError, "foo");
17
+ Exception ex(v);
18
+ ASSERT_EQUAL(ex.value(), v);
19
+ }
20
+
21
+ TESTCASE(copy_construct)
22
+ {
23
+ VALUE v = protect(rb_exc_new2, rb_eRuntimeError, "foo");
24
+ Exception ex1(v);
25
+ Exception ex2(v);
26
+ ASSERT_EQUAL(ex2.value(), v);
27
+ }
28
+
29
+ TESTCASE(construct_from_format_string)
30
+ {
31
+ Exception ex(rb_eRuntimeError, "%s", "foo");
32
+ ASSERT_EQUAL(ex.class_of(), Object(rb_eRuntimeError));
33
+ }
34
+
35
+ TESTCASE(message)
36
+ {
37
+ Exception ex(rb_eRuntimeError, "%s", "foo");
38
+ ASSERT_EQUAL(String("foo"), ex.message());
39
+ }
40
+
41
+ TESTCASE(what)
42
+ {
43
+ Exception ex(rb_eRuntimeError, "%s", "foo");
44
+ ASSERT_EQUAL("foo", ex.what());
45
+ }
46
+