diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-04-12 15:53:56 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:54:09 -0300 |
commit | c2c04ddd5107f0743441c9cf77c481254d168aae (patch) | |
tree | 0209a3ee7f8661976d2eca53cd6feb3d3bb50385 | |
parent | b1ab2a02604bca8abfb18a2f626643a52c5d4453 (diff) |
Fix bug 723 - "Missing QAbstractFileEngine.read and QAbstractFileEngine.readLine"
-rw-r--r-- | PySide/QtCore/typesystem_core.xml | 58 | ||||
-rw-r--r-- | tests/QtCore/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/QtCore/bug_723.py | 50 |
3 files changed, 104 insertions, 5 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml index eb3c45e15..cdaf97cbc 100644 --- a/PySide/QtCore/typesystem_core.xml +++ b/PySide/QtCore/typesystem_core.xml @@ -2070,7 +2070,13 @@ </inject-code> </add-function> </object-type> - <object-type name="QAbstractFileEngineHandler" /> + <object-type name="QAbstractFileEngineHandler"> + <modify-function signature="create(const QString↦)const"> + <modify-argument index="return"> + <define-ownership owner="c++"/> + </modify-argument> + </modify-function> + </object-type> <!-- <object-type name="QAbstractFileEngine::MapExtensionOption" /> --> <!-- <object-type name="QAbstractFileEngine::MapExtensionReturn" /> --> <!-- <object-type name="QAbstractFileEngine::UnMapExtensionOption" /> --> @@ -2113,10 +2119,52 @@ </inject-code> </modify-function> - <!-- ### See bug 723 --> - <modify-function signature="read(char*, qint64)" allow-thread="yes" remove="all" /> - <modify-function signature="readLine(char*, qint64)" allow-thread="yes" remove="all" /> - <!-- ### --> + <modify-function signature="read(char*, qint64)" allow-thread="yes"> + <inject-code class="target"> + QByteArray ba; + ba.resize(%2); + %CPPSELF.%FUNCTION_NAME(ba.data(), ba.size()); + %PYARG_0 = PyString_FromStringAndSize(ba.constData(), ba.size()); + </inject-code> + <modify-argument index="1"> + <remove-argument /> + </modify-argument> + <modify-argument index="return"> + <replace-type modified-type="PyObject"/> + <conversion-rule class="native"> + %RETURN_TYPE %out; + if (!PyString_Check(%PYARG_0)) { + %out = -1; + } else { + %out = PyString_GET_SIZE((PyObject*)%PYARG_0); + qstrncpy(%1, PyString_AS_STRING((PyObject*)%PYARG_0), %out + 1); + } + </conversion-rule> + </modify-argument> + </modify-function> + <modify-function signature="readLine(char*, qint64)" allow-thread="yes"> + <inject-code class="target"> + QByteArray ba; + ba.resize(%2); + %CPPSELF.%FUNCTION_NAME(ba.data(), ba.size()); + %PYARG_0 = PyString_FromStringAndSize(ba.constData(), ba.size()); + </inject-code> + <modify-argument index="1"> + <remove-argument /> + </modify-argument> + <modify-argument index="return"> + <replace-type modified-type="PyObject"/> + <conversion-rule class="native"> + %RETURN_TYPE %out; + if (!PyString_Check(%PYARG_0)) { + %out = -1; + } else { + %out = PyString_GET_SIZE((PyObject*)%PYARG_0); + qstrncpy(%1, PyString_AS_STRING((PyObject*)%PYARG_0), %out + 1); + } + </conversion-rule> + </modify-argument> + </modify-function> </object-type> <object-type name="QProcess"> <enum-type name="ExitStatus"/> diff --git a/tests/QtCore/CMakeLists.txt b/tests/QtCore/CMakeLists.txt index cbc9ee0b3..a7cd8b17d 100644 --- a/tests/QtCore/CMakeLists.txt +++ b/tests/QtCore/CMakeLists.txt @@ -8,6 +8,7 @@ PYSIDE_TEST(bug_515.py) PYSIDE_TEST(bug_656.py) PYSIDE_TEST(bug_699.py) PYSIDE_TEST(bug_706.py) +PYSIDE_TEST(bug_723.py) PYSIDE_TEST(bug_724.py) PYSIDE_TEST(blocking_signals_test.py) PYSIDE_TEST(child_event_test.py) diff --git a/tests/QtCore/bug_723.py b/tests/QtCore/bug_723.py new file mode 100644 index 000000000..68ebeab61 --- /dev/null +++ b/tests/QtCore/bug_723.py @@ -0,0 +1,50 @@ +import unittest +from PySide.QtCore import * + +class MyFileEngine (QAbstractFileEngine): + + def __init__(self): + QAbstractFileEngine.__init__(self) + self.contents = "Foo bar for the win!" + self.pos = 0 + + def open(self, mode): + return True + + def read(self, maxlen): + print "Reading... to return ", self.contents[self.pos:maxlen] + + if self.pos > len(self.contents): + return -1 + + res = self.contents[self.pos:maxlen] + self.pos += len(res) + return res + + def readLine(self, maxlen): + return self.contents[self.pos:maxlen] + +class MyFileEngineHandler (QAbstractFileEngineHandler): + + def create(self, fileName): + print "hey ho: ", fileName + if fileName.startswith("foo:/"): + return MyFileEngine() + return None + + +class TestBug723 (unittest.TestCase): + + def testIt(self): + fh = MyFileEngineHandler() + + f = QFile("foo:/bar") + + assert(f.open(QFile.ReadOnly | QFile.Text)) + contents = f.readAll() + self.assertEqual(contents, "Foo bar for the win!") + f.close() + + +if __name__ == '__main__': + unittest.main() |