rice 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/Doxyfile +1 -1
  2. data/Makefile.in +3 -2
  3. data/README +247 -16
  4. data/aclocal.m4 +62 -51
  5. data/configure +1585 -1456
  6. data/extconf.rb +9 -1
  7. data/rice/Arg.hpp +8 -0
  8. data/rice/Arg_impl.hpp +124 -0
  9. data/rice/Arg_operators.cpp +21 -0
  10. data/rice/Arg_operators.hpp +19 -0
  11. data/rice/Constructor.hpp +150 -0
  12. data/rice/Data_Type.ipp +51 -6
  13. data/rice/Director.cpp +19 -0
  14. data/rice/Director.hpp +47 -0
  15. data/rice/Enum.hpp +2 -3
  16. data/rice/Enum.ipp +1 -1
  17. data/rice/Hash.hpp +1 -1
  18. data/rice/Makefile.am +7 -0
  19. data/rice/Makefile.in +18 -7
  20. data/rice/Module_impl.hpp +36 -3
  21. data/rice/Module_impl.ipp +56 -7
  22. data/rice/VM.cpp +2 -2
  23. data/rice/config.hpp +1 -1
  24. data/rice/detail/Arguments.hpp +118 -0
  25. data/rice/detail/Auto_Function_Wrapper.hpp +206 -96
  26. data/rice/detail/Auto_Function_Wrapper.ipp +1687 -144
  27. data/rice/detail/Auto_Member_Function_Wrapper.hpp +234 -123
  28. data/rice/detail/Auto_Member_Function_Wrapper.ipp +1133 -306
  29. data/rice/detail/Caster.hpp +3 -1
  30. data/rice/detail/creation_funcs.hpp +0 -8
  31. data/rice/detail/creation_funcs.ipp +1 -27
  32. data/rice/detail/define_method_and_auto_wrap.hpp +3 -1
  33. data/rice/detail/define_method_and_auto_wrap.ipp +4 -3
  34. data/rice/detail/object_call.ipp +1 -1
  35. data/rice/detail/ruby.hpp +1 -33
  36. data/rice/detail/wrap_function.hpp +103 -48
  37. data/rice/detail/wrap_function.ipp +154 -96
  38. data/rice/generate_code.rb +520 -55
  39. data/rice/global_function.hpp +12 -1
  40. data/rice/global_function.ipp +14 -2
  41. data/ruby/Makefile.in +5 -4
  42. data/ruby/lib/Makefile.in +4 -3
  43. data/ruby/lib/version.rb +1 -1
  44. data/sample/Makefile.in +4 -3
  45. data/test/Makefile.am +2 -0
  46. data/test/Makefile.in +32 -13
  47. data/test/test_Class.cpp +36 -14
  48. data/test/test_Constructor.cpp +176 -1
  49. data/test/test_Data_Type.cpp +121 -0
  50. data/test/test_Director.cpp +225 -0
  51. data/test/test_Enum.cpp +33 -0
  52. data/test/test_Module.cpp +175 -0
  53. data/test/test_global_functions.cpp +70 -1
  54. metadata +27 -7
@@ -1,6 +1,8 @@
1
1
  #ifndef Rice__global_function__hpp_
2
2
  #define Rice__global_function__hpp_
3
3
 
4
+ #include "Arg.hpp"
5
+
4
6
  namespace Rice
5
7
  {
6
8
 
@@ -13,7 +15,16 @@ namespace Rice
13
15
  template<typename Func_T>
14
16
  void define_global_function(
15
17
  char const * name,
16
- Func_T func);
18
+ Func_T func,
19
+ Arguments* arguments = 0);
20
+
21
+ // FIXME: See Module::define_method with Arg
22
+ template<typename Func_T>
23
+ void define_global_function(
24
+ char const * name,
25
+ Func_T func,
26
+ Arg const& arg);
27
+
17
28
 
18
29
  } // Rice
19
30
 
@@ -3,8 +3,20 @@
3
3
  template<typename Func_T>
4
4
  void Rice::define_global_function(
5
5
  char const * name,
6
- Func_T func)
6
+ Func_T func,
7
+ Arguments* arguments)
7
8
  {
8
- Module(rb_mKernel).define_module_function(name, func);
9
+ Module(rb_mKernel).define_module_function(name, func, arguments);
10
+ }
11
+
12
+ template<typename Func_T>
13
+ void Rice::define_global_function(
14
+ char const * name,
15
+ Func_T func,
16
+ Arg const& arg)
17
+ {
18
+ Arguments* args = new Arguments();
19
+ args->add(arg);
20
+ define_global_function(name, func, args);
9
21
  }
10
22
 
@@ -1,4 +1,4 @@
1
- # Makefile.in generated by automake 1.10.1 from Makefile.am.
1
+ # Makefile.in generated by automake 1.10.2 from Makefile.am.
2
2
  # @configure_input@
3
3
 
4
4
  # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -183,6 +183,7 @@ sharedstatedir = @sharedstatedir@
183
183
  srcdir = @srcdir@
184
184
  sysconfdir = @sysconfdir@
185
185
  target_alias = @target_alias@
186
+ top_build_prefix = @top_build_prefix@
186
187
  top_builddir = @top_builddir@
187
188
  top_srcdir = @top_srcdir@
188
189
  SUBDIRS = lib
@@ -193,8 +194,8 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
193
194
  @for dep in $?; do \
194
195
  case '$(am__configure_deps)' in \
195
196
  *$$dep*) \
196
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
197
- && exit 0; \
197
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
198
+ && { if test -f $@; then exit 0; else break; fi; }; \
198
199
  exit 1;; \
199
200
  esac; \
200
201
  done; \
@@ -294,7 +295,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
294
295
  unique=`for i in $$list; do \
295
296
  if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
296
297
  done | \
297
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
298
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
298
299
  END { if (nonempty) { for (i in files) print i; }; }'`; \
299
300
  mkid -fID $$unique
300
301
  tags: TAGS
@@ -1,4 +1,4 @@
1
- # Makefile.in generated by automake 1.10.1 from Makefile.am.
1
+ # Makefile.in generated by automake 1.10.2 from Makefile.am.
2
2
  # @configure_input@
3
3
 
4
4
  # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -182,6 +182,7 @@ sharedstatedir = @sharedstatedir@
182
182
  srcdir = @srcdir@
183
183
  sysconfdir = @sysconfdir@
184
184
  target_alias = @target_alias@
185
+ top_build_prefix = @top_build_prefix@
185
186
  top_builddir = @top_builddir@
186
187
  top_srcdir = @top_srcdir@
187
188
  rubydir = @RUBY_SITELIBDIR@
@@ -193,8 +194,8 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
193
194
  @for dep in $?; do \
194
195
  case '$(am__configure_deps)' in \
195
196
  *$$dep*) \
196
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
197
- && exit 0; \
197
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
198
+ && { if test -f $@; then exit 0; else break; fi; }; \
198
199
  exit 1;; \
199
200
  esac; \
200
201
  done; \
@@ -1,3 +1,3 @@
1
1
  module Rice
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,4 +1,4 @@
1
- # Makefile.in generated by automake 1.10.1 from Makefile.am.
1
+ # Makefile.in generated by automake 1.10.2 from Makefile.am.
2
2
  # @configure_input@
3
3
 
4
4
  # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -171,6 +171,7 @@ sharedstatedir = @sharedstatedir@
171
171
  srcdir = @srcdir@
172
172
  sysconfdir = @sysconfdir@
173
173
  target_alias = @target_alias@
174
+ top_build_prefix = @top_build_prefix@
174
175
  top_builddir = @top_builddir@
175
176
  top_srcdir = @top_srcdir@
176
177
  RUBY_EXTCONF_OPTIONS = -I@RICE_ROOT@/ruby/lib
@@ -193,8 +194,8 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
193
194
  @for dep in $?; do \
194
195
  case '$(am__configure_deps)' in \
195
196
  *$$dep*) \
196
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
197
- && exit 0; \
197
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
198
+ && { if test -f $@; then exit 0; else break; fi; }; \
198
199
  exit 1;; \
199
200
  esac; \
200
201
  done; \
@@ -12,6 +12,8 @@ unittest_SOURCES = \
12
12
  test_Constructor.cpp \
13
13
  test_Critical_Guard.cpp \
14
14
  test_Data_Object.cpp \
15
+ test_Data_Type.cpp \
16
+ test_Director.cpp \
15
17
  test_Enum.cpp \
16
18
  test_Exception.cpp \
17
19
  test_Hash.cpp \
@@ -1,4 +1,4 @@
1
- # Makefile.in generated by automake 1.10.1 from Makefile.am.
1
+ # Makefile.in generated by automake 1.10.2 from Makefile.am.
2
2
  # @configure_input@
3
3
 
4
4
  # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -50,7 +50,8 @@ am_unittest_OBJECTS = unittest.$(OBJEXT) \
50
50
  test_Allocation_Strategies.$(OBJEXT) test_Array.$(OBJEXT) \
51
51
  test_Builtin_Object.$(OBJEXT) test_Class.$(OBJEXT) \
52
52
  test_Constructor.$(OBJEXT) test_Critical_Guard.$(OBJEXT) \
53
- test_Data_Object.$(OBJEXT) test_Enum.$(OBJEXT) \
53
+ test_Data_Object.$(OBJEXT) test_Data_Type.$(OBJEXT) \
54
+ test_Director.$(OBJEXT) test_Enum.$(OBJEXT) \
54
55
  test_Exception.$(OBJEXT) test_Hash.$(OBJEXT) \
55
56
  test_Identifier.$(OBJEXT) test_Jump_Tag.$(OBJEXT) \
56
57
  test_Module.$(OBJEXT) test_Object.$(OBJEXT) \
@@ -206,6 +207,7 @@ sharedstatedir = @sharedstatedir@
206
207
  srcdir = @srcdir@
207
208
  sysconfdir = @sysconfdir@
208
209
  target_alias = @target_alias@
210
+ top_build_prefix = @top_build_prefix@
209
211
  top_builddir = @top_builddir@
210
212
  top_srcdir = @top_srcdir@
211
213
  unittest_SOURCES = \
@@ -218,6 +220,8 @@ unittest_SOURCES = \
218
220
  test_Constructor.cpp \
219
221
  test_Critical_Guard.cpp \
220
222
  test_Data_Object.cpp \
223
+ test_Data_Type.cpp \
224
+ test_Director.cpp \
221
225
  test_Enum.cpp \
222
226
  test_Exception.cpp \
223
227
  test_Hash.cpp \
@@ -254,8 +258,8 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
254
258
  @for dep in $?; do \
255
259
  case '$(am__configure_deps)' in \
256
260
  *$$dep*) \
257
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
258
- && exit 0; \
261
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
262
+ && { if test -f $@; then exit 0; else break; fi; }; \
259
263
  exit 1;; \
260
264
  esac; \
261
265
  done; \
@@ -303,6 +307,8 @@ distclean-compile:
303
307
  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_Constructor.Po@am__quote@
304
308
  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_Critical_Guard.Po@am__quote@
305
309
  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_Data_Object.Po@am__quote@
310
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_Data_Type.Po@am__quote@
311
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_Director.Po@am__quote@
306
312
  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_Enum.Po@am__quote@
307
313
  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_Exception.Po@am__quote@
308
314
  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_Hash.Po@am__quote@
@@ -337,7 +343,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
337
343
  unique=`for i in $$list; do \
338
344
  if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
339
345
  done | \
340
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
346
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
341
347
  END { if (nonempty) { for (i in files) print i; }; }'`; \
342
348
  mkid -fID $$unique
343
349
  tags: TAGS
@@ -380,7 +386,7 @@ distclean-tags:
380
386
  -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
381
387
 
382
388
  check-TESTS: $(TESTS)
383
- @failed=0; all=0; xfail=0; xpass=0; skip=0; ws='[ ]'; \
389
+ @failed=0; all=0; xfail=0; xpass=0; skip=0; \
384
390
  srcdir=$(srcdir); export srcdir; \
385
391
  list=' $(TESTS) '; \
386
392
  if test -n "$$list"; then \
@@ -391,7 +397,7 @@ check-TESTS: $(TESTS)
391
397
  if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
392
398
  all=`expr $$all + 1`; \
393
399
  case " $(XFAIL_TESTS) " in \
394
- *$$ws$$tst$$ws*) \
400
+ *[\ \ ]$$tst[\ \ ]*) \
395
401
  xpass=`expr $$xpass + 1`; \
396
402
  failed=`expr $$failed + 1`; \
397
403
  echo "XPASS: $$tst"; \
@@ -403,7 +409,7 @@ check-TESTS: $(TESTS)
403
409
  elif test $$? -ne 77; then \
404
410
  all=`expr $$all + 1`; \
405
411
  case " $(XFAIL_TESTS) " in \
406
- *$$ws$$tst$$ws*) \
412
+ *[\ \ ]$$tst[\ \ ]*) \
407
413
  xfail=`expr $$xfail + 1`; \
408
414
  echo "XFAIL: $$tst"; \
409
415
  ;; \
@@ -417,23 +423,36 @@ check-TESTS: $(TESTS)
417
423
  echo "SKIP: $$tst"; \
418
424
  fi; \
419
425
  done; \
426
+ if test "$$all" -eq 1; then \
427
+ tests="test"; \
428
+ All=""; \
429
+ else \
430
+ tests="tests"; \
431
+ All="All "; \
432
+ fi; \
420
433
  if test "$$failed" -eq 0; then \
421
434
  if test "$$xfail" -eq 0; then \
422
- banner="All $$all tests passed"; \
435
+ banner="$$All$$all $$tests passed"; \
423
436
  else \
424
- banner="All $$all tests behaved as expected ($$xfail expected failures)"; \
437
+ if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
438
+ banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
425
439
  fi; \
426
440
  else \
427
441
  if test "$$xpass" -eq 0; then \
428
- banner="$$failed of $$all tests failed"; \
442
+ banner="$$failed of $$all $$tests failed"; \
429
443
  else \
430
- banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \
444
+ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
445
+ banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
431
446
  fi; \
432
447
  fi; \
433
448
  dashes="$$banner"; \
434
449
  skipped=""; \
435
450
  if test "$$skip" -ne 0; then \
436
- skipped="($$skip tests were not run)"; \
451
+ if test "$$skip" -eq 1; then \
452
+ skipped="($$skip test was not run)"; \
453
+ else \
454
+ skipped="($$skip tests were not run)"; \
455
+ fi; \
437
456
  test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
438
457
  dashes="$$skipped"; \
439
458
  fi; \
@@ -9,6 +9,7 @@
9
9
  #include <iostream>
10
10
 
11
11
  using namespace Rice;
12
+ using namespace std;
12
13
 
13
14
  TESTSUITE(Class);
14
15
 
@@ -87,7 +88,7 @@ namespace
87
88
 
88
89
  bool define_method_simple_ok;
89
90
 
90
- void define_method_simple_helper(Object o)
91
+ void define_method_simple_helper()
91
92
  {
92
93
  define_method_simple_ok = true;
93
94
  }
@@ -130,19 +131,27 @@ TESTCASE(define_module_function_simple)
130
131
  namespace
131
132
  {
132
133
 
133
- int define_method_int_result;
134
+ int define_method_int_result;
134
135
 
135
- void define_method_int_helper(Object o, int i)
136
- {
137
- define_method_int_result = i;
138
- }
136
+ class IntHelper {
137
+ public:
138
+ IntHelper() { }
139
+
140
+ void define_method_int_helper(int i)
141
+ {
142
+ define_method_int_result = i;
143
+ }
144
+ };
139
145
 
140
146
  } // namespace
141
147
 
142
148
  TESTCASE(define_method_int)
143
149
  {
144
- Class c(anonymous_class());
145
- c.define_method("foo", &define_method_int_helper);
150
+ Class c =
151
+ define_class<IntHelper>("IntHelper")
152
+ .define_constructor(Constructor<IntHelper>())
153
+ .define_method("foo", &IntHelper::define_method_int_helper);
154
+
146
155
  Object o = c.call("new");
147
156
  define_method_int_result = 0;
148
157
  o.call("foo", 42);
@@ -151,9 +160,13 @@ TESTCASE(define_method_int)
151
160
 
152
161
  TESTCASE(define_method_int_passed_two_args)
153
162
  {
154
- Class c(anonymous_class());
155
- c.define_method("foo", &define_method_int_helper);
163
+ Class c =
164
+ define_class<IntHelper>("IntHelper")
165
+ .define_constructor(Constructor<IntHelper>())
166
+ .define_method("foo", &IntHelper::define_method_int_helper);
167
+
156
168
  Object o = c.call("new");
169
+
157
170
  ASSERT_EXCEPTION_CHECK(
158
171
  Exception,
159
172
  o.call("foo", 1, 2),
@@ -166,9 +179,13 @@ TESTCASE(define_method_int_passed_two_args)
166
179
 
167
180
  TESTCASE(define_method_int_passed_no_args)
168
181
  {
169
- Class c(anonymous_class());
170
- c.define_method("foo", &define_method_int_helper);
182
+ Class c =
183
+ define_class<IntHelper>("IntHelper")
184
+ .define_constructor(Constructor<IntHelper>())
185
+ .define_method("foo", &IntHelper::define_method_int_helper);
186
+
171
187
  Object o = c.call("new");
188
+
172
189
  ASSERT_EXCEPTION_CHECK(
173
190
  Exception,
174
191
  o.call("foo"),
@@ -191,7 +208,7 @@ struct Foo
191
208
  int define_method_int_foo_result_i;
192
209
  Foo * define_method_int_foo_result_x;
193
210
 
194
- void define_method_int_foo_helper(Object o, int i, Foo * x)
211
+ void define_method_int_foo_helper(int i, Foo * x)
195
212
  {
196
213
  define_method_int_foo_result_i = i;
197
214
  define_method_int_foo_result_x = x;
@@ -221,6 +238,11 @@ TESTCASE(define_method_int_foo)
221
238
  ASSERT_EQUAL(foo, define_method_int_foo_result_x);
222
239
  }
223
240
 
241
+
242
+ TESTCASE(define_method_with_default_arguments)
243
+ {
244
+ }
245
+
224
246
  namespace
225
247
  {
226
248
 
@@ -234,7 +256,7 @@ void handle_silly_exception(Silly_Exception const & ex)
234
256
  throw Exception(rb_eRuntimeError, "SILLY");
235
257
  }
236
258
 
237
- void throw_silly_exception(Object self)
259
+ void throw_silly_exception()
238
260
  {
239
261
  throw Silly_Exception();
240
262
  }
@@ -1,7 +1,11 @@
1
1
  #include "unittest.hpp"
2
2
  #include "rice/Constructor.hpp"
3
3
  #include "rice/Data_Type.hpp"
4
- #include "rice/Constructor.hpp"
4
+
5
+ #include "rice/detail/env.hpp"
6
+
7
+ #include <iostream>
8
+ using namespace std;
5
9
 
6
10
  using namespace Rice;
7
11
 
@@ -60,4 +64,175 @@ TESTCASE(non_default_constructor)
60
64
  ASSERT_EQUAL(rb_cNon_Default_Constructible, o.class_of());
61
65
  ASSERT_EQUAL(42, o->i());
62
66
  }
67
+ /*
68
+ namespace {
69
+
70
+ class AbstractClass
71
+ {
72
+ public:
73
+
74
+ int doSomething()
75
+ {
76
+ return doSomethingImpl();
77
+ }
78
+
79
+ int doSomethingParam(int a, int b)
80
+ {
81
+ return doSomethingParamImpl(a, b);
82
+ }
83
+
84
+ virtual int doSomethingImpl() = 0;
85
+
86
+ virtual int doSomethingParamImpl(int a, int b) = 0;
87
+ };
88
+
89
+ class Director : public AbstractClass
90
+ {
91
+ Rice::Object m_rbSelf;
92
+
93
+ public:
94
+ Director(Rice::Object self) : m_rbSelf(self) { }
95
+
96
+ virtual int doSomethingImpl()
97
+ {
98
+ cout << endl << "In Impl, frame's last_func is " << rb_id2name(ruby_frame->last_func) << endl;
99
+ cout << endl << "In Impl, frame's orig_func is " << rb_id2name(ruby_frame->orig_func) << endl;
100
+ cout << endl << "In Impl, frame's last_class is " << Class(ruby_frame->last_class).name().str() << endl;
101
+
102
+ cout << endl << "In Impl, frame's prev's last_func is " << rb_id2name(ruby_frame->prev->last_func) << endl;
103
+ cout << endl << "In Impl, frame's prev's orig_func is " << rb_id2name(ruby_frame->prev->orig_func) << endl;
104
+
105
+ cout << endl << "We've got classname (frame) " << rb_obj_classname(ruby_frame->self) << " vs (self) " << rb_obj_classname(m_rbSelf.value()) << endl;
106
+ cout << endl << "We've got classname (frame prev) " << rb_obj_classname(ruby_frame->prev->self) << " vs (self) " << rb_obj_classname(m_rbSelf.value()) << endl;
107
+
108
+ // Need to get the Ruby callee, compare that to m_rbSelf, and
109
+ // if they're equal, go UP the chain, otherwise go DOWN
110
+ if(ruby_frame->self == m_rbSelf.value()) {
111
+ // As doSomethingImpl is pure virtual, we need to implement a default here so
112
+ // that super calls don't blow things up
113
+ return 100;
114
+ } else {
115
+ return from_ruby<int>( m_rbSelf.call("do_something_impl") );
116
+ }
117
+
118
+ }
119
+
120
+ virtual int doSomethingParamImpl(int a, int b)
121
+ {
122
+ return from_ruby<int>( m_rbSelf.call("do_something_param_impl", a, b) );
123
+ }
124
+ };
125
+ }
126
+
127
+ TESTCASE(director_system_polymorphic_calls)
128
+ {
129
+ Data_Type<AbstractClass> a = define_class<AbstractClass>("__AbstractClass__");
63
130
 
131
+ Data_Type<Director> d = define_class<Director, AbstractClass>("AbstractClass");
132
+ d.define_constructor(Constructor<Director, Rice::Object>());
133
+ d.define_method("do_something", &AbstractClass::doSomething);
134
+ d.define_method("do_something_impl", &Director::doSomethingImpl);
135
+
136
+ Module m = define_module("Testing");
137
+ m.instance_eval(
138
+ "class MyWorker < AbstractClass;"
139
+ "def do_something_impl; 8; end;"
140
+ "end"
141
+ );
142
+
143
+ Object result = m.instance_eval("worker = MyWorker.new; worker.do_something");
144
+
145
+ ASSERT_EQUAL(
146
+ 8, from_ruby<int>(result.value())
147
+ );
148
+ }
149
+
150
+ TESTCASE(director_system_polymorphic_calls_with_parameters)
151
+ {
152
+ Data_Type<AbstractClass> a = define_class<AbstractClass>("__AbstractClass__");
153
+
154
+ Data_Type<Director> d = define_class<Director, AbstractClass>("AbstractClass");
155
+ d.define_constructor(Constructor<Director, Rice::Object>());
156
+ d.define_method("do_something_param", &AbstractClass::doSomethingParam);
157
+ d.define_method("do_something_param_impl", &Director::doSomethingParamImpl);
158
+
159
+ Module m = define_module("Testing");
160
+ m.instance_eval(
161
+ "class MyWorker < AbstractClass;"
162
+ "def do_something_param_impl(a, b); a * b; end;"
163
+ "end"
164
+ );
165
+
166
+ Object result = m.instance_eval("worker = MyWorker.new; worker.do_something_param(2, 10)");
167
+
168
+ ASSERT_EQUAL(
169
+ 20, from_ruby<int>(result.value())
170
+ );
171
+ }
172
+
173
+ TESTCASE(director_system_polymorphic_calls_very_deep)
174
+ {
175
+ Data_Type<AbstractClass> a = define_class<AbstractClass>("__AbstractClass__");
176
+
177
+ Data_Type<Director> d = define_class<Director, AbstractClass>("AbstractClass");
178
+ d.define_constructor(Constructor<Director, Rice::Object>());
179
+ d.define_method("do_something", &AbstractClass::doSomething);
180
+ d.define_method("do_something_impl", &Director::doSomethingImpl);
181
+
182
+ Module m = define_module("Testing");
183
+ m.instance_eval(
184
+ "class MyWorker < AbstractClass;"
185
+ "def do_something_impl; 4; end;"
186
+ "end;"
187
+ "class MyWorker2 < MyWorker;"
188
+ "def do_something_impl; 6; end;"
189
+ "end;"
190
+ "class MyWorker3 < MyWorker2;"
191
+ "def do_something_impl; 8; end;"
192
+ "end;"
193
+ "class MyWorker4 < MyWorker3;"
194
+ "def do_something_impl; 10; end;"
195
+ "end;"
196
+ );
197
+
198
+ Object result = m.instance_eval("worker = MyWorker4.new; worker.do_something");
199
+
200
+ ASSERT_EQUAL(
201
+ 10, from_ruby<int>(result.value())
202
+ );
203
+ }
204
+
205
+ TESTCASE(director_system_super_calls_dont_infinite_loop)
206
+ {
207
+ Data_Type<AbstractClass> a = define_class<AbstractClass>("__AbstractClass__");
208
+
209
+ Data_Type<Director> d = define_class<Director, AbstractClass>("AbstractClass");
210
+ d.define_constructor(Constructor<Director, Rice::Object>());
211
+ d.define_method("do_something", &AbstractClass::doSomething);
212
+ d.define_method("do_something_impl", &Director::doSomethingImpl);
213
+
214
+ Module m = define_module("Testing");
215
+ m.instance_eval(
216
+ "class MyWorker < AbstractClass;"
217
+ "@@call_count = 0;"
218
+ "def do_something_impl;"
219
+ "@@call_count += 1;"
220
+ "if @@call_count == 1; super; else; -1; end;"
221
+ "end; end;"
222
+ );
223
+
224
+ Object result = m.instance_eval("worker = MyWorker.new; worker.do_something");
225
+
226
+ // -1 means that the do_something_impl got called twice, aka we were in an infinite loop
227
+ // had the class var check not been there
228
+ ASSERT_NOT_EQUAL(
229
+ -1,
230
+ from_ruby<int>(result.value())
231
+ );
232
+
233
+ ASSERT_EQUAL(
234
+ 100,
235
+ from_ruby<int>(result.value())
236
+ );
237
+ }
238
+ */