From fa27bddfab7817520b1fe8d6e62efceb8fca408d Mon Sep 17 00:00:00 2001 From: Bruno da Silva de Oliveira Date: Sat, 22 Mar 2003 19:35:55 +0000 Subject: [PATCH] - added a case: wrapper for a virtual method [SVN r18062] --- pyste/example/wrappertest.h | 7 +++++++ pyste/example/wrappertest.pyste | 6 ++++++ pyste/example/wrappertest_wrappers.h | 2 ++ pyste/tests/example_wrappertestUT.py | 9 +++++++++ 4 files changed, 24 insertions(+) diff --git a/pyste/example/wrappertest.h b/pyste/example/wrappertest.h index c5ef4f56..82887230 100644 --- a/pyste/example/wrappertest.h +++ b/pyste/example/wrappertest.h @@ -34,6 +34,13 @@ struct C } }; + +struct A +{ + virtual int f() { return 1; }; +}; + +int call_foo(A* a){ return a->f(); } } #endif diff --git a/pyste/example/wrappertest.pyste b/pyste/example/wrappertest.pyste index fd210c7e..12ba47b6 100644 --- a/pyste/example/wrappertest.pyste +++ b/pyste/example/wrappertest.pyste @@ -13,3 +13,9 @@ list MulWrapper(wrappertest::C& c, int value){ C = Class('wrappertest::C', 'wrappertest.h') set_wrapper(C.Mul, mul) + + +A = Class('wrappertest::A', 'wrappertest.h') +set_wrapper(A.f, 'f_wrapper') + +Function('wrappertest::call_foo', 'wrappertest.h') diff --git a/pyste/example/wrappertest_wrappers.h b/pyste/example/wrappertest_wrappers.h index 42e05d2c..7aec7309 100644 --- a/pyste/example/wrappertest_wrappers.h +++ b/pyste/example/wrappertest_wrappers.h @@ -23,4 +23,6 @@ list RangeWrapper(int count){ return VectorToList(wrappertest::Range(count)); } +int f_wrapper(wrappertest::A*) { return 10; } + #endif diff --git a/pyste/tests/example_wrappertestUT.py b/pyste/tests/example_wrappertestUT.py index ebffed2d..fa3c4236 100644 --- a/pyste/tests/example_wrappertestUT.py +++ b/pyste/tests/example_wrappertestUT.py @@ -7,5 +7,14 @@ class WrapperTest(unittest.TestCase): self.assertEqual(Range(10), range(10)) self.assertEqual(C().Mul(10), [x*10 for x in range(10)]) + a = A() + self.assertEqual(a.f(), 10) + self.assertEqual(call_foo(a), 10) + class D(A): + def f(self): return 2 + d = D() + self.assertEqual(d.f(), 2) + self.assertEqual(call_foo(d), 2) + if __name__ == '__main__': unittest.main()