##// END OF EJS Templates
updated test to new private module of pythonqt...
florianlink -
r103:e373024c904b
parent child
Show More
@@ -1,585 +1,585
1 /*
1 /*
2 *
2 *
3 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
3 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
4 *
4 *
5 * This library is free software; you can redistribute it and/or
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
8 * version 2.1 of the License, or (at your option) any later version.
9 *
9 *
10 * This library is distributed in the hope that it will be useful,
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
13 * Lesser General Public License for more details.
14 *
14 *
15 * Further, this software is distributed without any warranty that it is
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
20 * other software, or any other product whatsoever.
21 *
21 *
22 * You should have received a copy of the GNU Lesser General Public
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
25 *
26 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
26 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
27 * 28359 Bremen, Germany or:
27 * 28359 Bremen, Germany or:
28 *
28 *
29 * http://www.mevis.de
29 * http://www.mevis.de
30 *
30 *
31 */
31 */
32
32
33 //----------------------------------------------------------------------------------
33 //----------------------------------------------------------------------------------
34 /*!
34 /*!
35 // \file PythonQtTests.cpp
35 // \file PythonQtTests.cpp
36 // \author Florian Link
36 // \author Florian Link
37 // \author Last changed by $Author: florian $
37 // \author Last changed by $Author: florian $
38 // \date 2006-05
38 // \date 2006-05
39 */
39 */
40 //----------------------------------------------------------------------------------
40 //----------------------------------------------------------------------------------
41
41
42 #include "PythonQtTests.h"
42 #include "PythonQtTests.h"
43
43
44 void PythonQtTestSlotCalling::initTestCase()
44 void PythonQtTestSlotCalling::initTestCase()
45 {
45 {
46 _helper = new PythonQtTestSlotCallingHelper(this);
46 _helper = new PythonQtTestSlotCallingHelper(this);
47 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
47 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
48 main.evalScript("import PythonQt");
48 main.evalScript("import PythonQt");
49 PythonQt::self()->addObject(main, "obj", _helper);
49 PythonQt::self()->addObject(main, "obj", _helper);
50 }
50 }
51
51
52 void PythonQtTestSlotCalling::init() {
52 void PythonQtTestSlotCalling::init() {
53
53
54 }
54 }
55
55
56
56
57 void* polymorphic_ClassB_Handler(const void* ptr, char** className) {
57 void* polymorphic_ClassB_Handler(const void* ptr, char** className) {
58 ClassB* o = (ClassB*)ptr;
58 ClassB* o = (ClassB*)ptr;
59 if (o->type()==2) {
59 if (o->type()==2) {
60 *className = "ClassB";
60 *className = "ClassB";
61 return (ClassB*)o;
61 return (ClassB*)o;
62 }
62 }
63 if (o->type()==3) {
63 if (o->type()==3) {
64 *className = "ClassC";
64 *className = "ClassC";
65 return (ClassC*)o;
65 return (ClassC*)o;
66 }
66 }
67 if (o->type()==4) {
67 if (o->type()==4) {
68 *className = "ClassD";
68 *className = "ClassD";
69 return (ClassD*)o;
69 return (ClassD*)o;
70 }
70 }
71 return NULL;
71 return NULL;
72 }
72 }
73
73
74 void PythonQtTestSlotCalling::testInheritance() {
74 void PythonQtTestSlotCalling::testInheritance() {
75 PythonQt::self()->registerCPPClass("ClassA",NULL,NULL, PythonQtCreateObject<ClassAWrapper>);
75 PythonQt::self()->registerCPPClass("ClassA",NULL,NULL, PythonQtCreateObject<ClassAWrapper>);
76 PythonQt::self()->registerCPPClass("ClassB",NULL,NULL, PythonQtCreateObject<ClassBWrapper>);
76 PythonQt::self()->registerCPPClass("ClassB",NULL,NULL, PythonQtCreateObject<ClassBWrapper>);
77 PythonQt::self()->registerCPPClass("ClassC",NULL,NULL, PythonQtCreateObject<ClassCWrapper>);
77 PythonQt::self()->registerCPPClass("ClassC",NULL,NULL, PythonQtCreateObject<ClassCWrapper>);
78 PythonQt::self()->addParentClass("ClassC", "ClassA", PythonQtUpcastingOffset<ClassC,ClassA>());
78 PythonQt::self()->addParentClass("ClassC", "ClassA", PythonQtUpcastingOffset<ClassC,ClassA>());
79 PythonQt::self()->addParentClass("ClassC", "ClassB", PythonQtUpcastingOffset<ClassC,ClassB>());
79 PythonQt::self()->addParentClass("ClassC", "ClassB", PythonQtUpcastingOffset<ClassC,ClassB>());
80 PythonQt::self()->registerClass(&ClassD::staticMetaObject, NULL, PythonQtCreateObject<ClassDWrapper>);
80 PythonQt::self()->registerClass(&ClassD::staticMetaObject, NULL, PythonQtCreateObject<ClassDWrapper>);
81 PythonQt::self()->addParentClass("ClassD", "ClassA", PythonQtUpcastingOffset<ClassD,ClassA>());
81 PythonQt::self()->addParentClass("ClassD", "ClassA", PythonQtUpcastingOffset<ClassD,ClassA>());
82 PythonQt::self()->addParentClass("ClassD", "ClassB", PythonQtUpcastingOffset<ClassD,ClassB>());
82 PythonQt::self()->addParentClass("ClassD", "ClassB", PythonQtUpcastingOffset<ClassD,ClassB>());
83
83
84 PythonQtObjectPtr classA = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassA");
84 PythonQtObjectPtr classA = PythonQt::self()->getMainModule().getVariable("PythonQt.private.ClassA");
85 PythonQtObjectPtr classB = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassB");
85 PythonQtObjectPtr classB = PythonQt::self()->getMainModule().getVariable("PythonQt.private.ClassB");
86 PythonQtObjectPtr classC = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassC");
86 PythonQtObjectPtr classC = PythonQt::self()->getMainModule().getVariable("PythonQt.private.ClassC");
87 PythonQtObjectPtr classD = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassD");
87 PythonQtObjectPtr classD = PythonQt::self()->getMainModule().getVariable("PythonQt.private.ClassD");
88 QVERIFY(classA);
88 QVERIFY(classA);
89 QVERIFY(classB);
89 QVERIFY(classB);
90 QVERIFY(classC);
90 QVERIFY(classC);
91 QVERIFY(classD);
91 QVERIFY(classD);
92
92
93 QVERIFY(_helper->runScript("a = PythonQt.ClassA();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n"));
93 QVERIFY(_helper->runScript("a = PythonQt.private.ClassA();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n"));
94 QEXPECT_FAIL("", "ClassB can not be converted to ClassA", Continue);
94 QEXPECT_FAIL("", "ClassB can not be converted to ClassA", Continue);
95 QVERIFY(_helper->runScript("a = PythonQt.ClassB();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n"));
95 QVERIFY(_helper->runScript("a = PythonQt.private.ClassB();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n"));
96 QVERIFY(_helper->runScript("a = PythonQt.ClassC();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n"));
96 QVERIFY(_helper->runScript("a = PythonQt.private.ClassC();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n"));
97 QVERIFY(_helper->runScript("a = PythonQt.ClassD();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n"));
97 QVERIFY(_helper->runScript("a = PythonQt.private.ClassD();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n"));
98
98
99 QEXPECT_FAIL("", "ClassA can not be converted to ClassB", Continue);
99 QEXPECT_FAIL("", "ClassA can not be converted to ClassB", Continue);
100 QVERIFY(_helper->runScript("a = PythonQt.ClassA();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n"));
100 QVERIFY(_helper->runScript("a = PythonQt.private.ClassA();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n"));
101 QVERIFY(_helper->runScript("a = PythonQt.ClassB();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n"));
101 QVERIFY(_helper->runScript("a = PythonQt.private.ClassB();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n"));
102 QVERIFY(_helper->runScript("a = PythonQt.ClassC();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n"));
102 QVERIFY(_helper->runScript("a = PythonQt.private.ClassC();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n"));
103 QVERIFY(_helper->runScript("a = PythonQt.ClassD();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n"));
103 QVERIFY(_helper->runScript("a = PythonQt.private.ClassD();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n"));
104
104
105 QEXPECT_FAIL("", "ClassA can not be converted to ClassC", Continue);
105 QEXPECT_FAIL("", "ClassA can not be converted to ClassC", Continue);
106 QVERIFY(_helper->runScript("a = PythonQt.ClassA();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n"));
106 QVERIFY(_helper->runScript("a = PythonQt.private.ClassA();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n"));
107 QEXPECT_FAIL("", "ClassB can not be converted to ClassC", Continue);
107 QEXPECT_FAIL("", "ClassB can not be converted to ClassC", Continue);
108 QVERIFY(_helper->runScript("a = PythonQt.ClassB();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n"));
108 QVERIFY(_helper->runScript("a = PythonQt.private.ClassB();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n"));
109 QVERIFY(_helper->runScript("a = PythonQt.ClassC();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n"));
109 QVERIFY(_helper->runScript("a = PythonQt.private.ClassC();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n"));
110 QEXPECT_FAIL("", "ClassD can not be converted to ClassC", Continue);
110 QEXPECT_FAIL("", "ClassD can not be converted to ClassC", Continue);
111 QVERIFY(_helper->runScript("a = PythonQt.ClassD();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n"));
111 QVERIFY(_helper->runScript("a = PythonQt.private.ClassD();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n"));
112
112
113 QVERIFY(_helper->runScript("if type(obj.createClassA())==PythonQt.ClassA: obj.setPassed();\n"));
113 QVERIFY(_helper->runScript("if type(obj.createClassA())==PythonQt.private.ClassA: obj.setPassed();\n"));
114 QVERIFY(_helper->runScript("if type(obj.createClassB())==PythonQt.ClassB: obj.setPassed();\n"));
114 QVERIFY(_helper->runScript("if type(obj.createClassB())==PythonQt.private.ClassB: obj.setPassed();\n"));
115 QVERIFY(_helper->runScript("if type(obj.createClassCAsA())==PythonQt.ClassA: obj.setPassed();\n"));
115 QVERIFY(_helper->runScript("if type(obj.createClassCAsA())==PythonQt.private.ClassA: obj.setPassed();\n"));
116 QVERIFY(_helper->runScript("if type(obj.createClassCAsB())==PythonQt.ClassB: obj.setPassed();\n"));
116 QVERIFY(_helper->runScript("if type(obj.createClassCAsB())==PythonQt.private.ClassB: obj.setPassed();\n"));
117 QVERIFY(_helper->runScript("if type(obj.createClassD())==PythonQt.ClassD: obj.setPassed();\n"));
117 QVERIFY(_helper->runScript("if type(obj.createClassD())==PythonQt.private.ClassD: obj.setPassed();\n"));
118 QVERIFY(_helper->runScript("if type(obj.createClassDAsA())==PythonQt.ClassA: obj.setPassed();\n"));
118 QVERIFY(_helper->runScript("if type(obj.createClassDAsA())==PythonQt.private.ClassA: obj.setPassed();\n"));
119 QVERIFY(_helper->runScript("if type(obj.createClassDAsB())==PythonQt.ClassB: obj.setPassed();\n"));
119 QVERIFY(_helper->runScript("if type(obj.createClassDAsB())==PythonQt.private.ClassB: obj.setPassed();\n"));
120
120
121 PythonQt::self()->addPolymorphicHandler("ClassB", polymorphic_ClassB_Handler);
121 PythonQt::self()->addPolymorphicHandler("ClassB", polymorphic_ClassB_Handler);
122
122
123 QVERIFY(_helper->runScript("if type(obj.getClassBPtr(obj.createClassB()))==PythonQt.ClassB: obj.setPassed();\n"));
123 QVERIFY(_helper->runScript("if type(obj.getClassBPtr(obj.createClassB()))==PythonQt.private.ClassB: obj.setPassed();\n"));
124 QVERIFY(_helper->runScript("if type(obj.createClassCAsB())==PythonQt.ClassC: obj.setPassed();\n"));
124 QVERIFY(_helper->runScript("if type(obj.createClassCAsB())==PythonQt.private.ClassC: obj.setPassed();\n"));
125 QVERIFY(_helper->runScript("if type(obj.createClassDAsB())==PythonQt.ClassD: obj.setPassed();\n"));
125 QVERIFY(_helper->runScript("if type(obj.createClassDAsB())==PythonQt.private.ClassD: obj.setPassed();\n"));
126
126
127 }
127 }
128
128
129 void PythonQtTestSlotCalling::testAutoConversion() {
129 void PythonQtTestSlotCalling::testAutoConversion() {
130 QVERIFY(_helper->runScript("if obj.setAutoConvertColor(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red): obj.setPassed();\n"));
130 QVERIFY(_helper->runScript("if obj.setAutoConvertColor(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red): obj.setPassed();\n"));
131 QVERIFY(_helper->runScript("if obj.setAutoConvertBrush(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QBrush(PythonQt.QtCore.Qt.red): obj.setPassed();\n"));
131 QVERIFY(_helper->runScript("if obj.setAutoConvertBrush(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QBrush(PythonQt.QtCore.Qt.red): obj.setPassed();\n"));
132 QVERIFY(_helper->runScript("if obj.setAutoConvertPen(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QPen(PythonQt.QtCore.Qt.red): obj.setPassed();\n"));
132 QVERIFY(_helper->runScript("if obj.setAutoConvertPen(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QPen(PythonQt.QtCore.Qt.red): obj.setPassed();\n"));
133 QVERIFY(_helper->runScript("if obj.setAutoConvertBrush(PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red))==PythonQt.Qt.QBrush(PythonQt.QtCore.Qt.red): obj.setPassed();\n"));
133 QVERIFY(_helper->runScript("if obj.setAutoConvertBrush(PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red))==PythonQt.Qt.QBrush(PythonQt.QtCore.Qt.red): obj.setPassed();\n"));
134 QVERIFY(_helper->runScript("if obj.setAutoConvertPen(PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red))==PythonQt.Qt.QPen(PythonQt.QtCore.Qt.red): obj.setPassed();\n"));
134 QVERIFY(_helper->runScript("if obj.setAutoConvertPen(PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red))==PythonQt.Qt.QPen(PythonQt.QtCore.Qt.red): obj.setPassed();\n"));
135 QVERIFY(_helper->runScript("if obj.setAutoConvertCursor(PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor)).shape()==PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape(): obj.setPassed();\n"));
135 QVERIFY(_helper->runScript("if obj.setAutoConvertCursor(PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor)).shape()==PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape(): obj.setPassed();\n"));
136 QVERIFY(_helper->runScript("if obj.setAutoConvertCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape()==PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape(): obj.setPassed();\n"));
136 QVERIFY(_helper->runScript("if obj.setAutoConvertCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape()==PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape(): obj.setPassed();\n"));
137 }
137 }
138
138
139 void PythonQtTestSlotCalling::testNoArgSlotCall()
139 void PythonQtTestSlotCalling::testNoArgSlotCall()
140 {
140 {
141 QVERIFY(_helper->runScript("obj.testNoArg(); obj.setPassed();\n"));
141 QVERIFY(_helper->runScript("obj.testNoArg(); obj.setPassed();\n"));
142 }
142 }
143
143
144 void PythonQtTestSlotCalling::testOverloadedCall()
144 void PythonQtTestSlotCalling::testOverloadedCall()
145 {
145 {
146 QVERIFY(_helper->runScript("obj.overload(False); obj.setPassed();\n", 0));
146 QVERIFY(_helper->runScript("obj.overload(False); obj.setPassed();\n", 0));
147 QVERIFY(_helper->runScript("obj.overload(True); obj.setPassed();\n", 0));
147 QVERIFY(_helper->runScript("obj.overload(True); obj.setPassed();\n", 0));
148 QVERIFY(_helper->runScript("obj.overload(12.5); obj.setPassed();\n", 1));
148 QVERIFY(_helper->runScript("obj.overload(12.5); obj.setPassed();\n", 1));
149 QVERIFY(_helper->runScript("obj.overload(12); obj.setPassed();\n", 2));
149 QVERIFY(_helper->runScript("obj.overload(12); obj.setPassed();\n", 2));
150 QVERIFY(_helper->runScript("obj.overload('test'); obj.setPassed();\n", 3));
150 QVERIFY(_helper->runScript("obj.overload('test'); obj.setPassed();\n", 3));
151 QVERIFY(_helper->runScript("obj.overload(u'test'); obj.setPassed();\n", 3));
151 QVERIFY(_helper->runScript("obj.overload(u'test'); obj.setPassed();\n", 3));
152 QVERIFY(_helper->runScript("obj.overload(('test','test2')); obj.setPassed();\n", 4));
152 QVERIFY(_helper->runScript("obj.overload(('test','test2')); obj.setPassed();\n", 4));
153 QVERIFY(_helper->runScript("obj.overload(obj); obj.setPassed();\n", 5));
153 QVERIFY(_helper->runScript("obj.overload(obj); obj.setPassed();\n", 5));
154 QVERIFY(_helper->runScript("obj.overload(12,13); obj.setPassed();\n", 6));
154 QVERIFY(_helper->runScript("obj.overload(12,13); obj.setPassed();\n", 6));
155 }
155 }
156
156
157 void PythonQtTestSlotCalling::testPyObjectSlotCall()
157 void PythonQtTestSlotCalling::testPyObjectSlotCall()
158 {
158 {
159 QVERIFY(_helper->runScript("if obj.getPyObject(PythonQt)==PythonQt: obj.setPassed();\n"));
159 QVERIFY(_helper->runScript("if obj.getPyObject(PythonQt)==PythonQt: obj.setPassed();\n"));
160 QVERIFY(_helper->runScript("if obj.getPyObject('Hello')=='Hello': obj.setPassed();\n"));
160 QVERIFY(_helper->runScript("if obj.getPyObject('Hello')=='Hello': obj.setPassed();\n"));
161 QVERIFY(_helper->runScript("if obj.getPyObjectFromVariant(PythonQt)==PythonQt: obj.setPassed();\n"));
161 QVERIFY(_helper->runScript("if obj.getPyObjectFromVariant(PythonQt)==PythonQt: obj.setPassed();\n"));
162 QVERIFY(_helper->runScript("if obj.getPyObjectFromVariant2(PythonQt)==PythonQt: obj.setPassed();\n"));
162 QVERIFY(_helper->runScript("if obj.getPyObjectFromVariant2(PythonQt)==PythonQt: obj.setPassed();\n"));
163 // QVERIFY(_helper->runScript("if obj.getPyObjectFromPtr(PythonQt)==PythonQt: obj.setPassed();\n"));
163 // QVERIFY(_helper->runScript("if obj.getPyObjectFromPtr(PythonQt)==PythonQt: obj.setPassed();\n"));
164 }
164 }
165
165
166 void PythonQtTestSlotCalling::testCPPSlotCalls()
166 void PythonQtTestSlotCalling::testCPPSlotCalls()
167 {
167 {
168 // test QColor compare operation
168 // test QColor compare operation
169 QVERIFY(_helper->runScript("if PythonQt.QtGui.QColor(1,2,3)==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();obj.testNoArg()\n"));
169 QVERIFY(_helper->runScript("if PythonQt.QtGui.QColor(1,2,3)==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();obj.testNoArg()\n"));
170 QVERIFY(_helper->runScript("if PythonQt.QtGui.QColor(1,2,3)!=PythonQt.QtGui.QColor(3,2,1): obj.setPassed();obj.testNoArg()\n"));
170 QVERIFY(_helper->runScript("if PythonQt.QtGui.QColor(1,2,3)!=PythonQt.QtGui.QColor(3,2,1): obj.setPassed();obj.testNoArg()\n"));
171
171
172 // test passing/returning QColors
172 // test passing/returning QColors
173 QVERIFY(_helper->runScript("if obj.getQColor1(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n"));
173 QVERIFY(_helper->runScript("if obj.getQColor1(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n"));
174 QVERIFY(_helper->runScript("if obj.getQColor2(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n"));
174 QVERIFY(_helper->runScript("if obj.getQColor2(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n"));
175 QVERIFY(_helper->runScript("if obj.getQColor3(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n"));
175 QVERIFY(_helper->runScript("if obj.getQColor3(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n"));
176 QVERIFY(_helper->runScript("if obj.getQColor4(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n"));
176 QVERIFY(_helper->runScript("if obj.getQColor4(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n"));
177 QVERIFY(_helper->runScript("if obj.getQColor5()==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n"));
177 QVERIFY(_helper->runScript("if obj.getQColor5()==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n"));
178 }
178 }
179
179
180 void PythonQtTestSlotCalling::testPODSlotCalls()
180 void PythonQtTestSlotCalling::testPODSlotCalls()
181 {
181 {
182 QVERIFY(_helper->runScript("if obj.getBool(False)==False: obj.setPassed();\n"));
182 QVERIFY(_helper->runScript("if obj.getBool(False)==False: obj.setPassed();\n"));
183 QVERIFY(_helper->runScript("if obj.getBool(True)==True: obj.setPassed();\n"));
183 QVERIFY(_helper->runScript("if obj.getBool(True)==True: obj.setPassed();\n"));
184 QVERIFY(_helper->runScript("if obj.getInt(-42)==-42: obj.setPassed();\n"));
184 QVERIFY(_helper->runScript("if obj.getInt(-42)==-42: obj.setPassed();\n"));
185 QVERIFY(_helper->runScript("if obj.getUInt(42)==42: obj.setPassed();\n"));
185 QVERIFY(_helper->runScript("if obj.getUInt(42)==42: obj.setPassed();\n"));
186 QVERIFY(_helper->runScript("if obj.getShort(-43)==-43: obj.setPassed();\n"));
186 QVERIFY(_helper->runScript("if obj.getShort(-43)==-43: obj.setPassed();\n"));
187 QVERIFY(_helper->runScript("if obj.getUShort(43)==43: obj.setPassed();\n"));
187 QVERIFY(_helper->runScript("if obj.getUShort(43)==43: obj.setPassed();\n"));
188 QVERIFY(_helper->runScript("if obj.getChar(-12)==-12: obj.setPassed();\n"));
188 QVERIFY(_helper->runScript("if obj.getChar(-12)==-12: obj.setPassed();\n"));
189 QVERIFY(_helper->runScript("if obj.getUChar(12)==12: obj.setPassed();\n"));
189 QVERIFY(_helper->runScript("if obj.getUChar(12)==12: obj.setPassed();\n"));
190 QVERIFY(_helper->runScript("if obj.getLong(-256*256*256)==-256*256*256: obj.setPassed();\n"));
190 QVERIFY(_helper->runScript("if obj.getLong(-256*256*256)==-256*256*256: obj.setPassed();\n"));
191 QVERIFY(_helper->runScript("if obj.getULong(256*256*256)==256*256*256: obj.setPassed();\n"));
191 QVERIFY(_helper->runScript("if obj.getULong(256*256*256)==256*256*256: obj.setPassed();\n"));
192 QVERIFY(_helper->runScript("if obj.getLongLong(-42)==-42: obj.setPassed();\n"));
192 QVERIFY(_helper->runScript("if obj.getLongLong(-42)==-42: obj.setPassed();\n"));
193 QVERIFY(_helper->runScript("if obj.getULongLong(42)==42: obj.setPassed();\n"));
193 QVERIFY(_helper->runScript("if obj.getULongLong(42)==42: obj.setPassed();\n"));
194 QVERIFY(_helper->runScript("if obj.getQChar(4096)==4096: obj.setPassed();\n"));
194 QVERIFY(_helper->runScript("if obj.getQChar(4096)==4096: obj.setPassed();\n"));
195 QVERIFY(_helper->runScript("if obj.getDouble(47.12)==47.12: obj.setPassed();\n"));
195 QVERIFY(_helper->runScript("if obj.getDouble(47.12)==47.12: obj.setPassed();\n"));
196 QVERIFY(_helper->runScript("if abs(obj.getFloat(47.11)-47.11)<0.01: obj.setPassed();\n"));
196 QVERIFY(_helper->runScript("if abs(obj.getFloat(47.11)-47.11)<0.01: obj.setPassed();\n"));
197 QVERIFY(_helper->runScript("if obj.getQString('testStr')=='testStr': obj.setPassed();\n"));
197 QVERIFY(_helper->runScript("if obj.getQString('testStr')=='testStr': obj.setPassed();\n"));
198 QVERIFY(_helper->runScript("if obj.getQString('')=='': obj.setPassed();\n"));
198 QVERIFY(_helper->runScript("if obj.getQString('')=='': obj.setPassed();\n"));
199 QVERIFY(_helper->runScript("if obj.getQStringList(('test','test2'))==('test','test2'): obj.setPassed();\n"));
199 QVERIFY(_helper->runScript("if obj.getQStringList(('test','test2'))==('test','test2'): obj.setPassed();\n"));
200 }
200 }
201
201
202 void PythonQtTestSlotCalling::testQVariantSlotCalls()
202 void PythonQtTestSlotCalling::testQVariantSlotCalls()
203 {
203 {
204 QVERIFY(_helper->runScript("if obj.getQVariant(-42)==-42: obj.setPassed();\n"));
204 QVERIFY(_helper->runScript("if obj.getQVariant(-42)==-42: obj.setPassed();\n"));
205 QVERIFY(_helper->runScript("if obj.getQVariant('testStr')=='testStr': obj.setPassed();\n"));
205 QVERIFY(_helper->runScript("if obj.getQVariant('testStr')=='testStr': obj.setPassed();\n"));
206 QVERIFY(_helper->runScript("if obj.getQVariant(('test','test2'))==('test','test2'): obj.setPassed();\n"));
206 QVERIFY(_helper->runScript("if obj.getQVariant(('test','test2'))==('test','test2'): obj.setPassed();\n"));
207 QVERIFY(_helper->runScript("if obj.getQVariant(('test',12, 47.11))==('test',12, 47.11): obj.setPassed();\n"));
207 QVERIFY(_helper->runScript("if obj.getQVariant(('test',12, 47.11))==('test',12, 47.11): obj.setPassed();\n"));
208 QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n"));
208 QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n"));
209 QEXPECT_FAIL("", "Testing to pass a map and compare with a different map", Continue);
209 QEXPECT_FAIL("", "Testing to pass a map and compare with a different map", Continue);
210 QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla2','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n"));
210 QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla2','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n"));
211 QVERIFY(_helper->runScript("if obj.getQVariant(obj)==obj: obj.setPassed();\n"));
211 QVERIFY(_helper->runScript("if obj.getQVariant(obj)==obj: obj.setPassed();\n"));
212 }
212 }
213
213
214 void PythonQtTestSlotCalling::testObjectSlotCalls()
214 void PythonQtTestSlotCalling::testObjectSlotCalls()
215 {
215 {
216 QVERIFY(_helper->runScript("if obj.getQObject(obj)==obj: obj.setPassed();\n"));
216 QVERIFY(_helper->runScript("if obj.getQObject(obj)==obj: obj.setPassed();\n"));
217 QVERIFY(_helper->runScript("if obj.getTestObject(obj)==obj: obj.setPassed();\n"));
217 QVERIFY(_helper->runScript("if obj.getTestObject(obj)==obj: obj.setPassed();\n"));
218 QVERIFY(_helper->runScript("if obj.getNewObject().className()=='PythonQtTestSlotCallingHelper': obj.setPassed();\n"));
218 QVERIFY(_helper->runScript("if obj.getNewObject().className()=='PythonQtTestSlotCallingHelper': obj.setPassed();\n"));
219 QEXPECT_FAIL("", "Testing to pass a QObject when another object was expected", Continue);
219 QEXPECT_FAIL("", "Testing to pass a QObject when another object was expected", Continue);
220 QVERIFY(_helper->runScript("if obj.getQWidget(obj)==obj: obj.setPassed();\n"));
220 QVERIFY(_helper->runScript("if obj.getQWidget(obj)==obj: obj.setPassed();\n"));
221 }
221 }
222
222
223 void PythonQtTestSlotCalling::testCppFactory()
223 void PythonQtTestSlotCalling::testCppFactory()
224 {
224 {
225 PythonQtTestCppFactory* f = new PythonQtTestCppFactory;
225 PythonQtTestCppFactory* f = new PythonQtTestCppFactory;
226 PythonQt::self()->addInstanceDecorators(new PQCppObjectDecorator);
226 PythonQt::self()->addInstanceDecorators(new PQCppObjectDecorator);
227 // do not register, since we want to know if that works as well
227 // do not register, since we want to know if that works as well
228 //qRegisterMetaType<PQCppObjectNoWrap>("PQCppObjectNoWrap");
228 //qRegisterMetaType<PQCppObjectNoWrap>("PQCppObjectNoWrap");
229 PythonQt::self()->addDecorators(new PQCppObjectNoWrapDecorator);
229 PythonQt::self()->addDecorators(new PQCppObjectNoWrapDecorator);
230
230
231 PythonQt::self()->addWrapperFactory(f);
231 PythonQt::self()->addWrapperFactory(f);
232 QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getHeight()==12: obj.setPassed();\n"));
232 QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getHeight()==12: obj.setPassed();\n"));
233 QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getH()==12: obj.setPassed();\n"));
233 QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getH()==12: obj.setPassed();\n"));
234 QVERIFY(_helper->runScript("pq1 = obj.createPQCppObject(12);\n"
234 QVERIFY(_helper->runScript("pq1 = obj.createPQCppObject(12);\n"
235 "pq2 = obj.createPQCppObject(13);\n"
235 "pq2 = obj.createPQCppObject(13);\n"
236 "pq3 = obj.getPQCppObject(pq1);\n"
236 "pq3 = obj.getPQCppObject(pq1);\n"
237 "pq4 = obj.getPQCppObject(pq2);\n"
237 "pq4 = obj.getPQCppObject(pq2);\n"
238 "if pq3.getHeight()==12 and pq4.getHeight()==13: obj.setPassed();\n"
238 "if pq3.getHeight()==12 and pq4.getHeight()==13: obj.setPassed();\n"
239 ));
239 ));
240
240
241 QVERIFY(_helper->runScript("if obj.createPQCppObjectNoWrap(12).getH()==12: obj.setPassed();\n"));
241 QVERIFY(_helper->runScript("if obj.createPQCppObjectNoWrap(12).getH()==12: obj.setPassed();\n"));
242
242
243 QVERIFY(_helper->runScript("if obj.getPQCppObjectNoWrapAsValue().getH()==47: obj.setPassed();\n"));
243 QVERIFY(_helper->runScript("if obj.getPQCppObjectNoWrapAsValue().getH()==47: obj.setPassed();\n"));
244
244
245 qRegisterMetaType<PQUnknownButRegisteredValueObject>("PQUnknownButRegisteredValueObject");
245 qRegisterMetaType<PQUnknownButRegisteredValueObject>("PQUnknownButRegisteredValueObject");
246 QVERIFY(_helper->runScript("a = obj.getUnknownButRegisteredValueObjectAsPtr();print a;\nif a!=None: obj.setPassed();\n"));
246 QVERIFY(_helper->runScript("a = obj.getUnknownButRegisteredValueObjectAsPtr();print a;\nif a!=None: obj.setPassed();\n"));
247 QVERIFY(_helper->runScript("a = obj.getUnknownButRegisteredValueObjectAsValue();print a;\nif a!=None: obj.setPassed();\n"));
247 QVERIFY(_helper->runScript("a = obj.getUnknownButRegisteredValueObjectAsValue();print a;\nif a!=None: obj.setPassed();\n"));
248 QVERIFY(_helper->runScript("a = obj.getUnknownValueObjectAsPtr();print a;\nif a!=None: obj.setPassed();\n"));
248 QVERIFY(_helper->runScript("a = obj.getUnknownValueObjectAsPtr();print a;\nif a!=None: obj.setPassed();\n"));
249 QEXPECT_FAIL("", "Testing by value return without the object being registered as QMetaType or having registered a default constructor decorator", Continue);
249 QEXPECT_FAIL("", "Testing by value return without the object being registered as QMetaType or having registered a default constructor decorator", Continue);
250 QVERIFY(_helper->runScript("a = obj.getUnknownValueObjectAsValue();print a;\nif a!=None: obj.setPassed();\n"));
250 QVERIFY(_helper->runScript("a = obj.getUnknownValueObjectAsValue();print a;\nif a!=None: obj.setPassed();\n"));
251
251
252 // expect to get strict call to double overload
252 // expect to get strict call to double overload
253 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22.2)\nif a.getH()==2: obj.setPassed();\n"));
253 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt.private import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22.2)\nif a.getH()==2: obj.setPassed();\n"));
254 // expect to get un-strict call to double overload
254 // expect to get un-strict call to double overload
255 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22)\nif a.getH()==2: obj.setPassed();\n"));
255 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt.private import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22)\nif a.getH()==2: obj.setPassed();\n"));
256 // expect to get strict call to copy constructor overload
256 // expect to get strict call to copy constructor overload
257 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(PQCppObjectNoWrap())\nprint a.getH()\nif a.getH()==1: obj.setPassed();\n"));
257 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt.private import PQCppObjectNoWrap\na = PQCppObjectNoWrap(PQCppObjectNoWrap())\nprint a.getH()\nif a.getH()==1: obj.setPassed();\n"));
258
258
259 // test decorated enums
259 // test decorated enums
260 // already registered by signals test
260 // already registered by signals test
261 //PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject<PQCppObject2Decorator>);
261 //PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject<PQCppObject2Decorator>);
262
262
263 // local enum (decorated)
263 // local enum (decorated)
264 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nprint a.testEnumFlag1\nif a.testEnumFlag1(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n"));
264 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt.private import PQCppObject2\na = PQCppObject2()\nprint a.testEnumFlag1\nif a.testEnumFlag1(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n"));
265 // enum with namespace (decorated)
265 // enum with namespace (decorated)
266 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag2(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n"));
266 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt.private import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag2(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n"));
267 // with int overload to check overloading
267 // with int overload to check overloading
268 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag3(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n"));
268 QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt.private import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag3(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n"));
269
269
270 }
270 }
271
271
272 PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag1(PQCppObject2* obj, PQCppObject2Decorator::TestEnumFlag flag) {
272 PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag1(PQCppObject2* obj, PQCppObject2Decorator::TestEnumFlag flag) {
273 return flag;
273 return flag;
274 }
274 }
275
275
276 PQCppObject2::TestEnumFlag PQCppObject2Decorator::testEnumFlag2(PQCppObject2* obj, PQCppObject2::TestEnumFlag flag) {
276 PQCppObject2::TestEnumFlag PQCppObject2Decorator::testEnumFlag2(PQCppObject2* obj, PQCppObject2::TestEnumFlag flag) {
277 return flag;
277 return flag;
278 }
278 }
279
279
280 // with int overload
280 // with int overload
281 PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag3(PQCppObject2* obj, int flag) {
281 PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag3(PQCppObject2* obj, int flag) {
282 return (TestEnumFlag)-1;
282 return (TestEnumFlag)-1;
283 }
283 }
284 PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag3(PQCppObject2* obj, PQCppObject2Decorator::TestEnumFlag flag) {
284 PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag3(PQCppObject2* obj, PQCppObject2Decorator::TestEnumFlag flag) {
285 return flag;
285 return flag;
286 }
286 }
287
287
288 void PythonQtTestSlotCalling::testMultiArgsSlotCall()
288 void PythonQtTestSlotCalling::testMultiArgsSlotCall()
289 {
289 {
290 QVERIFY(_helper->runScript("if obj.getMultiArgs(12,47.11,'test')==(12,47.11,'test'): obj.setPassed();\n"));
290 QVERIFY(_helper->runScript("if obj.getMultiArgs(12,47.11,'test')==(12,47.11,'test'): obj.setPassed();\n"));
291 }
291 }
292
292
293 bool PythonQtTestSlotCallingHelper::runScript(const char* script, int expectedOverload)
293 bool PythonQtTestSlotCallingHelper::runScript(const char* script, int expectedOverload)
294 {
294 {
295 _called = false;
295 _called = false;
296 _passed = false;
296 _passed = false;
297 _calledOverload = -1;
297 _calledOverload = -1;
298 PyRun_SimpleString(script);
298 PyRun_SimpleString(script);
299 return _called && _passed && _calledOverload==expectedOverload;
299 return _called && _passed && _calledOverload==expectedOverload;
300 }
300 }
301
301
302
302
303 void PythonQtTestSignalHandler::initTestCase()
303 void PythonQtTestSignalHandler::initTestCase()
304 {
304 {
305 _helper = new PythonQtTestSignalHandlerHelper(this);
305 _helper = new PythonQtTestSignalHandlerHelper(this);
306 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
306 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
307 PythonQt::self()->addObject(main, "obj", _helper);
307 PythonQt::self()->addObject(main, "obj", _helper);
308 }
308 }
309
309
310 void PythonQtTestSignalHandler::testSignalHandler()
310 void PythonQtTestSignalHandler::testSignalHandler()
311 {
311 {
312 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
312 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
313 PyRun_SimpleString("def testIntSignal(a):\n if a==12: obj.setPassed();\n");
313 PyRun_SimpleString("def testIntSignal(a):\n if a==12: obj.setPassed();\n");
314 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal"));
314 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal"));
315 QVERIFY(_helper->emitIntSignal(12));
315 QVERIFY(_helper->emitIntSignal(12));
316
316
317 PyRun_SimpleString("def testFloatSignal(a):\n if a==12: obj.setPassed();\n");
317 PyRun_SimpleString("def testFloatSignal(a):\n if a==12: obj.setPassed();\n");
318 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal"));
318 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal"));
319 QVERIFY(_helper->emitFloatSignal(12));
319 QVERIFY(_helper->emitFloatSignal(12));
320
320
321 // test decorated enums
321 // test decorated enums
322 PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject<PQCppObject2Decorator>);
322 PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject<PQCppObject2Decorator>);
323
323
324 PyRun_SimpleString("def testEnumSignal(a):\n if a==1: obj.setPassed();\n");
324 PyRun_SimpleString("def testEnumSignal(a):\n if a==1: obj.setPassed();\n");
325 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal"));
325 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal"));
326 QVERIFY(_helper->emitEnumSignal(PQCppObject2::TestEnumValue2));
326 QVERIFY(_helper->emitEnumSignal(PQCppObject2::TestEnumValue2));
327
327
328 PyRun_SimpleString("def testVariantSignal(a):\n if a==obj.expectedVariant(): obj.setPassed();\n");
328 PyRun_SimpleString("def testVariantSignal(a):\n if a==obj.expectedVariant(): obj.setPassed();\n");
329 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal"));
329 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal"));
330 _helper->setExpectedVariant(QString("Test"));
330 _helper->setExpectedVariant(QString("Test"));
331 QVERIFY(_helper->emitVariantSignal(QString("Test")));
331 QVERIFY(_helper->emitVariantSignal(QString("Test")));
332 _helper->setExpectedVariant(12);
332 _helper->setExpectedVariant(12);
333 QVERIFY(_helper->emitVariantSignal(12));
333 QVERIFY(_helper->emitVariantSignal(12));
334 _helper->setExpectedVariant(QStringList() << "test1" << "test2");
334 _helper->setExpectedVariant(QStringList() << "test1" << "test2");
335 QVERIFY(_helper->emitVariantSignal(QStringList() << "test1" << "test2"));
335 QVERIFY(_helper->emitVariantSignal(QStringList() << "test1" << "test2"));
336 _helper->setExpectedVariant(qVariantFromValue((QObject*)_helper));
336 _helper->setExpectedVariant(qVariantFromValue((QObject*)_helper));
337 QVERIFY(_helper->emitVariantSignal(qVariantFromValue((QObject*)_helper)));
337 QVERIFY(_helper->emitVariantSignal(qVariantFromValue((QObject*)_helper)));
338
338
339 PyRun_SimpleString("def testComplexSignal(a,b,l,o):\n if a==12 and b==13 and l==('test1','test2') and o == obj: obj.setPassed();\n");
339 PyRun_SimpleString("def testComplexSignal(a,b,l,o):\n if a==12 and b==13 and l==('test1','test2') and o == obj: obj.setPassed();\n");
340 // intentionally not normalized signal:
340 // intentionally not normalized signal:
341 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal"));
341 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal"));
342 QVERIFY(_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper));
342 QVERIFY(_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper));
343
343
344 // try removing the handler
344 // try removing the handler
345 QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal"));
345 QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal"));
346 // and emit the signal, which should fail because the handler was removed
346 // and emit the signal, which should fail because the handler was removed
347 QVERIFY(!_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper));
347 QVERIFY(!_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper));
348
348
349 QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal"));
349 QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal"));
350 QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal"));
350 QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal"));
351 QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal"));
351 QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal"));
352 QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal"));
352 QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal"));
353
353
354 }
354 }
355
355
356 void PythonQtTestSignalHandler::testRecursiveSignalHandler()
356 void PythonQtTestSignalHandler::testRecursiveSignalHandler()
357 {
357 {
358 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
358 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
359 PyRun_SimpleString("def testSignal1(a):\n obj.emitSignal2(a);\n");
359 PyRun_SimpleString("def testSignal1(a):\n obj.emitSignal2(a);\n");
360 PyRun_SimpleString("def testSignal2(a):\n obj.emitSignal3(float(a));\n");
360 PyRun_SimpleString("def testSignal2(a):\n obj.emitSignal3(float(a));\n");
361 PyRun_SimpleString("def testSignal3(a):\n if a==12: obj.setPassed();\n");
361 PyRun_SimpleString("def testSignal3(a):\n if a==12: obj.setPassed();\n");
362 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal1(int)), main, "testSignal1"));
362 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal1(int)), main, "testSignal1"));
363 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal2(const QString&)), main, "testSignal2"));
363 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal2(const QString&)), main, "testSignal2"));
364 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal3(float)), main, "testSignal3"));
364 QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal3(float)), main, "testSignal3"));
365 QVERIFY(_helper->emitSignal1(12));
365 QVERIFY(_helper->emitSignal1(12));
366 }
366 }
367
367
368
368
369 void PythonQtTestApi::initTestCase()
369 void PythonQtTestApi::initTestCase()
370 {
370 {
371 _helper = new PythonQtTestApiHelper();
371 _helper = new PythonQtTestApiHelper();
372 _main = PythonQt::self()->getMainModule();
372 _main = PythonQt::self()->getMainModule();
373 _main.evalScript("import PythonQt");
373 _main.evalScript("import PythonQt");
374 _main.addObject("obj", _helper);
374 _main.addObject("obj", _helper);
375 }
375 }
376
376
377 void PythonQtTestApi::testProperties()
377 void PythonQtTestApi::testProperties()
378 {
378 {
379 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
379 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
380 // check for name alias (for backward comp to Qt3)
380 // check for name alias (for backward comp to Qt3)
381 main.evalScript("obj.name = 'hello'");
381 main.evalScript("obj.name = 'hello'");
382 QVERIFY(QString("hello") == main.getVariable("obj.name").toString());
382 QVERIFY(QString("hello") == main.getVariable("obj.name").toString());
383
383
384 main.evalScript("obj.objectName = 'hello2'");
384 main.evalScript("obj.objectName = 'hello2'");
385 QVERIFY(QString("hello2") == main.getVariable("obj.objectName").toString());
385 QVERIFY(QString("hello2") == main.getVariable("obj.objectName").toString());
386
386
387 }
387 }
388
388
389 void PythonQtTestApi::testDynamicProperties()
389 void PythonQtTestApi::testDynamicProperties()
390 {
390 {
391 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
391 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
392
392
393 // this fails and should fail, but how could that be tested?
393 // this fails and should fail, but how could that be tested?
394 // main.evalScript("obj.testProp = 1");
394 // main.evalScript("obj.testProp = 1");
395
395
396 // create a new dynamic property
396 // create a new dynamic property
397 main.evalScript("obj.setProperty('testProp','testValue')");
397 main.evalScript("obj.setProperty('testProp','testValue')");
398
398
399 // read the property
399 // read the property
400 QVERIFY(QString("testValue") == main.getVariable("obj.testProp").toString());
400 QVERIFY(QString("testValue") == main.getVariable("obj.testProp").toString());
401 // modify and read again
401 // modify and read again
402 main.evalScript("obj.testProp = 12");
402 main.evalScript("obj.testProp = 12");
403 QVERIFY(12 == main.getVariable("obj.testProp").toInt());
403 QVERIFY(12 == main.getVariable("obj.testProp").toInt());
404
404
405 // check if dynamic property is in dict
405 // check if dynamic property is in dict
406 QVERIFY(12 == main.evalScript("obj.__dict__['testProp']", Py_eval_input).toInt());
406 QVERIFY(12 == main.evalScript("obj.__dict__['testProp']", Py_eval_input).toInt());
407
407
408 // check if dynamic property is in introspection
408 // check if dynamic property is in introspection
409 QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), "obj", PythonQt::Anything);
409 QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), "obj", PythonQt::Anything);
410 QVERIFY(l.contains("testProp"));
410 QVERIFY(l.contains("testProp"));
411
411
412 // check with None, previous value expected
412 // check with None, previous value expected
413 main.evalScript("obj.testProp = None");
413 main.evalScript("obj.testProp = None");
414 QVERIFY(12 == main.getVariable("obj.testProp").toInt());
414 QVERIFY(12 == main.getVariable("obj.testProp").toInt());
415
415
416 // remove the dynamic property
416 // remove the dynamic property
417 main.evalScript("obj.setProperty('testProp', None)");
417 main.evalScript("obj.setProperty('testProp', None)");
418
418
419 // check if dynamic property is really gone
419 // check if dynamic property is really gone
420 QStringList l2 = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), "obj", PythonQt::Anything);
420 QStringList l2 = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), "obj", PythonQt::Anything);
421 QVERIFY(!l2.contains("testProp"));
421 QVERIFY(!l2.contains("testProp"));
422
422
423 }
423 }
424
424
425
425
426 bool PythonQtTestApiHelper::call(const QString& function, const QVariantList& args, const QVariant& expectedResult) {
426 bool PythonQtTestApiHelper::call(const QString& function, const QVariantList& args, const QVariant& expectedResult) {
427 _passed = false;
427 _passed = false;
428 QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), function, args);
428 QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), function, args);
429 return _passed && expectedResult==r;
429 return _passed && expectedResult==r;
430 }
430 }
431
431
432 void PythonQtTestApi::testCall()
432 void PythonQtTestApi::testCall()
433 {
433 {
434 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
434 PythonQtObjectPtr main = PythonQt::self()->getMainModule();
435
435
436 QVERIFY(qVariantValue<QObject*>(PythonQt::self()->getVariable(main, "obj"))==_helper);
436 QVERIFY(qVariantValue<QObject*>(PythonQt::self()->getVariable(main, "obj"))==_helper);
437
437
438 PyRun_SimpleString("def testCallNoArgs():\n obj.setPassed();\n");
438 PyRun_SimpleString("def testCallNoArgs():\n obj.setPassed();\n");
439 QVERIFY(_helper->call("testCallNoArgs", QVariantList(), QVariant()));
439 QVERIFY(_helper->call("testCallNoArgs", QVariantList(), QVariant()));
440
440
441 PyRun_SimpleString("def testCall1(a):\n if a=='test': obj.setPassed();\n return 'test2';\n");
441 PyRun_SimpleString("def testCall1(a):\n if a=='test': obj.setPassed();\n return 'test2';\n");
442 QVERIFY(_helper->call("testCall1", QVariantList() << QVariant("test"), QVariant(QString("test2"))));
442 QVERIFY(_helper->call("testCall1", QVariantList() << QVariant("test"), QVariant(QString("test2"))));
443
443
444 PyRun_SimpleString("def testCall2(a, b):\n if a=='test' and b==obj: obj.setPassed();\n return obj;\n");
444 PyRun_SimpleString("def testCall2(a, b):\n if a=='test' and b==obj: obj.setPassed();\n return obj;\n");
445 QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), "testCall2", QVariantList() << QVariant("test") << qVariantFromValue((QObject*)_helper));
445 QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), "testCall2", QVariantList() << QVariant("test") << qVariantFromValue((QObject*)_helper));
446 QObject* p = qVariantValue<QObject*>(r);
446 QObject* p = qVariantValue<QObject*>(r);
447 QVERIFY(p==_helper);
447 QVERIFY(p==_helper);
448 }
448 }
449
449
450 void PythonQtTestApi::testVariables()
450 void PythonQtTestApi::testVariables()
451 {
451 {
452 PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper);
452 PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper);
453 QVariant v = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject");
453 QVariant v = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject");
454 QObject* p = qVariantValue<QObject*>(v);
454 QObject* p = qVariantValue<QObject*>(v);
455 QVERIFY(p==_helper);
455 QVERIFY(p==_helper);
456 // test for unset variable
456 // test for unset variable
457 QVariant v2 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject2");
457 QVariant v2 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject2");
458 QVERIFY(v2==QVariant());
458 QVERIFY(v2==QVariant());
459
459
460 PythonQt::self()->addVariable(PythonQt::self()->getMainModule(), "someValue", QStringList() << "test1" << "test2");
460 PythonQt::self()->addVariable(PythonQt::self()->getMainModule(), "someValue", QStringList() << "test1" << "test2");
461 QVariant v3 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someValue");
461 QVariant v3 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someValue");
462 QVERIFY(v3 == QVariant(QStringList() << "test1" << "test2"));
462 QVERIFY(v3 == QVariant(QStringList() << "test1" << "test2"));
463
463
464 QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), QString::null, PythonQt::Variable);
464 QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), QString::null, PythonQt::Variable);
465 QSet<QString> s;
465 QSet<QString> s;
466 // check that at least these three variables are set
466 // check that at least these three variables are set
467 s << "obj" << "someObject" << "someValue";
467 s << "obj" << "someObject" << "someValue";
468 foreach (QString value, s) {
468 foreach (QString value, s) {
469 QVERIFY(l.indexOf(value)!=-1);
469 QVERIFY(l.indexOf(value)!=-1);
470 }
470 }
471
471
472 // insert a second time!
472 // insert a second time!
473 PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper);
473 PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper);
474 // and remove
474 // and remove
475 PythonQt::self()->removeVariable(PythonQt::self()->getMainModule(), "someObject");
475 PythonQt::self()->removeVariable(PythonQt::self()->getMainModule(), "someObject");
476 // we expect to find no variable
476 // we expect to find no variable
477 QVariant v4 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject");
477 QVariant v4 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject");
478 QVERIFY(v4==QVariant());
478 QVERIFY(v4==QVariant());
479 }
479 }
480
480
481 void PythonQtTestApi::testImporter()
481 void PythonQtTestApi::testImporter()
482 {
482 {
483 PythonQt::self()->setImporter(_helper);
483 PythonQt::self()->setImporter(_helper);
484 PythonQt::self()->overwriteSysPath(QStringList() << "c:\\test");
484 PythonQt::self()->overwriteSysPath(QStringList() << "c:\\test");
485 PyRun_SimpleString("import bla\n");
485 PyRun_SimpleString("import bla\n");
486 }
486 }
487
487
488 void PythonQtTestApi::testQtNamespace()
488 void PythonQtTestApi::testQtNamespace()
489 {
489 {
490 QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.red").toInt()==Qt::red);
490 QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.red").toInt()==Qt::red);
491 QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.FlatCap").toInt()==Qt::FlatCap);
491 QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.FlatCap").toInt()==Qt::FlatCap);
492 QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.escape")));
492 QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.escape")));
493 // check for an enum type wrapper
493 // check for an enum type wrapper
494 QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.AlignmentFlag")));
494 QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.AlignmentFlag")));
495 // check for a flags type wrapper
495 // check for a flags type wrapper
496 QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.Alignment")));
496 QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.Alignment")));
497 }
497 }
498
498
499 void PythonQtTestApi::testConnects()
499 void PythonQtTestApi::testConnects()
500 {
500 {
501 // QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(PythonQt.Qt.Qt.red)" ,Py_eval_input)) == QColor(Qt::red));
501 // QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(PythonQt.Qt.Qt.red)" ,Py_eval_input)) == QColor(Qt::red));
502 //TODO: add signal/slot connect both with QObject.connect and connect
502 //TODO: add signal/slot connect both with QObject.connect and connect
503 }
503 }
504
504
505 void PythonQtTestApi::testQColorDecorators()
505 void PythonQtTestApi::testQColorDecorators()
506 {
506 {
507 PythonQtObjectPtr colorClass = _main.getVariable("PythonQt.QtGui.QColor");
507 PythonQtObjectPtr colorClass = _main.getVariable("PythonQt.QtGui.QColor");
508 QVERIFY(colorClass);
508 QVERIFY(colorClass);
509 // verify that the class is in the correct module
509 // verify that the class is in the correct module
510 QVERIFY(colorClass.getVariable("__module__") == "PythonQt.QtGui");
510 QVERIFY(colorClass.getVariable("__module__") == "PythonQt.QtGui");
511 // test on Qt module as well:
511 // test on Qt module as well:
512 colorClass = _main.getVariable("PythonQt.Qt.QColor");
512 colorClass = _main.getVariable("PythonQt.Qt.QColor");
513 QVERIFY(colorClass);
513 QVERIFY(colorClass);
514 // constructors
514 // constructors
515 QVERIFY(qVariantValue<QColor>(colorClass.call(QVariantList() << 1 << 2 << 3)) == QColor(1,2,3));
515 QVERIFY(qVariantValue<QColor>(colorClass.call(QVariantList() << 1 << 2 << 3)) == QColor(1,2,3));
516 QVERIFY(qVariantValue<QColor>(colorClass.call()) == QColor());
516 QVERIFY(qVariantValue<QColor>(colorClass.call()) == QColor());
517 QEXPECT_FAIL("", "Testing non-existing constructor", Continue);
517 QEXPECT_FAIL("", "Testing non-existing constructor", Continue);
518 QVERIFY(colorClass.call(QVariantList() << 1 << 2) != QVariant());
518 QVERIFY(colorClass.call(QVariantList() << 1 << 2) != QVariant());
519
519
520 // check that enum overload is taken over int
520 // check that enum overload is taken over int
521 QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(PythonQt.Qt.Qt.red)" ,Py_eval_input)) == QColor(Qt::red));
521 QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(PythonQt.Qt.Qt.red)" ,Py_eval_input)) == QColor(Qt::red));
522 // check that int overload is taken over enum
522 // check that int overload is taken over enum
523 QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(0x112233)" ,Py_eval_input)) == QColor(0x112233));
523 QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(0x112233)" ,Py_eval_input)) == QColor(0x112233));
524
524
525 // check for decorated Cmyk enum value
525 // check for decorated Cmyk enum value
526 QVERIFY(colorClass.getVariable("Cmyk").toInt() == QColor::Cmyk);
526 QVERIFY(colorClass.getVariable("Cmyk").toInt() == QColor::Cmyk);
527 PythonQtObjectPtr staticMethod = colorClass.getVariable("fromRgb");
527 PythonQtObjectPtr staticMethod = colorClass.getVariable("fromRgb");
528 QVERIFY(staticMethod);
528 QVERIFY(staticMethod);
529 // direct call of static method via class
529 // direct call of static method via class
530 QVERIFY(qVariantValue<QColor>(colorClass.call("fromRgb", QVariantList() << 1 << 2 << 3)) == QColor(1,2,3));
530 QVERIFY(qVariantValue<QColor>(colorClass.call("fromRgb", QVariantList() << 1 << 2 << 3)) == QColor(1,2,3));
531 // direct call of static method
531 // direct call of static method
532 QVERIFY(qVariantValue<QColor>(staticMethod.call(QVariantList() << 1 << 2 << 3)) == QColor(1,2,3));
532 QVERIFY(qVariantValue<QColor>(staticMethod.call(QVariantList() << 1 << 2 << 3)) == QColor(1,2,3));
533 PythonQtObjectPtr publicMethod = colorClass.getVariable("red");
533 PythonQtObjectPtr publicMethod = colorClass.getVariable("red");
534 QVERIFY(publicMethod);
534 QVERIFY(publicMethod);
535 // call with passing self in:
535 // call with passing self in:
536 QVERIFY(colorClass.call("red", QVariantList() << QColor(255,0,0)).toInt() == 255);
536 QVERIFY(colorClass.call("red", QVariantList() << QColor(255,0,0)).toInt() == 255);
537 }
537 }
538
538
539 QByteArray PythonQtTestApiHelper::readFileAsBytes(const QString& filename)
539 QByteArray PythonQtTestApiHelper::readFileAsBytes(const QString& filename)
540 {
540 {
541 QByteArray b;
541 QByteArray b;
542 return b;
542 return b;
543 }
543 }
544
544
545 QByteArray PythonQtTestApiHelper::readSourceFile(const QString& filename, bool& ok)
545 QByteArray PythonQtTestApiHelper::readSourceFile(const QString& filename, bool& ok)
546 {
546 {
547 QByteArray b;
547 QByteArray b;
548 ok = true;
548 ok = true;
549 return b;
549 return b;
550 }
550 }
551
551
552 bool PythonQtTestApiHelper::exists(const QString& filename)
552 bool PythonQtTestApiHelper::exists(const QString& filename)
553 {
553 {
554 return true;
554 return true;
555 }
555 }
556
556
557 QDateTime PythonQtTestApiHelper::lastModifiedDate(const QString& filename) {
557 QDateTime PythonQtTestApiHelper::lastModifiedDate(const QString& filename) {
558 return QDateTime::currentDateTime();
558 return QDateTime::currentDateTime();
559 }
559 }
560
560
561
561
562 void PythonQtTestApi::testRedirect()
562 void PythonQtTestApi::testRedirect()
563 {
563 {
564 connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), _helper, SLOT(stdOut(const QString&)));
564 connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), _helper, SLOT(stdOut(const QString&)));
565 connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)), _helper, SLOT(stdErr(const QString&)));
565 connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)), _helper, SLOT(stdErr(const QString&)));
566 PyRun_SimpleString("print 'test'\n");
566 PyRun_SimpleString("print 'test'\n");
567 }
567 }
568
568
569 void PythonQtTestApiHelper::stdOut(const QString& s)
569 void PythonQtTestApiHelper::stdOut(const QString& s)
570 {
570 {
571 qDebug() << s;
571 qDebug() << s;
572 }
572 }
573
573
574 void PythonQtTestApiHelper::stdErr(const QString& s)
574 void PythonQtTestApiHelper::stdErr(const QString& s)
575 {
575 {
576 qDebug() << s;
576 qDebug() << s;
577 }
577 }
578
578
579 QObject* PythonQtTestCppFactory::create(const QByteArray& name, void *ptr)
579 QObject* PythonQtTestCppFactory::create(const QByteArray& name, void *ptr)
580 {
580 {
581 if (name == "PQCppObject") {
581 if (name == "PQCppObject") {
582 return new PQCppObjectWrapper(ptr);
582 return new PQCppObjectWrapper(ptr);
583 }
583 }
584 return NULL;
584 return NULL;
585 }
585 }
General Comments 0
You need to be logged in to leave comments. Login now