1 | /**************************************************************************** |
2 | * Copyright (C) 2018 Woboq GmbH |
3 | * Olivier Goffart <contact at woboq.com> |
4 | * https://woboq.com/ |
5 | * |
6 | * This program is free software: you can redistribute it and/or modify |
7 | * it under the terms of the GNU Lesser General Public License as |
8 | * published by the Free Software Foundation, either version 3 of the |
9 | * License, or (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this program. |
18 | * If not, see <http://www.gnu.org/licenses/>. |
19 | */ |
20 | #include <wobjectdefs.h> |
21 | #include <QtTest/QtTest> |
22 | |
23 | class tst_ManyProperties : public QObject |
24 | { |
25 | W_OBJECT(tst_ManyProperties) |
26 | |
27 | private slots: |
28 | void manyProperties(); |
29 | W_SLOT(manyProperties) |
30 | }; |
31 | |
32 | |
33 | class HasManyProperties : public QObject |
34 | { |
35 | W_OBJECT(HasManyProperties) |
36 | public: |
37 | #define DeclareProperty(Type, Name) \ |
38 | Type m_##Name; \ |
39 | void Name##Changed() W_SIGNAL(Name##Changed) \ |
40 | W_PROPERTY(Type, Name MEMBER m_##Name NOTIFY Name##Changed) \ |
41 | |
42 | |
43 | DeclareProperty(QString, prop0) |
44 | DeclareProperty(QString, prop1) |
45 | DeclareProperty(QString, prop2) |
46 | DeclareProperty(QString, prop3) |
47 | DeclareProperty(QString, prop4) |
48 | DeclareProperty(QString, prop5) |
49 | DeclareProperty(QString, prop6) |
50 | DeclareProperty(QString, prop7) |
51 | DeclareProperty(QString, prop8) |
52 | DeclareProperty(QString, prop9) |
53 | DeclareProperty(QString, prop10) |
54 | DeclareProperty(QString, prop11) |
55 | DeclareProperty(QString, prop12) |
56 | DeclareProperty(QString, prop13) |
57 | DeclareProperty(QString, prop14) |
58 | DeclareProperty(QString, prop15) |
59 | DeclareProperty(QString, prop16) |
60 | DeclareProperty(QString, prop17) |
61 | DeclareProperty(QString, prop18) |
62 | DeclareProperty(QString, prop19) |
63 | DeclareProperty(QString, prop20) |
64 | DeclareProperty(QString, prop21) |
65 | DeclareProperty(QString, prop22) |
66 | DeclareProperty(QString, prop23) |
67 | DeclareProperty(QString, prop24) |
68 | DeclareProperty(QString, prop25) |
69 | DeclareProperty(QString, prop26) |
70 | DeclareProperty(QString, prop27) |
71 | DeclareProperty(QString, prop28) |
72 | DeclareProperty(QString, prop29) |
73 | DeclareProperty(QString, prop30) |
74 | DeclareProperty(QString, prop31) |
75 | DeclareProperty(QString, prop32) |
76 | DeclareProperty(QString, prop33) |
77 | DeclareProperty(QString, prop34) |
78 | DeclareProperty(QString, prop35) |
79 | DeclareProperty(QString, prop36) |
80 | DeclareProperty(QString, prop37) |
81 | DeclareProperty(QString, prop38) |
82 | DeclareProperty(QString, prop39) |
83 | DeclareProperty(QString, prop40) |
84 | DeclareProperty(QString, prop41) |
85 | DeclareProperty(QString, prop42) |
86 | DeclareProperty(QString, prop43) |
87 | DeclareProperty(QString, prop44) |
88 | DeclareProperty(QString, prop45) |
89 | DeclareProperty(QString, prop46) |
90 | DeclareProperty(QString, prop47) |
91 | DeclareProperty(QString, prop48) |
92 | DeclareProperty(QString, prop49) |
93 | DeclareProperty(QString, prop50) |
94 | DeclareProperty(QString, prop51) |
95 | DeclareProperty(QString, prop52) |
96 | DeclareProperty(QString, prop53) |
97 | DeclareProperty(QString, prop54) |
98 | DeclareProperty(QString, prop55) |
99 | DeclareProperty(QString, prop56) |
100 | DeclareProperty(QString, prop57) |
101 | DeclareProperty(QString, prop58) |
102 | DeclareProperty(QString, prop59) |
103 | DeclareProperty(QString, prop60) |
104 | |
105 | DeclareProperty(int, intProp0) |
106 | }; |
107 | |
108 | |
109 | |
110 | #include <wobjectimpl.h> |
111 | |
112 | W_OBJECT_IMPL(tst_ManyProperties) |
113 | W_OBJECT_IMPL(HasManyProperties) |
114 | |
115 | void tst_ManyProperties::manyProperties() { |
116 | HasManyProperties obj; |
117 | |
118 | { // test that the corresponding signal is emitted when setting a prop |
119 | bool ok = false; |
120 | auto c = connect(&obj, &HasManyProperties::prop11Changed, [&ok] { ok = true; }); |
121 | |
122 | QVERIFY(obj.setProperty("prop45" , QStringLiteral("yo" ))); |
123 | QCOMPARE(ok, false); |
124 | |
125 | QVERIFY(obj.setProperty("prop11" , QStringLiteral("salut" ))); |
126 | QCOMPARE(ok, true); |
127 | QCOMPARE(obj.property("prop11" ), QVariant(QStringLiteral("salut" ))); |
128 | |
129 | disconnect(c); |
130 | } |
131 | { |
132 | QMetaProperty prop = obj.metaObject()->property(obj.metaObject()->indexOfProperty("prop34" )); |
133 | QCOMPARE(prop.name(), "prop34" ); |
134 | QCOMPARE(prop.typeName(), "QString" ); |
135 | QCOMPARE(prop.hasNotifySignal(), true); |
136 | QCOMPARE(prop.notifySignal().name(), QByteArray("prop34Changed" )); |
137 | } |
138 | { |
139 | QMetaProperty prop = obj.metaObject()->property(obj.metaObject()->indexOfProperty("intProp0" )); |
140 | QCOMPARE(prop.name(), "intProp0" ); |
141 | QCOMPARE(prop.typeName(), "int" ); |
142 | QCOMPARE(prop.hasNotifySignal(), true); |
143 | QCOMPARE(prop.notifySignal().name(), QByteArray("intProp0Changed" )); |
144 | } |
145 | } |
146 | |
147 | QTEST_MAIN(tst_ManyProperties) |
148 | |