aboutsummaryrefslogtreecommitdiffstats
path: root/tests/qtcore/qbytearray_test.py
diff options
context:
space:
mode:
authorLauro Neto <lauro.neto@openbossa.org>2010-02-01 18:00:43 -0300
committerHugo Lima <hugo.lima@openbossa.org>2010-02-02 18:19:28 -0200
commit74351882b5e613f109cfe1f3c0b60885dcad06bc (patch)
tree151063fd3ea5004e49a544836226a81ecf10679c /tests/qtcore/qbytearray_test.py
parent76529055ff3894793cf83be02248a9f189a1983f (diff)
Fixing several tests
Using isinstance instead of comparing classes names Removing unnecessary tuple check, treated by the return value unpacking Adding missing inject code tests Adding qfile.getchar test Fixing QLocale.to* methods fixing __setitem__ in qbytearray
Diffstat (limited to 'tests/qtcore/qbytearray_test.py')
-rw-r--r--tests/qtcore/qbytearray_test.py65
1 files changed, 60 insertions, 5 deletions
diff --git a/tests/qtcore/qbytearray_test.py b/tests/qtcore/qbytearray_test.py
index 67f99f3d4..20bba1400 100644
--- a/tests/qtcore/qbytearray_test.py
+++ b/tests/qtcore/qbytearray_test.py
@@ -10,17 +10,21 @@ from PySide.QtCore import QByteArray
class QByteArrayTestToNumber(unittest.TestCase):
def testToNumberInt(self):
obj = QByteArray('37')
- self.assertEqual(37, obj.toInt()[0])
+ self.assertEqual((37, True), obj.toInt())
+
+ def testToNumberUShort(self):
+ obj = QByteArray('37')
+ self.assertEqual((37, True), obj.toUShort())
def testToNumberFloat(self):
obj = QByteArray('37.109')
- self.assertEqual(ctypes.c_float(37.109).value,
- obj.toFloat()[0])
+ self.assertEqual((ctypes.c_float(37.109).value, True),
+ obj.toFloat())
def testToNumberDouble(self):
obj = QByteArray('37.109')
- self.assertEqual(ctypes.c_double(37.109).value,
- obj.toDouble()[0])
+ self.assertEqual((ctypes.c_double(37.109).value, True),
+ obj.toDouble())
class QByteArraySplit(unittest.TestCase):
'''Test case for QByteArray.split'''
@@ -38,6 +42,57 @@ class QByteArrayData(unittest.TestCase):
url = QByteArray("http://web.openbossa.org/")
self.assertEqual(url.data(), "http://web.openbossa.org/")
+class QByteArrayOperatorAtSetter(unittest.TestCase):
+ '''Test case for operator QByteArray[] - __setitem__'''
+
+ def testSetterString(self):
+ '''QByteArray[x] = pythonstring'''
+ obj = QByteArray('123456')
+ obj[1] = '0'
+ self.assertEqual(obj, QByteArray('103456'))
+
+ def testSetterStringLarge(self):
+ '''QByteArray[x] = pythonstring (larget than 1 char)'''
+ obj = QByteArray('123456')
+ obj[3] = 'abba'
+ self.assertEqual(obj, QByteArray('123abba56'))
+
+ def testSetterQByteArray(self):
+ '''QByteArray[x] = qbytearray'''
+ obj = QByteArray('123456')
+ obj[3] = QByteArray('array')
+ self.assertEqual(obj, QByteArray('123array56'))
+
+
+class QByteArrayOperatorAtSetterNegativeIndex(unittest.TestCase):
+ '''Test case for QByteArray[] - __setitem__ - for negative index'''
+
+ def testSetterNegativeIndex(self):
+ '''QByteArray[x] = string - negative index'''
+ obj = QByteArray('123456')
+ obj[-3] = 'array'
+ self.assertEqual(obj, QByteArray('123array56'))
+
+
+class QByteArrayOperatorAtSetterLargeIndex(unittest.TestCase):
+ '''Test case for QByteArray[] - __setitem__ - for 'overflown' index'''
+
+ def testSetterLargeIndexEmpty(self):
+ '''QByteArray[x] = somestring - Overflow index on empty string'''
+ # should pad with spaces if the index is larger
+ obj = QByteArray('')
+ obj[2] = 'a'
+ self.assertEqual(obj, QByteArray(' a'))
+
+ def testSetterLargeIndexNormal(self):
+ '''QByteArray[x] = somestring - Overflow index on normal string'''
+ # should pad with spaces if the index is larger
+ obj = QByteArray('mystring')
+ obj[10] = 'normal'
+ self.assertEqual(obj, QByteArray('mystring normal'))
+
+
+
if __name__ == '__main__':
unittest.main()