Tests for QString.to* and QByteArray imp convers.
This commit is contained in:
parent
5e0169fe50
commit
76529055ff
1 changed files with 64 additions and 2 deletions
|
|
@ -6,7 +6,7 @@ import unittest
|
||||||
import ctypes
|
import ctypes
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PySide.QtCore import QString, QByteArray
|
from PySide.QtCore import QString, QByteArray, QObject
|
||||||
|
|
||||||
class QStringToNumber(unittest.TestCase):
|
class QStringToNumber(unittest.TestCase):
|
||||||
def testReturnValueTypes(self):
|
def testReturnValueTypes(self):
|
||||||
|
|
@ -17,7 +17,59 @@ class QStringToNumber(unittest.TestCase):
|
||||||
|
|
||||||
def testToNumberInt(self):
|
def testToNumberInt(self):
|
||||||
obj = QString('37')
|
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):
|
def testToNumberIntUsingHex(self):
|
||||||
obj = QString('2A')
|
obj = QString('2A')
|
||||||
|
|
@ -117,5 +169,15 @@ class QStringIndexOf(unittest.TestCase):
|
||||||
string = QString("the quick brown fox")
|
string = QString("the quick brown fox")
|
||||||
self.assertEqual(string.indexOf("quick", 0), 4)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue