diff options
author | Lauro Neto <lauro.neto@openbossa.org> | 2009-10-31 13:31:01 -0300 |
---|---|---|
committer | Lauro Neto <lauro.neto@openbossa.org> | 2009-11-10 11:21:13 -0300 |
commit | 0f880ec413d0ecebd9beb1053ff04e7877183cca (patch) | |
tree | 907bb066aa73615b9227238bb5bd888a618b7c9a /tests | |
parent | 14b0bdd84be9a23419fea6b6e70370d4a1cb6501 (diff) |
Adding external operator to Collector (stream)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libsample/collector.cpp | 5 | ||||
-rw-r--r-- | tests/libsample/collector.h | 15 | ||||
-rw-r--r-- | tests/samplebinding/CMakeLists.txt | 1 | ||||
-rwxr-xr-x | tests/samplebinding/collector_test.py | 11 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 4 |
5 files changed, 34 insertions, 2 deletions
diff --git a/tests/libsample/collector.cpp b/tests/libsample/collector.cpp index 0b81b2996..cd499d2dd 100644 --- a/tests/libsample/collector.cpp +++ b/tests/libsample/collector.cpp @@ -59,3 +59,8 @@ Collector::size() return (int) m_items.size(); } +Collector &operator<<(Collector &s, const IntWrapper &w) +{ + s << w.value; + return s; +} diff --git a/tests/libsample/collector.h b/tests/libsample/collector.h index 1253cdd33..3c6adce28 100644 --- a/tests/libsample/collector.h +++ b/tests/libsample/collector.h @@ -52,6 +52,21 @@ public: private: std::list<int> m_items; + + Collector(const Collector&); + Collector& operator=(const Collector&); +}; + +/* Helper for testing external operators */ +class IntWrapper +{ +public: + IntWrapper(int x=0):value(x){} + + int value; }; + +Collector &operator<<(Collector&, const IntWrapper&); + #endif // COLLECTOR_H diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index 60df46126..32ebcf75f 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -11,6 +11,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/collector_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/derived_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/echo_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/implicitconv_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/intwrapper_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/listuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/mapuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/mbase1_wrapper.cpp diff --git a/tests/samplebinding/collector_test.py b/tests/samplebinding/collector_test.py index efa1a3876..a4c9248c4 100755 --- a/tests/samplebinding/collector_test.py +++ b/tests/samplebinding/collector_test.py @@ -29,7 +29,7 @@ import sys import unittest -from sample import Collector +from sample import Collector, IntWrapper class CollectorTest(unittest.TestCase): '''Test cases for Collector class' shift operators.''' @@ -48,6 +48,15 @@ class CollectorTest(unittest.TestCase): self.assertEqual(collector.size(), 5) self.assertEqual(collector.items(), [2, 3, 5, 7, 11]) +class CollectorExternalOperator(unittest.TestCase): + '''Test cases for external operators of Collector''' + + def testLShiftExternal(self): + '''Collector external operator''' + collector = Collector() + collector << IntWrapper(5) + self.assertEqual(collector.size(), 1) + self.assertEqual(collector.items(), [5]) if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 9712ebf16..1a1e09a6a 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -245,7 +245,9 @@ <value-type name="NonDefaultCtor" /> <value-type name="OddBoolUser" /> <value-type name="Overload" /> - <value-type name="Collector" /> + <object-type name="Collector" stream="yes"/> + + <value-type name="IntWrapper" /> <value-type name="Str"> <add-function signature="__str__()" return-type="PyObject*"> |