1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | #include <qtest.h> |
29 | #include <QtQml/qqmlengine.h> |
30 | #include <QtQml/qqmlcomponent.h> |
31 | #include <QtQml/qqmlincubator.h> |
32 | #include <QtCore/qcoreapplication.h> |
33 | #include <QtCore/qfile.h> |
34 | #include <QtCore/qdebug.h> |
35 | #include <QtCore/qfileinfo.h> |
36 | #include <QtCore/qdir.h> |
37 | #include <QtCore/qscopeguard.h> |
38 | #include <QSignalSpy> |
39 | #include <QFont> |
40 | #include <QQmlFileSelector> |
41 | #include <QFileSelector> |
42 | #include <QEasingCurve> |
43 | #include <QScopeGuard> |
44 | |
45 | #include <private/qqmlproperty_p.h> |
46 | #include <private/qqmlmetatype_p.h> |
47 | #include <private/qqmlglobal_p.h> |
48 | #include <private/qqmlscriptstring_p.h> |
49 | #include <private/qqmlvmemetaobject_p.h> |
50 | #include <private/qqmlcomponent_p.h> |
51 | #include <private/qqmltype_p_p.h> |
52 | |
53 | #include "testtypes.h" |
54 | #include "testhttpserver.h" |
55 | |
56 | #include "../../shared/util.h" |
57 | |
58 | #if defined(Q_OS_MAC) |
59 | #include <unistd.h> |
60 | #endif |
61 | |
62 | DEFINE_BOOL_CONFIG_OPTION(qmlCheckTypes, QML_CHECK_TYPES) |
63 | |
64 | static inline bool isCaseSensitiveFileSystem(const QString &path) { |
65 | Q_UNUSED(path) |
66 | #if defined(Q_OS_MAC) |
67 | return pathconf(path.toLatin1().constData(), _PC_CASE_SENSITIVE); |
68 | #elif defined(Q_OS_WIN) |
69 | return false; |
70 | #else |
71 | return true; |
72 | #endif |
73 | } |
74 | |
75 | /* |
76 | This test case covers QML language issues. This covers everything that does not |
77 | involve evaluating ECMAScript expressions and bindings. |
78 | |
79 | Evaluation of expressions and bindings is covered in qmlecmascript |
80 | */ |
81 | class tst_qqmllanguage : public QQmlDataTest |
82 | { |
83 | Q_OBJECT |
84 | |
85 | private slots: |
86 | void initTestCase(); |
87 | void cleanupTestCase(); |
88 | |
89 | void errors_data(); |
90 | void errors(); |
91 | |
92 | void insertedSemicolon_data(); |
93 | void insertedSemicolon(); |
94 | |
95 | void simpleObject(); |
96 | void simpleContainer(); |
97 | void interfaceProperty(); |
98 | void interfaceQList(); |
99 | void assignObjectToSignal(); |
100 | void assignObjectToVariant(); |
101 | void assignLiteralSignalProperty(); |
102 | void assignQmlComponent(); |
103 | void assignBasicTypes(); |
104 | void assignTypeExtremes(); |
105 | void assignCompositeToType(); |
106 | void assignLiteralToVariant(); |
107 | void assignLiteralToVar(); |
108 | void assignLiteralToJSValue(); |
109 | void assignNullStrings(); |
110 | void bindJSValueToVar(); |
111 | void bindJSValueToVariant(); |
112 | void bindJSValueToType(); |
113 | void bindTypeToJSValue(); |
114 | void customParserTypes(); |
115 | void customParserTypeInInlineComponent(); |
116 | void rootAsQmlComponent(); |
117 | void rootItemIsComponent(); |
118 | void inlineQmlComponents(); |
119 | void idProperty(); |
120 | void autoNotifyConnection(); |
121 | void assignSignal(); |
122 | void assignSignalFunctionExpression(); |
123 | void overrideSignal_data(); |
124 | void overrideSignal(); |
125 | void dynamicProperties(); |
126 | void dynamicPropertiesNested(); |
127 | void listProperties(); |
128 | void listPropertiesInheritanceNoCrash(); |
129 | void badListItemType(); |
130 | void dynamicObjectProperties(); |
131 | void dynamicSignalsAndSlots(); |
132 | void simpleBindings(); |
133 | void noDoubleEvaluationForFlushedBindings_data(); |
134 | void noDoubleEvaluationForFlushedBindings(); |
135 | void autoComponentCreation(); |
136 | void autoComponentCreationInGroupProperty(); |
137 | void propertyValueSource(); |
138 | void requiredProperty(); |
139 | void requiredPropertyFromCpp_data(); |
140 | void requiredPropertyFromCpp(); |
141 | void attachedProperties(); |
142 | void dynamicObjects(); |
143 | void customVariantTypes(); |
144 | void valueTypes(); |
145 | void cppnamespace(); |
146 | void aliasProperties(); |
147 | void aliasPropertiesAndSignals(); |
148 | void aliasPropertyChangeSignals(); |
149 | void qtbug_89822(); |
150 | void componentCompositeType(); |
151 | void i18n(); |
152 | void i18n_data(); |
153 | void onCompleted(); |
154 | void onDestruction(); |
155 | void scriptString(); |
156 | void scriptStringJs(); |
157 | void scriptStringWithoutSourceCode(); |
158 | void scriptStringComparison(); |
159 | void defaultPropertyListOrder(); |
160 | void declaredPropertyValues(); |
161 | void dontDoubleCallClassBegin(); |
162 | void reservedWords_data(); |
163 | void reservedWords(); |
164 | void inlineAssignmentsOverrideBindings(); |
165 | void nestedComponentRoots(); |
166 | void registrationOrder(); |
167 | void readonly(); |
168 | void readonlyObjectProperties(); |
169 | void receivers(); |
170 | void registeredCompositeType(); |
171 | void registeredCompositeTypeWithEnum(); |
172 | void registeredCompositeTypeWithAttachedProperty(); |
173 | void implicitImportsLast(); |
174 | |
175 | void basicRemote_data(); |
176 | void basicRemote(); |
177 | void importsBuiltin_data(); |
178 | void importsBuiltin(); |
179 | void importsLocal_data(); |
180 | void importsLocal(); |
181 | void importsRemote_data(); |
182 | void importsRemote(); |
183 | void importsInstalled_data(); |
184 | void importsInstalled(); |
185 | void importsInstalledRemote_data(); |
186 | void importsInstalledRemote(); |
187 | void importsPath_data(); |
188 | void importsPath(); |
189 | void importsOrder_data(); |
190 | void importsOrder(); |
191 | void importIncorrectCase(); |
192 | void importJs_data(); |
193 | void importJs(); |
194 | void importJsModule_data(); |
195 | void importJsModule(); |
196 | void explicitSelfImport(); |
197 | void importInternalType(); |
198 | |
199 | void qmlAttachedPropertiesObjectMethod(); |
200 | void customOnProperty(); |
201 | void variantNotify(); |
202 | |
203 | void revisions(); |
204 | void revisionOverloads(); |
205 | |
206 | void subclassedUncreateableRevision_data(); |
207 | void subclassedUncreateableRevision(); |
208 | |
209 | void subclassedExtendedUncreateableRevision_data(); |
210 | void subclassedExtendedUncreateableRevision(); |
211 | |
212 | void uncreatableTypesAsProperties(); |
213 | |
214 | void propertyInit(); |
215 | void remoteLoadCrash(); |
216 | void signalWithDefaultArg(); |
217 | void signalParameterTypes(); |
218 | void functionParameterTypes(); |
219 | |
220 | // regression tests for crashes |
221 | void crash1(); |
222 | void crash2(); |
223 | |
224 | void globalEnums(); |
225 | void lowercaseEnumRuntime_data(); |
226 | void lowercaseEnumRuntime(); |
227 | void lowercaseEnumCompileTime_data(); |
228 | void lowercaseEnumCompileTime(); |
229 | void scopedEnum(); |
230 | void scopedEnumsWithNameClash(); |
231 | void scopedEnumsWithResolvedNameClash(); |
232 | void qmlEnums(); |
233 | void literals_data(); |
234 | void literals(); |
235 | |
236 | void objectDeletionNotify_data(); |
237 | void objectDeletionNotify(); |
238 | |
239 | void scopedProperties(); |
240 | |
241 | void deepProperty(); |
242 | |
243 | void compositeSingletonProperties(); |
244 | void compositeSingletonSameEngine(); |
245 | void compositeSingletonDifferentEngine(); |
246 | void compositeSingletonNonTypeError(); |
247 | void compositeSingletonQualifiedNamespace(); |
248 | void compositeSingletonModule(); |
249 | void compositeSingletonModuleVersioned(); |
250 | void compositeSingletonModuleQualified(); |
251 | void compositeSingletonInstantiateError(); |
252 | void compositeSingletonDynamicPropertyError(); |
253 | void compositeSingletonDynamicSignalAndJavaScriptPragma(); |
254 | void compositeSingletonQmlRegisterTypeError(); |
255 | void compositeSingletonQmldirNoPragmaError(); |
256 | void compositeSingletonQmlDirError(); |
257 | void compositeSingletonRemote(); |
258 | void compositeSingletonSelectors(); |
259 | void compositeSingletonRegistered(); |
260 | void compositeSingletonCircular(); |
261 | |
262 | void singletonsHaveContextAndEngine(); |
263 | |
264 | void customParserBindingScopes(); |
265 | void customParserEvaluateEnum(); |
266 | void customParserProperties(); |
267 | void customParserWithExtendedObject(); |
268 | void nestedCustomParsers(); |
269 | |
270 | void preservePropertyCacheOnGroupObjects(); |
271 | void propertyCacheInSync(); |
272 | |
273 | void rootObjectInCreationNotForSubObjects(); |
274 | void lazyDeferredSubObject(); |
275 | void deferredProperties(); |
276 | void executeDeferredPropertiesOnce(); |
277 | |
278 | void noChildEvents(); |
279 | |
280 | void earlyIdObjectAccess(); |
281 | |
282 | void deleteSingletons(); |
283 | |
284 | void arrayBuffer_data(); |
285 | void arrayBuffer(); |
286 | |
287 | void defaultListProperty(); |
288 | void namespacedPropertyTypes(); |
289 | |
290 | void qmlTypeCanBeResolvedByName_data(); |
291 | void qmlTypeCanBeResolvedByName(); |
292 | |
293 | void instanceof_data(); |
294 | void instanceof(); |
295 | |
296 | void concurrentLoadQmlDir(); |
297 | |
298 | void accessDeletedObject(); |
299 | |
300 | void lowercaseTypeNames(); |
301 | |
302 | void thisInQmlScope(); |
303 | |
304 | void valueTypeGroupPropertiesInBehavior(); |
305 | |
306 | void retrieveQmlTypeId(); |
307 | |
308 | void polymorphicFunctionLookup(); |
309 | void anchorsToParentInPropertyChanges(); |
310 | |
311 | void typeWrapperToVariant(); |
312 | |
313 | void extendedForeignTypes(); |
314 | |
315 | void inlineComponent(); |
316 | void inlineComponent_data(); |
317 | void inlineComponentReferenceCycle_data(); |
318 | void inlineComponentReferenceCycle(); |
319 | void nestedInlineComponentNotAllowed(); |
320 | void inlineComponentStaticTypeResolution(); |
321 | void inlineComponentInSingleton(); |
322 | void nonExistingInlineComponent_data(); |
323 | void nonExistingInlineComponent(); |
324 | void inlineComponentFoundBeforeOtherImports(); |
325 | void inlineComponentDuplicateNameError(); |
326 | |
327 | void selfReference(); |
328 | void selfReferencingSingleton(); |
329 | |
330 | void listContainingDeletedObject(); |
331 | void overrideSingleton(); |
332 | |
333 | void arrayToContainer(); |
334 | void qualifiedScopeInCustomParser(); |
335 | void accessNullPointerPropertyCache(); |
336 | void bareInlineComponent(); |
337 | |
338 | void hangOnWarning(); |
339 | |
340 | void ambiguousContainingType(); |
341 | |
342 | private: |
343 | QQmlEngine engine; |
344 | QStringList defaultImportPathList; |
345 | |
346 | void testType(const QString& qml, const QString& type, const QString& error, bool partialMatch = false); |
347 | |
348 | // When calling into JavaScript, the specific type of the return value can differ if that return |
349 | // value is a number. This is not only the case for non-integral numbers, or numbers that do not |
350 | // fit into the (signed) integer range, but it also depends on which optimizations are run. So, |
351 | // to check if the return value is of a number type, use this method instead of checking against |
352 | // a specific userType. |
353 | static bool isJSNumberType(int userType) |
354 | { |
355 | return userType == (int) QVariant::Int |
356 | || userType == (int) QVariant::UInt |
357 | || userType == (int) QVariant::Double; |
358 | } |
359 | |
360 | void getSingletonInstance(QQmlEngine& engine, const char* fileName, const char* propertyName, QObject** result /* out */); |
361 | void getSingletonInstance(QObject* o, const char* propertyName, QObject** result /* out */); |
362 | }; |
363 | |
364 | #define DETERMINE_ERRORS(errorfile,expected,actual)\ |
365 | QList<QByteArray> expected; \ |
366 | QList<QByteArray> actual; \ |
367 | do { \ |
368 | QFile file(testFile(errorfile)); \ |
369 | QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); \ |
370 | QByteArray data = file.readAll(); \ |
371 | file.close(); \ |
372 | expected = data.split('\n'); \ |
373 | expected.removeAll(QByteArray("")); \ |
374 | QList<QQmlError> errors = component.errors(); \ |
375 | for (int ii = 0; ii < errors.count(); ++ii) { \ |
376 | const QQmlError &error = errors.at(ii); \ |
377 | QByteArray errorStr = QByteArray::number(error.line()) + ':' + \ |
378 | QByteArray::number(error.column()) + ':' + \ |
379 | error.description().toUtf8(); \ |
380 | actual << errorStr; \ |
381 | } \ |
382 | } while (false); |
383 | |
384 | #define VERIFY_ERRORS(errorfile) \ |
385 | if (!errorfile) { \ |
386 | if (qgetenv("DEBUG") != "" && !component.errors().isEmpty()) \ |
387 | qWarning() << "Unexpected Errors:" << component.errors(); \ |
388 | QVERIFY2(!component.isError(), qPrintable(component.errorString())); \ |
389 | QVERIFY(component.errors().isEmpty()); \ |
390 | } else { \ |
391 | DETERMINE_ERRORS(errorfile, |
---|