From 0f65c5e01031e65629b1680040a632806b8dc583 2009-05-19 08:02:44 From: florianlink Date: 2009-05-19 08:02:44 Subject: [PATCH] added tests for return by value of objects, unregistered objects still fail git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@80 ea8d5007-eb21-0410-b261-ccb3ea6e24a9 --- diff --git a/tests/PythonQtTests.cpp b/tests/PythonQtTests.cpp index 66806e3..29ec3b4 100644 --- a/tests/PythonQtTests.cpp +++ b/tests/PythonQtTests.cpp @@ -213,6 +213,7 @@ void PythonQtTestSlotCalling::testCppFactory() { PythonQtTestCppFactory* f = new PythonQtTestCppFactory; PythonQt::self()->addInstanceDecorators(new PQCppObjectDecorator); + qRegisterMetaType("PQCppObjectNoWrap"); PythonQt::self()->addDecorators(new PQCppObjectNoWrapDecorator); PythonQt::self()->addWrapperFactory(f); @@ -227,6 +228,13 @@ void PythonQtTestSlotCalling::testCppFactory() QVERIFY(_helper->runScript("if obj.createPQCppObjectNoWrap(12).getH()==12: obj.setPassed();\n")); + QVERIFY(_helper->runScript("if obj.getPQCppObjectNoWrapAsValue().getH()==47: obj.setPassed();\n")); + + qRegisterMetaType("PQUnknownButRegisteredValueObject"); + QVERIFY(_helper->runScript("a = obj.getUnknownButRegisteredValueObjectAsPtr();print a;\nif a!=None: obj.setPassed();\n")); + QVERIFY(_helper->runScript("a = obj.getUnknownButRegisteredValueObjectAsValue();print a;\nif a!=None: obj.setPassed();\n")); + QVERIFY(_helper->runScript("a = obj.getUnknownValueObjectAsPtr();print a;\nif a!=None: obj.setPassed();\n")); + QVERIFY(_helper->runScript("a = obj.getUnknownValueObjectAsValue();print a;\nif a!=None: obj.setPassed();\n")); // expect to get strict call to double overload QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22.2)\nif a.getH()==2: obj.setPassed();\n")); diff --git a/tests/PythonQtTests.h b/tests/PythonQtTests.h index d351eb3..c50687d 100644 --- a/tests/PythonQtTests.h +++ b/tests/PythonQtTests.h @@ -212,6 +212,7 @@ public slots: class PQCppObjectNoWrap { public: + PQCppObjectNoWrap() { _height = 0; } PQCppObjectNoWrap(int h) { _height = h; } int getHeight() { return _height; } @@ -238,6 +239,17 @@ public slots: }; +class PQUnknownValueObject +{ +public: + PQUnknownValueObject() {}; +}; + +class PQUnknownButRegisteredValueObject +{ +public: + PQUnknownButRegisteredValueObject() {}; +}; //! test the calling of slots class PythonQtTestSlotCalling : public QObject @@ -348,6 +360,15 @@ public slots: //! cpp wrapper factory test PQCppObjectNoWrap* getPQCppObjectNoWrap(PQCppObjectNoWrap* p) { _called = true; return p; } + //! get a return by value PQCppObjectNoWrap + PQCppObjectNoWrap getPQCppObjectNoWrapAsValue() { _called = true; return PQCppObjectNoWrap(47); } + + PQUnknownButRegisteredValueObject getUnknownButRegisteredValueObjectAsValue() { _called = true; return PQUnknownButRegisteredValueObject(); } + PQUnknownValueObject getUnknownValueObjectAsValue() { _called = true; return PQUnknownValueObject(); } + + PQUnknownButRegisteredValueObject* getUnknownButRegisteredValueObjectAsPtr() { _called = true; return new PQUnknownButRegisteredValueObject(); } + PQUnknownValueObject* getUnknownValueObjectAsPtr() { _called = true; return new PQUnknownValueObject(); } + ClassA* getClassAPtr(ClassA* o) { _called = true; return o; } ClassB* getClassBPtr(ClassB* o) { _called = true; return o; } ClassC* getClassCPtr(ClassC* o) { _called = true; return o; }