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