Fixed/implemented various QResources methods.

- data() is now exported and returns a Python read-only buffer object.
- (un)registerResourceData now accept buffers as arguments, and respects zeroes in the middle of data.
- Improved unit test.
This commit is contained in:
Hugo Parente Lima 2011-02-03 18:15:38 -02:00
commit 7b4968abab
5 changed files with 3568 additions and 26 deletions

View file

@ -4,27 +4,38 @@
import unittest
import os
from helper import adjust_filename
from PySide.QtCore import QFile, QIODevice
import resources_mc
class ResourcesUsage(unittest.TestCase):
'''Test case for resources usage'''
def setUp(self):
f = open(os.path.join(os.path.dirname(__file__), 'quoteEnUS.txt'))
self.text = f.read()
f.close()
def tearDown(self):
self.text = None
def testPhrase(self):
#Test loading of quote.txt resource
f = open(adjust_filename('quoteEnUS.txt', __file__))
orig = f.read()
f.close()
f = QFile(':/quote.txt')
f.open(QIODevice.ReadOnly|QIODevice.Text)
content = f.readAll()
copy = f.readAll()
f.close()
self.assertEqual(self.text, content)
self.assertEqual(orig, copy)
def testImage(self):
#Test loading of sample.png resource
f = open(adjust_filename('sample.png', __file__))
orig = f.read()
f.close()
f = QFile(':/sample.png')
f.open(QIODevice.ReadOnly)
copy = f.readAll()
f.close()
self.assertEqual(len(orig), len(copy))
self.assertEqual(orig, copy)
if __name__ == '__main__':
unittest.main()