@@ -244,6 +244,17 void PythonQtTestSlotCalling::testCppFactory() | |||
|
244 | 244 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22)\nif a.getH()==2: obj.setPassed();\n")); |
|
245 | 245 | // expect to get strict call to copy constructor overload |
|
246 | 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 | 291 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); |
|
281 | 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 |
|
|
284 | 302 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); |
|
285 | 303 | _helper->setExpectedVariant(QString("Test")); |
@@ -304,6 +322,7 void PythonQtTestSignalHandler::testSignalHandler() | |||
|
304 | 322 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); |
|
305 | 323 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); |
|
306 | 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 | 412 | void PythonQtTestApi::testQtNamespace() |
|
394 | 413 | { |
|
395 |
QVERIFY( |
|
|
414 | QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.red").toInt()==Qt::red); | |
|
396 | 415 | QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.FlatCap").toInt()==Qt::FlatCap); |
|
397 | 416 | QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.escape"))); |
|
398 | 417 | } |
@@ -224,6 +224,7 private: | |||
|
224 | 224 | |
|
225 | 225 | class PQCppObjectNoWrapDecorator : public QObject { |
|
226 | 226 | Q_OBJECT |
|
227 | ||
|
227 | 228 | public slots: |
|
228 | 229 | PQCppObjectNoWrap* new_PQCppObjectNoWrap() { |
|
229 | 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 | 286 | class PQUnknownValueObject |
|
243 | 287 | { |
|
244 | 288 | public: |
@@ -423,6 +467,7 public slots: | |||
|
423 | 467 | |
|
424 | 468 | bool emitIntSignal(int a) { _passed = false; emit intSignal(a); return _passed; }; |
|
425 | 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 | 472 | bool emitVariantSignal(const QVariant& v) { _passed = false; emit variantSignal(v); return _passed; }; |
|
428 | 473 | QVariant expectedVariant() { return _v; } |
@@ -439,6 +484,7 signals: | |||
|
439 | 484 | void floatSignal(float); |
|
440 | 485 | void variantSignal(const QVariant& v); |
|
441 | 486 | void complexSignal(int a, float b, const QStringList& l, QObject* obj); |
|
487 | void enumSignal(PQCppObject2::TestEnumFlag flag); | |
|
442 | 488 | |
|
443 | 489 | void signal1(int); |
|
444 | 490 | void signal2(const QString&); |
General Comments 0
You need to be logged in to leave comments.
Login now