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