@@ -53,6 +53,7 void PythonQtTestSlotCalling::init() { | |||||
53 |
|
53 | |||
54 | } |
|
54 | } | |
55 |
|
55 | |||
|
56 | ||||
56 | void* polymorphic_ClassB_Handler(const void* ptr, char** className) { |
|
57 | void* polymorphic_ClassB_Handler(const void* ptr, char** className) { | |
57 | ClassB* o = (ClassB*)ptr; |
|
58 | ClassB* o = (ClassB*)ptr; | |
58 | if (o->type()==2) { |
|
59 | if (o->type()==2) { | |
@@ -373,6 +374,48 void PythonQtTestApi::initTestCase() | |||||
373 | _main.addObject("obj", _helper); |
|
374 | _main.addObject("obj", _helper); | |
374 | } |
|
375 | } | |
375 |
|
376 | |||
|
377 | void PythonQtTestApi::testProperties() | |||
|
378 | { | |||
|
379 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); | |||
|
380 | // check for name alias (for backward comp to Qt3) | |||
|
381 | main.evalScript("obj.name = 'hello'"); | |||
|
382 | QVERIFY(QString("hello") == main.getVariable("obj.name").toString()); | |||
|
383 | ||||
|
384 | main.evalScript("obj.objectName = 'hello2'"); | |||
|
385 | QVERIFY(QString("hello2") == main.getVariable("obj.objectName").toString()); | |||
|
386 | ||||
|
387 | } | |||
|
388 | ||||
|
389 | void PythonQtTestApi::testDynamicProperties() | |||
|
390 | { | |||
|
391 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); | |||
|
392 | ||||
|
393 | // this fails and should fail, but how could that be tested? | |||
|
394 | // main.evalScript("obj.testProp = 1"); | |||
|
395 | ||||
|
396 | // create a new dynamic property | |||
|
397 | main.evalScript("obj.setProperty('testProp','testValue')"); | |||
|
398 | ||||
|
399 | // read the property | |||
|
400 | QVERIFY(QString("testValue") == main.getVariable("obj.testProp").toString()); | |||
|
401 | // modify and read again | |||
|
402 | main.evalScript("obj.testProp = 12"); | |||
|
403 | QVERIFY(12 == main.getVariable("obj.testProp").toInt()); | |||
|
404 | ||||
|
405 | // check if dynamic property is in dict | |||
|
406 | QVERIFY(12 == main.evalScript("obj.__dict__['testProp']", Py_eval_input).toInt()); | |||
|
407 | ||||
|
408 | // check if dynamic property is in introspection | |||
|
409 | QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), "obj", PythonQt::Anything); | |||
|
410 | QVERIFY(l.contains("testProp")); | |||
|
411 | ||||
|
412 | // check with None, previous value expected | |||
|
413 | main.evalScript("obj.testProp = None"); | |||
|
414 | QVERIFY(12 == main.getVariable("obj.testProp").toInt()); | |||
|
415 | ||||
|
416 | } | |||
|
417 | ||||
|
418 | ||||
376 | bool PythonQtTestApiHelper::call(const QString& function, const QVariantList& args, const QVariant& expectedResult) { |
|
419 | bool PythonQtTestApiHelper::call(const QString& function, const QVariantList& args, const QVariant& expectedResult) { | |
377 | _passed = false; |
|
420 | _passed = false; | |
378 | QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), function, args); |
|
421 | QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), function, args); |
@@ -72,6 +72,9 private slots: | |||||
72 | void testQtNamespace(); |
|
72 | void testQtNamespace(); | |
73 | void testConnects(); |
|
73 | void testConnects(); | |
74 |
|
74 | |||
|
75 | void testProperties(); | |||
|
76 | void testDynamicProperties(); | |||
|
77 | ||||
75 | private: |
|
78 | private: | |
76 | PythonQtTestApiHelper* _helper; |
|
79 | PythonQtTestApiHelper* _helper; | |
77 | PythonQtObjectPtr _main; |
|
80 | PythonQtObjectPtr _main; |
General Comments 0
You need to be logged in to leave comments.
Login now