diff options
author | Renato Filho <renato.filho@openbossa.org> | 2010-06-07 14:43:45 -0300 |
---|---|---|
committer | Renato Filho <renato.filho@openbossa.org> | 2010-06-07 16:57:11 -0300 |
commit | ab918abc1e103e0ca86939f7d057e8a44ac8a4ef (patch) | |
tree | 53c6f57d089dcf5e145d766b1ceef704714046d8 /tests/QtGui/qmatrix_test.py | |
parent | 471486732b03cbb42b884158604a59d5a18e8a35 (diff) |
Created new unittest model.
Separete unittest for module.
Only run unittest for compiled modules.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>,
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests/QtGui/qmatrix_test.py')
-rw-r--r-- | tests/QtGui/qmatrix_test.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/QtGui/qmatrix_test.py b/tests/QtGui/qmatrix_test.py new file mode 100644 index 000000000..7c87e23a4 --- /dev/null +++ b/tests/QtGui/qmatrix_test.py @@ -0,0 +1,49 @@ +import unittest + +from PySide.QtCore import QPoint +from PySide.QtGui import QMatrix, QMatrix4x4 + + +def qpointTimesQMatrix(point, matrix): + '''As seen in "QPoint QMatrix::map(const QPoint &p) const" C++ implementation.''' + return QPoint(matrix.m11() * point.x() + matrix.m21() * point.y() + matrix.dx(), + matrix.m12() * point.x() + matrix.m22() * point.y() + matrix.dy()) + +class QMatrixTest(unittest.TestCase): + + def testMatrix(self): + matrix = QMatrix(11, 12, 21, 22, 100, 200) + point = QPoint(3, 3) + self.assertEqual(point * matrix, qpointTimesQMatrix(point, matrix)) + + def testMatrixWithWrongType(self): + matrix = QMatrix(11, 12, 21, 22, 100, 200) + point = QPoint(3, 3) + self.assertRaises(TypeError, matrix.__mul__, point) + + def testMatrix4x4(self): + self.assertRaises(TypeError, QMatrix4x4, [0.0, 1.0, 2.0, 3.0]) + self.assertRaises(TypeError, QMatrix4x4, [0.0, 1.0, 2.0, 'I', + 4.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 'N', 11.0, + 12.0, 'd', 14.0, 'T']) + + my_data = [0.0, 1.0, 2.0, 3.0, + 4.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 10.0, 11.0, + 12.0, 13.0, 14.0, 15.0] + my_datac = [0.0, 4.0, 8.0, 12.0, + 1.0, 5.0, 9.0, 13.0, + 2.0, 6.0, 10.0, 14.0, + 3.0, 7.0, 11.0, 15.0] + + m = QMatrix4x4(my_data) + d = m.data() + self.assert_(my_datac, d) + + d = m.copyDataTo() + self.assert_(my_data == list(d)) + +if __name__ == '__main__': + unittest.main() + |