From 20b51a7f92f32e44a6ff3d283cdedb315458ddeb Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Sat, 4 Oct 2008 17:26:23 +0100 Subject: [PATCH] Add a unit test for scanning/wrapping output reference to container parameter (e.g.std::vector &outVec) --- tests/foo.cc | 8 ++++++++ tests/foo.h | 3 +++ tests/foomodulegen.py | 6 +++++- tests/footest.py | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/foo.cc b/tests/foo.cc index d0e9934..77acdf1 100644 --- a/tests/foo.cc +++ b/tests/foo.cc @@ -354,6 +354,14 @@ TestContainer::set_simple_vec (std::vector list) return count; } +void +TestContainer::get_vec (std::vector &outVec) +{ + outVec.clear (); + outVec.push_back ("hello"); + outVec.push_back ("world"); +} + std::map get_map () { diff --git a/tests/foo.h b/tests/foo.h index 9029409..36991ba 100644 --- a/tests/foo.h +++ b/tests/foo.h @@ -764,6 +764,9 @@ public: virtual SimpleStructVec get_simple_vec (); virtual int set_simple_vec (SimpleStructVec vec); + // -#- @outVec(direction=out) -#- + void get_vec (std::vector &outVec); + private: SimpleStructList m_simpleList; }; diff --git a/tests/foomodulegen.py b/tests/foomodulegen.py index 64749e6..d1c0750 100755 --- a/tests/foomodulegen.py +++ b/tests/foomodulegen.py @@ -407,10 +407,14 @@ int %s::custom_method_added_by_a_hook(int x) direction=Parameter.DIRECTION_INOUT)], is_virtual=True) - SimpleStructList = mod.add_container('std::vector', ReturnValue.new('simple_struct_t'), 'vector') + mod.add_container('std::vector', ReturnValue.new('simple_struct_t'), 'vector') TestContainer.add_method('get_simple_vec', ReturnValue.new('std::vector'), [], is_virtual=True) TestContainer.add_method('set_simple_vec', 'int', [Parameter.new('std::vector', 'vec')], is_virtual=True) + mod.add_container('std::vector', 'std::string', 'vector') + TestContainer.add_method('get_vec', 'void', [Parameter.new('std::vector &', 'outVec', + direction=Parameter.DIRECTION_OUT)]) + #### --- error handler --- class MyErrorHandler(pybindgen.settings.ErrorHandler): diff --git a/tests/footest.py b/tests/footest.py index 8e2c5a2..d8fba8f 100644 --- a/tests/footest.py +++ b/tests/footest.py @@ -990,6 +990,10 @@ class TestFoo(unittest.TestCase): v = list(t.m_floatSet) self.assertEqual(v, [1,2,3]) + def test_out_vec(self): + t = foo.TestContainer() + v = list(t.get_vec()) + self.assertEqual(v, ["hello", "world"]) if __name__ == '__main__': unittest.main()