diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2011-08-02 13:06:58 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:17:07 -0300 |
commit | 6bb2780c978d93b6ebe7b423adda27e4292467f2 (patch) | |
tree | 975bb03485f15e28e514a5333fdced6f8a2c246f /tests | |
parent | f3b6eeccd43fc8b81bb7fe48424b6f4c6e4e454d (diff) |
Added test for removed pointer out argument.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libsample/point.cpp | 9 | ||||
-rw-r--r-- | tests/libsample/point.h | 6 | ||||
-rw-r--r-- | tests/libsample/pointf.cpp | 9 | ||||
-rw-r--r-- | tests/libsample/pointf.h | 8 | ||||
-rw-r--r-- | tests/samplebinding/point_test.py | 7 | ||||
-rw-r--r-- | tests/samplebinding/pointf_test.py | 7 | ||||
-rw-r--r-- | 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 @@ -34,6 +34,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() { cout << "(x: " << m_x << ", y: " << m_y << ")"; 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); </inject-code> </add-function> + + <modify-function signature="midpoint(const Point&, Point*)const"> + <modify-argument index="2"> + <remove-argument /> + </modify-argument> + <modify-argument index="return"> + <replace-type modified-type="Point" /> + </modify-argument> + <inject-code class="target" position="beginning"> + Point _midpoint; + // The test consists in *NOT* using the ARGUMENT_NAMES type system variable. + %CPPSELF.%FUNCTION_NAME(%1, &_midpoint); + %PYARG_0 = %CONVERTTOPYTHON[Point](_midpoint); + </inject-code> + </modify-function> + <template name="return_self"> %PYARG_0 = %PYARG_1; Py_INCREF(%PYARG_1); @@ -1182,6 +1198,21 @@ %PYARG_0 = Py_BuildValue("(OO)", type, args); </inject-code> </add-function> + + <modify-function signature="midpoint(const PointF&, PointF*)const"> + <modify-argument index="2"> + <remove-argument /> + </modify-argument> + <modify-argument index="return"> + <replace-type modified-type="PointF" /> + </modify-argument> + <inject-code class="target" position="beginning"> + PointF _midpoint; + // The test consists in using the ARGUMENT_NAMES type system variable. + %CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, &_midpoint); + %PYARG_0 = %CONVERTTOPYTHON[PointF](_midpoint); + </inject-code> + </modify-function> </value-type> <value-type name="Rect" /> |