@@ -244,6 +244,17 void PythonQtTestSlotCalling::testCppFactory() | |||||
244 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22)\nif a.getH()==2: obj.setPassed();\n")); |
|
244 | 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 |
|
245 | // 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")); |
|
246 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(PQCppObjectNoWrap())\nprint a.getH()\nif a.getH()==1: obj.setPassed();\n")); | |
|
247 | ||||
|
248 | // test decorated enums | |||
|
249 | PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject<PQCppObject2Decorator>); | |||
|
250 | ||||
|
251 | // enum with namespace (decorated) | |||
|
252 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag2(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); | |||
|
253 | // local enum (decorated) | |||
|
254 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag1(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); | |||
|
255 | // with int overload to check overloading | |||
|
256 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag3(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); | |||
|
257 | ||||
247 | } |
|
258 | } | |
248 |
|
259 | |||
249 |
|
260 | |||
@@ -280,6 +291,13 void PythonQtTestSignalHandler::testSignalHandler() | |||||
280 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); |
|
291 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); | |
281 | QVERIFY(_helper->emitFloatSignal(12)); |
|
292 | QVERIFY(_helper->emitFloatSignal(12)); | |
282 |
|
293 | |||
|
294 | // test decorated enums | |||
|
295 | PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject<PQCppObject2Decorator>); | |||
|
296 | ||||
|
297 | PyRun_SimpleString("def testEnumSignal(a):\n if a==1: obj.setPassed();\n"); | |||
|
298 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal")); | |||
|
299 | QVERIFY(_helper->emitEnumSignal(PQCppObject2::TestEnumValue2)); | |||
|
300 | ||||
283 |
|
|
301 | PyRun_SimpleString("def testVariantSignal(a):\n if a==obj.expectedVariant(): obj.setPassed();\n"); | |
284 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); |
|
302 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); | |
285 | _helper->setExpectedVariant(QString("Test")); |
|
303 | _helper->setExpectedVariant(QString("Test")); | |
@@ -304,6 +322,7 void PythonQtTestSignalHandler::testSignalHandler() | |||||
304 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); |
|
322 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); | |
305 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); |
|
323 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); | |
306 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); |
|
324 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); | |
|
325 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal")); | |||
307 |
|
326 | |||
308 | } |
|
327 | } | |
309 |
|
328 | |||
@@ -392,7 +411,7 void PythonQtTestApi::testImporter() | |||||
392 |
|
411 | |||
393 | void PythonQtTestApi::testQtNamespace() |
|
412 | void PythonQtTestApi::testQtNamespace() | |
394 | { |
|
413 | { | |
395 |
QVERIFY( |
|
414 | QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.red").toInt()==Qt::red); | |
396 | QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.FlatCap").toInt()==Qt::FlatCap); |
|
415 | QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.FlatCap").toInt()==Qt::FlatCap); | |
397 | QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.escape"))); |
|
416 | QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.escape"))); | |
398 | } |
|
417 | } |
@@ -224,6 +224,7 private: | |||||
224 |
|
224 | |||
225 | class PQCppObjectNoWrapDecorator : public QObject { |
|
225 | class PQCppObjectNoWrapDecorator : public QObject { | |
226 | Q_OBJECT |
|
226 | Q_OBJECT | |
|
227 | ||||
227 | public slots: |
|
228 | public slots: | |
228 | PQCppObjectNoWrap* new_PQCppObjectNoWrap() { |
|
229 | PQCppObjectNoWrap* new_PQCppObjectNoWrap() { | |
229 | return new PQCppObjectNoWrap(0); |
|
230 | return new PQCppObjectNoWrap(0); | |
@@ -239,6 +240,49 public slots: | |||||
239 |
|
240 | |||
240 | }; |
|
241 | }; | |
241 |
|
242 | |||
|
243 | ||||
|
244 | //! an cpp object that is to be wrapped by decorators only | |||
|
245 | class PQCppObject2 { | |||
|
246 | ||||
|
247 | public: | |||
|
248 | enum TestEnumFlag { | |||
|
249 | TestEnumValue1 = 0, | |||
|
250 | TestEnumValue2 = 1 | |||
|
251 | }; | |||
|
252 | ||||
|
253 | PQCppObject2() {} | |||
|
254 | ||||
|
255 | }; | |||
|
256 | ||||
|
257 | class PQCppObject2Decorator : public QObject { | |||
|
258 | Q_OBJECT | |||
|
259 | ||||
|
260 | public: | |||
|
261 | Q_ENUMS(TestEnumFlag) | |||
|
262 | Q_FLAGS(TestEnum) | |||
|
263 | ||||
|
264 | enum TestEnumFlag { | |||
|
265 | TestEnumValue1 = 0, | |||
|
266 | TestEnumValue2 = 1 | |||
|
267 | }; | |||
|
268 | ||||
|
269 | Q_DECLARE_FLAGS(TestEnum, TestEnumFlag) | |||
|
270 | ||||
|
271 | public slots: | |||
|
272 | PQCppObject2* new_PQCppObject2() { | |||
|
273 | return new PQCppObject2(); | |||
|
274 | } | |||
|
275 | ||||
|
276 | TestEnumFlag testEnumFlag1(PQCppObject2* obj, TestEnumFlag flag) { return flag; } | |||
|
277 | ||||
|
278 | PQCppObject2::TestEnumFlag testEnumFlag2(PQCppObject2* obj, PQCppObject2::TestEnumFlag flag) { return flag; } | |||
|
279 | ||||
|
280 | // with int overload | |||
|
281 | TestEnumFlag testEnumFlag3(PQCppObject2* obj, int flag) { return (TestEnumFlag)-1; } | |||
|
282 | TestEnumFlag testEnumFlag3(PQCppObject2* obj, TestEnumFlag flag) { return flag; } | |||
|
283 | ||||
|
284 | }; | |||
|
285 | ||||
242 | class PQUnknownValueObject |
|
286 | class PQUnknownValueObject | |
243 | { |
|
287 | { | |
244 | public: |
|
288 | public: | |
@@ -423,6 +467,7 public slots: | |||||
423 |
|
467 | |||
424 | bool emitIntSignal(int a) { _passed = false; emit intSignal(a); return _passed; }; |
|
468 | bool emitIntSignal(int a) { _passed = false; emit intSignal(a); return _passed; }; | |
425 | bool emitFloatSignal(float a) { _passed = false; emit floatSignal(a); return _passed; }; |
|
469 | bool emitFloatSignal(float a) { _passed = false; emit floatSignal(a); return _passed; }; | |
|
470 | bool emitEnumSignal(PQCppObject2::TestEnumFlag flag) { _passed = false; emit enumSignal(flag); return _passed; }; | |||
426 |
|
471 | |||
427 | bool emitVariantSignal(const QVariant& v) { _passed = false; emit variantSignal(v); return _passed; }; |
|
472 | bool emitVariantSignal(const QVariant& v) { _passed = false; emit variantSignal(v); return _passed; }; | |
428 | QVariant expectedVariant() { return _v; } |
|
473 | QVariant expectedVariant() { return _v; } | |
@@ -439,6 +484,7 signals: | |||||
439 | void floatSignal(float); |
|
484 | void floatSignal(float); | |
440 | void variantSignal(const QVariant& v); |
|
485 | void variantSignal(const QVariant& v); | |
441 | void complexSignal(int a, float b, const QStringList& l, QObject* obj); |
|
486 | void complexSignal(int a, float b, const QStringList& l, QObject* obj); | |
|
487 | void enumSignal(PQCppObject2::TestEnumFlag flag); | |||
442 |
|
488 | |||
443 | void signal1(int); |
|
489 | void signal1(int); | |
444 | void signal2(const QString&); |
|
490 | void signal2(const QString&); |
General Comments 0
You need to be logged in to leave comments.
Login now