@@ -1,535 +1,578 | |||||
1 | /* |
|
1 | /* | |
2 | * |
|
2 | * | |
3 | * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. |
|
3 | * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. | |
4 | * |
|
4 | * | |
5 | * This library is free software; you can redistribute it and/or |
|
5 | * This library is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU Lesser General Public |
|
6 | * modify it under the terms of the GNU Lesser General Public | |
7 | * License as published by the Free Software Foundation; either |
|
7 | * License as published by the Free Software Foundation; either | |
8 | * version 2.1 of the License, or (at your option) any later version. |
|
8 | * version 2.1 of the License, or (at your option) any later version. | |
9 | * |
|
9 | * | |
10 | * This library is distributed in the hope that it will be useful, |
|
10 | * This library is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. |
|
13 | * Lesser General Public License for more details. | |
14 | * |
|
14 | * | |
15 | * Further, this software is distributed without any warranty that it is |
|
15 | * Further, this software is distributed without any warranty that it is | |
16 | * free of the rightful claim of any third person regarding infringement |
|
16 | * free of the rightful claim of any third person regarding infringement | |
17 | * or the like. Any license provided herein, whether implied or |
|
17 | * or the like. Any license provided herein, whether implied or | |
18 | * otherwise, applies only to this software file. Patent licenses, if |
|
18 | * otherwise, applies only to this software file. Patent licenses, if | |
19 | * any, provided herein do not apply to combinations of this program with |
|
19 | * any, provided herein do not apply to combinations of this program with | |
20 | * other software, or any other product whatsoever. |
|
20 | * other software, or any other product whatsoever. | |
21 | * |
|
21 | * | |
22 | * You should have received a copy of the GNU Lesser General Public |
|
22 | * You should have received a copy of the GNU Lesser General Public | |
23 | * License along with this library; if not, write to the Free Software |
|
23 | * License along with this library; if not, write to the Free Software | |
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
25 | * |
|
25 | * | |
26 | * Contact information: MeVis Research GmbH, Universitaetsallee 29, |
|
26 | * Contact information: MeVis Research GmbH, Universitaetsallee 29, | |
27 | * 28359 Bremen, Germany or: |
|
27 | * 28359 Bremen, Germany or: | |
28 | * |
|
28 | * | |
29 | * http://www.mevis.de |
|
29 | * http://www.mevis.de | |
30 | * |
|
30 | * | |
31 | */ |
|
31 | */ | |
32 |
|
32 | |||
33 | //---------------------------------------------------------------------------------- |
|
33 | //---------------------------------------------------------------------------------- | |
34 | /*! |
|
34 | /*! | |
35 | // \file PythonQtTests.cpp |
|
35 | // \file PythonQtTests.cpp | |
36 | // \author Florian Link |
|
36 | // \author Florian Link | |
37 | // \author Last changed by $Author: florian $ |
|
37 | // \author Last changed by $Author: florian $ | |
38 | // \date 2006-05 |
|
38 | // \date 2006-05 | |
39 | */ |
|
39 | */ | |
40 | //---------------------------------------------------------------------------------- |
|
40 | //---------------------------------------------------------------------------------- | |
41 |
|
41 | |||
42 | #include "PythonQtTests.h" |
|
42 | #include "PythonQtTests.h" | |
43 |
|
43 | |||
44 | void PythonQtTestSlotCalling::initTestCase() |
|
44 | void PythonQtTestSlotCalling::initTestCase() | |
45 | { |
|
45 | { | |
46 | _helper = new PythonQtTestSlotCallingHelper(this); |
|
46 | _helper = new PythonQtTestSlotCallingHelper(this); | |
47 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); |
|
47 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); | |
48 | main.evalScript("import PythonQt"); |
|
48 | main.evalScript("import PythonQt"); | |
49 | PythonQt::self()->addObject(main, "obj", _helper); |
|
49 | PythonQt::self()->addObject(main, "obj", _helper); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void PythonQtTestSlotCalling::init() { |
|
52 | 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) { | |
59 | *className = "ClassB"; |
|
60 | *className = "ClassB"; | |
60 | return (ClassB*)o; |
|
61 | return (ClassB*)o; | |
61 | } |
|
62 | } | |
62 | if (o->type()==3) { |
|
63 | if (o->type()==3) { | |
63 | *className = "ClassC"; |
|
64 | *className = "ClassC"; | |
64 | return (ClassC*)o; |
|
65 | return (ClassC*)o; | |
65 | } |
|
66 | } | |
66 | if (o->type()==4) { |
|
67 | if (o->type()==4) { | |
67 | *className = "ClassD"; |
|
68 | *className = "ClassD"; | |
68 | return (ClassD*)o; |
|
69 | return (ClassD*)o; | |
69 | } |
|
70 | } | |
70 | return NULL; |
|
71 | return NULL; | |
71 | } |
|
72 | } | |
72 |
|
73 | |||
73 | void PythonQtTestSlotCalling::testInheritance() { |
|
74 | void PythonQtTestSlotCalling::testInheritance() { | |
74 | PythonQt::self()->registerCPPClass("ClassA",NULL,NULL, PythonQtCreateObject<ClassAWrapper>); |
|
75 | PythonQt::self()->registerCPPClass("ClassA",NULL,NULL, PythonQtCreateObject<ClassAWrapper>); | |
75 | PythonQt::self()->registerCPPClass("ClassB",NULL,NULL, PythonQtCreateObject<ClassBWrapper>); |
|
76 | PythonQt::self()->registerCPPClass("ClassB",NULL,NULL, PythonQtCreateObject<ClassBWrapper>); | |
76 | PythonQt::self()->registerCPPClass("ClassC",NULL,NULL, PythonQtCreateObject<ClassCWrapper>); |
|
77 | PythonQt::self()->registerCPPClass("ClassC",NULL,NULL, PythonQtCreateObject<ClassCWrapper>); | |
77 | PythonQt::self()->addParentClass("ClassC", "ClassA", PythonQtUpcastingOffset<ClassC,ClassA>()); |
|
78 | PythonQt::self()->addParentClass("ClassC", "ClassA", PythonQtUpcastingOffset<ClassC,ClassA>()); | |
78 | PythonQt::self()->addParentClass("ClassC", "ClassB", PythonQtUpcastingOffset<ClassC,ClassB>()); |
|
79 | PythonQt::self()->addParentClass("ClassC", "ClassB", PythonQtUpcastingOffset<ClassC,ClassB>()); | |
79 | PythonQt::self()->registerClass(&ClassD::staticMetaObject, NULL, PythonQtCreateObject<ClassDWrapper>); |
|
80 | PythonQt::self()->registerClass(&ClassD::staticMetaObject, NULL, PythonQtCreateObject<ClassDWrapper>); | |
80 | PythonQt::self()->addParentClass("ClassD", "ClassA", PythonQtUpcastingOffset<ClassD,ClassA>()); |
|
81 | PythonQt::self()->addParentClass("ClassD", "ClassA", PythonQtUpcastingOffset<ClassD,ClassA>()); | |
81 | PythonQt::self()->addParentClass("ClassD", "ClassB", PythonQtUpcastingOffset<ClassD,ClassB>()); |
|
82 | PythonQt::self()->addParentClass("ClassD", "ClassB", PythonQtUpcastingOffset<ClassD,ClassB>()); | |
82 |
|
83 | |||
83 | PythonQtObjectPtr classA = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassA"); |
|
84 | PythonQtObjectPtr classA = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassA"); | |
84 | PythonQtObjectPtr classB = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassB"); |
|
85 | PythonQtObjectPtr classB = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassB"); | |
85 | PythonQtObjectPtr classC = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassC"); |
|
86 | PythonQtObjectPtr classC = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassC"); | |
86 | PythonQtObjectPtr classD = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassD"); |
|
87 | PythonQtObjectPtr classD = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassD"); | |
87 | QVERIFY(classA); |
|
88 | QVERIFY(classA); | |
88 | QVERIFY(classB); |
|
89 | QVERIFY(classB); | |
89 | QVERIFY(classC); |
|
90 | QVERIFY(classC); | |
90 | QVERIFY(classD); |
|
91 | QVERIFY(classD); | |
91 |
|
92 | |||
92 | QVERIFY(_helper->runScript("a = PythonQt.ClassA();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n")); |
|
93 | QVERIFY(_helper->runScript("a = PythonQt.ClassA();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n")); | |
93 | QEXPECT_FAIL("", "ClassB can not be converted to ClassA", Continue); |
|
94 | QEXPECT_FAIL("", "ClassB can not be converted to ClassA", Continue); | |
94 | QVERIFY(_helper->runScript("a = PythonQt.ClassB();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n")); |
|
95 | QVERIFY(_helper->runScript("a = PythonQt.ClassB();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n")); | |
95 | QVERIFY(_helper->runScript("a = PythonQt.ClassC();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n")); |
|
96 | QVERIFY(_helper->runScript("a = PythonQt.ClassC();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n")); | |
96 | QVERIFY(_helper->runScript("a = PythonQt.ClassD();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n")); |
|
97 | QVERIFY(_helper->runScript("a = PythonQt.ClassD();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n")); | |
97 |
|
98 | |||
98 | QEXPECT_FAIL("", "ClassA can not be converted to ClassB", Continue); |
|
99 | QEXPECT_FAIL("", "ClassA can not be converted to ClassB", Continue); | |
99 | QVERIFY(_helper->runScript("a = PythonQt.ClassA();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n")); |
|
100 | QVERIFY(_helper->runScript("a = PythonQt.ClassA();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n")); | |
100 | QVERIFY(_helper->runScript("a = PythonQt.ClassB();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n")); |
|
101 | QVERIFY(_helper->runScript("a = PythonQt.ClassB();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n")); | |
101 | QVERIFY(_helper->runScript("a = PythonQt.ClassC();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n")); |
|
102 | QVERIFY(_helper->runScript("a = PythonQt.ClassC();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n")); | |
102 | QVERIFY(_helper->runScript("a = PythonQt.ClassD();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n")); |
|
103 | QVERIFY(_helper->runScript("a = PythonQt.ClassD();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n")); | |
103 |
|
104 | |||
104 | QEXPECT_FAIL("", "ClassA can not be converted to ClassC", Continue); |
|
105 | QEXPECT_FAIL("", "ClassA can not be converted to ClassC", Continue); | |
105 | QVERIFY(_helper->runScript("a = PythonQt.ClassA();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n")); |
|
106 | QVERIFY(_helper->runScript("a = PythonQt.ClassA();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n")); | |
106 | QEXPECT_FAIL("", "ClassB can not be converted to ClassC", Continue); |
|
107 | QEXPECT_FAIL("", "ClassB can not be converted to ClassC", Continue); | |
107 | QVERIFY(_helper->runScript("a = PythonQt.ClassB();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n")); |
|
108 | QVERIFY(_helper->runScript("a = PythonQt.ClassB();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n")); | |
108 | QVERIFY(_helper->runScript("a = PythonQt.ClassC();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n")); |
|
109 | QVERIFY(_helper->runScript("a = PythonQt.ClassC();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n")); | |
109 | QEXPECT_FAIL("", "ClassD can not be converted to ClassC", Continue); |
|
110 | QEXPECT_FAIL("", "ClassD can not be converted to ClassC", Continue); | |
110 | QVERIFY(_helper->runScript("a = PythonQt.ClassD();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n")); |
|
111 | QVERIFY(_helper->runScript("a = PythonQt.ClassD();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n")); | |
111 |
|
112 | |||
112 | QVERIFY(_helper->runScript("if type(obj.createClassA())==PythonQt.ClassA: obj.setPassed();\n")); |
|
113 | QVERIFY(_helper->runScript("if type(obj.createClassA())==PythonQt.ClassA: obj.setPassed();\n")); | |
113 | QVERIFY(_helper->runScript("if type(obj.createClassB())==PythonQt.ClassB: obj.setPassed();\n")); |
|
114 | QVERIFY(_helper->runScript("if type(obj.createClassB())==PythonQt.ClassB: obj.setPassed();\n")); | |
114 | QVERIFY(_helper->runScript("if type(obj.createClassCAsA())==PythonQt.ClassA: obj.setPassed();\n")); |
|
115 | QVERIFY(_helper->runScript("if type(obj.createClassCAsA())==PythonQt.ClassA: obj.setPassed();\n")); | |
115 | QVERIFY(_helper->runScript("if type(obj.createClassCAsB())==PythonQt.ClassB: obj.setPassed();\n")); |
|
116 | QVERIFY(_helper->runScript("if type(obj.createClassCAsB())==PythonQt.ClassB: obj.setPassed();\n")); | |
116 | QVERIFY(_helper->runScript("if type(obj.createClassD())==PythonQt.ClassD: obj.setPassed();\n")); |
|
117 | QVERIFY(_helper->runScript("if type(obj.createClassD())==PythonQt.ClassD: obj.setPassed();\n")); | |
117 | QVERIFY(_helper->runScript("if type(obj.createClassDAsA())==PythonQt.ClassA: obj.setPassed();\n")); |
|
118 | QVERIFY(_helper->runScript("if type(obj.createClassDAsA())==PythonQt.ClassA: obj.setPassed();\n")); | |
118 | QVERIFY(_helper->runScript("if type(obj.createClassDAsB())==PythonQt.ClassB: obj.setPassed();\n")); |
|
119 | QVERIFY(_helper->runScript("if type(obj.createClassDAsB())==PythonQt.ClassB: obj.setPassed();\n")); | |
119 |
|
120 | |||
120 | PythonQt::self()->addPolymorphicHandler("ClassB", polymorphic_ClassB_Handler); |
|
121 | PythonQt::self()->addPolymorphicHandler("ClassB", polymorphic_ClassB_Handler); | |
121 |
|
122 | |||
122 | QVERIFY(_helper->runScript("if type(obj.getClassBPtr(obj.createClassB()))==PythonQt.ClassB: obj.setPassed();\n")); |
|
123 | QVERIFY(_helper->runScript("if type(obj.getClassBPtr(obj.createClassB()))==PythonQt.ClassB: obj.setPassed();\n")); | |
123 | QVERIFY(_helper->runScript("if type(obj.createClassCAsB())==PythonQt.ClassC: obj.setPassed();\n")); |
|
124 | QVERIFY(_helper->runScript("if type(obj.createClassCAsB())==PythonQt.ClassC: obj.setPassed();\n")); | |
124 | QVERIFY(_helper->runScript("if type(obj.createClassDAsB())==PythonQt.ClassD: obj.setPassed();\n")); |
|
125 | QVERIFY(_helper->runScript("if type(obj.createClassDAsB())==PythonQt.ClassD: obj.setPassed();\n")); | |
125 |
|
126 | |||
126 | } |
|
127 | } | |
127 |
|
128 | |||
128 | void PythonQtTestSlotCalling::testAutoConversion() { |
|
129 | void PythonQtTestSlotCalling::testAutoConversion() { | |
129 | QVERIFY(_helper->runScript("if obj.setAutoConvertColor(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red): obj.setPassed();\n")); |
|
130 | QVERIFY(_helper->runScript("if obj.setAutoConvertColor(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red): obj.setPassed();\n")); | |
130 | QVERIFY(_helper->runScript("if obj.setAutoConvertBrush(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QBrush(PythonQt.QtCore.Qt.red): obj.setPassed();\n")); |
|
131 | QVERIFY(_helper->runScript("if obj.setAutoConvertBrush(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QBrush(PythonQt.QtCore.Qt.red): obj.setPassed();\n")); | |
131 | QVERIFY(_helper->runScript("if obj.setAutoConvertPen(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QPen(PythonQt.QtCore.Qt.red): obj.setPassed();\n")); |
|
132 | QVERIFY(_helper->runScript("if obj.setAutoConvertPen(PythonQt.QtCore.Qt.red)==PythonQt.Qt.QPen(PythonQt.QtCore.Qt.red): obj.setPassed();\n")); | |
132 | QVERIFY(_helper->runScript("if obj.setAutoConvertBrush(PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red))==PythonQt.Qt.QBrush(PythonQt.QtCore.Qt.red): obj.setPassed();\n")); |
|
133 | QVERIFY(_helper->runScript("if obj.setAutoConvertBrush(PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red))==PythonQt.Qt.QBrush(PythonQt.QtCore.Qt.red): obj.setPassed();\n")); | |
133 | QVERIFY(_helper->runScript("if obj.setAutoConvertPen(PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red))==PythonQt.Qt.QPen(PythonQt.QtCore.Qt.red): obj.setPassed();\n")); |
|
134 | QVERIFY(_helper->runScript("if obj.setAutoConvertPen(PythonQt.Qt.QColor(PythonQt.QtCore.Qt.red))==PythonQt.Qt.QPen(PythonQt.QtCore.Qt.red): obj.setPassed();\n")); | |
134 | QVERIFY(_helper->runScript("if obj.setAutoConvertCursor(PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor)).shape()==PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape(): obj.setPassed();\n")); |
|
135 | QVERIFY(_helper->runScript("if obj.setAutoConvertCursor(PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor)).shape()==PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape(): obj.setPassed();\n")); | |
135 | QVERIFY(_helper->runScript("if obj.setAutoConvertCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape()==PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape(): obj.setPassed();\n")); |
|
136 | QVERIFY(_helper->runScript("if obj.setAutoConvertCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape()==PythonQt.Qt.QCursor(PythonQt.QtCore.Qt.UpArrowCursor).shape(): obj.setPassed();\n")); | |
136 | } |
|
137 | } | |
137 |
|
138 | |||
138 | void PythonQtTestSlotCalling::testNoArgSlotCall() |
|
139 | void PythonQtTestSlotCalling::testNoArgSlotCall() | |
139 | { |
|
140 | { | |
140 | QVERIFY(_helper->runScript("obj.testNoArg(); obj.setPassed();\n")); |
|
141 | QVERIFY(_helper->runScript("obj.testNoArg(); obj.setPassed();\n")); | |
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | void PythonQtTestSlotCalling::testOverloadedCall() |
|
144 | void PythonQtTestSlotCalling::testOverloadedCall() | |
144 | { |
|
145 | { | |
145 | QVERIFY(_helper->runScript("obj.overload(False); obj.setPassed();\n", 0)); |
|
146 | QVERIFY(_helper->runScript("obj.overload(False); obj.setPassed();\n", 0)); | |
146 | QVERIFY(_helper->runScript("obj.overload(True); obj.setPassed();\n", 0)); |
|
147 | QVERIFY(_helper->runScript("obj.overload(True); obj.setPassed();\n", 0)); | |
147 | QVERIFY(_helper->runScript("obj.overload(12.5); obj.setPassed();\n", 1)); |
|
148 | QVERIFY(_helper->runScript("obj.overload(12.5); obj.setPassed();\n", 1)); | |
148 | QVERIFY(_helper->runScript("obj.overload(12); obj.setPassed();\n", 2)); |
|
149 | QVERIFY(_helper->runScript("obj.overload(12); obj.setPassed();\n", 2)); | |
149 | QVERIFY(_helper->runScript("obj.overload('test'); obj.setPassed();\n", 3)); |
|
150 | QVERIFY(_helper->runScript("obj.overload('test'); obj.setPassed();\n", 3)); | |
150 | QVERIFY(_helper->runScript("obj.overload(u'test'); obj.setPassed();\n", 3)); |
|
151 | QVERIFY(_helper->runScript("obj.overload(u'test'); obj.setPassed();\n", 3)); | |
151 | QVERIFY(_helper->runScript("obj.overload(('test','test2')); obj.setPassed();\n", 4)); |
|
152 | QVERIFY(_helper->runScript("obj.overload(('test','test2')); obj.setPassed();\n", 4)); | |
152 | QVERIFY(_helper->runScript("obj.overload(obj); obj.setPassed();\n", 5)); |
|
153 | QVERIFY(_helper->runScript("obj.overload(obj); obj.setPassed();\n", 5)); | |
153 | QVERIFY(_helper->runScript("obj.overload(12,13); obj.setPassed();\n", 6)); |
|
154 | QVERIFY(_helper->runScript("obj.overload(12,13); obj.setPassed();\n", 6)); | |
154 | } |
|
155 | } | |
155 |
|
156 | |||
156 | void PythonQtTestSlotCalling::testPyObjectSlotCall() |
|
157 | void PythonQtTestSlotCalling::testPyObjectSlotCall() | |
157 | { |
|
158 | { | |
158 | QVERIFY(_helper->runScript("if obj.getPyObject(PythonQt)==PythonQt: obj.setPassed();\n")); |
|
159 | QVERIFY(_helper->runScript("if obj.getPyObject(PythonQt)==PythonQt: obj.setPassed();\n")); | |
159 | QVERIFY(_helper->runScript("if obj.getPyObject('Hello')=='Hello': obj.setPassed();\n")); |
|
160 | QVERIFY(_helper->runScript("if obj.getPyObject('Hello')=='Hello': obj.setPassed();\n")); | |
160 | QVERIFY(_helper->runScript("if obj.getPyObjectFromVariant(PythonQt)==PythonQt: obj.setPassed();\n")); |
|
161 | QVERIFY(_helper->runScript("if obj.getPyObjectFromVariant(PythonQt)==PythonQt: obj.setPassed();\n")); | |
161 | QVERIFY(_helper->runScript("if obj.getPyObjectFromVariant2(PythonQt)==PythonQt: obj.setPassed();\n")); |
|
162 | QVERIFY(_helper->runScript("if obj.getPyObjectFromVariant2(PythonQt)==PythonQt: obj.setPassed();\n")); | |
162 | // QVERIFY(_helper->runScript("if obj.getPyObjectFromPtr(PythonQt)==PythonQt: obj.setPassed();\n")); |
|
163 | // QVERIFY(_helper->runScript("if obj.getPyObjectFromPtr(PythonQt)==PythonQt: obj.setPassed();\n")); | |
163 | } |
|
164 | } | |
164 |
|
165 | |||
165 | void PythonQtTestSlotCalling::testCPPSlotCalls() |
|
166 | void PythonQtTestSlotCalling::testCPPSlotCalls() | |
166 | { |
|
167 | { | |
167 | // test QColor compare operation |
|
168 | // test QColor compare operation | |
168 | QVERIFY(_helper->runScript("if PythonQt.QtGui.QColor(1,2,3)==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();obj.testNoArg()\n")); |
|
169 | QVERIFY(_helper->runScript("if PythonQt.QtGui.QColor(1,2,3)==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();obj.testNoArg()\n")); | |
169 | QVERIFY(_helper->runScript("if PythonQt.QtGui.QColor(1,2,3)!=PythonQt.QtGui.QColor(3,2,1): obj.setPassed();obj.testNoArg()\n")); |
|
170 | QVERIFY(_helper->runScript("if PythonQt.QtGui.QColor(1,2,3)!=PythonQt.QtGui.QColor(3,2,1): obj.setPassed();obj.testNoArg()\n")); | |
170 |
|
171 | |||
171 | // test passing/returning QColors |
|
172 | // test passing/returning QColors | |
172 | QVERIFY(_helper->runScript("if obj.getQColor1(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); |
|
173 | QVERIFY(_helper->runScript("if obj.getQColor1(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); | |
173 | QVERIFY(_helper->runScript("if obj.getQColor2(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); |
|
174 | QVERIFY(_helper->runScript("if obj.getQColor2(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); | |
174 | QVERIFY(_helper->runScript("if obj.getQColor3(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); |
|
175 | QVERIFY(_helper->runScript("if obj.getQColor3(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); | |
175 | QVERIFY(_helper->runScript("if obj.getQColor4(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); |
|
176 | QVERIFY(_helper->runScript("if obj.getQColor4(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); | |
176 | QVERIFY(_helper->runScript("if obj.getQColor5()==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); |
|
177 | QVERIFY(_helper->runScript("if obj.getQColor5()==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); | |
177 | } |
|
178 | } | |
178 |
|
179 | |||
179 | void PythonQtTestSlotCalling::testPODSlotCalls() |
|
180 | void PythonQtTestSlotCalling::testPODSlotCalls() | |
180 | { |
|
181 | { | |
181 | QVERIFY(_helper->runScript("if obj.getBool(False)==False: obj.setPassed();\n")); |
|
182 | QVERIFY(_helper->runScript("if obj.getBool(False)==False: obj.setPassed();\n")); | |
182 | QVERIFY(_helper->runScript("if obj.getBool(True)==True: obj.setPassed();\n")); |
|
183 | QVERIFY(_helper->runScript("if obj.getBool(True)==True: obj.setPassed();\n")); | |
183 | QVERIFY(_helper->runScript("if obj.getInt(-42)==-42: obj.setPassed();\n")); |
|
184 | QVERIFY(_helper->runScript("if obj.getInt(-42)==-42: obj.setPassed();\n")); | |
184 | QVERIFY(_helper->runScript("if obj.getUInt(42)==42: obj.setPassed();\n")); |
|
185 | QVERIFY(_helper->runScript("if obj.getUInt(42)==42: obj.setPassed();\n")); | |
185 | QVERIFY(_helper->runScript("if obj.getShort(-43)==-43: obj.setPassed();\n")); |
|
186 | QVERIFY(_helper->runScript("if obj.getShort(-43)==-43: obj.setPassed();\n")); | |
186 | QVERIFY(_helper->runScript("if obj.getUShort(43)==43: obj.setPassed();\n")); |
|
187 | QVERIFY(_helper->runScript("if obj.getUShort(43)==43: obj.setPassed();\n")); | |
187 | QVERIFY(_helper->runScript("if obj.getChar(-12)==-12: obj.setPassed();\n")); |
|
188 | QVERIFY(_helper->runScript("if obj.getChar(-12)==-12: obj.setPassed();\n")); | |
188 | QVERIFY(_helper->runScript("if obj.getUChar(12)==12: obj.setPassed();\n")); |
|
189 | QVERIFY(_helper->runScript("if obj.getUChar(12)==12: obj.setPassed();\n")); | |
189 | QVERIFY(_helper->runScript("if obj.getLong(-256*256*256)==-256*256*256: obj.setPassed();\n")); |
|
190 | QVERIFY(_helper->runScript("if obj.getLong(-256*256*256)==-256*256*256: obj.setPassed();\n")); | |
190 | QVERIFY(_helper->runScript("if obj.getULong(256*256*256)==256*256*256: obj.setPassed();\n")); |
|
191 | QVERIFY(_helper->runScript("if obj.getULong(256*256*256)==256*256*256: obj.setPassed();\n")); | |
191 | QVERIFY(_helper->runScript("if obj.getLongLong(-42)==-42: obj.setPassed();\n")); |
|
192 | QVERIFY(_helper->runScript("if obj.getLongLong(-42)==-42: obj.setPassed();\n")); | |
192 | QVERIFY(_helper->runScript("if obj.getULongLong(42)==42: obj.setPassed();\n")); |
|
193 | QVERIFY(_helper->runScript("if obj.getULongLong(42)==42: obj.setPassed();\n")); | |
193 | QVERIFY(_helper->runScript("if obj.getQChar(4096)==4096: obj.setPassed();\n")); |
|
194 | QVERIFY(_helper->runScript("if obj.getQChar(4096)==4096: obj.setPassed();\n")); | |
194 | QVERIFY(_helper->runScript("if obj.getDouble(47.12)==47.12: obj.setPassed();\n")); |
|
195 | QVERIFY(_helper->runScript("if obj.getDouble(47.12)==47.12: obj.setPassed();\n")); | |
195 | QVERIFY(_helper->runScript("if abs(obj.getFloat(47.11)-47.11)<0.01: obj.setPassed();\n")); |
|
196 | QVERIFY(_helper->runScript("if abs(obj.getFloat(47.11)-47.11)<0.01: obj.setPassed();\n")); | |
196 | QVERIFY(_helper->runScript("if obj.getQString('testStr')=='testStr': obj.setPassed();\n")); |
|
197 | QVERIFY(_helper->runScript("if obj.getQString('testStr')=='testStr': obj.setPassed();\n")); | |
197 | QVERIFY(_helper->runScript("if obj.getQString('')=='': obj.setPassed();\n")); |
|
198 | QVERIFY(_helper->runScript("if obj.getQString('')=='': obj.setPassed();\n")); | |
198 | QVERIFY(_helper->runScript("if obj.getQStringList(('test','test2'))==('test','test2'): obj.setPassed();\n")); |
|
199 | QVERIFY(_helper->runScript("if obj.getQStringList(('test','test2'))==('test','test2'): obj.setPassed();\n")); | |
199 | } |
|
200 | } | |
200 |
|
201 | |||
201 | void PythonQtTestSlotCalling::testQVariantSlotCalls() |
|
202 | void PythonQtTestSlotCalling::testQVariantSlotCalls() | |
202 | { |
|
203 | { | |
203 | QVERIFY(_helper->runScript("if obj.getQVariant(-42)==-42: obj.setPassed();\n")); |
|
204 | QVERIFY(_helper->runScript("if obj.getQVariant(-42)==-42: obj.setPassed();\n")); | |
204 | QVERIFY(_helper->runScript("if obj.getQVariant('testStr')=='testStr': obj.setPassed();\n")); |
|
205 | QVERIFY(_helper->runScript("if obj.getQVariant('testStr')=='testStr': obj.setPassed();\n")); | |
205 | QVERIFY(_helper->runScript("if obj.getQVariant(('test','test2'))==('test','test2'): obj.setPassed();\n")); |
|
206 | QVERIFY(_helper->runScript("if obj.getQVariant(('test','test2'))==('test','test2'): obj.setPassed();\n")); | |
206 | QVERIFY(_helper->runScript("if obj.getQVariant(('test',12, 47.11))==('test',12, 47.11): obj.setPassed();\n")); |
|
207 | QVERIFY(_helper->runScript("if obj.getQVariant(('test',12, 47.11))==('test',12, 47.11): obj.setPassed();\n")); | |
207 | QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n")); |
|
208 | QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n")); | |
208 | QEXPECT_FAIL("", "Testing to pass a map and compare with a different map", Continue); |
|
209 | QEXPECT_FAIL("", "Testing to pass a map and compare with a different map", Continue); | |
209 | QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla2','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n")); |
|
210 | QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla2','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n")); | |
210 | QVERIFY(_helper->runScript("if obj.getQVariant(obj)==obj: obj.setPassed();\n")); |
|
211 | QVERIFY(_helper->runScript("if obj.getQVariant(obj)==obj: obj.setPassed();\n")); | |
211 | } |
|
212 | } | |
212 |
|
213 | |||
213 | void PythonQtTestSlotCalling::testObjectSlotCalls() |
|
214 | void PythonQtTestSlotCalling::testObjectSlotCalls() | |
214 | { |
|
215 | { | |
215 | QVERIFY(_helper->runScript("if obj.getQObject(obj)==obj: obj.setPassed();\n")); |
|
216 | QVERIFY(_helper->runScript("if obj.getQObject(obj)==obj: obj.setPassed();\n")); | |
216 | QVERIFY(_helper->runScript("if obj.getTestObject(obj)==obj: obj.setPassed();\n")); |
|
217 | QVERIFY(_helper->runScript("if obj.getTestObject(obj)==obj: obj.setPassed();\n")); | |
217 | QVERIFY(_helper->runScript("if obj.getNewObject().className()=='PythonQtTestSlotCallingHelper': obj.setPassed();\n")); |
|
218 | QVERIFY(_helper->runScript("if obj.getNewObject().className()=='PythonQtTestSlotCallingHelper': obj.setPassed();\n")); | |
218 | QEXPECT_FAIL("", "Testing to pass a QObject when another object was expected", Continue); |
|
219 | QEXPECT_FAIL("", "Testing to pass a QObject when another object was expected", Continue); | |
219 | QVERIFY(_helper->runScript("if obj.getQWidget(obj)==obj: obj.setPassed();\n")); |
|
220 | QVERIFY(_helper->runScript("if obj.getQWidget(obj)==obj: obj.setPassed();\n")); | |
220 | } |
|
221 | } | |
221 |
|
222 | |||
222 | void PythonQtTestSlotCalling::testCppFactory() |
|
223 | void PythonQtTestSlotCalling::testCppFactory() | |
223 | { |
|
224 | { | |
224 | PythonQtTestCppFactory* f = new PythonQtTestCppFactory; |
|
225 | PythonQtTestCppFactory* f = new PythonQtTestCppFactory; | |
225 | PythonQt::self()->addInstanceDecorators(new PQCppObjectDecorator); |
|
226 | PythonQt::self()->addInstanceDecorators(new PQCppObjectDecorator); | |
226 | // do not register, since we want to know if that works as well |
|
227 | // do not register, since we want to know if that works as well | |
227 | //qRegisterMetaType<PQCppObjectNoWrap>("PQCppObjectNoWrap"); |
|
228 | //qRegisterMetaType<PQCppObjectNoWrap>("PQCppObjectNoWrap"); | |
228 | PythonQt::self()->addDecorators(new PQCppObjectNoWrapDecorator); |
|
229 | PythonQt::self()->addDecorators(new PQCppObjectNoWrapDecorator); | |
229 |
|
230 | |||
230 | PythonQt::self()->addWrapperFactory(f); |
|
231 | PythonQt::self()->addWrapperFactory(f); | |
231 | QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getHeight()==12: obj.setPassed();\n")); |
|
232 | QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getHeight()==12: obj.setPassed();\n")); | |
232 | QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getH()==12: obj.setPassed();\n")); |
|
233 | QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getH()==12: obj.setPassed();\n")); | |
233 | QVERIFY(_helper->runScript("pq1 = obj.createPQCppObject(12);\n" |
|
234 | QVERIFY(_helper->runScript("pq1 = obj.createPQCppObject(12);\n" | |
234 | "pq2 = obj.createPQCppObject(13);\n" |
|
235 | "pq2 = obj.createPQCppObject(13);\n" | |
235 | "pq3 = obj.getPQCppObject(pq1);\n" |
|
236 | "pq3 = obj.getPQCppObject(pq1);\n" | |
236 | "pq4 = obj.getPQCppObject(pq2);\n" |
|
237 | "pq4 = obj.getPQCppObject(pq2);\n" | |
237 | "if pq3.getHeight()==12 and pq4.getHeight()==13: obj.setPassed();\n" |
|
238 | "if pq3.getHeight()==12 and pq4.getHeight()==13: obj.setPassed();\n" | |
238 | )); |
|
239 | )); | |
239 |
|
240 | |||
240 | QVERIFY(_helper->runScript("if obj.createPQCppObjectNoWrap(12).getH()==12: obj.setPassed();\n")); |
|
241 | QVERIFY(_helper->runScript("if obj.createPQCppObjectNoWrap(12).getH()==12: obj.setPassed();\n")); | |
241 |
|
242 | |||
242 | QVERIFY(_helper->runScript("if obj.getPQCppObjectNoWrapAsValue().getH()==47: obj.setPassed();\n")); |
|
243 | QVERIFY(_helper->runScript("if obj.getPQCppObjectNoWrapAsValue().getH()==47: obj.setPassed();\n")); | |
243 |
|
244 | |||
244 | qRegisterMetaType<PQUnknownButRegisteredValueObject>("PQUnknownButRegisteredValueObject"); |
|
245 | qRegisterMetaType<PQUnknownButRegisteredValueObject>("PQUnknownButRegisteredValueObject"); | |
245 | QVERIFY(_helper->runScript("a = obj.getUnknownButRegisteredValueObjectAsPtr();print a;\nif a!=None: obj.setPassed();\n")); |
|
246 | QVERIFY(_helper->runScript("a = obj.getUnknownButRegisteredValueObjectAsPtr();print a;\nif a!=None: obj.setPassed();\n")); | |
246 | QVERIFY(_helper->runScript("a = obj.getUnknownButRegisteredValueObjectAsValue();print a;\nif a!=None: obj.setPassed();\n")); |
|
247 | QVERIFY(_helper->runScript("a = obj.getUnknownButRegisteredValueObjectAsValue();print a;\nif a!=None: obj.setPassed();\n")); | |
247 | QVERIFY(_helper->runScript("a = obj.getUnknownValueObjectAsPtr();print a;\nif a!=None: obj.setPassed();\n")); |
|
248 | QVERIFY(_helper->runScript("a = obj.getUnknownValueObjectAsPtr();print a;\nif a!=None: obj.setPassed();\n")); | |
248 | QEXPECT_FAIL("", "Testing by value return without the object being registered as QMetaType or having registered a default constructor decorator", Continue); |
|
249 | QEXPECT_FAIL("", "Testing by value return without the object being registered as QMetaType or having registered a default constructor decorator", Continue); | |
249 | QVERIFY(_helper->runScript("a = obj.getUnknownValueObjectAsValue();print a;\nif a!=None: obj.setPassed();\n")); |
|
250 | QVERIFY(_helper->runScript("a = obj.getUnknownValueObjectAsValue();print a;\nif a!=None: obj.setPassed();\n")); | |
250 |
|
251 | |||
251 | // expect to get strict call to double overload |
|
252 | // expect to get strict call to double overload | |
252 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22.2)\nif a.getH()==2: obj.setPassed();\n")); |
|
253 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22.2)\nif a.getH()==2: obj.setPassed();\n")); | |
253 | // expect to get un-strict call to double overload |
|
254 | // expect to get un-strict call to double overload | |
254 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22)\nif a.getH()==2: obj.setPassed();\n")); |
|
255 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(22)\nif a.getH()==2: obj.setPassed();\n")); | |
255 | // expect to get strict call to copy constructor overload |
|
256 | // expect to get strict call to copy constructor overload | |
256 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(PQCppObjectNoWrap())\nprint a.getH()\nif a.getH()==1: obj.setPassed();\n")); |
|
257 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObjectNoWrap\na = PQCppObjectNoWrap(PQCppObjectNoWrap())\nprint a.getH()\nif a.getH()==1: obj.setPassed();\n")); | |
257 |
|
258 | |||
258 | // test decorated enums |
|
259 | // test decorated enums | |
259 | // already registered by signals test |
|
260 | // already registered by signals test | |
260 | //PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject<PQCppObject2Decorator>); |
|
261 | //PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject<PQCppObject2Decorator>); | |
261 |
|
262 | |||
262 | // local enum (decorated) |
|
263 | // local enum (decorated) | |
263 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nprint a.testEnumFlag1\nif a.testEnumFlag1(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); |
|
264 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nprint a.testEnumFlag1\nif a.testEnumFlag1(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); | |
264 | // enum with namespace (decorated) |
|
265 | // enum with namespace (decorated) | |
265 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag2(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); |
|
266 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag2(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); | |
266 | // with int overload to check overloading |
|
267 | // with int overload to check overloading | |
267 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag3(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); |
|
268 | QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag3(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); | |
268 |
|
269 | |||
269 | } |
|
270 | } | |
270 |
|
271 | |||
271 | PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag1(PQCppObject2* obj, PQCppObject2Decorator::TestEnumFlag flag) { |
|
272 | PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag1(PQCppObject2* obj, PQCppObject2Decorator::TestEnumFlag flag) { | |
272 | return flag; |
|
273 | return flag; | |
273 | } |
|
274 | } | |
274 |
|
275 | |||
275 | PQCppObject2::TestEnumFlag PQCppObject2Decorator::testEnumFlag2(PQCppObject2* obj, PQCppObject2::TestEnumFlag flag) { |
|
276 | PQCppObject2::TestEnumFlag PQCppObject2Decorator::testEnumFlag2(PQCppObject2* obj, PQCppObject2::TestEnumFlag flag) { | |
276 | return flag; |
|
277 | return flag; | |
277 | } |
|
278 | } | |
278 |
|
279 | |||
279 | // with int overload |
|
280 | // with int overload | |
280 | PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag3(PQCppObject2* obj, int flag) { |
|
281 | PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag3(PQCppObject2* obj, int flag) { | |
281 | return (TestEnumFlag)-1; |
|
282 | return (TestEnumFlag)-1; | |
282 | } |
|
283 | } | |
283 | PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag3(PQCppObject2* obj, PQCppObject2Decorator::TestEnumFlag flag) { |
|
284 | PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag3(PQCppObject2* obj, PQCppObject2Decorator::TestEnumFlag flag) { | |
284 | return flag; |
|
285 | return flag; | |
285 | } |
|
286 | } | |
286 |
|
287 | |||
287 | void PythonQtTestSlotCalling::testMultiArgsSlotCall() |
|
288 | void PythonQtTestSlotCalling::testMultiArgsSlotCall() | |
288 | { |
|
289 | { | |
289 | QVERIFY(_helper->runScript("if obj.getMultiArgs(12,47.11,'test')==(12,47.11,'test'): obj.setPassed();\n")); |
|
290 | QVERIFY(_helper->runScript("if obj.getMultiArgs(12,47.11,'test')==(12,47.11,'test'): obj.setPassed();\n")); | |
290 | } |
|
291 | } | |
291 |
|
292 | |||
292 | bool PythonQtTestSlotCallingHelper::runScript(const char* script, int expectedOverload) |
|
293 | bool PythonQtTestSlotCallingHelper::runScript(const char* script, int expectedOverload) | |
293 | { |
|
294 | { | |
294 | _called = false; |
|
295 | _called = false; | |
295 | _passed = false; |
|
296 | _passed = false; | |
296 | _calledOverload = -1; |
|
297 | _calledOverload = -1; | |
297 | PyRun_SimpleString(script); |
|
298 | PyRun_SimpleString(script); | |
298 | return _called && _passed && _calledOverload==expectedOverload; |
|
299 | return _called && _passed && _calledOverload==expectedOverload; | |
299 | } |
|
300 | } | |
300 |
|
301 | |||
301 |
|
302 | |||
302 | void PythonQtTestSignalHandler::initTestCase() |
|
303 | void PythonQtTestSignalHandler::initTestCase() | |
303 | { |
|
304 | { | |
304 | _helper = new PythonQtTestSignalHandlerHelper(this); |
|
305 | _helper = new PythonQtTestSignalHandlerHelper(this); | |
305 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); |
|
306 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); | |
306 | PythonQt::self()->addObject(main, "obj", _helper); |
|
307 | PythonQt::self()->addObject(main, "obj", _helper); | |
307 | } |
|
308 | } | |
308 |
|
309 | |||
309 | void PythonQtTestSignalHandler::testSignalHandler() |
|
310 | void PythonQtTestSignalHandler::testSignalHandler() | |
310 | { |
|
311 | { | |
311 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); |
|
312 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); | |
312 | PyRun_SimpleString("def testIntSignal(a):\n if a==12: obj.setPassed();\n"); |
|
313 | PyRun_SimpleString("def testIntSignal(a):\n if a==12: obj.setPassed();\n"); | |
313 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); |
|
314 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); | |
314 | QVERIFY(_helper->emitIntSignal(12)); |
|
315 | QVERIFY(_helper->emitIntSignal(12)); | |
315 |
|
316 | |||
316 | PyRun_SimpleString("def testFloatSignal(a):\n if a==12: obj.setPassed();\n"); |
|
317 | PyRun_SimpleString("def testFloatSignal(a):\n if a==12: obj.setPassed();\n"); | |
317 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); |
|
318 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); | |
318 | QVERIFY(_helper->emitFloatSignal(12)); |
|
319 | QVERIFY(_helper->emitFloatSignal(12)); | |
319 |
|
320 | |||
320 | // test decorated enums |
|
321 | // test decorated enums | |
321 | PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject<PQCppObject2Decorator>); |
|
322 | PythonQt::self()->registerCPPClass("PQCppObject2",NULL,NULL, PythonQtCreateObject<PQCppObject2Decorator>); | |
322 |
|
323 | |||
323 | PyRun_SimpleString("def testEnumSignal(a):\n if a==1: obj.setPassed();\n"); |
|
324 | PyRun_SimpleString("def testEnumSignal(a):\n if a==1: obj.setPassed();\n"); | |
324 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal")); |
|
325 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal")); | |
325 | QVERIFY(_helper->emitEnumSignal(PQCppObject2::TestEnumValue2)); |
|
326 | QVERIFY(_helper->emitEnumSignal(PQCppObject2::TestEnumValue2)); | |
326 |
|
327 | |||
327 | PyRun_SimpleString("def testVariantSignal(a):\n if a==obj.expectedVariant(): obj.setPassed();\n"); |
|
328 | PyRun_SimpleString("def testVariantSignal(a):\n if a==obj.expectedVariant(): obj.setPassed();\n"); | |
328 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); |
|
329 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); | |
329 | _helper->setExpectedVariant(QString("Test")); |
|
330 | _helper->setExpectedVariant(QString("Test")); | |
330 | QVERIFY(_helper->emitVariantSignal(QString("Test"))); |
|
331 | QVERIFY(_helper->emitVariantSignal(QString("Test"))); | |
331 | _helper->setExpectedVariant(12); |
|
332 | _helper->setExpectedVariant(12); | |
332 | QVERIFY(_helper->emitVariantSignal(12)); |
|
333 | QVERIFY(_helper->emitVariantSignal(12)); | |
333 | _helper->setExpectedVariant(QStringList() << "test1" << "test2"); |
|
334 | _helper->setExpectedVariant(QStringList() << "test1" << "test2"); | |
334 | QVERIFY(_helper->emitVariantSignal(QStringList() << "test1" << "test2")); |
|
335 | QVERIFY(_helper->emitVariantSignal(QStringList() << "test1" << "test2")); | |
335 | _helper->setExpectedVariant(qVariantFromValue((QObject*)_helper)); |
|
336 | _helper->setExpectedVariant(qVariantFromValue((QObject*)_helper)); | |
336 | QVERIFY(_helper->emitVariantSignal(qVariantFromValue((QObject*)_helper))); |
|
337 | QVERIFY(_helper->emitVariantSignal(qVariantFromValue((QObject*)_helper))); | |
337 |
|
338 | |||
338 | PyRun_SimpleString("def testComplexSignal(a,b,l,o):\n if a==12 and b==13 and l==('test1','test2') and o == obj: obj.setPassed();\n"); |
|
339 | PyRun_SimpleString("def testComplexSignal(a,b,l,o):\n if a==12 and b==13 and l==('test1','test2') and o == obj: obj.setPassed();\n"); | |
339 | // intentionally not normalized signal: |
|
340 | // intentionally not normalized signal: | |
340 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal")); |
|
341 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal")); | |
341 | QVERIFY(_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper)); |
|
342 | QVERIFY(_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper)); | |
342 |
|
343 | |||
343 | // try removing the handler |
|
344 | // try removing the handler | |
344 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal")); |
|
345 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal")); | |
345 | // and emit the signal, which should fail because the handler was removed |
|
346 | // and emit the signal, which should fail because the handler was removed | |
346 | QVERIFY(!_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper)); |
|
347 | QVERIFY(!_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper)); | |
347 |
|
348 | |||
348 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); |
|
349 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); | |
349 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); |
|
350 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); | |
350 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); |
|
351 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); | |
351 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal")); |
|
352 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(enumSignal(PQCppObject2::TestEnumFlag)), main, "testEnumSignal")); | |
352 |
|
353 | |||
353 | } |
|
354 | } | |
354 |
|
355 | |||
355 | void PythonQtTestSignalHandler::testRecursiveSignalHandler() |
|
356 | void PythonQtTestSignalHandler::testRecursiveSignalHandler() | |
356 | { |
|
357 | { | |
357 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); |
|
358 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); | |
358 | PyRun_SimpleString("def testSignal1(a):\n obj.emitSignal2(a);\n"); |
|
359 | PyRun_SimpleString("def testSignal1(a):\n obj.emitSignal2(a);\n"); | |
359 | PyRun_SimpleString("def testSignal2(a):\n obj.emitSignal3(float(a));\n"); |
|
360 | PyRun_SimpleString("def testSignal2(a):\n obj.emitSignal3(float(a));\n"); | |
360 | PyRun_SimpleString("def testSignal3(a):\n if a==12: obj.setPassed();\n"); |
|
361 | PyRun_SimpleString("def testSignal3(a):\n if a==12: obj.setPassed();\n"); | |
361 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal1(int)), main, "testSignal1")); |
|
362 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal1(int)), main, "testSignal1")); | |
362 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal2(const QString&)), main, "testSignal2")); |
|
363 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal2(const QString&)), main, "testSignal2")); | |
363 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal3(float)), main, "testSignal3")); |
|
364 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal3(float)), main, "testSignal3")); | |
364 | QVERIFY(_helper->emitSignal1(12)); |
|
365 | QVERIFY(_helper->emitSignal1(12)); | |
365 | } |
|
366 | } | |
366 |
|
367 | |||
367 |
|
368 | |||
368 | void PythonQtTestApi::initTestCase() |
|
369 | void PythonQtTestApi::initTestCase() | |
369 | { |
|
370 | { | |
370 | _helper = new PythonQtTestApiHelper(); |
|
371 | _helper = new PythonQtTestApiHelper(); | |
371 | _main = PythonQt::self()->getMainModule(); |
|
372 | _main = PythonQt::self()->getMainModule(); | |
372 | _main.evalScript("import PythonQt"); |
|
373 | _main.evalScript("import PythonQt"); | |
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); | |
379 | return _passed && expectedResult==r; |
|
422 | return _passed && expectedResult==r; | |
380 | } |
|
423 | } | |
381 |
|
424 | |||
382 | void PythonQtTestApi::testCall() |
|
425 | void PythonQtTestApi::testCall() | |
383 | { |
|
426 | { | |
384 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); |
|
427 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); | |
385 |
|
428 | |||
386 | QVERIFY(qVariantValue<QObject*>(PythonQt::self()->getVariable(main, "obj"))==_helper); |
|
429 | QVERIFY(qVariantValue<QObject*>(PythonQt::self()->getVariable(main, "obj"))==_helper); | |
387 |
|
430 | |||
388 | PyRun_SimpleString("def testCallNoArgs():\n obj.setPassed();\n"); |
|
431 | PyRun_SimpleString("def testCallNoArgs():\n obj.setPassed();\n"); | |
389 | QVERIFY(_helper->call("testCallNoArgs", QVariantList(), QVariant())); |
|
432 | QVERIFY(_helper->call("testCallNoArgs", QVariantList(), QVariant())); | |
390 |
|
433 | |||
391 | PyRun_SimpleString("def testCall1(a):\n if a=='test': obj.setPassed();\n return 'test2';\n"); |
|
434 | PyRun_SimpleString("def testCall1(a):\n if a=='test': obj.setPassed();\n return 'test2';\n"); | |
392 | QVERIFY(_helper->call("testCall1", QVariantList() << QVariant("test"), QVariant(QString("test2")))); |
|
435 | QVERIFY(_helper->call("testCall1", QVariantList() << QVariant("test"), QVariant(QString("test2")))); | |
393 |
|
436 | |||
394 | PyRun_SimpleString("def testCall2(a, b):\n if a=='test' and b==obj: obj.setPassed();\n return obj;\n"); |
|
437 | PyRun_SimpleString("def testCall2(a, b):\n if a=='test' and b==obj: obj.setPassed();\n return obj;\n"); | |
395 | QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), "testCall2", QVariantList() << QVariant("test") << qVariantFromValue((QObject*)_helper)); |
|
438 | QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), "testCall2", QVariantList() << QVariant("test") << qVariantFromValue((QObject*)_helper)); | |
396 | QObject* p = qVariantValue<QObject*>(r); |
|
439 | QObject* p = qVariantValue<QObject*>(r); | |
397 | QVERIFY(p==_helper); |
|
440 | QVERIFY(p==_helper); | |
398 | } |
|
441 | } | |
399 |
|
442 | |||
400 | void PythonQtTestApi::testVariables() |
|
443 | void PythonQtTestApi::testVariables() | |
401 | { |
|
444 | { | |
402 | PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper); |
|
445 | PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper); | |
403 | QVariant v = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject"); |
|
446 | QVariant v = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject"); | |
404 | QObject* p = qVariantValue<QObject*>(v); |
|
447 | QObject* p = qVariantValue<QObject*>(v); | |
405 | QVERIFY(p==_helper); |
|
448 | QVERIFY(p==_helper); | |
406 | // test for unset variable |
|
449 | // test for unset variable | |
407 | QVariant v2 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject2"); |
|
450 | QVariant v2 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject2"); | |
408 | QVERIFY(v2==QVariant()); |
|
451 | QVERIFY(v2==QVariant()); | |
409 |
|
452 | |||
410 | PythonQt::self()->addVariable(PythonQt::self()->getMainModule(), "someValue", QStringList() << "test1" << "test2"); |
|
453 | PythonQt::self()->addVariable(PythonQt::self()->getMainModule(), "someValue", QStringList() << "test1" << "test2"); | |
411 | QVariant v3 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someValue"); |
|
454 | QVariant v3 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someValue"); | |
412 | QVERIFY(v3 == QVariant(QStringList() << "test1" << "test2")); |
|
455 | QVERIFY(v3 == QVariant(QStringList() << "test1" << "test2")); | |
413 |
|
456 | |||
414 | QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), QString::null, PythonQt::Variable); |
|
457 | QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), QString::null, PythonQt::Variable); | |
415 | QSet<QString> s; |
|
458 | QSet<QString> s; | |
416 | // check that at least these three variables are set |
|
459 | // check that at least these three variables are set | |
417 | s << "obj" << "someObject" << "someValue"; |
|
460 | s << "obj" << "someObject" << "someValue"; | |
418 | foreach (QString value, s) { |
|
461 | foreach (QString value, s) { | |
419 | QVERIFY(l.indexOf(value)!=-1); |
|
462 | QVERIFY(l.indexOf(value)!=-1); | |
420 | } |
|
463 | } | |
421 |
|
464 | |||
422 | // insert a second time! |
|
465 | // insert a second time! | |
423 | PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper); |
|
466 | PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper); | |
424 | // and remove |
|
467 | // and remove | |
425 | PythonQt::self()->removeVariable(PythonQt::self()->getMainModule(), "someObject"); |
|
468 | PythonQt::self()->removeVariable(PythonQt::self()->getMainModule(), "someObject"); | |
426 | // we expect to find no variable |
|
469 | // we expect to find no variable | |
427 | QVariant v4 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject"); |
|
470 | QVariant v4 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject"); | |
428 | QVERIFY(v4==QVariant()); |
|
471 | QVERIFY(v4==QVariant()); | |
429 | } |
|
472 | } | |
430 |
|
473 | |||
431 | void PythonQtTestApi::testImporter() |
|
474 | void PythonQtTestApi::testImporter() | |
432 | { |
|
475 | { | |
433 | PythonQt::self()->setImporter(_helper); |
|
476 | PythonQt::self()->setImporter(_helper); | |
434 | PythonQt::self()->overwriteSysPath(QStringList() << "c:\\test"); |
|
477 | PythonQt::self()->overwriteSysPath(QStringList() << "c:\\test"); | |
435 | PyRun_SimpleString("import bla\n"); |
|
478 | PyRun_SimpleString("import bla\n"); | |
436 | } |
|
479 | } | |
437 |
|
480 | |||
438 | void PythonQtTestApi::testQtNamespace() |
|
481 | void PythonQtTestApi::testQtNamespace() | |
439 | { |
|
482 | { | |
440 | QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.red").toInt()==Qt::red); |
|
483 | QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.red").toInt()==Qt::red); | |
441 | QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.FlatCap").toInt()==Qt::FlatCap); |
|
484 | QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.FlatCap").toInt()==Qt::FlatCap); | |
442 | QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.escape"))); |
|
485 | QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.escape"))); | |
443 | // check for an enum type wrapper |
|
486 | // check for an enum type wrapper | |
444 | QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.AlignmentFlag"))); |
|
487 | QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.AlignmentFlag"))); | |
445 | // check for a flags type wrapper |
|
488 | // check for a flags type wrapper | |
446 | QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.Alignment"))); |
|
489 | QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.Alignment"))); | |
447 | } |
|
490 | } | |
448 |
|
491 | |||
449 | void PythonQtTestApi::testConnects() |
|
492 | void PythonQtTestApi::testConnects() | |
450 | { |
|
493 | { | |
451 | // QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(PythonQt.Qt.Qt.red)" ,Py_eval_input)) == QColor(Qt::red)); |
|
494 | // QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(PythonQt.Qt.Qt.red)" ,Py_eval_input)) == QColor(Qt::red)); | |
452 | //TODO: add signal/slot connect both with QObject.connect and connect |
|
495 | //TODO: add signal/slot connect both with QObject.connect and connect | |
453 | } |
|
496 | } | |
454 |
|
497 | |||
455 | void PythonQtTestApi::testQColorDecorators() |
|
498 | void PythonQtTestApi::testQColorDecorators() | |
456 | { |
|
499 | { | |
457 | PythonQtObjectPtr colorClass = _main.getVariable("PythonQt.QtGui.QColor"); |
|
500 | PythonQtObjectPtr colorClass = _main.getVariable("PythonQt.QtGui.QColor"); | |
458 | QVERIFY(colorClass); |
|
501 | QVERIFY(colorClass); | |
459 | // verify that the class is in the correct module |
|
502 | // verify that the class is in the correct module | |
460 | QVERIFY(colorClass.getVariable("__module__") == "PythonQt.QtGui"); |
|
503 | QVERIFY(colorClass.getVariable("__module__") == "PythonQt.QtGui"); | |
461 | // test on Qt module as well: |
|
504 | // test on Qt module as well: | |
462 | colorClass = _main.getVariable("PythonQt.Qt.QColor"); |
|
505 | colorClass = _main.getVariable("PythonQt.Qt.QColor"); | |
463 | QVERIFY(colorClass); |
|
506 | QVERIFY(colorClass); | |
464 | // constructors |
|
507 | // constructors | |
465 | QVERIFY(qVariantValue<QColor>(colorClass.call(QVariantList() << 1 << 2 << 3)) == QColor(1,2,3)); |
|
508 | QVERIFY(qVariantValue<QColor>(colorClass.call(QVariantList() << 1 << 2 << 3)) == QColor(1,2,3)); | |
466 | QVERIFY(qVariantValue<QColor>(colorClass.call()) == QColor()); |
|
509 | QVERIFY(qVariantValue<QColor>(colorClass.call()) == QColor()); | |
467 | QEXPECT_FAIL("", "Testing non-existing constructor", Continue); |
|
510 | QEXPECT_FAIL("", "Testing non-existing constructor", Continue); | |
468 | QVERIFY(colorClass.call(QVariantList() << 1 << 2) != QVariant()); |
|
511 | QVERIFY(colorClass.call(QVariantList() << 1 << 2) != QVariant()); | |
469 |
|
512 | |||
470 | // check that enum overload is taken over int |
|
513 | // check that enum overload is taken over int | |
471 | QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(PythonQt.Qt.Qt.red)" ,Py_eval_input)) == QColor(Qt::red)); |
|
514 | QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(PythonQt.Qt.Qt.red)" ,Py_eval_input)) == QColor(Qt::red)); | |
472 | // check that int overload is taken over enum |
|
515 | // check that int overload is taken over enum | |
473 | QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(0x112233)" ,Py_eval_input)) == QColor(0x112233)); |
|
516 | QVERIFY(qVariantValue<QColor>(_main.evalScript("PythonQt.Qt.QColor(0x112233)" ,Py_eval_input)) == QColor(0x112233)); | |
474 |
|
517 | |||
475 | // check for decorated Cmyk enum value |
|
518 | // check for decorated Cmyk enum value | |
476 | QVERIFY(colorClass.getVariable("Cmyk").toInt() == QColor::Cmyk); |
|
519 | QVERIFY(colorClass.getVariable("Cmyk").toInt() == QColor::Cmyk); | |
477 | PythonQtObjectPtr staticMethod = colorClass.getVariable("fromRgb"); |
|
520 | PythonQtObjectPtr staticMethod = colorClass.getVariable("fromRgb"); | |
478 | QVERIFY(staticMethod); |
|
521 | QVERIFY(staticMethod); | |
479 | // direct call of static method via class |
|
522 | // direct call of static method via class | |
480 | QVERIFY(qVariantValue<QColor>(colorClass.call("fromRgb", QVariantList() << 1 << 2 << 3)) == QColor(1,2,3)); |
|
523 | QVERIFY(qVariantValue<QColor>(colorClass.call("fromRgb", QVariantList() << 1 << 2 << 3)) == QColor(1,2,3)); | |
481 | // direct call of static method |
|
524 | // direct call of static method | |
482 | QVERIFY(qVariantValue<QColor>(staticMethod.call(QVariantList() << 1 << 2 << 3)) == QColor(1,2,3)); |
|
525 | QVERIFY(qVariantValue<QColor>(staticMethod.call(QVariantList() << 1 << 2 << 3)) == QColor(1,2,3)); | |
483 | PythonQtObjectPtr publicMethod = colorClass.getVariable("red"); |
|
526 | PythonQtObjectPtr publicMethod = colorClass.getVariable("red"); | |
484 | QVERIFY(publicMethod); |
|
527 | QVERIFY(publicMethod); | |
485 | // call with passing self in: |
|
528 | // call with passing self in: | |
486 | QVERIFY(colorClass.call("red", QVariantList() << QColor(255,0,0)).toInt() == 255); |
|
529 | QVERIFY(colorClass.call("red", QVariantList() << QColor(255,0,0)).toInt() == 255); | |
487 | } |
|
530 | } | |
488 |
|
531 | |||
489 | QByteArray PythonQtTestApiHelper::readFileAsBytes(const QString& filename) |
|
532 | QByteArray PythonQtTestApiHelper::readFileAsBytes(const QString& filename) | |
490 | { |
|
533 | { | |
491 | QByteArray b; |
|
534 | QByteArray b; | |
492 | return b; |
|
535 | return b; | |
493 | } |
|
536 | } | |
494 |
|
537 | |||
495 | QByteArray PythonQtTestApiHelper::readSourceFile(const QString& filename, bool& ok) |
|
538 | QByteArray PythonQtTestApiHelper::readSourceFile(const QString& filename, bool& ok) | |
496 | { |
|
539 | { | |
497 | QByteArray b; |
|
540 | QByteArray b; | |
498 | ok = true; |
|
541 | ok = true; | |
499 | return b; |
|
542 | return b; | |
500 | } |
|
543 | } | |
501 |
|
544 | |||
502 | bool PythonQtTestApiHelper::exists(const QString& filename) |
|
545 | bool PythonQtTestApiHelper::exists(const QString& filename) | |
503 | { |
|
546 | { | |
504 | return true; |
|
547 | return true; | |
505 | } |
|
548 | } | |
506 |
|
549 | |||
507 | QDateTime PythonQtTestApiHelper::lastModifiedDate(const QString& filename) { |
|
550 | QDateTime PythonQtTestApiHelper::lastModifiedDate(const QString& filename) { | |
508 | return QDateTime::currentDateTime(); |
|
551 | return QDateTime::currentDateTime(); | |
509 | } |
|
552 | } | |
510 |
|
553 | |||
511 |
|
554 | |||
512 | void PythonQtTestApi::testRedirect() |
|
555 | void PythonQtTestApi::testRedirect() | |
513 | { |
|
556 | { | |
514 | connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), _helper, SLOT(stdOut(const QString&))); |
|
557 | connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), _helper, SLOT(stdOut(const QString&))); | |
515 | connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)), _helper, SLOT(stdErr(const QString&))); |
|
558 | connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)), _helper, SLOT(stdErr(const QString&))); | |
516 | PyRun_SimpleString("print 'test'\n"); |
|
559 | PyRun_SimpleString("print 'test'\n"); | |
517 | } |
|
560 | } | |
518 |
|
561 | |||
519 | void PythonQtTestApiHelper::stdOut(const QString& s) |
|
562 | void PythonQtTestApiHelper::stdOut(const QString& s) | |
520 | { |
|
563 | { | |
521 | qDebug() << s; |
|
564 | qDebug() << s; | |
522 | } |
|
565 | } | |
523 |
|
566 | |||
524 | void PythonQtTestApiHelper::stdErr(const QString& s) |
|
567 | void PythonQtTestApiHelper::stdErr(const QString& s) | |
525 | { |
|
568 | { | |
526 | qDebug() << s; |
|
569 | qDebug() << s; | |
527 | } |
|
570 | } | |
528 |
|
571 | |||
529 | QObject* PythonQtTestCppFactory::create(const QByteArray& name, void *ptr) |
|
572 | QObject* PythonQtTestCppFactory::create(const QByteArray& name, void *ptr) | |
530 | { |
|
573 | { | |
531 | if (name == "PQCppObject") { |
|
574 | if (name == "PQCppObject") { | |
532 | return new PQCppObjectWrapper(ptr); |
|
575 | return new PQCppObjectWrapper(ptr); | |
533 | } |
|
576 | } | |
534 | return NULL; |
|
577 | return NULL; | |
535 | } |
|
578 | } |
@@ -1,512 +1,515 | |||||
1 | #ifndef _PYTHONQTTESTS_H |
|
1 | #ifndef _PYTHONQTTESTS_H | |
2 | #define _PYTHONQTTESTS_H |
|
2 | #define _PYTHONQTTESTS_H | |
3 |
|
3 | |||
4 | /* |
|
4 | /* | |
5 | * |
|
5 | * | |
6 | * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. |
|
6 | * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved. | |
7 | * |
|
7 | * | |
8 | * This library is free software; you can redistribute it and/or |
|
8 | * This library is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public |
|
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either |
|
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. |
|
11 | * version 2.1 of the License, or (at your option) any later version. | |
12 | * |
|
12 | * | |
13 | * This library is distributed in the hope that it will be useful, |
|
13 | * This library is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * Lesser General Public License for more details. |
|
16 | * Lesser General Public License for more details. | |
17 | * |
|
17 | * | |
18 | * Further, this software is distributed without any warranty that it is |
|
18 | * Further, this software is distributed without any warranty that it is | |
19 | * free of the rightful claim of any third person regarding infringement |
|
19 | * free of the rightful claim of any third person regarding infringement | |
20 | * or the like. Any license provided herein, whether implied or |
|
20 | * or the like. Any license provided herein, whether implied or | |
21 | * otherwise, applies only to this software file. Patent licenses, if |
|
21 | * otherwise, applies only to this software file. Patent licenses, if | |
22 | * any, provided herein do not apply to combinations of this program with |
|
22 | * any, provided herein do not apply to combinations of this program with | |
23 | * other software, or any other product whatsoever. |
|
23 | * other software, or any other product whatsoever. | |
24 | * |
|
24 | * | |
25 | * You should have received a copy of the GNU Lesser General Public |
|
25 | * You should have received a copy of the GNU Lesser General Public | |
26 | * License along with this library; if not, write to the Free Software |
|
26 | * License along with this library; if not, write to the Free Software | |
27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
28 | * |
|
28 | * | |
29 | * Contact information: MeVis Research GmbH, Universitaetsallee 29, |
|
29 | * Contact information: MeVis Research GmbH, Universitaetsallee 29, | |
30 | * 28359 Bremen, Germany or: |
|
30 | * 28359 Bremen, Germany or: | |
31 | * |
|
31 | * | |
32 | * http://www.mevis.de |
|
32 | * http://www.mevis.de | |
33 | * |
|
33 | * | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | //---------------------------------------------------------------------------------- |
|
36 | //---------------------------------------------------------------------------------- | |
37 | /*! |
|
37 | /*! | |
38 | // \file PythonQtTests.h |
|
38 | // \file PythonQtTests.h | |
39 | // \author Florian Link |
|
39 | // \author Florian Link | |
40 | // \author Last changed by $Author: florian $ |
|
40 | // \author Last changed by $Author: florian $ | |
41 | // \date 2006-05 |
|
41 | // \date 2006-05 | |
42 | */ |
|
42 | */ | |
43 | //---------------------------------------------------------------------------------- |
|
43 | //---------------------------------------------------------------------------------- | |
44 |
|
44 | |||
45 | #include "PythonQt.h" |
|
45 | #include "PythonQt.h" | |
46 | #include <QtTest/QtTest> |
|
46 | #include <QtTest/QtTest> | |
47 | #include <QVariant> |
|
47 | #include <QVariant> | |
48 | #include "PythonQtImportFileInterface.h" |
|
48 | #include "PythonQtImportFileInterface.h" | |
49 | #include "PythonQtCppWrapperFactory.h" |
|
49 | #include "PythonQtCppWrapperFactory.h" | |
50 |
|
50 | |||
51 | #include <QPen> |
|
51 | #include <QPen> | |
52 | #include <QColor> |
|
52 | #include <QColor> | |
53 | #include <QBrush> |
|
53 | #include <QBrush> | |
54 | #include <QCursor> |
|
54 | #include <QCursor> | |
55 |
|
55 | |||
56 | class PythonQtTestSlotCallingHelper; |
|
56 | class PythonQtTestSlotCallingHelper; | |
57 | class PythonQtTestApiHelper; |
|
57 | class PythonQtTestApiHelper; | |
58 | class QWidget; |
|
58 | class QWidget; | |
59 |
|
59 | |||
60 | //! test the PythonQt api |
|
60 | //! test the PythonQt api | |
61 | class PythonQtTestApi : public QObject |
|
61 | class PythonQtTestApi : public QObject | |
62 | { |
|
62 | { | |
63 | Q_OBJECT |
|
63 | Q_OBJECT | |
64 |
|
64 | |||
65 | private slots: |
|
65 | private slots: | |
66 | void initTestCase(); |
|
66 | void initTestCase(); | |
67 | void testCall(); |
|
67 | void testCall(); | |
68 | void testVariables(); |
|
68 | void testVariables(); | |
69 | void testRedirect(); |
|
69 | void testRedirect(); | |
70 | void testImporter(); |
|
70 | void testImporter(); | |
71 | void testQColorDecorators(); |
|
71 | void testQColorDecorators(); | |
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; | |
78 |
|
81 | |||
79 | }; |
|
82 | }; | |
80 |
|
83 | |||
81 | class ClassA { |
|
84 | class ClassA { | |
82 | public: |
|
85 | public: | |
83 | ClassA() { x = 1; } |
|
86 | ClassA() { x = 1; } | |
84 | int x; |
|
87 | int x; | |
85 | }; |
|
88 | }; | |
86 |
|
89 | |||
87 | class ClassB { |
|
90 | class ClassB { | |
88 | public: |
|
91 | public: | |
89 | ClassB() { y = 2; } |
|
92 | ClassB() { y = 2; } | |
90 | int y; |
|
93 | int y; | |
91 |
|
94 | |||
92 | virtual int type() { return 2; } |
|
95 | virtual int type() { return 2; } | |
93 | }; |
|
96 | }; | |
94 |
|
97 | |||
95 | class ClassC : public ClassA, public ClassB { |
|
98 | class ClassC : public ClassA, public ClassB { | |
96 | public: |
|
99 | public: | |
97 | ClassC() { z = 3; } |
|
100 | ClassC() { z = 3; } | |
98 | int z; |
|
101 | int z; | |
99 |
|
102 | |||
100 | virtual int type() { return 3; } |
|
103 | virtual int type() { return 3; } | |
101 | }; |
|
104 | }; | |
102 |
|
105 | |||
103 | class ClassD : public QObject, public ClassA, public ClassB { |
|
106 | class ClassD : public QObject, public ClassA, public ClassB { | |
104 | Q_OBJECT |
|
107 | Q_OBJECT | |
105 | public: |
|
108 | public: | |
106 | ClassD() { d = 4; } |
|
109 | ClassD() { d = 4; } | |
107 | public slots: |
|
110 | public slots: | |
108 | int getD() { return d; } |
|
111 | int getD() { return d; } | |
109 | private: |
|
112 | private: | |
110 | int d; |
|
113 | int d; | |
111 |
|
114 | |||
112 | virtual int type() { return 4; } |
|
115 | virtual int type() { return 4; } | |
113 | }; |
|
116 | }; | |
114 |
|
117 | |||
115 | class ClassAWrapper : public QObject { |
|
118 | class ClassAWrapper : public QObject { | |
116 | Q_OBJECT |
|
119 | Q_OBJECT | |
117 | public slots: |
|
120 | public slots: | |
118 | ClassA* new_ClassA() { return new ClassA; } |
|
121 | ClassA* new_ClassA() { return new ClassA; } | |
119 | int getX(ClassA* o) { return o->x; } |
|
122 | int getX(ClassA* o) { return o->x; } | |
120 | }; |
|
123 | }; | |
121 |
|
124 | |||
122 | class ClassBWrapper : public QObject { |
|
125 | class ClassBWrapper : public QObject { | |
123 | Q_OBJECT |
|
126 | Q_OBJECT | |
124 | public slots: |
|
127 | public slots: | |
125 | ClassB* new_ClassB() { return new ClassB; } |
|
128 | ClassB* new_ClassB() { return new ClassB; } | |
126 | int getY(ClassB* o) { return o->y; } |
|
129 | int getY(ClassB* o) { return o->y; } | |
127 | }; |
|
130 | }; | |
128 |
|
131 | |||
129 | class ClassCWrapper : public QObject { |
|
132 | class ClassCWrapper : public QObject { | |
130 | Q_OBJECT |
|
133 | Q_OBJECT | |
131 | public slots: |
|
134 | public slots: | |
132 | ClassC* new_ClassC() { return new ClassC; } |
|
135 | ClassC* new_ClassC() { return new ClassC; } | |
133 | int getZ(ClassC* o) { return o->z; } |
|
136 | int getZ(ClassC* o) { return o->z; } | |
134 | }; |
|
137 | }; | |
135 |
|
138 | |||
136 | class ClassDWrapper : public QObject { |
|
139 | class ClassDWrapper : public QObject { | |
137 | Q_OBJECT |
|
140 | Q_OBJECT | |
138 | public slots: |
|
141 | public slots: | |
139 | ClassD* new_ClassD() { return new ClassD; } |
|
142 | ClassD* new_ClassD() { return new ClassD; } | |
140 | }; |
|
143 | }; | |
141 |
|
144 | |||
142 |
|
145 | |||
143 | //! test the PythonQt api (helper) |
|
146 | //! test the PythonQt api (helper) | |
144 | class PythonQtTestApiHelper : public QObject , public PythonQtImportFileInterface |
|
147 | class PythonQtTestApiHelper : public QObject , public PythonQtImportFileInterface | |
145 | { |
|
148 | { | |
146 | Q_OBJECT |
|
149 | Q_OBJECT | |
147 | public: |
|
150 | public: | |
148 | PythonQtTestApiHelper() { |
|
151 | PythonQtTestApiHelper() { | |
149 | }; |
|
152 | }; | |
150 |
|
153 | |||
151 | bool call(const QString& function, const QVariantList& args, const QVariant& expectedResult); |
|
154 | bool call(const QString& function, const QVariantList& args, const QVariant& expectedResult); | |
152 |
|
155 | |||
153 | virtual QByteArray readFileAsBytes(const QString& filename); |
|
156 | virtual QByteArray readFileAsBytes(const QString& filename); | |
154 |
|
157 | |||
155 | virtual QByteArray readSourceFile(const QString& filename, bool& ok); |
|
158 | virtual QByteArray readSourceFile(const QString& filename, bool& ok); | |
156 |
|
159 | |||
157 | virtual bool exists(const QString& filename); |
|
160 | virtual bool exists(const QString& filename); | |
158 |
|
161 | |||
159 | virtual QDateTime lastModifiedDate(const QString& filename); |
|
162 | virtual QDateTime lastModifiedDate(const QString& filename); | |
160 |
|
163 | |||
161 | public slots: |
|
164 | public slots: | |
162 |
|
165 | |||
163 | //! call to set that the test has passed (from Python!) |
|
166 | //! call to set that the test has passed (from Python!) | |
164 | void setPassed() { _passed = true; } |
|
167 | void setPassed() { _passed = true; } | |
165 |
|
168 | |||
166 | void stdOut(const QString&); |
|
169 | void stdOut(const QString&); | |
167 | void stdErr(const QString&); |
|
170 | void stdErr(const QString&); | |
168 |
|
171 | |||
169 | private: |
|
172 | private: | |
170 | bool _passed; |
|
173 | bool _passed; | |
171 | }; |
|
174 | }; | |
172 |
|
175 | |||
173 |
|
176 | |||
174 | // test implementation of the wrapper factory |
|
177 | // test implementation of the wrapper factory | |
175 | class PythonQtTestCppFactory : public PythonQtCppWrapperFactory |
|
178 | class PythonQtTestCppFactory : public PythonQtCppWrapperFactory | |
176 | { |
|
179 | { | |
177 | public: |
|
180 | public: | |
178 | virtual QObject* create(const QByteArray& name, void *ptr); |
|
181 | virtual QObject* create(const QByteArray& name, void *ptr); | |
179 | }; |
|
182 | }; | |
180 |
|
183 | |||
181 | //! an cpp object to be wrapped |
|
184 | //! an cpp object to be wrapped | |
182 | class PQCppObject { |
|
185 | class PQCppObject { | |
183 |
|
186 | |||
184 | public: |
|
187 | public: | |
185 | PQCppObject(int h) { _height = h; } |
|
188 | PQCppObject(int h) { _height = h; } | |
186 |
|
189 | |||
187 | int getHeight() { return _height; } |
|
190 | int getHeight() { return _height; } | |
188 | void setHeight(int h) { _height = h; } |
|
191 | void setHeight(int h) { _height = h; } | |
189 |
|
192 | |||
190 | private: |
|
193 | private: | |
191 | int _height; |
|
194 | int _height; | |
192 | }; |
|
195 | }; | |
193 |
|
196 | |||
194 | //! an qobject that wraps the existing cpp object |
|
197 | //! an qobject that wraps the existing cpp object | |
195 | class PQCppObjectWrapper : public QObject { |
|
198 | class PQCppObjectWrapper : public QObject { | |
196 | Q_OBJECT |
|
199 | Q_OBJECT | |
197 | public: |
|
200 | public: | |
198 | PQCppObjectWrapper(void* ptr) { |
|
201 | PQCppObjectWrapper(void* ptr) { | |
199 | _ptr = (PQCppObject*)ptr; |
|
202 | _ptr = (PQCppObject*)ptr; | |
200 | } |
|
203 | } | |
201 |
|
204 | |||
202 | public slots: |
|
205 | public slots: | |
203 | int getHeight() { return _ptr->getHeight(); } |
|
206 | int getHeight() { return _ptr->getHeight(); } | |
204 | void setHeight(int h) { _ptr->setHeight(h); } |
|
207 | void setHeight(int h) { _ptr->setHeight(h); } | |
205 |
|
208 | |||
206 | private: |
|
209 | private: | |
207 | PQCppObject* _ptr; |
|
210 | PQCppObject* _ptr; | |
208 | }; |
|
211 | }; | |
209 |
|
212 | |||
210 | class PQCppObjectDecorator : public QObject { |
|
213 | class PQCppObjectDecorator : public QObject { | |
211 | Q_OBJECT |
|
214 | Q_OBJECT | |
212 | public slots: |
|
215 | public slots: | |
213 | int getH(PQCppObject* obj) { return obj->getHeight(); } |
|
216 | int getH(PQCppObject* obj) { return obj->getHeight(); } | |
214 |
|
217 | |||
215 | }; |
|
218 | }; | |
216 |
|
219 | |||
217 | //! an cpp object to be wrapped by decorators only |
|
220 | //! an cpp object to be wrapped by decorators only | |
218 | class PQCppObjectNoWrap { |
|
221 | class PQCppObjectNoWrap { | |
219 |
|
222 | |||
220 | public: |
|
223 | public: | |
221 | PQCppObjectNoWrap() { _height = 0; } |
|
224 | PQCppObjectNoWrap() { _height = 0; } | |
222 | PQCppObjectNoWrap(int h) { _height = h; } |
|
225 | PQCppObjectNoWrap(int h) { _height = h; } | |
223 |
|
226 | |||
224 | int getHeight() { return _height; } |
|
227 | int getHeight() { return _height; } | |
225 | void setHeight(int h) { _height = h; } |
|
228 | void setHeight(int h) { _height = h; } | |
226 |
|
229 | |||
227 | private: |
|
230 | private: | |
228 | int _height; |
|
231 | int _height; | |
229 | }; |
|
232 | }; | |
230 |
|
233 | |||
231 | class PQCppObjectNoWrapDecorator : public QObject { |
|
234 | class PQCppObjectNoWrapDecorator : public QObject { | |
232 | Q_OBJECT |
|
235 | Q_OBJECT | |
233 |
|
236 | |||
234 | public slots: |
|
237 | public slots: | |
235 | PQCppObjectNoWrap* new_PQCppObjectNoWrap() { |
|
238 | PQCppObjectNoWrap* new_PQCppObjectNoWrap() { | |
236 | return new PQCppObjectNoWrap(0); |
|
239 | return new PQCppObjectNoWrap(0); | |
237 | } |
|
240 | } | |
238 | PQCppObjectNoWrap* new_PQCppObjectNoWrap(const PQCppObjectNoWrap& other) { |
|
241 | PQCppObjectNoWrap* new_PQCppObjectNoWrap(const PQCppObjectNoWrap& other) { | |
239 | return new PQCppObjectNoWrap(1); |
|
242 | return new PQCppObjectNoWrap(1); | |
240 | } |
|
243 | } | |
241 | PQCppObjectNoWrap* new_PQCppObjectNoWrap(double value) { |
|
244 | PQCppObjectNoWrap* new_PQCppObjectNoWrap(double value) { | |
242 | return new PQCppObjectNoWrap(2); |
|
245 | return new PQCppObjectNoWrap(2); | |
243 | } |
|
246 | } | |
244 |
|
247 | |||
245 | int getH(PQCppObjectNoWrap* obj) { return obj->getHeight(); } |
|
248 | int getH(PQCppObjectNoWrap* obj) { return obj->getHeight(); } | |
246 |
|
249 | |||
247 | }; |
|
250 | }; | |
248 |
|
251 | |||
249 |
|
252 | |||
250 | //! an cpp object that is to be wrapped by decorators only |
|
253 | //! an cpp object that is to be wrapped by decorators only | |
251 | class PQCppObject2 { |
|
254 | class PQCppObject2 { | |
252 |
|
255 | |||
253 | public: |
|
256 | public: | |
254 | enum TestEnumFlag { |
|
257 | enum TestEnumFlag { | |
255 | TestEnumValue1 = 0, |
|
258 | TestEnumValue1 = 0, | |
256 | TestEnumValue2 = 1 |
|
259 | TestEnumValue2 = 1 | |
257 | }; |
|
260 | }; | |
258 |
|
261 | |||
259 | PQCppObject2() {} |
|
262 | PQCppObject2() {} | |
260 |
|
263 | |||
261 | }; |
|
264 | }; | |
262 |
|
265 | |||
263 | class PQCppObject2Decorator : public QObject { |
|
266 | class PQCppObject2Decorator : public QObject { | |
264 | Q_OBJECT |
|
267 | Q_OBJECT | |
265 |
|
268 | |||
266 | public: |
|
269 | public: | |
267 | Q_ENUMS(TestEnumFlag) |
|
270 | Q_ENUMS(TestEnumFlag) | |
268 | Q_FLAGS(TestEnum) |
|
271 | Q_FLAGS(TestEnum) | |
269 |
|
272 | |||
270 | enum TestEnumFlag { |
|
273 | enum TestEnumFlag { | |
271 | TestEnumValue1 = 0, |
|
274 | TestEnumValue1 = 0, | |
272 | TestEnumValue2 = 1 |
|
275 | TestEnumValue2 = 1 | |
273 | }; |
|
276 | }; | |
274 |
|
277 | |||
275 | Q_DECLARE_FLAGS(TestEnum, TestEnumFlag) |
|
278 | Q_DECLARE_FLAGS(TestEnum, TestEnumFlag) | |
276 |
|
279 | |||
277 | public slots: |
|
280 | public slots: | |
278 | PQCppObject2* new_PQCppObject2() { |
|
281 | PQCppObject2* new_PQCppObject2() { | |
279 | return new PQCppObject2(); |
|
282 | return new PQCppObject2(); | |
280 | } |
|
283 | } | |
281 |
|
284 | |||
282 | TestEnumFlag testEnumFlag1(PQCppObject2* obj, TestEnumFlag flag); |
|
285 | TestEnumFlag testEnumFlag1(PQCppObject2* obj, TestEnumFlag flag); | |
283 |
|
286 | |||
284 | PQCppObject2::TestEnumFlag testEnumFlag2(PQCppObject2* obj, PQCppObject2::TestEnumFlag flag); |
|
287 | PQCppObject2::TestEnumFlag testEnumFlag2(PQCppObject2* obj, PQCppObject2::TestEnumFlag flag); | |
285 |
|
288 | |||
286 | // with int overload |
|
289 | // with int overload | |
287 | TestEnumFlag testEnumFlag3(PQCppObject2* obj, int flag); |
|
290 | TestEnumFlag testEnumFlag3(PQCppObject2* obj, int flag); | |
288 | TestEnumFlag testEnumFlag3(PQCppObject2* obj, TestEnumFlag flag); |
|
291 | TestEnumFlag testEnumFlag3(PQCppObject2* obj, TestEnumFlag flag); | |
289 |
|
292 | |||
290 | }; |
|
293 | }; | |
291 |
|
294 | |||
292 | class PQUnknownValueObject |
|
295 | class PQUnknownValueObject | |
293 | { |
|
296 | { | |
294 | public: |
|
297 | public: | |
295 | PQUnknownValueObject() {}; |
|
298 | PQUnknownValueObject() {}; | |
296 | }; |
|
299 | }; | |
297 |
|
300 | |||
298 | class PQUnknownButRegisteredValueObject |
|
301 | class PQUnknownButRegisteredValueObject | |
299 | { |
|
302 | { | |
300 | public: |
|
303 | public: | |
301 | PQUnknownButRegisteredValueObject() {}; |
|
304 | PQUnknownButRegisteredValueObject() {}; | |
302 | }; |
|
305 | }; | |
303 |
|
306 | |||
304 | //! test the calling of slots |
|
307 | //! test the calling of slots | |
305 | class PythonQtTestSlotCalling : public QObject |
|
308 | class PythonQtTestSlotCalling : public QObject | |
306 | { |
|
309 | { | |
307 | Q_OBJECT |
|
310 | Q_OBJECT | |
308 |
|
311 | |||
309 | private slots: |
|
312 | private slots: | |
310 | void initTestCase(); |
|
313 | void initTestCase(); | |
311 | void init(); |
|
314 | void init(); | |
312 |
|
315 | |||
313 | void testNoArgSlotCall(); |
|
316 | void testNoArgSlotCall(); | |
314 | void testPODSlotCalls(); |
|
317 | void testPODSlotCalls(); | |
315 | void testCPPSlotCalls(); |
|
318 | void testCPPSlotCalls(); | |
316 | void testQVariantSlotCalls(); |
|
319 | void testQVariantSlotCalls(); | |
317 | void testObjectSlotCalls(); |
|
320 | void testObjectSlotCalls(); | |
318 | void testMultiArgsSlotCall(); |
|
321 | void testMultiArgsSlotCall(); | |
319 | void testPyObjectSlotCall(); |
|
322 | void testPyObjectSlotCall(); | |
320 | void testOverloadedCall(); |
|
323 | void testOverloadedCall(); | |
321 | void testCppFactory(); |
|
324 | void testCppFactory(); | |
322 | void testInheritance(); |
|
325 | void testInheritance(); | |
323 | void testAutoConversion(); |
|
326 | void testAutoConversion(); | |
324 |
|
327 | |||
325 | private: |
|
328 | private: | |
326 | PythonQtTestSlotCallingHelper* _helper; |
|
329 | PythonQtTestSlotCallingHelper* _helper; | |
327 |
|
330 | |||
328 | }; |
|
331 | }; | |
329 |
|
332 | |||
330 | //! helper class for slot calling test |
|
333 | //! helper class for slot calling test | |
331 | class PythonQtTestSlotCallingHelper : public QObject |
|
334 | class PythonQtTestSlotCallingHelper : public QObject | |
332 | { |
|
335 | { | |
333 | Q_OBJECT |
|
336 | Q_OBJECT | |
334 | public: |
|
337 | public: | |
335 | PythonQtTestSlotCallingHelper(PythonQtTestSlotCalling* test) { |
|
338 | PythonQtTestSlotCallingHelper(PythonQtTestSlotCalling* test) { | |
336 | _test = test; |
|
339 | _test = test; | |
337 | }; |
|
340 | }; | |
338 |
|
341 | |||
339 | bool runScript(const char* script, int expectedOverload = -1); |
|
342 | bool runScript(const char* script, int expectedOverload = -1); | |
340 |
|
343 | |||
341 | public slots: |
|
344 | public slots: | |
342 |
|
345 | |||
343 | //! call to set that the test has passed (from Python!) |
|
346 | //! call to set that the test has passed (from Python!) | |
344 | void setPassed() { _passed = true; } |
|
347 | void setPassed() { _passed = true; } | |
345 |
|
348 | |||
346 | //! no arguments, no return value: |
|
349 | //! no arguments, no return value: | |
347 | void testNoArg() { _called = true; } |
|
350 | void testNoArg() { _called = true; } | |
348 |
|
351 | |||
349 | //! overload test! |
|
352 | //! overload test! | |
350 | void overload(bool a) { _calledOverload = 0; _called = true; } |
|
353 | void overload(bool a) { _calledOverload = 0; _called = true; } | |
351 | void overload(float a) { _calledOverload = 1; _called = true;} |
|
354 | void overload(float a) { _calledOverload = 1; _called = true;} | |
352 | void overload(int a) { _calledOverload = 2; _called = true;} |
|
355 | void overload(int a) { _calledOverload = 2; _called = true;} | |
353 | void overload(const QString& str) { _calledOverload = 3; _called = true;} |
|
356 | void overload(const QString& str) { _calledOverload = 3; _called = true;} | |
354 | void overload(const QStringList& str) { _calledOverload = 4; _called = true;} |
|
357 | void overload(const QStringList& str) { _calledOverload = 4; _called = true;} | |
355 | void overload(QObject* str) { _calledOverload = 5; _called = true;} |
|
358 | void overload(QObject* str) { _calledOverload = 5; _called = true;} | |
356 | void overload(float a, int b) { _calledOverload = 6; _called = true;} |
|
359 | void overload(float a, int b) { _calledOverload = 6; _called = true;} | |
357 |
|
360 | |||
358 | //! POD values: |
|
361 | //! POD values: | |
359 | int getInt(int a) { _called = true; return a; } |
|
362 | int getInt(int a) { _called = true; return a; } | |
360 | unsigned int getUInt(unsigned int a) { _called = true; return a; } |
|
363 | unsigned int getUInt(unsigned int a) { _called = true; return a; } | |
361 | bool getBool(bool a) { _called = true; return a; } |
|
364 | bool getBool(bool a) { _called = true; return a; } | |
362 | char getChar(char a) { _called = true; return a; } |
|
365 | char getChar(char a) { _called = true; return a; } | |
363 | unsigned char getUChar(unsigned char a) { _called = true; return a; } |
|
366 | unsigned char getUChar(unsigned char a) { _called = true; return a; } | |
364 | long getLong(long a) { _called = true; return a; } |
|
367 | long getLong(long a) { _called = true; return a; } | |
365 | unsigned long getULong(unsigned long a) { _called = true; return a; } |
|
368 | unsigned long getULong(unsigned long a) { _called = true; return a; } | |
366 | short getShort(short a) { _called = true; return a; } |
|
369 | short getShort(short a) { _called = true; return a; } | |
367 | unsigned short getUShort(unsigned short a) { _called = true; return a; } |
|
370 | unsigned short getUShort(unsigned short a) { _called = true; return a; } | |
368 | QChar getQChar(QChar a) { _called = true; return a; } |
|
371 | QChar getQChar(QChar a) { _called = true; return a; } | |
369 | qint64 getLongLong(qint64 a) { _called = true; return a; } |
|
372 | qint64 getLongLong(qint64 a) { _called = true; return a; } | |
370 | quint64 getULongLong(quint64 a) { _called = true; return a; } |
|
373 | quint64 getULongLong(quint64 a) { _called = true; return a; } | |
371 | double getDouble(double d) { _called = true; return d; } |
|
374 | double getDouble(double d) { _called = true; return d; } | |
372 | float getFloat(float d) { _called = true; return d; } |
|
375 | float getFloat(float d) { _called = true; return d; } | |
373 |
|
376 | |||
374 | //! important qt types: |
|
377 | //! important qt types: | |
375 | QString getQString(const QString& s) { _called = true; return s; } |
|
378 | QString getQString(const QString& s) { _called = true; return s; } | |
376 | QStringList getQStringList(const QStringList& l) { _called = true; return l; } |
|
379 | QStringList getQStringList(const QStringList& l) { _called = true; return l; } | |
377 | QVariant getQVariant(const QVariant& var) { _called = true; return var; } |
|
380 | QVariant getQVariant(const QVariant& var) { _called = true; return var; } | |
378 |
|
381 | |||
379 | // QColor as representative for C++ value classes |
|
382 | // QColor as representative for C++ value classes | |
380 | QColor getQColor1(const QColor& var) { _called = true; return var; } |
|
383 | QColor getQColor1(const QColor& var) { _called = true; return var; } | |
381 | QColor getQColor2(QColor& var) { _called = true; return var; } |
|
384 | QColor getQColor2(QColor& var) { _called = true; return var; } | |
382 | QColor getQColor3(QColor* col) { _called = true; return *col; } |
|
385 | QColor getQColor3(QColor* col) { _called = true; return *col; } | |
383 | QColor getQColor4(const QVariant& color) { _called = true; return qVariantValue<QColor>(color); } |
|
386 | QColor getQColor4(const QVariant& color) { _called = true; return qVariantValue<QColor>(color); } | |
384 | QColor* getQColor5() { _called = true; static QColor c(1,2,3); return &c; } |
|
387 | QColor* getQColor5() { _called = true; static QColor c(1,2,3); return &c; } | |
385 |
|
388 | |||
386 | PyObject* getPyObject(PyObject* obj) { _called = true; return obj; } |
|
389 | PyObject* getPyObject(PyObject* obj) { _called = true; return obj; } | |
387 | PyObject* getPyObjectFromVariant(const QVariant& val) { _called = true; return PythonQtObjectPtr(val); }; |
|
390 | PyObject* getPyObjectFromVariant(const QVariant& val) { _called = true; return PythonQtObjectPtr(val); }; | |
388 | QVariant getPyObjectFromVariant2(const QVariant& val) { _called = true; return val; }; |
|
391 | QVariant getPyObjectFromVariant2(const QVariant& val) { _called = true; return val; }; | |
389 | // this does not yet work but is not required to work: |
|
392 | // this does not yet work but is not required to work: | |
390 | //PyObject* getPyObjectFromPtr(const PythonQtObjectPtr& val) { _called = true; return val; }; |
|
393 | //PyObject* getPyObjectFromPtr(const PythonQtObjectPtr& val) { _called = true; return val; }; | |
391 |
|
394 | |||
392 | //! testing pointer passing |
|
395 | //! testing pointer passing | |
393 | PythonQtTestSlotCallingHelper* getTestObject(PythonQtTestSlotCallingHelper* obj) { _called = true; return obj; } |
|
396 | PythonQtTestSlotCallingHelper* getTestObject(PythonQtTestSlotCallingHelper* obj) { _called = true; return obj; } | |
394 | //! testing inheritance checking |
|
397 | //! testing inheritance checking | |
395 | QObject* getQObject(QObject* obj) { _called = true; return obj; } |
|
398 | QObject* getQObject(QObject* obj) { _called = true; return obj; } | |
396 | QWidget* getQWidget(QWidget* obj) { _called = true; return obj; } |
|
399 | QWidget* getQWidget(QWidget* obj) { _called = true; return obj; } | |
397 | //! testing if an object that was not wrapped is wrapped earlier is wrapped correctly |
|
400 | //! testing if an object that was not wrapped is wrapped earlier is wrapped correctly | |
398 | QObject* getNewObject() { _called = true; return new PythonQtTestSlotCallingHelper(NULL); } |
|
401 | QObject* getNewObject() { _called = true; return new PythonQtTestSlotCallingHelper(NULL); } | |
399 |
|
402 | |||
400 | QVariantList getMultiArgs(int a, double b, const QString& str) { _called = true; return (QVariantList() << a << b << str); } |
|
403 | QVariantList getMultiArgs(int a, double b, const QString& str) { _called = true; return (QVariantList() << a << b << str); } | |
401 |
|
404 | |||
402 | //! cpp wrapper factory test |
|
405 | //! cpp wrapper factory test | |
403 | PQCppObject* createPQCppObject(int h) { _called = true; return new PQCppObject(h); } |
|
406 | PQCppObject* createPQCppObject(int h) { _called = true; return new PQCppObject(h); } | |
404 |
|
407 | |||
405 | //! cpp wrapper factory test |
|
408 | //! cpp wrapper factory test | |
406 | PQCppObject* getPQCppObject(PQCppObject* p) { _called = true; return p; } |
|
409 | PQCppObject* getPQCppObject(PQCppObject* p) { _called = true; return p; } | |
407 |
|
410 | |||
408 | //! cpp wrapper factory test |
|
411 | //! cpp wrapper factory test | |
409 | PQCppObjectNoWrap* createPQCppObjectNoWrap(int h) { _called = true; return new PQCppObjectNoWrap(h); } |
|
412 | PQCppObjectNoWrap* createPQCppObjectNoWrap(int h) { _called = true; return new PQCppObjectNoWrap(h); } | |
410 |
|
413 | |||
411 | //! cpp wrapper factory test |
|
414 | //! cpp wrapper factory test | |
412 | PQCppObjectNoWrap* getPQCppObjectNoWrap(PQCppObjectNoWrap* p) { _called = true; return p; } |
|
415 | PQCppObjectNoWrap* getPQCppObjectNoWrap(PQCppObjectNoWrap* p) { _called = true; return p; } | |
413 |
|
416 | |||
414 | //! get a return by value PQCppObjectNoWrap |
|
417 | //! get a return by value PQCppObjectNoWrap | |
415 | PQCppObjectNoWrap getPQCppObjectNoWrapAsValue() { _called = true; return PQCppObjectNoWrap(47); } |
|
418 | PQCppObjectNoWrap getPQCppObjectNoWrapAsValue() { _called = true; return PQCppObjectNoWrap(47); } | |
416 |
|
419 | |||
417 | PQUnknownButRegisteredValueObject getUnknownButRegisteredValueObjectAsValue() { _called = true; return PQUnknownButRegisteredValueObject(); } |
|
420 | PQUnknownButRegisteredValueObject getUnknownButRegisteredValueObjectAsValue() { _called = true; return PQUnknownButRegisteredValueObject(); } | |
418 | PQUnknownValueObject getUnknownValueObjectAsValue() { _called = true; return PQUnknownValueObject(); } |
|
421 | PQUnknownValueObject getUnknownValueObjectAsValue() { _called = true; return PQUnknownValueObject(); } | |
419 |
|
422 | |||
420 | PQUnknownButRegisteredValueObject* getUnknownButRegisteredValueObjectAsPtr() { _called = true; return new PQUnknownButRegisteredValueObject(); } |
|
423 | PQUnknownButRegisteredValueObject* getUnknownButRegisteredValueObjectAsPtr() { _called = true; return new PQUnknownButRegisteredValueObject(); } | |
421 | PQUnknownValueObject* getUnknownValueObjectAsPtr() { _called = true; return new PQUnknownValueObject(); } |
|
424 | PQUnknownValueObject* getUnknownValueObjectAsPtr() { _called = true; return new PQUnknownValueObject(); } | |
422 |
|
425 | |||
423 | ClassA* getClassAPtr(ClassA* o) { _called = true; return o; } |
|
426 | ClassA* getClassAPtr(ClassA* o) { _called = true; return o; } | |
424 | ClassB* getClassBPtr(ClassB* o) { _called = true; return o; } |
|
427 | ClassB* getClassBPtr(ClassB* o) { _called = true; return o; } | |
425 | ClassC* getClassCPtr(ClassC* o) { _called = true; return o; } |
|
428 | ClassC* getClassCPtr(ClassC* o) { _called = true; return o; } | |
426 | ClassD* getClassDPtr(ClassD* o) { _called = true; return o; } |
|
429 | ClassD* getClassDPtr(ClassD* o) { _called = true; return o; } | |
427 |
|
430 | |||
428 | ClassA* createClassA() { _called = true; return new ClassA; } |
|
431 | ClassA* createClassA() { _called = true; return new ClassA; } | |
429 | ClassB* createClassB() { _called = true; return new ClassB; } |
|
432 | ClassB* createClassB() { _called = true; return new ClassB; } | |
430 | ClassC* createClassC() { _called = true; return new ClassC; } |
|
433 | ClassC* createClassC() { _called = true; return new ClassC; } | |
431 | ClassD* createClassD() { _called = true; return new ClassD; } |
|
434 | ClassD* createClassD() { _called = true; return new ClassD; } | |
432 | ClassA* createClassCAsA() { _called = true; return new ClassC; } |
|
435 | ClassA* createClassCAsA() { _called = true; return new ClassC; } | |
433 | ClassB* createClassCAsB() { _called = true; return new ClassC; } |
|
436 | ClassB* createClassCAsB() { _called = true; return new ClassC; } | |
434 | ClassA* createClassDAsA() { _called = true; return new ClassD; } |
|
437 | ClassA* createClassDAsA() { _called = true; return new ClassD; } | |
435 | ClassB* createClassDAsB() { _called = true; return new ClassD; } |
|
438 | ClassB* createClassDAsB() { _called = true; return new ClassD; } | |
436 |
|
439 | |||
437 | QColor setAutoConvertColor(const QColor& color) { _called = true; return color; }; |
|
440 | QColor setAutoConvertColor(const QColor& color) { _called = true; return color; }; | |
438 | QBrush setAutoConvertBrush(const QBrush& brush) { _called = true; return brush; }; |
|
441 | QBrush setAutoConvertBrush(const QBrush& brush) { _called = true; return brush; }; | |
439 | QPen setAutoConvertPen(const QPen& pen) { _called = true; return pen; }; |
|
442 | QPen setAutoConvertPen(const QPen& pen) { _called = true; return pen; }; | |
440 | QCursor setAutoConvertCursor(const QCursor& cursor) { _called = true; return cursor; }; |
|
443 | QCursor setAutoConvertCursor(const QCursor& cursor) { _called = true; return cursor; }; | |
441 |
|
444 | |||
442 | private: |
|
445 | private: | |
443 | bool _passed; |
|
446 | bool _passed; | |
444 | bool _called; |
|
447 | bool _called; | |
445 | int _calledOverload; |
|
448 | int _calledOverload; | |
446 | PythonQtTestSlotCalling* _test; |
|
449 | PythonQtTestSlotCalling* _test; | |
447 | }; |
|
450 | }; | |
448 |
|
451 | |||
449 | class PythonQtTestSignalHandlerHelper; |
|
452 | class PythonQtTestSignalHandlerHelper; | |
450 |
|
453 | |||
451 | //! test the connection of signals to python |
|
454 | //! test the connection of signals to python | |
452 | class PythonQtTestSignalHandler : public QObject |
|
455 | class PythonQtTestSignalHandler : public QObject | |
453 | { |
|
456 | { | |
454 | Q_OBJECT |
|
457 | Q_OBJECT | |
455 |
|
458 | |||
456 | private slots: |
|
459 | private slots: | |
457 | void initTestCase(); |
|
460 | void initTestCase(); | |
458 |
|
461 | |||
459 | void testSignalHandler(); |
|
462 | void testSignalHandler(); | |
460 | void testRecursiveSignalHandler(); |
|
463 | void testRecursiveSignalHandler(); | |
461 |
|
464 | |||
462 | private: |
|
465 | private: | |
463 | PythonQtTestSignalHandlerHelper* _helper; |
|
466 | PythonQtTestSignalHandlerHelper* _helper; | |
464 |
|
467 | |||
465 | }; |
|
468 | }; | |
466 |
|
469 | |||
467 | //! helper class for signal testing |
|
470 | //! helper class for signal testing | |
468 | class PythonQtTestSignalHandlerHelper : public QObject |
|
471 | class PythonQtTestSignalHandlerHelper : public QObject | |
469 | { |
|
472 | { | |
470 | Q_OBJECT |
|
473 | Q_OBJECT | |
471 |
|
474 | |||
472 | public: |
|
475 | public: | |
473 | PythonQtTestSignalHandlerHelper(PythonQtTestSignalHandler* test) { |
|
476 | PythonQtTestSignalHandlerHelper(PythonQtTestSignalHandler* test) { | |
474 | _test = test; |
|
477 | _test = test; | |
475 | }; |
|
478 | }; | |
476 |
|
479 | |||
477 | public slots: |
|
480 | public slots: | |
478 | void setPassed() { _passed = true; } |
|
481 | void setPassed() { _passed = true; } | |
479 |
|
482 | |||
480 | bool emitIntSignal(int a) { _passed = false; emit intSignal(a); return _passed; }; |
|
483 | bool emitIntSignal(int a) { _passed = false; emit intSignal(a); return _passed; }; | |
481 | bool emitFloatSignal(float a) { _passed = false; emit floatSignal(a); return _passed; }; |
|
484 | bool emitFloatSignal(float a) { _passed = false; emit floatSignal(a); return _passed; }; | |
482 | bool emitEnumSignal(PQCppObject2::TestEnumFlag flag) { _passed = false; emit enumSignal(flag); return _passed; }; |
|
485 | bool emitEnumSignal(PQCppObject2::TestEnumFlag flag) { _passed = false; emit enumSignal(flag); return _passed; }; | |
483 |
|
486 | |||
484 | bool emitVariantSignal(const QVariant& v) { _passed = false; emit variantSignal(v); return _passed; }; |
|
487 | bool emitVariantSignal(const QVariant& v) { _passed = false; emit variantSignal(v); return _passed; }; | |
485 | QVariant expectedVariant() { return _v; } |
|
488 | QVariant expectedVariant() { return _v; } | |
486 | void setExpectedVariant(const QVariant& v) { _v = v; } |
|
489 | void setExpectedVariant(const QVariant& v) { _v = v; } | |
487 |
|
490 | |||
488 | bool emitComplexSignal(int a, float b, const QStringList& l, QObject* obj) { _passed = false; emit complexSignal(a,b,l,obj); return _passed; }; |
|
491 | bool emitComplexSignal(int a, float b, const QStringList& l, QObject* obj) { _passed = false; emit complexSignal(a,b,l,obj); return _passed; }; | |
489 |
|
492 | |||
490 | bool emitSignal1(int a) { _passed = false; emit signal1(a); return _passed; }; |
|
493 | bool emitSignal1(int a) { _passed = false; emit signal1(a); return _passed; }; | |
491 | bool emitSignal2(const QString& s) { _passed = false; emit signal2(s); return _passed; }; |
|
494 | bool emitSignal2(const QString& s) { _passed = false; emit signal2(s); return _passed; }; | |
492 | bool emitSignal3(float a) { _passed = false; emit signal3(a); return _passed; }; |
|
495 | bool emitSignal3(float a) { _passed = false; emit signal3(a); return _passed; }; | |
493 |
|
496 | |||
494 | signals: |
|
497 | signals: | |
495 | void intSignal(int); |
|
498 | void intSignal(int); | |
496 | void floatSignal(float); |
|
499 | void floatSignal(float); | |
497 | void variantSignal(const QVariant& v); |
|
500 | void variantSignal(const QVariant& v); | |
498 | void complexSignal(int a, float b, const QStringList& l, QObject* obj); |
|
501 | void complexSignal(int a, float b, const QStringList& l, QObject* obj); | |
499 | void enumSignal(PQCppObject2::TestEnumFlag flag); |
|
502 | void enumSignal(PQCppObject2::TestEnumFlag flag); | |
500 |
|
503 | |||
501 | void signal1(int); |
|
504 | void signal1(int); | |
502 | void signal2(const QString&); |
|
505 | void signal2(const QString&); | |
503 | void signal3(float); |
|
506 | void signal3(float); | |
504 |
|
507 | |||
505 | private: |
|
508 | private: | |
506 | bool _passed; |
|
509 | bool _passed; | |
507 | QVariant _v; |
|
510 | QVariant _v; | |
508 |
|
511 | |||
509 | PythonQtTestSignalHandler* _test; |
|
512 | PythonQtTestSignalHandler* _test; | |
510 | }; |
|
513 | }; | |
511 |
|
514 | |||
512 | #endif |
|
515 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now