diff options
author | Lauro Neto <lauro.neto@openbossa.org> | 2010-01-27 14:21:52 -0300 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2010-02-02 18:19:28 -0200 |
commit | 76529055ff3894793cf83be02248a9f189a1983f (patch) | |
tree | 74a4deed47efe120de970c6a0fc1ab21130fde2f /tests | |
parent | 5e0169fe506aafe246029acd6f90ecef054fc074 (diff) |
Tests for QString.to* and QByteArray imp convers.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/qtcore/qstring_test.py | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/tests/qtcore/qstring_test.py b/tests/qtcore/qstring_test.py index d9152447d..193ef0910 100644 --- a/tests/qtcore/qstring_test.py +++ b/tests/qtcore/qstring_test.py @@ -6,7 +6,7 @@ import unittest import ctypes import sys -from PySide.QtCore import QString, QByteArray +from PySide.QtCore import QString, QByteArray, QObject class QStringToNumber(unittest.TestCase): def testReturnValueTypes(self): @@ -17,7 +17,59 @@ class QStringToNumber(unittest.TestCase): def testToNumberInt(self): obj = QString('37') - self.assertEqual(37, obj.toInt()[0]) + self.assertEqual((37, True), obj.toInt()) + + def testToNumberLong(self): + obj = QString('3700000') + self.assertEqual((3700000, True), obj.toInt()) + + def testToNumberShort(self): + obj = QString('33') + self.assertEqual((ctypes.c_short(33).value, True), obj.toShort()) + + def testToNumberShortNegative(self): + obj = QString('-4') + self.assertEqual((ctypes.c_short(-4).value, True), obj.toShort()) + + def testToNumberShortOverflow(self): + obj = QString('1000000') + self.assertEqual(False, obj.toShort()[1]) + + def testToNumberUInt(self): + obj = QString('33') + self.assertEqual((ctypes.c_uint(33).value, True), obj.toUInt()) + + def testToNumberUIntNegative(self): + obj = QString('-4') + self.assertEqual(False, obj.toUInt()[1]) + + def testToNumberUIntOverflow(self): + obj = QString('10000000000000') + self.assertEqual(False, obj.toUInt()[1]) + + def testToNumberULong(self): + obj = QString('33') + self.assertEqual((ctypes.c_ulong(33).value, True), obj.toULong()) + + def testToNumberULongNegative(self): + obj = QString('-4') + self.assertEqual(False, obj.toULong()[1]) + + def testToNumberUShort(self): + obj = QString('33') + self.assertEqual((ctypes.c_ushort(33).value, True), obj.toUShort()) + + def testToNumberUShortLarge(self): + obj = QString('128') + self.assertEqual((ctypes.c_ushort(128).value, True), obj.toUShort()) + + def testToNumberUShortOverflow(self): + obj = QString('205000') + self.assertEqual(False, obj.toUShort()[1]) + + def testToNumberUShortNegative(self): + obj = QString('-4') + self.assertEqual(False, obj.toUShort()[1]) def testToNumberIntUsingHex(self): obj = QString('2A') @@ -117,5 +169,15 @@ class QStringIndexOf(unittest.TestCase): string = QString("the quick brown fox") self.assertEqual(string.indexOf("quick", 0), 4) + +class QStringImplicitConvertion(unittest.TestCase): + '''Implicit conversions for QString''' + + def testQByteArray(self): + '''QString implicitly conversion: QByteArray''' + obj = QObject() + obj.setObjectName(QByteArray('foobar')) + self.assertEqual(obj.objectName(), QString('foobar')) + if __name__ == '__main__': unittest.main() |