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