aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-11-03 17:20:31 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-11-03 17:20:31 -0300
commite01eba39663c2f7d0f1137ab30ed18891394afb5 (patch)
treecbd3d28de96353e870258f183b9df3b4948af957 /tests
parent2b54063938045567453daaa17c33b323e68b890f (diff)
updated Point tests with cases for returning Point pointer,
const pointer and const reference
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/point.cpp11
-rw-r--r--tests/libsample/point.h5
-rwxr-xr-xtests/samplebinding/point_test.py26
3 files changed, 40 insertions, 2 deletions
diff --git a/tests/libsample/point.cpp b/tests/libsample/point.cpp
index 410e1c8cb..0b6540202 100644
--- a/tests/libsample/point.cpp
+++ b/tests/libsample/point.cpp
@@ -39,12 +39,19 @@ using namespace std;
Point::Point(int x, int y) : m_x(x), m_y(y)
{
- // cout << __PRETTY_FUNCTION__ << " [x=0, y=0]" << endl;
}
Point::Point(double x, double y) : m_x(x), m_y(y)
{
- // cout << __PRETTY_FUNCTION__ << endl;
+}
+
+Point*
+Point::copy() const
+{
+ Point* pt = new Point();
+ pt->m_x = m_x;
+ pt->m_y = m_y;
+ return pt;
}
void
diff --git a/tests/libsample/point.h b/tests/libsample/point.h
index 6c8638742..be73e4d43 100644
--- a/tests/libsample/point.h
+++ b/tests/libsample/point.h
@@ -51,6 +51,11 @@ public:
void setX(double x) { m_x = x; }
void setY(double y) { m_y = y; }
+ Point* copy() const;
+
+ const Point& getConstReferenceToSelf() const { return *this; }
+ const Point* getSelf() const { return this; }
+
bool operator==(const Point& other);
Point operator+(const Point& other);
Point operator-(const Point& other);
diff --git a/tests/samplebinding/point_test.py b/tests/samplebinding/point_test.py
index 8b50cf6f0..453068503 100755
--- a/tests/samplebinding/point_test.py
+++ b/tests/samplebinding/point_test.py
@@ -61,6 +61,32 @@ class PointTest(unittest.TestCase):
pt2 = Point(5.0, 2.3)
self.assertRaises(NotImplementedError, lambda : pt1.__ne__(pt2))
+ def testReturnNewCopy(self):
+ '''Point returns a copy of itself.'''
+ pt1 = Point(1.1, 2.3)
+ pt2 = pt1.copy()
+ self.assertEqual(pt1, pt2)
+ pt2 += pt1
+ self.assertNotEqual(pt1, pt2)
+
+ def testReturnConstPointer(self):
+ '''Point returns a const pointer for itself.'''
+ pt1 = Point(5.0, 2.3)
+ refcount1 = sys.getrefcount(pt1)
+ pt2 = pt1.getSelf()
+ self.assertEqual(pt1, pt2)
+ self.assertEqual(sys.getrefcount(pt1), refcount1 + 1)
+ self.assertEqual(sys.getrefcount(pt1), sys.getrefcount(pt2))
+
+ def testReturnConstReference(self):
+ '''Point returns a const reference for itself.'''
+ pt1 = Point(5.0, 2.3)
+ refcount1 = sys.getrefcount(pt1)
+ pt2 = pt1.getConstReferenceToSelf()
+ self.assertEqual(pt1, pt2)
+ self.assertEqual(sys.getrefcount(pt1), refcount1 + 1)
+ self.assertEqual(sys.getrefcount(pt1), sys.getrefcount(pt2))
+
if __name__ == '__main__':
unittest.main()