@@ -1,61 +1,68 | |||||
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 "PythonQt.h" |
|
42 | #include "PythonQt.h" | |
43 | #include "PythonQtTests.h" |
|
43 | #include "PythonQtTests.h" | |
44 |
|
44 | |||
45 | int main( int argc, char **argv ) |
|
45 | int main( int argc, char **argv ) | |
46 | { |
|
46 | { | |
47 | QApplication qapp(argc, argv); |
|
47 | QApplication qapp(argc, argv); | |
48 |
|
48 | |||
49 | PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut); |
|
49 | PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut); | |
50 |
|
50 | |||
|
51 | int failCount = 0; | |||
51 | PythonQtTestApi api; |
|
52 | PythonQtTestApi api; | |
52 | QTest::qExec(&api, argc, argv); |
|
53 | failCount += QTest::qExec(&api, argc, argv); | |
53 | PythonQtTestSignalHandler signalHandler; |
|
54 | PythonQtTestSignalHandler signalHandler; | |
54 | QTest::qExec(&signalHandler, argc, argv); |
|
55 | failCount += QTest::qExec(&signalHandler, argc, argv); | |
55 | PythonQtTestSlotCalling slotCalling; |
|
56 | PythonQtTestSlotCalling slotCalling; | |
56 | QTest::qExec(&slotCalling, argc, argv); |
|
57 | failCount += QTest::qExec(&slotCalling, argc, argv); | |
57 |
|
58 | |||
58 | PythonQt::cleanup(); |
|
59 | PythonQt::cleanup(); | |
59 | return 0; |
|
60 | ||
|
61 | if (failCount>0) { | |||
|
62 | std::cerr << "Tests failed: " << failCount << std::endl; | |||
|
63 | } else { | |||
|
64 | std::cout << "All tests passed successfully." << std::endl; | |||
|
65 | } | |||
|
66 | return failCount; | |||
60 | } |
|
67 | } | |
61 |
|
68 |
@@ -1,324 +1,457 | |||||
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 | PythonQt::self()->addObject(main, "obj", _helper); |
|
49 | PythonQt::self()->addObject(main, "obj", _helper); | |
49 | } |
|
50 | } | |
50 |
|
51 | |||
51 | void PythonQtTestSlotCalling::init() { |
|
52 | void PythonQtTestSlotCalling::init() { | |
52 |
|
53 | |||
53 | } |
|
54 | } | |
54 |
|
55 | |||
|
56 | void* polymorphic_ClassB_Handler(const void* ptr, char** className) { | |||
|
57 | ClassB* o = (ClassB*)ptr; | |||
|
58 | if (o->type()==2) { | |||
|
59 | *className = "ClassB"; | |||
|
60 | return (ClassB*)o; | |||
|
61 | } | |||
|
62 | if (o->type()==3) { | |||
|
63 | *className = "ClassC"; | |||
|
64 | return (ClassC*)o; | |||
|
65 | } | |||
|
66 | if (o->type()==4) { | |||
|
67 | *className = "ClassD"; | |||
|
68 | return (ClassD*)o; | |||
|
69 | } | |||
|
70 | return NULL; | |||
|
71 | } | |||
|
72 | ||||
|
73 | void PythonQtTestSlotCalling::testInheritance() { | |||
|
74 | PythonQt::self()->registerCPPClass("ClassA",NULL,NULL, PythonQtCreateObject<ClassAWrapper>); | |||
|
75 | PythonQt::self()->registerCPPClass("ClassB",NULL,NULL, PythonQtCreateObject<ClassBWrapper>); | |||
|
76 | PythonQt::self()->registerCPPClass("ClassC",NULL,NULL, PythonQtCreateObject<ClassCWrapper>); | |||
|
77 | PythonQt::self()->addParentClass("ClassC", "ClassA", PythonQtUpcastingOffset<ClassC,ClassA>()); | |||
|
78 | PythonQt::self()->addParentClass("ClassC", "ClassB", PythonQtUpcastingOffset<ClassC,ClassB>()); | |||
|
79 | PythonQt::self()->registerClass(&ClassD::staticMetaObject, NULL, PythonQtCreateObject<ClassDWrapper>); | |||
|
80 | PythonQt::self()->addParentClass("ClassD", "ClassA", PythonQtUpcastingOffset<ClassD,ClassA>()); | |||
|
81 | PythonQt::self()->addParentClass("ClassD", "ClassB", PythonQtUpcastingOffset<ClassD,ClassB>()); | |||
|
82 | ||||
|
83 | PythonQtObjectPtr classA = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassA"); | |||
|
84 | PythonQtObjectPtr classB = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassB"); | |||
|
85 | PythonQtObjectPtr classC = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassC"); | |||
|
86 | PythonQtObjectPtr classD = PythonQt::self()->getMainModule().getVariable("PythonQt.ClassD"); | |||
|
87 | QVERIFY(classA); | |||
|
88 | QVERIFY(classB); | |||
|
89 | QVERIFY(classC); | |||
|
90 | QVERIFY(classD); | |||
|
91 | ||||
|
92 | 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 | 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.ClassD();\nif obj.getClassAPtr(a).getX()==1: obj.setPassed();\n")); | |||
|
97 | ||||
|
98 | 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.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.ClassD();\nif obj.getClassBPtr(a).getY()==2: obj.setPassed();\n")); | |||
|
103 | ||||
|
104 | 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 | 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.ClassC();\nif obj.getClassCPtr(a).getX()==1: obj.setPassed();\n")); | |||
|
109 | 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 | ||||
|
112 | 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.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.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.createClassDAsB())==PythonQt.ClassB: obj.setPassed();\n")); | |||
|
119 | ||||
|
120 | PythonQt::self()->addPolymorphicHandler("ClassB", polymorphic_ClassB_Handler); | |||
|
121 | ||||
|
122 | 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.createClassDAsB())==PythonQt.ClassD: obj.setPassed();\n")); | |||
|
125 | ||||
|
126 | } | |||
|
127 | ||||
55 | void PythonQtTestSlotCalling::testNoArgSlotCall() |
|
128 | void PythonQtTestSlotCalling::testNoArgSlotCall() | |
56 | { |
|
129 | { | |
57 | QVERIFY(_helper->runScript("obj.testNoArg(); obj.setPassed();\n")); |
|
130 | QVERIFY(_helper->runScript("obj.testNoArg(); obj.setPassed();\n")); | |
58 | } |
|
131 | } | |
59 |
|
132 | |||
60 | void PythonQtTestSlotCalling::testOverloadedCall() |
|
133 | void PythonQtTestSlotCalling::testOverloadedCall() | |
61 | { |
|
134 | { | |
62 | QVERIFY(_helper->runScript("obj.overload(False); obj.setPassed();\n", 0)); |
|
135 | QVERIFY(_helper->runScript("obj.overload(False); obj.setPassed();\n", 0)); | |
63 | QVERIFY(_helper->runScript("obj.overload(True); obj.setPassed();\n", 0)); |
|
136 | QVERIFY(_helper->runScript("obj.overload(True); obj.setPassed();\n", 0)); | |
64 | QVERIFY(_helper->runScript("obj.overload(12.5); obj.setPassed();\n", 1)); |
|
137 | QVERIFY(_helper->runScript("obj.overload(12.5); obj.setPassed();\n", 1)); | |
65 | QVERIFY(_helper->runScript("obj.overload(12); obj.setPassed();\n", 2)); |
|
138 | QVERIFY(_helper->runScript("obj.overload(12); obj.setPassed();\n", 2)); | |
66 | QVERIFY(_helper->runScript("obj.overload('test'); obj.setPassed();\n", 3)); |
|
139 | QVERIFY(_helper->runScript("obj.overload('test'); obj.setPassed();\n", 3)); | |
67 | QVERIFY(_helper->runScript("obj.overload(u'test'); obj.setPassed();\n", 3)); |
|
140 | QVERIFY(_helper->runScript("obj.overload(u'test'); obj.setPassed();\n", 3)); | |
68 | QVERIFY(_helper->runScript("obj.overload(('test','test2')); obj.setPassed();\n", 4)); |
|
141 | QVERIFY(_helper->runScript("obj.overload(('test','test2')); obj.setPassed();\n", 4)); | |
69 | QVERIFY(_helper->runScript("obj.overload(obj); obj.setPassed();\n", 5)); |
|
142 | QVERIFY(_helper->runScript("obj.overload(obj); obj.setPassed();\n", 5)); | |
70 | QVERIFY(_helper->runScript("obj.overload(12,13); obj.setPassed();\n", 6)); |
|
143 | QVERIFY(_helper->runScript("obj.overload(12,13); obj.setPassed();\n", 6)); | |
71 | } |
|
144 | } | |
72 |
|
145 | |||
|
146 | void PythonQtTestSlotCalling::testPyObjectSlotCall() | |||
|
147 | { | |||
|
148 | QVERIFY(_helper->runScript("if obj.getPyObject(PythonQt)==PythonQt: obj.setPassed();\n")); | |||
|
149 | QVERIFY(_helper->runScript("if obj.getPyObject('Hello')=='Hello': obj.setPassed();\n")); | |||
|
150 | QVERIFY(_helper->runScript("if obj.getPyObjectFromVariant(PythonQt)==PythonQt: obj.setPassed();\n")); | |||
|
151 | QVERIFY(_helper->runScript("if obj.getPyObjectFromVariant2(PythonQt)==PythonQt: obj.setPassed();\n")); | |||
|
152 | // QVERIFY(_helper->runScript("if obj.getPyObjectFromPtr(PythonQt)==PythonQt: obj.setPassed();\n")); | |||
|
153 | } | |||
|
154 | ||||
|
155 | void PythonQtTestSlotCalling::testCPPSlotCalls() | |||
|
156 | { | |||
|
157 | // test QColor compare operation | |||
|
158 | QVERIFY(_helper->runScript("if PythonQt.QtGui.QColor(1,2,3)==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();obj.testNoArg()\n")); | |||
|
159 | QVERIFY(_helper->runScript("if PythonQt.QtGui.QColor(1,2,3)!=PythonQt.QtGui.QColor(3,2,1): obj.setPassed();obj.testNoArg()\n")); | |||
|
160 | ||||
|
161 | // test passing/returning QColors | |||
|
162 | QVERIFY(_helper->runScript("if obj.getQColor1(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); | |||
|
163 | QVERIFY(_helper->runScript("if obj.getQColor2(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); | |||
|
164 | QVERIFY(_helper->runScript("if obj.getQColor3(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); | |||
|
165 | QVERIFY(_helper->runScript("if obj.getQColor4(PythonQt.QtGui.QColor(1,2,3))==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); | |||
|
166 | QVERIFY(_helper->runScript("if obj.getQColor5()==PythonQt.QtGui.QColor(1,2,3): obj.setPassed();\n")); | |||
|
167 | } | |||
|
168 | ||||
73 | void PythonQtTestSlotCalling::testPODSlotCalls() |
|
169 | void PythonQtTestSlotCalling::testPODSlotCalls() | |
74 | { |
|
170 | { | |
75 | QVERIFY(_helper->runScript("if obj.getBool(False)==False: obj.setPassed();\n")); |
|
171 | QVERIFY(_helper->runScript("if obj.getBool(False)==False: obj.setPassed();\n")); | |
76 | QVERIFY(_helper->runScript("if obj.getBool(True)==True: obj.setPassed();\n")); |
|
172 | QVERIFY(_helper->runScript("if obj.getBool(True)==True: obj.setPassed();\n")); | |
77 | QVERIFY(_helper->runScript("if obj.getInt(-42)==-42: obj.setPassed();\n")); |
|
173 | QVERIFY(_helper->runScript("if obj.getInt(-42)==-42: obj.setPassed();\n")); | |
78 | QVERIFY(_helper->runScript("if obj.getUInt(42)==42: obj.setPassed();\n")); |
|
174 | QVERIFY(_helper->runScript("if obj.getUInt(42)==42: obj.setPassed();\n")); | |
79 | QVERIFY(_helper->runScript("if obj.getShort(-43)==-43: obj.setPassed();\n")); |
|
175 | QVERIFY(_helper->runScript("if obj.getShort(-43)==-43: obj.setPassed();\n")); | |
80 | QVERIFY(_helper->runScript("if obj.getUShort(43)==43: obj.setPassed();\n")); |
|
176 | QVERIFY(_helper->runScript("if obj.getUShort(43)==43: obj.setPassed();\n")); | |
81 | QVERIFY(_helper->runScript("if obj.getChar(-12)==-12: obj.setPassed();\n")); |
|
177 | QVERIFY(_helper->runScript("if obj.getChar(-12)==-12: obj.setPassed();\n")); | |
82 | QVERIFY(_helper->runScript("if obj.getUChar(12)==12: obj.setPassed();\n")); |
|
178 | QVERIFY(_helper->runScript("if obj.getUChar(12)==12: obj.setPassed();\n")); | |
83 | QVERIFY(_helper->runScript("if obj.getLong(-256*256*256)==-256*256*256: obj.setPassed();\n")); |
|
179 | QVERIFY(_helper->runScript("if obj.getLong(-256*256*256)==-256*256*256: obj.setPassed();\n")); | |
84 | QVERIFY(_helper->runScript("if obj.getULong(256*256*256)==256*256*256: obj.setPassed();\n")); |
|
180 | QVERIFY(_helper->runScript("if obj.getULong(256*256*256)==256*256*256: obj.setPassed();\n")); | |
85 | QVERIFY(_helper->runScript("if obj.getLongLong(-42)==-42: obj.setPassed();\n")); |
|
181 | QVERIFY(_helper->runScript("if obj.getLongLong(-42)==-42: obj.setPassed();\n")); | |
86 | QVERIFY(_helper->runScript("if obj.getULongLong(42)==42: obj.setPassed();\n")); |
|
182 | QVERIFY(_helper->runScript("if obj.getULongLong(42)==42: obj.setPassed();\n")); | |
87 | QVERIFY(_helper->runScript("if obj.getQChar(4096)==4096: obj.setPassed();\n")); |
|
183 | QVERIFY(_helper->runScript("if obj.getQChar(4096)==4096: obj.setPassed();\n")); | |
88 | QVERIFY(_helper->runScript("if obj.getDouble(47.12)==47.12: obj.setPassed();\n")); |
|
184 | QVERIFY(_helper->runScript("if obj.getDouble(47.12)==47.12: obj.setPassed();\n")); | |
89 | QVERIFY(_helper->runScript("if abs(obj.getFloat(47.11)-47.11)<0.01: obj.setPassed();\n")); |
|
185 | QVERIFY(_helper->runScript("if abs(obj.getFloat(47.11)-47.11)<0.01: obj.setPassed();\n")); | |
90 | QVERIFY(_helper->runScript("if obj.getQString('testStr')=='testStr': obj.setPassed();\n")); |
|
186 | QVERIFY(_helper->runScript("if obj.getQString('testStr')=='testStr': obj.setPassed();\n")); | |
91 | QVERIFY(_helper->runScript("if obj.getQString('')=='': obj.setPassed();\n")); |
|
187 | QVERIFY(_helper->runScript("if obj.getQString('')=='': obj.setPassed();\n")); | |
92 | QVERIFY(_helper->runScript("if obj.getQStringList(('test','test2'))==('test','test2'): obj.setPassed();\n")); |
|
188 | QVERIFY(_helper->runScript("if obj.getQStringList(('test','test2'))==('test','test2'): obj.setPassed();\n")); | |
93 | } |
|
189 | } | |
94 |
|
190 | |||
95 | void PythonQtTestSlotCalling::testQVariantSlotCalls() |
|
191 | void PythonQtTestSlotCalling::testQVariantSlotCalls() | |
96 | { |
|
192 | { | |
97 | QVERIFY(_helper->runScript("if obj.getQVariant(-42)==-42: obj.setPassed();\n")); |
|
193 | QVERIFY(_helper->runScript("if obj.getQVariant(-42)==-42: obj.setPassed();\n")); | |
98 | QVERIFY(_helper->runScript("if obj.getQVariant('testStr')=='testStr': obj.setPassed();\n")); |
|
194 | QVERIFY(_helper->runScript("if obj.getQVariant('testStr')=='testStr': obj.setPassed();\n")); | |
99 | QVERIFY(_helper->runScript("if obj.getQVariant(('test','test2'))==('test','test2'): obj.setPassed();\n")); |
|
195 | QVERIFY(_helper->runScript("if obj.getQVariant(('test','test2'))==('test','test2'): obj.setPassed();\n")); | |
100 | QVERIFY(_helper->runScript("if obj.getQVariant(('test',12, 47.11))==('test',12, 47.11): obj.setPassed();\n")); |
|
196 | QVERIFY(_helper->runScript("if obj.getQVariant(('test',12, 47.11))==('test',12, 47.11): obj.setPassed();\n")); | |
101 | QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n")); |
|
197 | QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n")); | |
102 | QEXPECT_FAIL("", "Testing to pass a map and compare with a different map", Continue); |
|
198 | QEXPECT_FAIL("", "Testing to pass a map and compare with a different map", Continue); | |
103 | QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla2','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n")); |
|
199 | QVERIFY(_helper->runScript("if obj.getQVariant({'test':'bla2','test2':47.11})=={'test':'bla','test2':47.11}: obj.setPassed();\n")); | |
104 | QVERIFY(_helper->runScript("if obj.getQVariant(obj)==obj: obj.setPassed();\n")); |
|
200 | QVERIFY(_helper->runScript("if obj.getQVariant(obj)==obj: obj.setPassed();\n")); | |
105 | } |
|
201 | } | |
106 |
|
202 | |||
107 | void PythonQtTestSlotCalling::testObjectSlotCalls() |
|
203 | void PythonQtTestSlotCalling::testObjectSlotCalls() | |
108 | { |
|
204 | { | |
109 | QVERIFY(_helper->runScript("if obj.getQObject(obj)==obj: obj.setPassed();\n")); |
|
205 | QVERIFY(_helper->runScript("if obj.getQObject(obj)==obj: obj.setPassed();\n")); | |
110 | QVERIFY(_helper->runScript("if obj.getTestObject(obj)==obj: obj.setPassed();\n")); |
|
206 | QVERIFY(_helper->runScript("if obj.getTestObject(obj)==obj: obj.setPassed();\n")); | |
111 | QVERIFY(_helper->runScript("if obj.getNewObject().className()=='PythonQtTestSlotCallingHelper': obj.setPassed();\n")); |
|
207 | QVERIFY(_helper->runScript("if obj.getNewObject().className()=='PythonQtTestSlotCallingHelper': obj.setPassed();\n")); | |
112 | QEXPECT_FAIL("", "Testing to pass a QObject when another object was expected", Continue); |
|
208 | QEXPECT_FAIL("", "Testing to pass a QObject when another object was expected", Continue); | |
113 | QVERIFY(_helper->runScript("if obj.getQWidget(obj)==obj: obj.setPassed();\n")); |
|
209 | QVERIFY(_helper->runScript("if obj.getQWidget(obj)==obj: obj.setPassed();\n")); | |
114 | } |
|
210 | } | |
115 |
|
211 | |||
116 | void PythonQtTestSlotCalling::testCppFactory() |
|
212 | void PythonQtTestSlotCalling::testCppFactory() | |
117 | { |
|
213 | { | |
118 | PythonQtTestCppFactory* f = new PythonQtTestCppFactory; |
|
214 | PythonQtTestCppFactory* f = new PythonQtTestCppFactory; | |
119 | PythonQt::self()->addInstanceDecorators(new PQCppObjectDecorator); |
|
215 | PythonQt::self()->addInstanceDecorators(new PQCppObjectDecorator); | |
120 | PythonQt::self()->addInstanceDecorators(new PQCppObjectNoWrapDecorator); |
|
216 | PythonQt::self()->addInstanceDecorators(new PQCppObjectNoWrapDecorator); | |
121 |
|
217 | |||
122 | PythonQt::self()->addWrapperFactory(f); |
|
218 | PythonQt::self()->addWrapperFactory(f); | |
123 | QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getHeight()==12: obj.setPassed();\n")); |
|
219 | QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getHeight()==12: obj.setPassed();\n")); | |
124 | QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getH()==12: obj.setPassed();\n")); |
|
220 | QVERIFY(_helper->runScript("if obj.createPQCppObject(12).getH()==12: obj.setPassed();\n")); | |
125 | QVERIFY(_helper->runScript("pq1 = obj.createPQCppObject(12);\n" |
|
221 | QVERIFY(_helper->runScript("pq1 = obj.createPQCppObject(12);\n" | |
126 | "pq2 = obj.createPQCppObject(13);\n" |
|
222 | "pq2 = obj.createPQCppObject(13);\n" | |
127 | "pq3 = obj.getPQCppObject(pq1);\n" |
|
223 | "pq3 = obj.getPQCppObject(pq1);\n" | |
128 | "pq4 = obj.getPQCppObject(pq2);\n" |
|
224 | "pq4 = obj.getPQCppObject(pq2);\n" | |
129 | "if pq3.getHeight()==12 and pq4.getHeight()==13: obj.setPassed();\n" |
|
225 | "if pq3.getHeight()==12 and pq4.getHeight()==13: obj.setPassed();\n" | |
130 | )); |
|
226 | )); | |
131 |
|
227 | |||
132 | QVERIFY(_helper->runScript("if obj.createPQCppObjectNoWrap(12).getH()==12: obj.setPassed();\n")); |
|
228 | QVERIFY(_helper->runScript("if obj.createPQCppObjectNoWrap(12).getH()==12: obj.setPassed();\n")); | |
133 | } |
|
229 | } | |
134 |
|
230 | |||
135 |
|
231 | |||
136 | void PythonQtTestSlotCalling::testMultiArgsSlotCall() |
|
232 | void PythonQtTestSlotCalling::testMultiArgsSlotCall() | |
137 | { |
|
233 | { | |
138 | QVERIFY(_helper->runScript("if obj.getMultiArgs(12,47.11,'test')==(12,47.11,'test'): obj.setPassed();\n")); |
|
234 | QVERIFY(_helper->runScript("if obj.getMultiArgs(12,47.11,'test')==(12,47.11,'test'): obj.setPassed();\n")); | |
139 | } |
|
235 | } | |
140 |
|
236 | |||
141 | bool PythonQtTestSlotCallingHelper::runScript(const char* script, int expectedOverload) |
|
237 | bool PythonQtTestSlotCallingHelper::runScript(const char* script, int expectedOverload) | |
142 | { |
|
238 | { | |
143 | _called = false; |
|
239 | _called = false; | |
144 | _passed = false; |
|
240 | _passed = false; | |
145 | _calledOverload = -1; |
|
241 | _calledOverload = -1; | |
146 | PyRun_SimpleString(script); |
|
242 | PyRun_SimpleString(script); | |
147 | return _called && _passed && _calledOverload==expectedOverload; |
|
243 | return _called && _passed && _calledOverload==expectedOverload; | |
148 | } |
|
244 | } | |
149 |
|
245 | |||
150 |
|
246 | |||
151 | void PythonQtTestSignalHandler::initTestCase() |
|
247 | void PythonQtTestSignalHandler::initTestCase() | |
152 | { |
|
248 | { | |
153 | _helper = new PythonQtTestSignalHandlerHelper(this); |
|
249 | _helper = new PythonQtTestSignalHandlerHelper(this); | |
154 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); |
|
250 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); | |
155 | PythonQt::self()->addObject(main, "obj", _helper); |
|
251 | PythonQt::self()->addObject(main, "obj", _helper); | |
156 | } |
|
252 | } | |
157 |
|
253 | |||
158 | void PythonQtTestSignalHandler::testSignalHandler() |
|
254 | void PythonQtTestSignalHandler::testSignalHandler() | |
159 | { |
|
255 | { | |
160 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); |
|
256 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); | |
161 | PyRun_SimpleString("def testIntSignal(a):\n if a==12: obj.setPassed();\n"); |
|
257 | PyRun_SimpleString("def testIntSignal(a):\n if a==12: obj.setPassed();\n"); | |
162 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); |
|
258 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); | |
163 | QVERIFY(_helper->emitIntSignal(12)); |
|
259 | QVERIFY(_helper->emitIntSignal(12)); | |
164 |
|
260 | |||
165 | PyRun_SimpleString("def testFloatSignal(a):\n if a==12: obj.setPassed();\n"); |
|
261 | PyRun_SimpleString("def testFloatSignal(a):\n if a==12: obj.setPassed();\n"); | |
166 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); |
|
262 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); | |
167 | QVERIFY(_helper->emitFloatSignal(12)); |
|
263 | QVERIFY(_helper->emitFloatSignal(12)); | |
168 |
|
264 | |||
169 | PyRun_SimpleString("def testVariantSignal(a):\n if a==obj.expectedVariant(): obj.setPassed();\n"); |
|
265 | PyRun_SimpleString("def testVariantSignal(a):\n if a==obj.expectedVariant(): obj.setPassed();\n"); | |
170 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); |
|
266 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); | |
171 | _helper->setExpectedVariant(QString("Test")); |
|
267 | _helper->setExpectedVariant(QString("Test")); | |
172 | QVERIFY(_helper->emitVariantSignal(QString("Test"))); |
|
268 | QVERIFY(_helper->emitVariantSignal(QString("Test"))); | |
173 | _helper->setExpectedVariant(12); |
|
269 | _helper->setExpectedVariant(12); | |
174 | QVERIFY(_helper->emitVariantSignal(12)); |
|
270 | QVERIFY(_helper->emitVariantSignal(12)); | |
175 | _helper->setExpectedVariant(QStringList() << "test1" << "test2"); |
|
271 | _helper->setExpectedVariant(QStringList() << "test1" << "test2"); | |
176 | QVERIFY(_helper->emitVariantSignal(QStringList() << "test1" << "test2")); |
|
272 | QVERIFY(_helper->emitVariantSignal(QStringList() << "test1" << "test2")); | |
177 | _helper->setExpectedVariant(qVariantFromValue((QObject*)_helper)); |
|
273 | _helper->setExpectedVariant(qVariantFromValue((QObject*)_helper)); | |
178 | QVERIFY(_helper->emitVariantSignal(qVariantFromValue((QObject*)_helper))); |
|
274 | QVERIFY(_helper->emitVariantSignal(qVariantFromValue((QObject*)_helper))); | |
179 |
|
275 | |||
180 | 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"); |
|
276 | 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"); | |
181 | // intentionally not normalized signal: |
|
277 | // intentionally not normalized signal: | |
182 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal")); |
|
278 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal")); | |
183 | QVERIFY(_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper)); |
|
279 | QVERIFY(_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper)); | |
184 |
|
280 | |||
185 | // try removing the handler |
|
281 | // try removing the handler | |
186 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal")); |
|
282 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(complexSignal( int, float , const QStringList , QObject*)), main, "testComplexSignal")); | |
187 | // and emit the signal, which should fail because the handler was removed |
|
283 | // and emit the signal, which should fail because the handler was removed | |
188 | QVERIFY(!_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper)); |
|
284 | QVERIFY(!_helper->emitComplexSignal(12,13,QStringList() << "test1" << "test2", _helper)); | |
189 |
|
285 | |||
190 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); |
|
286 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(intSignal(int)), main, "testIntSignal")); | |
191 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); |
|
287 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(floatSignal(float)), main, "testFloatSignal")); | |
192 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); |
|
288 | QVERIFY(PythonQt::self()->removeSignalHandler(_helper, SIGNAL(variantSignal(QVariant)), main, "testVariantSignal")); | |
193 |
|
289 | |||
194 | } |
|
290 | } | |
195 |
|
291 | |||
196 | void PythonQtTestSignalHandler::testRecursiveSignalHandler() |
|
292 | void PythonQtTestSignalHandler::testRecursiveSignalHandler() | |
197 | { |
|
293 | { | |
198 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); |
|
294 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); | |
199 | PyRun_SimpleString("def testSignal1(a):\n obj.emitSignal2(a);\n"); |
|
295 | PyRun_SimpleString("def testSignal1(a):\n obj.emitSignal2(a);\n"); | |
200 | PyRun_SimpleString("def testSignal2(a):\n obj.emitSignal3(float(a));\n"); |
|
296 | PyRun_SimpleString("def testSignal2(a):\n obj.emitSignal3(float(a));\n"); | |
201 | PyRun_SimpleString("def testSignal3(a):\n if a==12: obj.setPassed();\n"); |
|
297 | PyRun_SimpleString("def testSignal3(a):\n if a==12: obj.setPassed();\n"); | |
202 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal1(int)), main, "testSignal1")); |
|
298 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal1(int)), main, "testSignal1")); | |
203 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal2(const QString&)), main, "testSignal2")); |
|
299 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal2(const QString&)), main, "testSignal2")); | |
204 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal3(float)), main, "testSignal3")); |
|
300 | QVERIFY(PythonQt::self()->addSignalHandler(_helper, SIGNAL(signal3(float)), main, "testSignal3")); | |
205 | QVERIFY(_helper->emitSignal1(12)); |
|
301 | QVERIFY(_helper->emitSignal1(12)); | |
206 | } |
|
302 | } | |
207 |
|
303 | |||
208 |
|
304 | |||
209 | void PythonQtTestApi::initTestCase() |
|
305 | void PythonQtTestApi::initTestCase() | |
210 | { |
|
306 | { | |
211 | _helper = new PythonQtTestApiHelper(); |
|
307 | _helper = new PythonQtTestApiHelper(); | |
212 |
|
|
308 | _main = PythonQt::self()->getMainModule(); | |
213 | PythonQt::self()->addObject(main, "obj", _helper); |
|
309 | _main.evalScript("import PythonQt"); | |
|
310 | _main.addObject("obj", _helper); | |||
214 | } |
|
311 | } | |
215 |
|
312 | |||
216 | bool PythonQtTestApiHelper::call(const QString& function, const QVariantList& args, const QVariant& expectedResult) { |
|
313 | bool PythonQtTestApiHelper::call(const QString& function, const QVariantList& args, const QVariant& expectedResult) { | |
217 | _passed = false; |
|
314 | _passed = false; | |
218 | QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), function, args); |
|
315 | QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), function, args); | |
219 | return _passed && expectedResult==r; |
|
316 | return _passed && expectedResult==r; | |
220 | } |
|
317 | } | |
221 |
|
318 | |||
222 | void PythonQtTestApi::testCall() |
|
319 | void PythonQtTestApi::testCall() | |
223 | { |
|
320 | { | |
224 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); |
|
321 | PythonQtObjectPtr main = PythonQt::self()->getMainModule(); | |
225 |
|
322 | |||
226 | QVERIFY(qVariantValue<QObject*>(PythonQt::self()->getVariable(main, "obj"))==_helper); |
|
323 | QVERIFY(qVariantValue<QObject*>(PythonQt::self()->getVariable(main, "obj"))==_helper); | |
227 |
|
324 | |||
228 | PyRun_SimpleString("def testCallNoArgs():\n obj.setPassed();\n"); |
|
325 | PyRun_SimpleString("def testCallNoArgs():\n obj.setPassed();\n"); | |
229 | QVERIFY(_helper->call("testCallNoArgs", QVariantList(), QVariant())); |
|
326 | QVERIFY(_helper->call("testCallNoArgs", QVariantList(), QVariant())); | |
230 |
|
327 | |||
231 | PyRun_SimpleString("def testCall1(a):\n if a=='test': obj.setPassed();\n return 'test2';\n"); |
|
328 | PyRun_SimpleString("def testCall1(a):\n if a=='test': obj.setPassed();\n return 'test2';\n"); | |
232 | QVERIFY(_helper->call("testCall1", QVariantList() << QVariant("test"), QVariant(QString("test2")))); |
|
329 | QVERIFY(_helper->call("testCall1", QVariantList() << QVariant("test"), QVariant(QString("test2")))); | |
233 |
|
330 | |||
234 | PyRun_SimpleString("def testCall2(a, b):\n if a=='test' and b==obj: obj.setPassed();\n return obj;\n"); |
|
331 | PyRun_SimpleString("def testCall2(a, b):\n if a=='test' and b==obj: obj.setPassed();\n return obj;\n"); | |
235 | QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), "testCall2", QVariantList() << QVariant("test") << qVariantFromValue((QObject*)_helper)); |
|
332 | QVariant r = PythonQt::self()->call(PythonQt::self()->getMainModule(), "testCall2", QVariantList() << QVariant("test") << qVariantFromValue((QObject*)_helper)); | |
236 | QObject* p = qVariantValue<QObject*>(r); |
|
333 | QObject* p = qVariantValue<QObject*>(r); | |
237 | QVERIFY(p==_helper); |
|
334 | QVERIFY(p==_helper); | |
238 | } |
|
335 | } | |
239 |
|
336 | |||
240 | void PythonQtTestApi::testVariables() |
|
337 | void PythonQtTestApi::testVariables() | |
241 | { |
|
338 | { | |
242 | PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper); |
|
339 | PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper); | |
243 | QVariant v = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject"); |
|
340 | QVariant v = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject"); | |
244 | QObject* p = qVariantValue<QObject*>(v); |
|
341 | QObject* p = qVariantValue<QObject*>(v); | |
245 | QVERIFY(p==_helper); |
|
342 | QVERIFY(p==_helper); | |
246 | // test for unset variable |
|
343 | // test for unset variable | |
247 | QVariant v2 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject2"); |
|
344 | QVariant v2 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject2"); | |
248 | QVERIFY(v2==QVariant()); |
|
345 | QVERIFY(v2==QVariant()); | |
249 |
|
346 | |||
250 | PythonQt::self()->addVariable(PythonQt::self()->getMainModule(), "someValue", QStringList() << "test1" << "test2"); |
|
347 | PythonQt::self()->addVariable(PythonQt::self()->getMainModule(), "someValue", QStringList() << "test1" << "test2"); | |
251 | QVariant v3 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someValue"); |
|
348 | QVariant v3 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someValue"); | |
252 | QVERIFY(v3 == QVariant(QStringList() << "test1" << "test2")); |
|
349 | QVERIFY(v3 == QVariant(QStringList() << "test1" << "test2")); | |
253 |
|
350 | |||
254 | QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), QString::null, PythonQt::Variable); |
|
351 | QStringList l = PythonQt::self()->introspection(PythonQt::self()->getMainModule(), QString::null, PythonQt::Variable); | |
255 | QSet<QString> s; |
|
352 | QSet<QString> s; | |
256 | // check that at least these three variables are set |
|
353 | // check that at least these three variables are set | |
257 | s << "obj" << "someObject" << "someValue"; |
|
354 | s << "obj" << "someObject" << "someValue"; | |
258 | foreach (QString value, s) { |
|
355 | foreach (QString value, s) { | |
259 | QVERIFY(l.indexOf(value)!=-1); |
|
356 | QVERIFY(l.indexOf(value)!=-1); | |
260 | } |
|
357 | } | |
261 |
|
358 | |||
262 | // insert a second time! |
|
359 | // insert a second time! | |
263 | PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper); |
|
360 | PythonQt::self()->addObject(PythonQt::self()->getMainModule(), "someObject", _helper); | |
264 | // and remove |
|
361 | // and remove | |
265 | PythonQt::self()->removeVariable(PythonQt::self()->getMainModule(), "someObject"); |
|
362 | PythonQt::self()->removeVariable(PythonQt::self()->getMainModule(), "someObject"); | |
266 | // we expect to find no variable |
|
363 | // we expect to find no variable | |
267 | QVariant v4 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject"); |
|
364 | QVariant v4 = PythonQt::self()->getVariable(PythonQt::self()->getMainModule(), "someObject"); | |
268 | QVERIFY(v4==QVariant()); |
|
365 | QVERIFY(v4==QVariant()); | |
269 | } |
|
366 | } | |
270 |
|
367 | |||
271 | void PythonQtTestApi::testImporter() |
|
368 | void PythonQtTestApi::testImporter() | |
272 | { |
|
369 | { | |
273 | PythonQt::self()->setImporter(_helper); |
|
370 | PythonQt::self()->setImporter(_helper); | |
274 | PythonQt::self()->overwriteSysPath(QStringList() << "c:\\test"); |
|
371 | PythonQt::self()->overwriteSysPath(QStringList() << "c:\\test"); | |
275 | PyRun_SimpleString("import bla\n"); |
|
372 | PyRun_SimpleString("import bla\n"); | |
276 | } |
|
373 | } | |
277 |
|
374 | |||
|
375 | void PythonQtTestApi::testQtNamespace() | |||
|
376 | { | |||
|
377 | QVERIFY(!_main.getVariable("PythonQt.QtCore.Qt.red").toInt()==Qt::red); | |||
|
378 | QVERIFY(_main.getVariable("PythonQt.QtCore.Qt.FlatCap").toInt()==Qt::FlatCap); | |||
|
379 | QVERIFY(PythonQtObjectPtr(_main.getVariable("PythonQt.QtCore.Qt.escape"))); | |||
|
380 | } | |||
|
381 | ||||
|
382 | void PythonQtTestApi::testQColorDecorators() | |||
|
383 | { | |||
|
384 | PythonQtObjectPtr colorClass = _main.getVariable("PythonQt.QtGui.QColor"); | |||
|
385 | QVERIFY(colorClass); | |||
|
386 | // verify that the class is in the correct module | |||
|
387 | QVERIFY(colorClass.getVariable("__module__") == "PythonQt.QtGui"); | |||
|
388 | // test on Qt module as well: | |||
|
389 | colorClass = _main.getVariable("PythonQt.Qt.QColor"); | |||
|
390 | QVERIFY(colorClass); | |||
|
391 | // constructors | |||
|
392 | QVERIFY(qVariantValue<QColor>(colorClass.call(QVariantList() << 1 << 2 << 3)) == QColor(1,2,3)); | |||
|
393 | QVERIFY(qVariantValue<QColor>(colorClass.call()) == QColor()); | |||
|
394 | QEXPECT_FAIL("", "Testing non-existing constructor", Continue); | |||
|
395 | QVERIFY(colorClass.call(QVariantList() << 1 << 2) != QVariant()); | |||
|
396 | ||||
|
397 | // check for decorated Cmyk enum value | |||
|
398 | QVERIFY(colorClass.getVariable("Cmyk").toInt() == QColor::Cmyk); | |||
|
399 | PythonQtObjectPtr staticMethod = colorClass.getVariable("fromRgb"); | |||
|
400 | QVERIFY(staticMethod); | |||
|
401 | // direct call of static method via class | |||
|
402 | QVERIFY(qVariantValue<QColor>(colorClass.call("fromRgb", QVariantList() << 1 << 2 << 3)) == QColor(1,2,3)); | |||
|
403 | // direct call of static method | |||
|
404 | QVERIFY(qVariantValue<QColor>(staticMethod.call(QVariantList() << 1 << 2 << 3)) == QColor(1,2,3)); | |||
|
405 | PythonQtObjectPtr publicMethod = colorClass.getVariable("red"); | |||
|
406 | QVERIFY(publicMethod); | |||
|
407 | // call with passing self in: | |||
|
408 | QVERIFY(colorClass.call("red", QVariantList() << QColor(255,0,0)).toInt() == 255); | |||
|
409 | } | |||
|
410 | ||||
278 | QByteArray PythonQtTestApiHelper::readFileAsBytes(const QString& filename) |
|
411 | QByteArray PythonQtTestApiHelper::readFileAsBytes(const QString& filename) | |
279 | { |
|
412 | { | |
280 | QByteArray b; |
|
413 | QByteArray b; | |
281 | return b; |
|
414 | return b; | |
282 | } |
|
415 | } | |
283 |
|
416 | |||
284 | QByteArray PythonQtTestApiHelper::readSourceFile(const QString& filename, bool& ok) |
|
417 | QByteArray PythonQtTestApiHelper::readSourceFile(const QString& filename, bool& ok) | |
285 | { |
|
418 | { | |
286 | QByteArray b; |
|
419 | QByteArray b; | |
287 | ok = true; |
|
420 | ok = true; | |
288 | return b; |
|
421 | return b; | |
289 | } |
|
422 | } | |
290 |
|
423 | |||
291 | bool PythonQtTestApiHelper::exists(const QString& filename) |
|
424 | bool PythonQtTestApiHelper::exists(const QString& filename) | |
292 | { |
|
425 | { | |
293 | return true; |
|
426 | return true; | |
294 | } |
|
427 | } | |
295 |
|
428 | |||
296 | QDateTime PythonQtTestApiHelper::lastModifiedDate(const QString& filename) { |
|
429 | QDateTime PythonQtTestApiHelper::lastModifiedDate(const QString& filename) { | |
297 | return QDateTime::currentDateTime(); |
|
430 | return QDateTime::currentDateTime(); | |
298 | } |
|
431 | } | |
299 |
|
432 | |||
300 |
|
433 | |||
301 | void PythonQtTestApi::testRedirect() |
|
434 | void PythonQtTestApi::testRedirect() | |
302 | { |
|
435 | { | |
303 | connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), _helper, SLOT(stdOut(const QString&))); |
|
436 | connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), _helper, SLOT(stdOut(const QString&))); | |
304 | connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)), _helper, SLOT(stdErr(const QString&))); |
|
437 | connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)), _helper, SLOT(stdErr(const QString&))); | |
305 | PyRun_SimpleString("print 'test'\n"); |
|
438 | PyRun_SimpleString("print 'test'\n"); | |
306 | } |
|
439 | } | |
307 |
|
440 | |||
308 | void PythonQtTestApiHelper::stdOut(const QString& s) |
|
441 | void PythonQtTestApiHelper::stdOut(const QString& s) | |
309 | { |
|
442 | { | |
310 | qDebug() << s; |
|
443 | qDebug() << s; | |
311 | } |
|
444 | } | |
312 |
|
445 | |||
313 | void PythonQtTestApiHelper::stdErr(const QString& s) |
|
446 | void PythonQtTestApiHelper::stdErr(const QString& s) | |
314 | { |
|
447 | { | |
315 | qDebug() << s; |
|
448 | qDebug() << s; | |
316 | } |
|
449 | } | |
317 |
|
450 | |||
318 | QObject* PythonQtTestCppFactory::create(const QByteArray& name, void *ptr) |
|
451 | QObject* PythonQtTestCppFactory::create(const QByteArray& name, void *ptr) | |
319 | { |
|
452 | { | |
320 | if (name == "PQCppObject") { |
|
453 | if (name == "PQCppObject") { | |
321 | return new PQCppObjectWrapper(ptr); |
|
454 | return new PQCppObjectWrapper(ptr); | |
322 | } |
|
455 | } | |
323 | return NULL; |
|
456 | return NULL; | |
324 | } |
|
457 | } |
@@ -1,332 +1,423 | |||||
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 | class PythonQtTestSlotCallingHelper; |
|
51 | class PythonQtTestSlotCallingHelper; | |
52 | class PythonQtTestApiHelper; |
|
52 | class PythonQtTestApiHelper; | |
53 | class QWidget; |
|
53 | class QWidget; | |
54 |
|
54 | |||
55 | //! test the PythonQt api |
|
55 | //! test the PythonQt api | |
56 | class PythonQtTestApi : public QObject |
|
56 | class PythonQtTestApi : public QObject | |
57 | { |
|
57 | { | |
58 | Q_OBJECT |
|
58 | Q_OBJECT | |
59 |
|
59 | |||
60 | private slots: |
|
60 | private slots: | |
61 | void initTestCase(); |
|
61 | void initTestCase(); | |
62 | void testCall(); |
|
62 | void testCall(); | |
63 | void testVariables(); |
|
63 | void testVariables(); | |
64 | void testRedirect(); |
|
64 | void testRedirect(); | |
65 | void testImporter(); |
|
65 | void testImporter(); | |
|
66 | void testQColorDecorators(); | |||
|
67 | void testQtNamespace(); | |||
66 |
|
68 | |||
67 | private: |
|
69 | private: | |
68 | PythonQtTestApiHelper* _helper; |
|
70 | PythonQtTestApiHelper* _helper; | |
|
71 | PythonQtObjectPtr _main; | |||
69 |
|
72 | |||
70 | }; |
|
73 | }; | |
71 |
|
74 | |||
|
75 | class ClassA { | |||
|
76 | public: | |||
|
77 | ClassA() { x = 1; } | |||
|
78 | int x; | |||
|
79 | }; | |||
|
80 | ||||
|
81 | class ClassB { | |||
|
82 | public: | |||
|
83 | ClassB() { y = 2; } | |||
|
84 | int y; | |||
|
85 | ||||
|
86 | virtual int type() { return 2; } | |||
|
87 | }; | |||
|
88 | ||||
|
89 | class ClassC : public ClassA, public ClassB { | |||
|
90 | public: | |||
|
91 | ClassC() { z = 3; } | |||
|
92 | int z; | |||
|
93 | ||||
|
94 | virtual int type() { return 3; } | |||
|
95 | }; | |||
|
96 | ||||
|
97 | class ClassD : public QObject, public ClassA, public ClassB { | |||
|
98 | Q_OBJECT | |||
|
99 | public: | |||
|
100 | ClassD() { d = 4; } | |||
|
101 | public slots: | |||
|
102 | int getD() { return d; } | |||
|
103 | private: | |||
|
104 | int d; | |||
|
105 | ||||
|
106 | virtual int type() { return 4; } | |||
|
107 | }; | |||
|
108 | ||||
|
109 | class ClassAWrapper : public QObject { | |||
|
110 | Q_OBJECT | |||
|
111 | public slots: | |||
|
112 | ClassA* new_ClassA() { return new ClassA; } | |||
|
113 | int getX(ClassA* o) { return o->x; } | |||
|
114 | }; | |||
|
115 | ||||
|
116 | class ClassBWrapper : public QObject { | |||
|
117 | Q_OBJECT | |||
|
118 | public slots: | |||
|
119 | ClassB* new_ClassB() { return new ClassB; } | |||
|
120 | int getY(ClassB* o) { return o->y; } | |||
|
121 | }; | |||
|
122 | ||||
|
123 | class ClassCWrapper : public QObject { | |||
|
124 | Q_OBJECT | |||
|
125 | public slots: | |||
|
126 | ClassC* new_ClassC() { return new ClassC; } | |||
|
127 | int getZ(ClassC* o) { return o->z; } | |||
|
128 | }; | |||
|
129 | ||||
|
130 | class ClassDWrapper : public QObject { | |||
|
131 | Q_OBJECT | |||
|
132 | public slots: | |||
|
133 | ClassD* new_ClassD() { return new ClassD; } | |||
|
134 | }; | |||
|
135 | ||||
|
136 | ||||
72 | //! test the PythonQt api (helper) |
|
137 | //! test the PythonQt api (helper) | |
73 | class PythonQtTestApiHelper : public QObject , public PythonQtImportFileInterface |
|
138 | class PythonQtTestApiHelper : public QObject , public PythonQtImportFileInterface | |
74 | { |
|
139 | { | |
75 | Q_OBJECT |
|
140 | Q_OBJECT | |
76 | public: |
|
141 | public: | |
77 | PythonQtTestApiHelper() { |
|
142 | PythonQtTestApiHelper() { | |
78 | }; |
|
143 | }; | |
79 |
|
144 | |||
80 | bool call(const QString& function, const QVariantList& args, const QVariant& expectedResult); |
|
145 | bool call(const QString& function, const QVariantList& args, const QVariant& expectedResult); | |
81 |
|
146 | |||
82 | virtual QByteArray readFileAsBytes(const QString& filename); |
|
147 | virtual QByteArray readFileAsBytes(const QString& filename); | |
83 |
|
148 | |||
84 | virtual QByteArray readSourceFile(const QString& filename, bool& ok); |
|
149 | virtual QByteArray readSourceFile(const QString& filename, bool& ok); | |
85 |
|
150 | |||
86 | virtual bool exists(const QString& filename); |
|
151 | virtual bool exists(const QString& filename); | |
87 |
|
152 | |||
88 | virtual QDateTime lastModifiedDate(const QString& filename); |
|
153 | virtual QDateTime lastModifiedDate(const QString& filename); | |
89 |
|
154 | |||
90 | public slots: |
|
155 | public slots: | |
91 |
|
156 | |||
92 | //! call to set that the test has passed (from Python!) |
|
157 | //! call to set that the test has passed (from Python!) | |
93 | void setPassed() { _passed = true; } |
|
158 | void setPassed() { _passed = true; } | |
94 |
|
159 | |||
95 | void stdOut(const QString&); |
|
160 | void stdOut(const QString&); | |
96 | void stdErr(const QString&); |
|
161 | void stdErr(const QString&); | |
97 |
|
162 | |||
98 | private: |
|
163 | private: | |
99 | bool _passed; |
|
164 | bool _passed; | |
100 | }; |
|
165 | }; | |
101 |
|
166 | |||
|
167 | ||||
102 | // test implementation of the wrapper factory |
|
168 | // test implementation of the wrapper factory | |
103 | class PythonQtTestCppFactory : public PythonQtCppWrapperFactory |
|
169 | class PythonQtTestCppFactory : public PythonQtCppWrapperFactory | |
104 | { |
|
170 | { | |
105 | public: |
|
171 | public: | |
106 | virtual QObject* create(const QByteArray& name, void *ptr); |
|
172 | virtual QObject* create(const QByteArray& name, void *ptr); | |
107 | }; |
|
173 | }; | |
108 |
|
174 | |||
109 | //! an cpp object to be wrapped |
|
175 | //! an cpp object to be wrapped | |
110 | class PQCppObject { |
|
176 | class PQCppObject { | |
111 |
|
177 | |||
112 | public: |
|
178 | public: | |
113 | PQCppObject(int h) { _height = h; } |
|
179 | PQCppObject(int h) { _height = h; } | |
114 |
|
180 | |||
115 | int getHeight() { return _height; } |
|
181 | int getHeight() { return _height; } | |
116 | void setHeight(int h) { _height = h; } |
|
182 | void setHeight(int h) { _height = h; } | |
117 |
|
183 | |||
118 | private: |
|
184 | private: | |
119 | int _height; |
|
185 | int _height; | |
120 | }; |
|
186 | }; | |
121 |
|
187 | |||
122 | //! an qobject that wraps the existing cpp object |
|
188 | //! an qobject that wraps the existing cpp object | |
123 | class PQCppObjectWrapper : public QObject { |
|
189 | class PQCppObjectWrapper : public QObject { | |
124 | Q_OBJECT |
|
190 | Q_OBJECT | |
125 | public: |
|
191 | public: | |
126 | PQCppObjectWrapper(void* ptr) { |
|
192 | PQCppObjectWrapper(void* ptr) { | |
127 | _ptr = (PQCppObject*)ptr; |
|
193 | _ptr = (PQCppObject*)ptr; | |
128 | } |
|
194 | } | |
129 |
|
195 | |||
130 | public slots: |
|
196 | public slots: | |
131 | int getHeight() { return _ptr->getHeight(); } |
|
197 | int getHeight() { return _ptr->getHeight(); } | |
132 | void setHeight(int h) { _ptr->setHeight(h); } |
|
198 | void setHeight(int h) { _ptr->setHeight(h); } | |
133 |
|
199 | |||
134 | private: |
|
200 | private: | |
135 | PQCppObject* _ptr; |
|
201 | PQCppObject* _ptr; | |
136 | }; |
|
202 | }; | |
137 |
|
203 | |||
138 | class PQCppObjectDecorator : public QObject { |
|
204 | class PQCppObjectDecorator : public QObject { | |
139 | Q_OBJECT |
|
205 | Q_OBJECT | |
140 | public slots: |
|
206 | public slots: | |
141 | int getH(PQCppObject* obj) { return obj->getHeight(); } |
|
207 | int getH(PQCppObject* obj) { return obj->getHeight(); } | |
142 |
|
208 | |||
143 | }; |
|
209 | }; | |
144 |
|
210 | |||
145 | //! an cpp object to be wrapped by decorators only |
|
211 | //! an cpp object to be wrapped by decorators only | |
146 | class PQCppObjectNoWrap { |
|
212 | class PQCppObjectNoWrap { | |
147 |
|
213 | |||
148 | public: |
|
214 | public: | |
149 | PQCppObjectNoWrap(int h) { _height = h; } |
|
215 | PQCppObjectNoWrap(int h) { _height = h; } | |
150 |
|
216 | |||
151 | int getHeight() { return _height; } |
|
217 | int getHeight() { return _height; } | |
152 | void setHeight(int h) { _height = h; } |
|
218 | void setHeight(int h) { _height = h; } | |
153 |
|
219 | |||
154 | private: |
|
220 | private: | |
155 | int _height; |
|
221 | int _height; | |
156 | }; |
|
222 | }; | |
157 |
|
223 | |||
158 | class PQCppObjectNoWrapDecorator : public QObject { |
|
224 | class PQCppObjectNoWrapDecorator : public QObject { | |
159 | Q_OBJECT |
|
225 | Q_OBJECT | |
160 | public slots: |
|
226 | public slots: | |
161 | int getH(PQCppObjectNoWrap* obj) { return obj->getHeight(); } |
|
227 | int getH(PQCppObjectNoWrap* obj) { return obj->getHeight(); } | |
162 |
|
228 | |||
163 | }; |
|
229 | }; | |
164 |
|
230 | |||
165 |
|
231 | |||
166 | //! test the calling of slots |
|
232 | //! test the calling of slots | |
167 | class PythonQtTestSlotCalling : public QObject |
|
233 | class PythonQtTestSlotCalling : public QObject | |
168 | { |
|
234 | { | |
169 | Q_OBJECT |
|
235 | Q_OBJECT | |
170 |
|
236 | |||
171 | private slots: |
|
237 | private slots: | |
172 | void initTestCase(); |
|
238 | void initTestCase(); | |
173 | void init(); |
|
239 | void init(); | |
174 |
|
240 | |||
175 | void testNoArgSlotCall(); |
|
241 | void testNoArgSlotCall(); | |
176 | void testPODSlotCalls(); |
|
242 | void testPODSlotCalls(); | |
|
243 | void testCPPSlotCalls(); | |||
177 | void testQVariantSlotCalls(); |
|
244 | void testQVariantSlotCalls(); | |
178 | void testObjectSlotCalls(); |
|
245 | void testObjectSlotCalls(); | |
179 | void testMultiArgsSlotCall(); |
|
246 | void testMultiArgsSlotCall(); | |
180 |
|
247 | void testPyObjectSlotCall(); | ||
181 | void testOverloadedCall(); |
|
248 | void testOverloadedCall(); | |
182 |
|
||||
183 | void testCppFactory(); |
|
249 | void testCppFactory(); | |
|
250 | void testInheritance(); | |||
184 |
|
251 | |||
185 | private: |
|
252 | private: | |
186 | PythonQtTestSlotCallingHelper* _helper; |
|
253 | PythonQtTestSlotCallingHelper* _helper; | |
187 |
|
254 | |||
188 | }; |
|
255 | }; | |
189 |
|
256 | |||
190 | //! helper class for slot calling test |
|
257 | //! helper class for slot calling test | |
191 | class PythonQtTestSlotCallingHelper : public QObject |
|
258 | class PythonQtTestSlotCallingHelper : public QObject | |
192 | { |
|
259 | { | |
193 | Q_OBJECT |
|
260 | Q_OBJECT | |
194 | public: |
|
261 | public: | |
195 | PythonQtTestSlotCallingHelper(PythonQtTestSlotCalling* test) { |
|
262 | PythonQtTestSlotCallingHelper(PythonQtTestSlotCalling* test) { | |
196 | _test = test; |
|
263 | _test = test; | |
197 | }; |
|
264 | }; | |
198 |
|
265 | |||
199 | bool runScript(const char* script, int expectedOverload = -1); |
|
266 | bool runScript(const char* script, int expectedOverload = -1); | |
200 |
|
267 | |||
201 | public slots: |
|
268 | public slots: | |
202 |
|
269 | |||
203 | //! call to set that the test has passed (from Python!) |
|
270 | //! call to set that the test has passed (from Python!) | |
204 | void setPassed() { _passed = true; } |
|
271 | void setPassed() { _passed = true; } | |
205 |
|
272 | |||
206 | //! no arguments, no return value: |
|
273 | //! no arguments, no return value: | |
207 | void testNoArg() { _called = true; } |
|
274 | void testNoArg() { _called = true; } | |
208 |
|
275 | |||
209 | //! overload test! |
|
276 | //! overload test! | |
210 | void overload(bool a) { _calledOverload = 0; _called = true; } |
|
277 | void overload(bool a) { _calledOverload = 0; _called = true; } | |
211 | void overload(float a) { _calledOverload = 1; _called = true;} |
|
278 | void overload(float a) { _calledOverload = 1; _called = true;} | |
212 | void overload(int a) { _calledOverload = 2; _called = true;} |
|
279 | void overload(int a) { _calledOverload = 2; _called = true;} | |
213 | void overload(const QString& str) { _calledOverload = 3; _called = true;} |
|
280 | void overload(const QString& str) { _calledOverload = 3; _called = true;} | |
214 | void overload(const QStringList& str) { _calledOverload = 4; _called = true;} |
|
281 | void overload(const QStringList& str) { _calledOverload = 4; _called = true;} | |
215 | void overload(QObject* str) { _calledOverload = 5; _called = true;} |
|
282 | void overload(QObject* str) { _calledOverload = 5; _called = true;} | |
216 | void overload(float a, int b) { _calledOverload = 6; _called = true;} |
|
283 | void overload(float a, int b) { _calledOverload = 6; _called = true;} | |
217 |
|
284 | |||
218 | //! POD values: |
|
285 | //! POD values: | |
219 | int getInt(int a) { _called = true; return a; } |
|
286 | int getInt(int a) { _called = true; return a; } | |
220 | unsigned int getUInt(unsigned int a) { _called = true; return a; } |
|
287 | unsigned int getUInt(unsigned int a) { _called = true; return a; } | |
221 | bool getBool(bool a) { _called = true; return a; } |
|
288 | bool getBool(bool a) { _called = true; return a; } | |
222 | char getChar(char a) { _called = true; return a; } |
|
289 | char getChar(char a) { _called = true; return a; } | |
223 | unsigned char getUChar(unsigned char a) { _called = true; return a; } |
|
290 | unsigned char getUChar(unsigned char a) { _called = true; return a; } | |
224 | long getLong(long a) { _called = true; return a; } |
|
291 | long getLong(long a) { _called = true; return a; } | |
225 | unsigned long getULong(unsigned long a) { _called = true; return a; } |
|
292 | unsigned long getULong(unsigned long a) { _called = true; return a; } | |
226 | short getShort(short a) { _called = true; return a; } |
|
293 | short getShort(short a) { _called = true; return a; } | |
227 | unsigned short getUShort(unsigned short a) { _called = true; return a; } |
|
294 | unsigned short getUShort(unsigned short a) { _called = true; return a; } | |
228 | QChar getQChar(QChar a) { _called = true; return a; } |
|
295 | QChar getQChar(QChar a) { _called = true; return a; } | |
229 | qint64 getLongLong(qint64 a) { _called = true; return a; } |
|
296 | qint64 getLongLong(qint64 a) { _called = true; return a; } | |
230 | quint64 getULongLong(quint64 a) { _called = true; return a; } |
|
297 | quint64 getULongLong(quint64 a) { _called = true; return a; } | |
231 | double getDouble(double d) { _called = true; return d; } |
|
298 | double getDouble(double d) { _called = true; return d; } | |
232 | float getFloat(float d) { _called = true; return d; } |
|
299 | float getFloat(float d) { _called = true; return d; } | |
233 |
|
300 | |||
234 | //! important qt types: |
|
301 | //! important qt types: | |
235 | QString getQString(const QString& s) { _called = true; return s; } |
|
302 | QString getQString(const QString& s) { _called = true; return s; } | |
236 | QStringList getQStringList(const QStringList& l) { _called = true; return l; } |
|
303 | QStringList getQStringList(const QStringList& l) { _called = true; return l; } | |
237 | QVariant getQVariant(const QVariant& var) { _called = true; return var; } |
|
304 | QVariant getQVariant(const QVariant& var) { _called = true; return var; } | |
238 |
|
305 | |||
|
306 | // QColor as representative for C++ value classes | |||
|
307 | QColor getQColor1(const QColor& var) { _called = true; return var; } | |||
|
308 | QColor getQColor2(QColor& var) { _called = true; return var; } | |||
|
309 | QColor getQColor3(QColor* col) { _called = true; return *col; } | |||
|
310 | QColor getQColor4(const QVariant& color) { _called = true; return qVariantValue<QColor>(color); } | |||
|
311 | QColor* getQColor5() { _called = true; static QColor c(1,2,3); return &c; } | |||
|
312 | ||||
|
313 | PyObject* getPyObject(PyObject* obj) { _called = true; return obj; } | |||
|
314 | PyObject* getPyObjectFromVariant(const QVariant& val) { _called = true; return PythonQtObjectPtr(val); }; | |||
|
315 | QVariant getPyObjectFromVariant2(const QVariant& val) { _called = true; return val; }; | |||
|
316 | // this does not yet work but is not required to work: | |||
|
317 | //PyObject* getPyObjectFromPtr(const PythonQtObjectPtr& val) { _called = true; return val; }; | |||
|
318 | ||||
239 | //! testing pointer passing |
|
319 | //! testing pointer passing | |
240 | PythonQtTestSlotCallingHelper* getTestObject(PythonQtTestSlotCallingHelper* obj) { _called = true; return obj; } |
|
320 | PythonQtTestSlotCallingHelper* getTestObject(PythonQtTestSlotCallingHelper* obj) { _called = true; return obj; } | |
241 | //! testing inheritance checking |
|
321 | //! testing inheritance checking | |
242 | QObject* getQObject(QObject* obj) { _called = true; return obj; } |
|
322 | QObject* getQObject(QObject* obj) { _called = true; return obj; } | |
243 | QWidget* getQWidget(QWidget* obj) { _called = true; return obj; } |
|
323 | QWidget* getQWidget(QWidget* obj) { _called = true; return obj; } | |
244 | //! testing if an object that was not wrapped is wrapped earlier is wrapped correctly |
|
324 | //! testing if an object that was not wrapped is wrapped earlier is wrapped correctly | |
245 | QObject* getNewObject() { _called = true; return new PythonQtTestSlotCallingHelper(NULL); } |
|
325 | QObject* getNewObject() { _called = true; return new PythonQtTestSlotCallingHelper(NULL); } | |
246 |
|
326 | |||
247 | QVariantList getMultiArgs(int a, double b, const QString& str) { _called = true; return (QVariantList() << a << b << str); } |
|
327 | QVariantList getMultiArgs(int a, double b, const QString& str) { _called = true; return (QVariantList() << a << b << str); } | |
248 | // more exotic, not yet tested |
|
|||
249 | //void setByteArray(QByteArray array) { qDebug() << array.data(); } |
|
|||
250 | //void setCharPtr(char* data) { qDebug() << data; } |
|
|||
251 |
|
328 | |||
252 | //! cpp wrapper factory test |
|
329 | //! cpp wrapper factory test | |
253 | PQCppObject* createPQCppObject(int h) { _called = true; return new PQCppObject(h); } |
|
330 | PQCppObject* createPQCppObject(int h) { _called = true; return new PQCppObject(h); } | |
254 |
|
331 | |||
255 | //! cpp wrapper factory test |
|
332 | //! cpp wrapper factory test | |
256 | PQCppObject* getPQCppObject(PQCppObject* p) { _called = true; return p; } |
|
333 | PQCppObject* getPQCppObject(PQCppObject* p) { _called = true; return p; } | |
257 |
|
334 | |||
258 | //! cpp wrapper factory test |
|
335 | //! cpp wrapper factory test | |
259 | PQCppObjectNoWrap* createPQCppObjectNoWrap(int h) { _called = true; return new PQCppObjectNoWrap(h); } |
|
336 | PQCppObjectNoWrap* createPQCppObjectNoWrap(int h) { _called = true; return new PQCppObjectNoWrap(h); } | |
260 |
|
337 | |||
261 | //! cpp wrapper factory test |
|
338 | //! cpp wrapper factory test | |
262 | PQCppObjectNoWrap* getPQCppObjectNoWrap(PQCppObjectNoWrap* p) { _called = true; return p; } |
|
339 | PQCppObjectNoWrap* getPQCppObjectNoWrap(PQCppObjectNoWrap* p) { _called = true; return p; } | |
263 |
|
340 | |||
|
341 | ClassA* getClassAPtr(ClassA* o) { _called = true; return o; } | |||
|
342 | ClassB* getClassBPtr(ClassB* o) { _called = true; return o; } | |||
|
343 | ClassC* getClassCPtr(ClassC* o) { _called = true; return o; } | |||
|
344 | ClassD* getClassDPtr(ClassD* o) { _called = true; return o; } | |||
|
345 | ||||
|
346 | ClassA* createClassA() { _called = true; return new ClassA; } | |||
|
347 | ClassB* createClassB() { _called = true; return new ClassB; } | |||
|
348 | ClassC* createClassC() { _called = true; return new ClassC; } | |||
|
349 | ClassD* createClassD() { _called = true; return new ClassD; } | |||
|
350 | ClassA* createClassCAsA() { _called = true; return new ClassC; } | |||
|
351 | ClassB* createClassCAsB() { _called = true; return new ClassC; } | |||
|
352 | ClassA* createClassDAsA() { _called = true; return new ClassD; } | |||
|
353 | ClassB* createClassDAsB() { _called = true; return new ClassD; } | |||
|
354 | ||||
264 | private: |
|
355 | private: | |
265 | bool _passed; |
|
356 | bool _passed; | |
266 | bool _called; |
|
357 | bool _called; | |
267 | int _calledOverload; |
|
358 | int _calledOverload; | |
268 | PythonQtTestSlotCalling* _test; |
|
359 | PythonQtTestSlotCalling* _test; | |
269 | }; |
|
360 | }; | |
270 |
|
361 | |||
271 | class PythonQtTestSignalHandlerHelper; |
|
362 | class PythonQtTestSignalHandlerHelper; | |
272 |
|
363 | |||
273 | //! test the connection of signals to python |
|
364 | //! test the connection of signals to python | |
274 | class PythonQtTestSignalHandler : public QObject |
|
365 | class PythonQtTestSignalHandler : public QObject | |
275 | { |
|
366 | { | |
276 | Q_OBJECT |
|
367 | Q_OBJECT | |
277 |
|
368 | |||
278 | private slots: |
|
369 | private slots: | |
279 | void initTestCase(); |
|
370 | void initTestCase(); | |
280 |
|
371 | |||
281 | void testSignalHandler(); |
|
372 | void testSignalHandler(); | |
282 | void testRecursiveSignalHandler(); |
|
373 | void testRecursiveSignalHandler(); | |
283 |
|
374 | |||
284 | private: |
|
375 | private: | |
285 | PythonQtTestSignalHandlerHelper* _helper; |
|
376 | PythonQtTestSignalHandlerHelper* _helper; | |
286 |
|
377 | |||
287 | }; |
|
378 | }; | |
288 |
|
379 | |||
289 | //! helper class for signal testing |
|
380 | //! helper class for signal testing | |
290 | class PythonQtTestSignalHandlerHelper : public QObject |
|
381 | class PythonQtTestSignalHandlerHelper : public QObject | |
291 | { |
|
382 | { | |
292 | Q_OBJECT |
|
383 | Q_OBJECT | |
293 |
|
384 | |||
294 | public: |
|
385 | public: | |
295 | PythonQtTestSignalHandlerHelper(PythonQtTestSignalHandler* test) { |
|
386 | PythonQtTestSignalHandlerHelper(PythonQtTestSignalHandler* test) { | |
296 | _test = test; |
|
387 | _test = test; | |
297 | }; |
|
388 | }; | |
298 |
|
389 | |||
299 | public slots: |
|
390 | public slots: | |
300 | void setPassed() { _passed = true; } |
|
391 | void setPassed() { _passed = true; } | |
301 |
|
392 | |||
302 | bool emitIntSignal(int a) { _passed = false; emit intSignal(a); return _passed; }; |
|
393 | bool emitIntSignal(int a) { _passed = false; emit intSignal(a); return _passed; }; | |
303 | bool emitFloatSignal(float a) { _passed = false; emit floatSignal(a); return _passed; }; |
|
394 | bool emitFloatSignal(float a) { _passed = false; emit floatSignal(a); return _passed; }; | |
304 |
|
395 | |||
305 | bool emitVariantSignal(const QVariant& v) { _passed = false; emit variantSignal(v); return _passed; }; |
|
396 | bool emitVariantSignal(const QVariant& v) { _passed = false; emit variantSignal(v); return _passed; }; | |
306 | QVariant expectedVariant() { return _v; } |
|
397 | QVariant expectedVariant() { return _v; } | |
307 | void setExpectedVariant(const QVariant& v) { _v = v; } |
|
398 | void setExpectedVariant(const QVariant& v) { _v = v; } | |
308 |
|
399 | |||
309 | bool emitComplexSignal(int a, float b, const QStringList& l, QObject* obj) { _passed = false; emit complexSignal(a,b,l,obj); return _passed; }; |
|
400 | bool emitComplexSignal(int a, float b, const QStringList& l, QObject* obj) { _passed = false; emit complexSignal(a,b,l,obj); return _passed; }; | |
310 |
|
401 | |||
311 | bool emitSignal1(int a) { _passed = false; emit signal1(a); return _passed; }; |
|
402 | bool emitSignal1(int a) { _passed = false; emit signal1(a); return _passed; }; | |
312 | bool emitSignal2(const QString& s) { _passed = false; emit signal2(s); return _passed; }; |
|
403 | bool emitSignal2(const QString& s) { _passed = false; emit signal2(s); return _passed; }; | |
313 | bool emitSignal3(float a) { _passed = false; emit signal3(a); return _passed; }; |
|
404 | bool emitSignal3(float a) { _passed = false; emit signal3(a); return _passed; }; | |
314 |
|
405 | |||
315 | signals: |
|
406 | signals: | |
316 | void intSignal(int); |
|
407 | void intSignal(int); | |
317 | void floatSignal(float); |
|
408 | void floatSignal(float); | |
318 | void variantSignal(const QVariant& v); |
|
409 | void variantSignal(const QVariant& v); | |
319 | void complexSignal(int a, float b, const QStringList& l, QObject* obj); |
|
410 | void complexSignal(int a, float b, const QStringList& l, QObject* obj); | |
320 |
|
411 | |||
321 | void signal1(int); |
|
412 | void signal1(int); | |
322 | void signal2(const QString&); |
|
413 | void signal2(const QString&); | |
323 | void signal3(float); |
|
414 | void signal3(float); | |
324 |
|
415 | |||
325 | private: |
|
416 | private: | |
326 | bool _passed; |
|
417 | bool _passed; | |
327 | QVariant _v; |
|
418 | QVariant _v; | |
328 |
|
419 | |||
329 | PythonQtTestSignalHandler* _test; |
|
420 | PythonQtTestSignalHandler* _test; | |
330 | }; |
|
421 | }; | |
331 |
|
422 | |||
332 | #endif |
|
423 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now