From 6bb2780c978d93b6ebe7b423adda27e4292467f2 Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Tue, 2 Aug 2011 13:06:58 -0300 Subject: Added test for removed pointer out argument. --- tests/libsample/point.cpp | 9 +++++++++ tests/libsample/point.h | 6 +++++- tests/libsample/pointf.cpp | 9 +++++++++ tests/libsample/pointf.h | 8 ++++++-- tests/samplebinding/point_test.py | 7 ++++++- tests/samplebinding/pointf_test.py | 7 ++++++- tests/samplebinding/typesystem_sample.xml | 31 +++++++++++++++++++++++++++++++ 7 files changed, 72 insertions(+), 5 deletions(-) diff --git a/tests/libsample/point.cpp b/tests/libsample/point.cpp index 484e7c11c..61e2830e4 100644 --- a/tests/libsample/point.cpp +++ b/tests/libsample/point.cpp @@ -33,6 +33,15 @@ Point::Point(double x, double y) : m_x(x), m_y(y) { } +void +Point::midpoint(const Point& other, Point* midpoint) const +{ + if (!midpoint) + return; + midpoint->setX((m_x + other.m_x) / 2.0); + midpoint->setY((m_y + other.m_y) / 2.0); +} + Point* Point::copy() const { diff --git a/tests/libsample/point.h b/tests/libsample/point.h index cc7a1bc5a..45b1edd39 100644 --- a/tests/libsample/point.h +++ b/tests/libsample/point.h @@ -43,6 +43,11 @@ public: inline void setXAsUint(unsigned int x) { m_x = x; } inline void setYAsUint(unsigned int y) { m_y = y; } + // This method could simply return the midpoint, + // but the interesting part of the test is to set the + // result in the pointer argument. + void midpoint(const Point& other, Point* midpoint) const; + Point* copy() const; inline const Point& getConstReferenceToSelf() const { return *this; } @@ -86,4 +91,3 @@ LIBSAMPLE_API Point transmuteComplexIntoPoint(const Complex& cpx); LIBSAMPLE_API Point operator*(const Point& pt, double multiplier); #endif // POINT_H - diff --git a/tests/libsample/pointf.cpp b/tests/libsample/pointf.cpp index 2464c22bb..509863c41 100644 --- a/tests/libsample/pointf.cpp +++ b/tests/libsample/pointf.cpp @@ -33,6 +33,15 @@ PointF::PointF(double x, double y) : m_x(x), m_y(y) { } +void +PointF::midpoint(const PointF& other, PointF* midpoint) const +{ + if (!midpoint) + return; + midpoint->setX((m_x + other.m_x) / 2.0); + midpoint->setY((m_y + other.m_y) / 2.0); +} + void PointF::show() { diff --git a/tests/libsample/pointf.h b/tests/libsample/pointf.h index 832c3b323..f5ad11659 100644 --- a/tests/libsample/pointf.h +++ b/tests/libsample/pointf.h @@ -41,8 +41,13 @@ public: inline void setX(double x) { m_x = x; } inline void setY(double y) { m_y = y; } + // This method could simply return the midpoint, + // but the interesting part of the test is to set the + // result in the pointer argument. + void midpoint(const PointF& other, PointF* midpoint) const; + // The != operator is not implemented for the purpose of testing - // for the absense of the __ne__ method in the Python binding. + // for the absence of the __ne__ method in the Python binding. bool operator==(const PointF& other); PointF operator+(const PointF& other); @@ -75,4 +80,3 @@ LIBSAMPLE_API bool operator!(const PointF& pt); LIBSAMPLE_API PointF operator*(const PointF& pt, double multiplier); #endif // POINTF_H - diff --git a/tests/samplebinding/point_test.py b/tests/samplebinding/point_test.py index 3b45db4ad..6d9fc8fca 100644 --- a/tests/samplebinding/point_test.py +++ b/tests/samplebinding/point_test.py @@ -93,6 +93,11 @@ class PointTest(unittest.TestCase): r = u'Hi' - p self.assertEqual(r, u'Hi') + def testModifiedMethod(self): + pt1 = Point(0.0, 0.0) + pt2 = Point(10.0, 10.0) + expected = Point((pt1.x() + pt2.x()) / 2.0, (pt1.y() + pt2.y()) / 2.0) + self.assertEqual(pt1.midpoint(pt2), expected) + if __name__ == '__main__': unittest.main() - diff --git a/tests/samplebinding/pointf_test.py b/tests/samplebinding/pointf_test.py index f9aac9f20..5cb84800a 100644 --- a/tests/samplebinding/pointf_test.py +++ b/tests/samplebinding/pointf_test.py @@ -54,6 +54,11 @@ class PointFTest(unittest.TestCase): self.assertTrue(pt1 == pt2) self.assertFalse(pt1 == pt3) + def testModifiedMethod(self): + pt1 = PointF(0.0, 0.0) + pt2 = PointF(10.0, 10.0) + expected = PointF((pt1.x() + pt2.x()) / 2.0, (pt1.y() + pt2.y()) / 2.0) + self.assertEqual(pt1.midpoint(pt2), expected) + if __name__ == '__main__': unittest.main() - diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 25301973e..5184526e4 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -1135,6 +1135,22 @@ %PYARG_0 = Py_BuildValue("(OO)", type, args); + + + + + + + + + + Point _midpoint; + // The test consists in *NOT* using the ARGUMENT_NAMES type system variable. + %CPPSELF.%FUNCTION_NAME(%1, &_midpoint); + %PYARG_0 = %CONVERTTOPYTHON[Point](_midpoint); + + +