From ef758f9ae3a75acc4ae215a6b42571804427863c 2009-05-24 08:55:48 From: florianlink Date: 2009-05-24 08:55:48 Subject: [PATCH] added new tests to validate enums return values, enums passed in slots and enums in signals (enums in signals is not yet implemented and fails) git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@86 ea8d5007-eb21-0410-b261-ccb3ea6e24a9 --- diff --git a/tests/PythonQtTests.cpp b/tests/PythonQtTests.cpp index 65f6829..49971e2 100644 --- a/tests/PythonQtTests.cpp +++ b/tests/PythonQtTests.cpp @@ -244,6 +244,17 @@ void PythonQtTestSlotCalling::testCppFactory() QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22)\nif a.getH()==2: obj.setPassed();\n")); // expect to get strict call to copy constructor overload QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(PQCppObjectNoWrap())\nprint a.getH()\nif a.getH()==1: obj.setPassed();\n")); + + // test decorated enums + PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject); + + // enum with namespace (decorated) + QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag2(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); + // local enum (decorated) + QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag1(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); + // with int overload to check overloading + QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag3(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); + } @@ -280,6 +291,13 @@ void PythonQtTestSignalHandler::testSignalHandler() QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); QVERIFY(_helper->emitFloatSignal(12)); + // test decorated enums + PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject); + + PyRun_SimpleString("def testEnumSignal(a):\n if a==1: obj.setPassed();\n"); + QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal")); + QVERIFY(_helper->emitEnumSignal(PQCppObject2::TestEnumValue2)); + PyRun_SimpleString("def testVariantSignal(a):\n if a==obj.expectedVariant(): obj.setPassed();\n"); QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); _helper->setExpectedVariant(QString("Test")); @@ -304,6 +322,7 @@ void PythonQtTestSignalHandler::testSignalHandler() QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); + QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal")); } @@ -392,7 +411,7 @@ void PythonQtTestApi::testImporter() void PythonQtTestApi::testQtNamespace() { - QVERIFY(!_main.getVariable("PythonQt.QtCore.Qt.red").toInt()==Qt::red); + QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.red").toInt()==Qt::red); QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.FlatCap").toInt()==Qt::FlatCap); QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.escape"))); } diff --git a/tests/PythonQtTests.h b/tests/PythonQtTests.h index c50687d..ab0f833 100644 --- a/tests/PythonQtTests.h +++ b/tests/PythonQtTests.h @@ -224,6 +224,7 @@ private: class PQCppObjectNoWrapDecorator : public QObject { Q_OBJECT + public slots: PQCppObjectNoWrap* new_PQCppObjectNoWrap() { return new PQCppObjectNoWrap(0); @@ -239,6 +240,49 @@ public slots: }; + +//! an cpp object that is to be wrapped by decorators only +class PQCppObject2 { + +public: + enum TestEnumFlag { + TestEnumValue1 = 0, + TestEnumValue2 = 1 + }; + + PQCppObject2() {} + +}; + +class PQCppObject2Decorator : public QObject { + Q_OBJECT + +public: + Q_ENUMS(TestEnumFlag) + Q_FLAGS(TestEnum) + + enum TestEnumFlag { + TestEnumValue1 = 0, + TestEnumValue2 = 1 + }; + + Q_DECLARE_FLAGS(TestEnum, TestEnumFlag) + + public slots: + PQCppObject2* new_PQCppObject2() { + return new PQCppObject2(); + } + + TestEnumFlag testEnumFlag1(PQCppObject2* obj, TestEnumFlag flag) { return flag; } + + PQCppObject2::TestEnumFlag testEnumFlag2(PQCppObject2* obj, PQCppObject2::TestEnumFlag flag) { return flag; } + + // with int overload + TestEnumFlag testEnumFlag3(PQCppObject2* obj, int flag) { return (TestEnumFlag)-1; } + TestEnumFlag testEnumFlag3(PQCppObject2* obj, TestEnumFlag flag) { return flag; } + +}; + class PQUnknownValueObject { public: @@ -423,6 +467,7 @@ public slots: bool emitIntSignal(int a) { _passed = false; emit intSignal(a); return _passed; }; bool emitFloatSignal(float a) { _passed = false; emit floatSignal(a); return _passed; }; + bool emitEnumSignal(PQCppObject2::TestEnumFlag flag) { _passed = false; emit enumSignal(flag); return _passed; }; bool emitVariantSignal(const QVariant& v) { _passed = false; emit variantSignal(v); return _passed; }; QVariant expectedVariant() { return _v; } @@ -439,6 +484,7 @@ signals: void floatSignal(float); void variantSignal(const QVariant& v); void complexSignal(int a, float b, const QStringList& l, QObject* obj); + void enumSignal(PQCppObject2::TestEnumFlag flag); void signal1(int); void signal2(const QString&);