summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-12-21 12:17:56 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-12-21 12:23:39 -0300
commitbb39c847d356831dae3bc7b09f3963b6ec4dd69b (patch)
tree7a56f835ddc9b5a61954e4c7b6805469c301ad03
parent14a5405837736160ca94a2707916e1bacced39cb (diff)
downloadpyside-bb39c847d356831dae3bc7b09f3963b6ec4dd69b.tar.gz
pyside-bb39c847d356831dae3bc7b09f3963b6ec4dd69b.tar.xz
pyside-bb39c847d356831dae3bc7b09f3963b6ec4dd69b.zip
Fixed global functions from QT_TR_NOOP and QT_TRANSLATE_NOOP family.
These function just return one of their arguments as result, and the buggy implementation was forgetting to increment the reference count for the returned object. A new unit test was added. Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Renato Ara├║jo <renato.filho@openbossa.org>
-rw-r--r--PySide/QtCore/typesystem_core.xml30
-rw-r--r--PySide/typesystem_templates.xml6
-rw-r--r--tests/QtCore/CMakeLists.txt1
-rw-r--r--tests/QtCore/tr_noop_test.py48
4 files changed, 75 insertions, 10 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index 76bcaeb..e416e57 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -2895,20 +2895,30 @@
</inject-code>
</add-function>
- <add-function signature="QT_TR_NOOP(const char*)" return-type="PyString*">
- <inject-code class="target" position="beginning">(void)%1;%PYARG_0 = %PYARG_1;</inject-code>
+ <add-function signature="QT_TR_NOOP(PyObject)" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="return_argument"><replace from="#" to="1" /></insert-template>
+ </inject-code>
</add-function>
- <add-function signature="QT_TR_NOOP_UTF8(const char*)" return-type="PyString*">
- <inject-code class="target" position="beginning">(void)%1;%PYARG_0 = %PYARG_1;</inject-code>
+ <add-function signature="QT_TR_NOOP_UTF8(PyObject)" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="return_argument"><replace from="#" to="1" /></insert-template>
+ </inject-code>
</add-function>
- <add-function signature="QT_TRANSLATE_NOOP(const char*, const char*)" return-type="PyString*">
- <inject-code class="target" position="beginning">(void)%1;(void)%2;%PYARG_0 = %PYARG_2;</inject-code>
+ <add-function signature="QT_TRANSLATE_NOOP(PyObject, PyObject)" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="return_argument"><replace from="#" to="2" /></insert-template>
+ </inject-code>
</add-function>
- <add-function signature="QT_TRANSLATE_NOOP3(const char*, const char*, const char*)" return-type="PyString*">
- <inject-code class="target" position="beginning">(void)%1;(void)%2;(void)%3;%PYARG_0 = %PYARG_2;</inject-code>
+ <add-function signature="QT_TRANSLATE_NOOP3(PyObject, PyObject, PyObject)" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="return_argument"><replace from="#" to="2" /></insert-template>
+ </inject-code>
</add-function>
- <add-function signature="QT_TRANSLATE_NOOP_UTF8(const char*)" return-type="PyString*">
- <inject-code class="target" position="beginning">(void)%1;%PYARG_0 = %PYARG_1;</inject-code>
+ <add-function signature="QT_TRANSLATE_NOOP_UTF8(PyObject)" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="return_argument"><replace from="#" to="1" /></insert-template>
+ </inject-code>
</add-function>
<inject-code class="native" position="beginning">
diff --git a/PySide/typesystem_templates.xml b/PySide/typesystem_templates.xml
index 9d39bb4..4604fda 100644
--- a/PySide/typesystem_templates.xml
+++ b/PySide/typesystem_templates.xml
@@ -238,5 +238,11 @@
return %CONVERTTOPYTHON[%TRANSPOSED_TYPE](%CPPSELF.transposed());
</template>
+ <!-- Replace '#' for the argument number you want. -->
+ <template name="return_argument">
+ Py_INCREF(%PYARG_#);
+ %PYARG_0 = %PYARG_#;
+ </template>
+
</typesystem>
diff --git a/tests/QtCore/CMakeLists.txt b/tests/QtCore/CMakeLists.txt
index b5bffe7..8ec3cdd 100644
--- a/tests/QtCore/CMakeLists.txt
+++ b/tests/QtCore/CMakeLists.txt
@@ -71,6 +71,7 @@ PYSIDE_TEST(setprop_on_ctor_test.py)
PYSIDE_TEST(static_method_test.py)
PYSIDE_TEST(static_protected_methods_test.py)
PYSIDE_TEST(thread_signals_test.py)
+PYSIDE_TEST(tr_noop_test.py)
PYSIDE_TEST(translation_test.py)
PYSIDE_TEST(unaryoperator_test.py)
PYSIDE_TEST(unicode_test.py)
diff --git a/tests/QtCore/tr_noop_test.py b/tests/QtCore/tr_noop_test.py
new file mode 100644
index 0000000..92029e0
--- /dev/null
+++ b/tests/QtCore/tr_noop_test.py
@@ -0,0 +1,48 @@
+import unittest
+
+import sys
+from PySide.QtCore import QT_TR_NOOP, QT_TR_NOOP_UTF8
+from PySide.QtCore import QT_TRANSLATE_NOOP, QT_TRANSLATE_NOOP3, QT_TRANSLATE_NOOP_UTF8
+
+class QtTrNoopTest(unittest.TestCase):
+
+ def setUp(self):
+ self.txt = 'Cthulhu fhtag!'
+
+ def tearDown(self):
+ del self.txt
+
+ def testQtTrNoop(self):
+ refcnt = sys.getrefcount(self.txt)
+ result = QT_TR_NOOP(self.txt)
+ self.assertEqual(result, self.txt)
+ self.assertEqual(sys.getrefcount(result), refcnt + 1)
+
+ def testQtTrNoopUtf8(self):
+ refcnt = sys.getrefcount(self.txt)
+ result = QT_TR_NOOP_UTF8(self.txt)
+ self.assertEqual(result, self.txt)
+ self.assertEqual(sys.getrefcount(result), refcnt + 1)
+
+ def testQtTranslateNoop(self):
+ refcnt = sys.getrefcount(self.txt)
+ result = QT_TRANSLATE_NOOP(None, self.txt)
+ self.assertEqual(result, self.txt)
+ self.assertEqual(sys.getrefcount(result), refcnt + 1)
+
+ def testQtTranslateNoopUtf8(self):
+ refcnt = sys.getrefcount(self.txt)
+ result = QT_TRANSLATE_NOOP_UTF8(self.txt)
+ self.assertEqual(result, self.txt)
+ self.assertEqual(sys.getrefcount(result), refcnt + 1)
+
+ def testQtTranslateNoop3(self):
+ refcnt = sys.getrefcount(self.txt)
+ result = QT_TRANSLATE_NOOP3(None, self.txt, None)
+ self.assertEqual(result, self.txt)
+ self.assertEqual(sys.getrefcount(result), refcnt + 1)
+
+
+if __name__ == '__main__':
+ unittest.main()
+