Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qmltest/quicktest.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | class QTestRootObject : public QObject | - | ||||||||||||||||||
10 | { | - | ||||||||||||||||||
11 | public: | - | ||||||||||||||||||
12 | #pragma GCC diagnostic push | - | ||||||||||||||||||
13 | - | |||||||||||||||||||
14 | #pragma GCC diagnostic ignored "-Wsuggest-override" | - | ||||||||||||||||||
15 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: | - | ||||||||||||||||||
16 | #pragma GCC diagnostic ignored "-Wattributes" | - | ||||||||||||||||||
17 | __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||||||||
18 | #pragma GCC diagnostic pop | - | ||||||||||||||||||
19 | struct QPrivateSignal {}; | - | ||||||||||||||||||
20 | - | |||||||||||||||||||
21 | - | |||||||||||||||||||
22 | - | |||||||||||||||||||
23 | public: | - | ||||||||||||||||||
24 | QTestRootObject(QObject *parent = nullptr) | - | ||||||||||||||||||
25 | : QObject(parent), hasQuit(false), m_windowShown(false), m_hasTestCase(false) { | - | ||||||||||||||||||
26 | m_defined = new QQmlPropertyMap(this); | - | ||||||||||||||||||
27 | - | |||||||||||||||||||
28 | - | |||||||||||||||||||
29 | - | |||||||||||||||||||
30 | } executed 32 times by 4 tests: end of block Executed by:
| 32 | ||||||||||||||||||
31 | - | |||||||||||||||||||
32 | static QTestRootObject *instance() { | - | ||||||||||||||||||
33 | static QPointer<QTestRootObject> object = new QTestRootObject; | - | ||||||||||||||||||
34 | if (!object
| 16-176 | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | object = new QTestRootObject; | - | ||||||||||||||||||
37 | } executed 16 times by 3 tests: end of block Executed by:
| 16 | ||||||||||||||||||
38 | return executed 192 times by 4 tests: object;return object; Executed by:
executed 192 times by 4 tests: return object; Executed by:
| 192 | ||||||||||||||||||
39 | } | - | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | bool hasQuit:1; | - | ||||||||||||||||||
42 | bool hasTestCase() const { return never executed: m_hasTestCase;return m_hasTestCase; never executed: }return m_hasTestCase; | 0 | ||||||||||||||||||
43 | void setHasTestCase(bool value) { m_hasTestCase = value; hasTestCaseChanged(); } executed 64 times by 4 tests: end of block Executed by:
| 64 | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | bool windowShown() const { return executed 48 times by 4 tests: m_windowShown;return m_windowShown; Executed by:
executed 48 times by 4 tests: }return m_windowShown; Executed by:
| 48 | ||||||||||||||||||
46 | void setWindowShown(bool value) { m_windowShown = value; windowShownChanged(); } executed 48 times by 4 tests: end of block Executed by:
| 48 | ||||||||||||||||||
47 | QQmlPropertyMap *defined() const { return never executed: m_defined;return m_defined; never executed: }return m_defined; | 0 | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | void init() { setWindowShown(false); setHasTestCase(false); hasQuit = false; } executed 32 times by 4 tests: end of block Executed by:
| 32 | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | public : | - | ||||||||||||||||||
52 | void windowShownChanged(); | - | ||||||||||||||||||
53 | void hasTestCaseChanged(); | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | private : | - | ||||||||||||||||||
56 | void quit() { hasQuit = true; } executed 32 times by 4 tests: end of block Executed by:
| 32 | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | private: | - | ||||||||||||||||||
59 | bool m_windowShown : 1; | - | ||||||||||||||||||
60 | bool m_hasTestCase :1; | - | ||||||||||||||||||
61 | QQmlPropertyMap *m_defined; | - | ||||||||||||||||||
62 | }; | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | static QObject *testRootObject(QQmlEngine *engine, QJSEngine *jsEngine) | - | ||||||||||||||||||
65 | { | - | ||||||||||||||||||
66 | (void)engine;; | - | ||||||||||||||||||
67 | (void)jsEngine;; | - | ||||||||||||||||||
68 | return executed 32 times by 4 tests: QTestRootObject::instance();return QTestRootObject::instance(); Executed by:
executed 32 times by 4 tests: return QTestRootObject::instance(); Executed by:
| 32 | ||||||||||||||||||
69 | } | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | static inline QString stripQuotes(const QString &s) | - | ||||||||||||||||||
72 | { | - | ||||||||||||||||||
73 | if (s.length() >= 2
| 0 | ||||||||||||||||||
74 | return never executed: s.mid(1, s.length() - 2);return s.mid(1, s.length() - 2); never executed: return s.mid(1, s.length() - 2); | 0 | ||||||||||||||||||
75 | else | - | ||||||||||||||||||
76 | return never executed: s;return s; never executed: return s; | 0 | ||||||||||||||||||
77 | } | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | void handleCompileErrors(const QFileInfo &fi, QQuickView *view) | - | ||||||||||||||||||
80 | { | - | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | const QList<QQmlError> errors = view->errors(); | - | ||||||||||||||||||
83 | QuickTestResult results; | - | ||||||||||||||||||
84 | results.setTestCaseName(fi.baseName()); | - | ||||||||||||||||||
85 | results.startLogging(); | - | ||||||||||||||||||
86 | results.setFunctionName(QLatin1String("compile")); | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | QString message; | - | ||||||||||||||||||
89 | QTextStream str(&message); | - | ||||||||||||||||||
90 | str << "\n " << QDir::toNativeSeparators(fi.absoluteFilePath()) << " produced " | - | ||||||||||||||||||
91 | << errors.size() << " error(s):\n"; | - | ||||||||||||||||||
92 | for (const QQmlError &e : errors) { | - | ||||||||||||||||||
93 | str << " "; | - | ||||||||||||||||||
94 | if (e.url().isLocalFile()
| 0 | ||||||||||||||||||
95 | str << QDir::toNativeSeparators(e.url().toLocalFile()); | - | ||||||||||||||||||
96 | } never executed: else {end of block | 0 | ||||||||||||||||||
97 | str << e.url().toString(); | - | ||||||||||||||||||
98 | } never executed: end of block | 0 | ||||||||||||||||||
99 | if (e.line() > 0
| 0 | ||||||||||||||||||
100 | str << ':' << e.line() << ',' << e.column(); never executed: str << ':' << e.line() << ',' << e.column(); | 0 | ||||||||||||||||||
101 | str << ": " << e.description() << '\n'; | - | ||||||||||||||||||
102 | } never executed: end of block | 0 | ||||||||||||||||||
103 | str << " Working directory: " << QDir::toNativeSeparators(QDir::current().absolutePath()) << '\n'; | - | ||||||||||||||||||
104 | if (QQmlEngine *engine = view->engine()
| 0 | ||||||||||||||||||
105 | str << " View: " << view->metaObject()->className() << ", import paths:\n"; | - | ||||||||||||||||||
106 | const auto importPaths = engine->importPathList(); | - | ||||||||||||||||||
107 | for (const QString &i : importPaths) | - | ||||||||||||||||||
108 | str << " '" << QDir::toNativeSeparators(i) << "'\n"; never executed: str << " '" << QDir::toNativeSeparators(i) << "'\n"; | 0 | ||||||||||||||||||
109 | const QStringList pluginPaths = engine->pluginPathList(); | - | ||||||||||||||||||
110 | str << " Plugin paths:\n"; | - | ||||||||||||||||||
111 | for (const QString &p : pluginPaths) | - | ||||||||||||||||||
112 | str << " '" << QDir::toNativeSeparators(p) << "'\n"; never executed: str << " '" << QDir::toNativeSeparators(p) << "'\n"; | 0 | ||||||||||||||||||
113 | } never executed: end of block | 0 | ||||||||||||||||||
114 | QMessageLogger(__FILE__, 172, __PRETTY_FUNCTION__).warning("%s", QtPrivate::asString(message).toLocal8Bit().constData()); | - | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | results.fail(errors.at(0).description(), | - | ||||||||||||||||||
117 | errors.at(0).url(), errors.at(0).line()); | - | ||||||||||||||||||
118 | results.finishTestData(); | - | ||||||||||||||||||
119 | results.finishTestDataCleanup(); | - | ||||||||||||||||||
120 | results.finishTestFunction(); | - | ||||||||||||||||||
121 | results.setFunctionName(QString()); | - | ||||||||||||||||||
122 | results.stopLogging(); | - | ||||||||||||||||||
123 | } never executed: end of block | 0 | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | bool qWaitForSignal(QObject *obj, const char* signal, int timeout = 5000) | - | ||||||||||||||||||
126 | { | - | ||||||||||||||||||
127 | QSignalSpy spy(obj, signal); | - | ||||||||||||||||||
128 | QElapsedTimer timer; | - | ||||||||||||||||||
129 | timer.start(); | - | ||||||||||||||||||
130 | - | |||||||||||||||||||
131 | while (!spy.size()
| 56-109 | ||||||||||||||||||
132 | int remaining = timeout - int(timer.elapsed()); | - | ||||||||||||||||||
133 | if (remaining <= 0
| 0-109 | ||||||||||||||||||
134 | break; never executed: break; | 0 | ||||||||||||||||||
135 | QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); | - | ||||||||||||||||||
136 | QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); | - | ||||||||||||||||||
137 | QTest::qSleep(10); | - | ||||||||||||||||||
138 | } executed 109 times by 1 test: end of block Executed by:
| 109 | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | return executed 56 times by 1 test: spy.size();return spy.size(); Executed by:
executed 56 times by 1 test: return spy.size(); Executed by:
| 56 | ||||||||||||||||||
141 | } | - | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | using namespace QV4::CompiledData; | - | ||||||||||||||||||
144 | - | |||||||||||||||||||
145 | class TestCaseCollector | - | ||||||||||||||||||
146 | { | - | ||||||||||||||||||
147 | public: | - | ||||||||||||||||||
148 | typedef QList<QString> TestCaseList; | - | ||||||||||||||||||
149 | - | |||||||||||||||||||
150 | TestCaseCollector(const QFileInfo &fileInfo, QQmlEngine *engine) | - | ||||||||||||||||||
151 | { | - | ||||||||||||||||||
152 | QString path = fileInfo.absoluteFilePath(); | - | ||||||||||||||||||
153 | if (path.startsWith(QLatin1String(":/"))
| 0-42 | ||||||||||||||||||
154 | path.prepend(QLatin1String("qrc")); never executed: path.prepend(QLatin1String("qrc")); | 0 | ||||||||||||||||||
155 | - | |||||||||||||||||||
156 | QQmlComponent component(engine, path); | - | ||||||||||||||||||
157 | m_errors += component.errors(); | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | if (component.isReady()
| 0-42 | ||||||||||||||||||
160 | QQmlRefPointer<CompilationUnit> rootCompilationUnit = QQmlComponentPrivate::get(&component)->compilationUnit; | - | ||||||||||||||||||
161 | TestCaseEnumerationResult result = enumerateTestCases(rootCompilationUnit.data()); | - | ||||||||||||||||||
162 | m_testCases = result.testCases + result.finalizedPartialTestCases(); | - | ||||||||||||||||||
163 | m_errors += result.errors; | - | ||||||||||||||||||
164 | } executed 42 times by 4 tests: end of block Executed by:
| 42 | ||||||||||||||||||
165 | } executed 42 times by 4 tests: end of block Executed by:
| 42 | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | TestCaseList testCases() const { return executed 42 times by 4 tests: m_testCases;return m_testCases; Executed by:
executed 42 times by 4 tests: }return m_testCases; Executed by:
| 42 | ||||||||||||||||||
168 | QList<QQmlError> errors() const { return executed 42 times by 4 tests: m_errors;return m_errors; Executed by:
executed 42 times by 4 tests: }return m_errors; Executed by:
| 42 | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | private: | - | ||||||||||||||||||
171 | TestCaseList m_testCases; | - | ||||||||||||||||||
172 | QList<QQmlError> m_errors; | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | struct TestCaseEnumerationResult | - | ||||||||||||||||||
175 | { | - | ||||||||||||||||||
176 | TestCaseList testCases; | - | ||||||||||||||||||
177 | QList<QQmlError> errors; | - | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | - | |||||||||||||||||||
180 | bool isTestCase = false; | - | ||||||||||||||||||
181 | TestCaseList testFunctions; | - | ||||||||||||||||||
182 | QString testCaseName; | - | ||||||||||||||||||
183 | - | |||||||||||||||||||
184 | TestCaseList finalizedPartialTestCases() const | - | ||||||||||||||||||
185 | { | - | ||||||||||||||||||
186 | TestCaseList result; | - | ||||||||||||||||||
187 | for (const QString &function : testFunctions) | - | ||||||||||||||||||
188 | result << QString(([]() noexcept -> QString { enum { Size = sizeof(u"" "%1::%2")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "%1::%2" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 168 times by 3 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 168 times by 3 tests: }())).arg(testCaseName).arg(function);return qstring_literal_temp; Executed by:
executed 168 times by 3 tests: result << QString(([]() noexcept -> QString { enum { Size = sizeof(u"" "%1::%2")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "%1::%2" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())).arg(testCaseName).arg(function); Executed by:
| 168 | ||||||||||||||||||
189 | return executed 430 times by 4 tests: result;return result; Executed by:
executed 430 times by 4 tests: return result; Executed by:
| 430 | ||||||||||||||||||
190 | } | - | ||||||||||||||||||
191 | - | |||||||||||||||||||
192 | TestCaseEnumerationResult &operator<<(const TestCaseEnumerationResult &other) | - | ||||||||||||||||||
193 | { | - | ||||||||||||||||||
194 | testCases += other.testCases + other.finalizedPartialTestCases(); | - | ||||||||||||||||||
195 | errors += other.errors; | - | ||||||||||||||||||
196 | return executed 388 times by 2 tests: *this;return *this; Executed by:
executed 388 times by 2 tests: return *this; Executed by:
| 388 | ||||||||||||||||||
197 | } | - | ||||||||||||||||||
198 | }; | - | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | TestCaseEnumerationResult enumerateTestCases(CompilationUnit *compilationUnit, const Object *object = nullptr) | - | ||||||||||||||||||
201 | { | - | ||||||||||||||||||
202 | QQmlType testCaseType; | - | ||||||||||||||||||
203 | for (quint32 i = 0; i < compilationUnit->data->nImports
| 0-860 | ||||||||||||||||||
204 | const Import *import = compilationUnit->data->importAt(i); | - | ||||||||||||||||||
205 | if (compilationUnit->stringAt(import->uriIndex) != QLatin1Literal("QtTest")
| 430 | ||||||||||||||||||
206 | continue; executed 430 times by 4 tests: continue; Executed by:
| 430 | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | QString testCaseTypeName(([]() noexcept -> QString { enum { Size = sizeof(u"" "TestCase")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "TestCase" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 430 times by 4 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 430 times by 4 tests: }()));return qstring_literal_temp; Executed by:
| 430 | ||||||||||||||||||
209 | QString typeQualifier = compilationUnit->stringAt(import->qualifierIndex); | - | ||||||||||||||||||
210 | if (!typeQualifier.isEmpty()
| 0-430 | ||||||||||||||||||
211 | testCaseTypeName = typeQualifier % QLatin1Char('.') % testCaseTypeName; never executed: testCaseTypeName = typeQualifier % QLatin1Char('.') % testCaseTypeName; | 0 | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | testCaseType = compilationUnit->typeNameCache->query(testCaseTypeName).type; | - | ||||||||||||||||||
214 | if (testCaseType.isValid()
| 0-430 | ||||||||||||||||||
215 | break; executed 430 times by 4 tests: break; Executed by:
| 430 | ||||||||||||||||||
216 | } never executed: end of block | 0 | ||||||||||||||||||
217 | - | |||||||||||||||||||
218 | TestCaseEnumerationResult result; | - | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | if (!object
| 42-388 | ||||||||||||||||||
221 | object = compilationUnit->objectAt(0); executed 42 times by 4 tests: object = compilationUnit->objectAt(0); Executed by:
| 42 | ||||||||||||||||||
222 | - | |||||||||||||||||||
223 | if (CompilationUnit *superTypeUnit = compilationUnit->resolvedTypes.value(object->inheritedTypeNameIndex)->compilationUnit.data()
| 42-388 | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | if (testCaseType.isValid()
| 0-42 | ||||||||||||||||||
226 | result.isTestCase = true; executed 42 times by 4 tests: result.isTestCase = true; Executed by:
| 42 | ||||||||||||||||||
227 | else | - | ||||||||||||||||||
228 | result = enumerateTestCases(superTypeUnit); never executed: result = enumerateTestCases(superTypeUnit); | 0 | ||||||||||||||||||
229 | - | |||||||||||||||||||
230 | if (result.isTestCase
| 0-42 | ||||||||||||||||||
231 | - | |||||||||||||||||||
232 | for (auto binding = object->bindingsBegin(); binding != object->bindingsEnd()
| 0-70 | ||||||||||||||||||
233 | if (compilationUnit->stringAt(binding->propertyNameIndex) == QLatin1Literal("name")
| 28-42 | ||||||||||||||||||
234 | if (binding->type == QV4::CompiledData::Binding::Type_String
| 0-42 | ||||||||||||||||||
235 | result.testCaseName = compilationUnit->stringAt(binding->stringIndex); | - | ||||||||||||||||||
236 | } executed 42 times by 4 tests: else {end of block Executed by:
| 42 | ||||||||||||||||||
237 | QQmlError error; | - | ||||||||||||||||||
238 | error.setUrl(compilationUnit->url()); | - | ||||||||||||||||||
239 | error.setLine(binding->location.line); | - | ||||||||||||||||||
240 | error.setColumn(binding->location.column); | - | ||||||||||||||||||
241 | error.setDescription(([]() noexcept -> QString { enum { Size = sizeof(u"" "the 'name' property of a TestCase must be a literal string")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "the 'name' property of a TestCase must be a literal string" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp;return qstring_literal_temp; never executed: }()));return qstring_literal_temp; | 0 | ||||||||||||||||||
242 | result.errors << error; | - | ||||||||||||||||||
243 | } never executed: end of block | 0 | ||||||||||||||||||
244 | break; executed 42 times by 4 tests: break; Executed by:
| 42 | ||||||||||||||||||
245 | } | - | ||||||||||||||||||
246 | } executed 28 times by 2 tests: end of block Executed by:
| 28 | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | - | |||||||||||||||||||
249 | auto functionsEnd = compilationUnit->objectFunctionsEnd(object); | - | ||||||||||||||||||
250 | for (auto function = compilationUnit->objectFunctionsBegin(object); function != functionsEnd
| 42-190 | ||||||||||||||||||
251 | QString functionName = compilationUnit->stringAt(function->nameIndex); | - | ||||||||||||||||||
252 | if (!(functionName.startsWith(QLatin1Literal("test_"))
| 0-180 | ||||||||||||||||||
253 | continue; executed 10 times by 2 tests: continue; Executed by:
| 10 | ||||||||||||||||||
254 | - | |||||||||||||||||||
255 | if (functionName.endsWith(QLatin1Literal("_data"))
| 12-168 | ||||||||||||||||||
256 | continue; executed 12 times by 2 tests: continue; Executed by:
| 12 | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | result.testFunctions << functionName; | - | ||||||||||||||||||
259 | } executed 168 times by 3 tests: end of block Executed by:
| 168 | ||||||||||||||||||
260 | } executed 42 times by 4 tests: end of block Executed by:
| 42 | ||||||||||||||||||
261 | } executed 42 times by 4 tests: end of block Executed by:
| 42 | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | for (auto binding = object->bindingsBegin(); binding != object->bindingsEnd()
| 430-1254 | ||||||||||||||||||
264 | if (binding->type == QV4::CompiledData::Binding::Type_Object
| 388-866 | ||||||||||||||||||
265 | const Object *child = compilationUnit->objectAt(binding->value.objectIndex); | - | ||||||||||||||||||
266 | result << enumerateTestCases(compilationUnit, child); | - | ||||||||||||||||||
267 | } executed 388 times by 2 tests: end of block Executed by:
| 388 | ||||||||||||||||||
268 | } executed 1254 times by 4 tests: end of block Executed by:
| 1254 | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | return executed 430 times by 4 tests: result;return result; Executed by:
executed 430 times by 4 tests: return result; Executed by:
| 430 | ||||||||||||||||||
271 | } | - | ||||||||||||||||||
272 | }; | - | ||||||||||||||||||
273 | - | |||||||||||||||||||
274 | int quick_test_main(int argc, char **argv, const char *name, const char *sourceDir) | - | ||||||||||||||||||
275 | { | - | ||||||||||||||||||
276 | return executed 16 times by 3 tests: quick_test_main_with_setup(argc, argv, name, sourceDir, nullptr);return quick_test_main_with_setup(argc, argv, name, sourceDir, nullptr); Executed by:
executed 16 times by 3 tests: return quick_test_main_with_setup(argc, argv, name, sourceDir, nullptr); Executed by:
| 16 | ||||||||||||||||||
277 | } | - | ||||||||||||||||||
278 | - | |||||||||||||||||||
279 | int quick_test_main_with_setup(int argc, char **argv, const char *name, const char *sourceDir, QObject *setup) | - | ||||||||||||||||||
280 | { | - | ||||||||||||||||||
281 | - | |||||||||||||||||||
282 | - | |||||||||||||||||||
283 | bool withWidgets = false; | - | ||||||||||||||||||
284 | for (int index = 1; index < argc
| 18-20 | ||||||||||||||||||
285 | if (strcmp(argv[index], "-widgets") == 0
| 0-20 | ||||||||||||||||||
286 | withWidgets = true; | - | ||||||||||||||||||
287 | break; never executed: break; | 0 | ||||||||||||||||||
288 | } | - | ||||||||||||||||||
289 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | - | |||||||||||||||||||
292 | QCoreApplication *app = nullptr; | - | ||||||||||||||||||
293 | if (!QCoreApplication::instance()
| 0-18 | ||||||||||||||||||
294 | - | |||||||||||||||||||
295 | if (withWidgets
| 0-18 | ||||||||||||||||||
296 | app = new QApplication(argc, argv); never executed: app = new QApplication(argc, argv); | 0 | ||||||||||||||||||
297 | else | - | ||||||||||||||||||
298 | - | |||||||||||||||||||
299 | { | - | ||||||||||||||||||
300 | app = new QGuiApplication(argc, argv); | - | ||||||||||||||||||
301 | } executed 18 times by 4 tests: end of block Executed by:
| 18 | ||||||||||||||||||
302 | } | - | ||||||||||||||||||
303 | - | |||||||||||||||||||
304 | if (setup
| 2-16 | ||||||||||||||||||
305 | - | |||||||||||||||||||
306 | QMetaObject::invokeMethod(setup, "applicationAvailable"); | - | ||||||||||||||||||
307 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
308 | - | |||||||||||||||||||
309 | - | |||||||||||||||||||
310 | - | |||||||||||||||||||
311 | - | |||||||||||||||||||
312 | - | |||||||||||||||||||
313 | - | |||||||||||||||||||
314 | - | |||||||||||||||||||
315 | QStringList imports; | - | ||||||||||||||||||
316 | QStringList pluginPaths; | - | ||||||||||||||||||
317 | QString testPath; | - | ||||||||||||||||||
318 | QString translationFile; | - | ||||||||||||||||||
319 | QStringList fileSelectors; | - | ||||||||||||||||||
320 | int index = 1; | - | ||||||||||||||||||
321 | QScopedArrayPointer<char *> testArgV(new char *[argc + 1]); | - | ||||||||||||||||||
322 | testArgV[0] = argv[0]; | - | ||||||||||||||||||
323 | int testArgC = 1; | - | ||||||||||||||||||
324 | while (index < argc
| 18-20 | ||||||||||||||||||
325 | if (strcmp(argv[index], "-import") == 0
| 0-20 | ||||||||||||||||||
326 | imports += stripQuotes(QString::fromLocal8Bit(argv[index + 1])); | - | ||||||||||||||||||
327 | index += 2; | - | ||||||||||||||||||
328 | } never executed: else if (strcmp(argv[index], "-plugins") == 0end of block
| 0-20 | ||||||||||||||||||
329 | pluginPaths += stripQuotes(QString::fromLocal8Bit(argv[index + 1])); | - | ||||||||||||||||||
330 | index += 2; | - | ||||||||||||||||||
331 | } never executed: else if (strcmp(argv[index], "-input") == 0end of block
| 0-20 | ||||||||||||||||||
332 | testPath = stripQuotes(QString::fromLocal8Bit(argv[index + 1])); | - | ||||||||||||||||||
333 | index += 2; | - | ||||||||||||||||||
334 | } never executed: else if (strcmp(argv[index], "-opengl") == 0end of block
| 0-20 | ||||||||||||||||||
335 | ++index; | - | ||||||||||||||||||
336 | - | |||||||||||||||||||
337 | } never executed: else if (strcmp(argv[index], "-widgets") == 0end of block
| 0-20 | ||||||||||||||||||
338 | withWidgets = true; | - | ||||||||||||||||||
339 | ++index; | - | ||||||||||||||||||
340 | - | |||||||||||||||||||
341 | } never executed: else if (strcmp(argv[index], "-translation") == 0end of block
| 0-20 | ||||||||||||||||||
342 | translationFile = stripQuotes(QString::fromLocal8Bit(argv[index + 1])); | - | ||||||||||||||||||
343 | index += 2; | - | ||||||||||||||||||
344 | } never executed: else if (strcmp(argv[index], "-file-selector") == 0end of block
| 0-20 | ||||||||||||||||||
345 | fileSelectors += stripQuotes(QString::fromLocal8Bit(argv[index + 1])); | - | ||||||||||||||||||
346 | index += 2; | - | ||||||||||||||||||
347 | } never executed: else {end of block | 0 | ||||||||||||||||||
348 | testArgV[testArgC++] = argv[index++]; | - | ||||||||||||||||||
349 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
350 | } | - | ||||||||||||||||||
351 | testArgV[testArgC] = 0; | - | ||||||||||||||||||
352 | - | |||||||||||||||||||
353 | - | |||||||||||||||||||
354 | - | |||||||||||||||||||
355 | QuickTestResult::setCurrentAppname(argv[0]); | - | ||||||||||||||||||
356 | QuickTestResult::setProgramName(name); | - | ||||||||||||||||||
357 | - | |||||||||||||||||||
358 | QuickTestResult::parseArgs(testArgC, testArgV.data()); | - | ||||||||||||||||||
359 | - | |||||||||||||||||||
360 | - | |||||||||||||||||||
361 | QTranslator translator; | - | ||||||||||||||||||
362 | if (!translationFile.isEmpty()
| 0-18 | ||||||||||||||||||
363 | if (translator.load(translationFile)
| 0 | ||||||||||||||||||
364 | app->installTranslator(&translator); | - | ||||||||||||||||||
365 | } never executed: else {end of block | 0 | ||||||||||||||||||
366 | QMessageLogger(__FILE__, 424, __PRETTY_FUNCTION__).warning("Could not load the translation file '%s'.", QtPrivate::asString(translationFile).toLocal8Bit().constData()); | - | ||||||||||||||||||
367 | } never executed: end of block | 0 | ||||||||||||||||||
368 | } | - | ||||||||||||||||||
369 | if (testPath.isEmpty()
| 0-18 | ||||||||||||||||||
370 | const QString s = QString::fromLocal8Bit(sourceDir); | - | ||||||||||||||||||
371 | if (QFile::exists(s)
| 0-18 | ||||||||||||||||||
372 | testPath = s; executed 18 times by 4 tests: testPath = s; Executed by:
| 18 | ||||||||||||||||||
373 | } executed 18 times by 4 tests: end of block Executed by:
| 18 | ||||||||||||||||||
374 | if (testPath.isEmpty()
| 0-18 | ||||||||||||||||||
375 | QDir current = QDir::current(); | - | ||||||||||||||||||
376 | - | |||||||||||||||||||
377 | - | |||||||||||||||||||
378 | - | |||||||||||||||||||
379 | - | |||||||||||||||||||
380 | - | |||||||||||||||||||
381 | - | |||||||||||||||||||
382 | testPath = current.absolutePath(); | - | ||||||||||||||||||
383 | } never executed: end of block | 0 | ||||||||||||||||||
384 | QStringList files; | - | ||||||||||||||||||
385 | - | |||||||||||||||||||
386 | const QFileInfo testPathInfo(testPath); | - | ||||||||||||||||||
387 | if (testPathInfo.isFile()
| 0-18 | ||||||||||||||||||
388 | if (!testPath.endsWith(QLatin1String(".qml"))
| 0 | ||||||||||||||||||
389 | QMessageLogger(__FILE__, 455, __PRETTY_FUNCTION__).warning("'%s' does not have the suffix '.qml'.", QtPrivate::asString(testPath).toLocal8Bit().constData()); | - | ||||||||||||||||||
390 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
391 | } | - | ||||||||||||||||||
392 | files << testPath; | - | ||||||||||||||||||
393 | } never executed: else if (testPathInfo.isDir()end of block
| 0-18 | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | const QStringList filters(([]() noexcept -> QString { enum { Size = sizeof(u"" "tst_*.qml")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "tst_*.qml" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return executed 18 times by 4 tests: qstring_literal_temp;return qstring_literal_temp; Executed by:
executed 18 times by 4 tests: }()));return qstring_literal_temp; Executed by:
| 18 | ||||||||||||||||||
396 | QDirIterator iter(testPathInfo.absoluteFilePath(), filters, QDir::Files, | - | ||||||||||||||||||
397 | QDirIterator::Subdirectories | | - | ||||||||||||||||||
398 | QDirIterator::FollowSymlinks); | - | ||||||||||||||||||
399 | while (iter.hasNext()
| 18-42 | ||||||||||||||||||
400 | files += iter.next(); executed 42 times by 4 tests: files += iter.next(); Executed by:
| 42 | ||||||||||||||||||
401 | files.sort(); | - | ||||||||||||||||||
402 | if (files.isEmpty()
| 0-18 | ||||||||||||||||||
403 | QMessageLogger(__FILE__, 469, __PRETTY_FUNCTION__).warning("The directory '%s' does not contain any test files matching '%s'", | - | ||||||||||||||||||
404 | QtPrivate::asString(testPath).toLocal8Bit().constData(), QtPrivate::asString(filters.front()).toLocal8Bit().constData()); | - | ||||||||||||||||||
405 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
406 | } | - | ||||||||||||||||||
407 | } executed 18 times by 4 tests: else {end of block Executed by:
| 18 | ||||||||||||||||||
408 | QMessageLogger(__FILE__, 474, __PRETTY_FUNCTION__).warning("'%s' does not exist under '%s'.", | - | ||||||||||||||||||
409 | QtPrivate::asString(testPath).toLocal8Bit().constData(), QtPrivate::asString(QDir::currentPath()).toLocal8Bit().constData()); | - | ||||||||||||||||||
410 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||||||||||||||
411 | } | - | ||||||||||||||||||
412 | - | |||||||||||||||||||
413 | qputenv("QT_QTESTLIB_RUNNING", "1"); | - | ||||||||||||||||||
414 | - | |||||||||||||||||||
415 | - | |||||||||||||||||||
416 | qmlRegisterSingletonType<QTestRootObject>("Qt.test.qtestroot", 1, 0, "QTestRootObject", testRootObject); | - | ||||||||||||||||||
417 | - | |||||||||||||||||||
418 | QSet<QString> commandLineTestFunctions = QTest::testFunctions.toSet(); | - | ||||||||||||||||||
419 | const bool filteringTestFunctions = !commandLineTestFunctions.isEmpty(); | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | - | |||||||||||||||||||
422 | - | |||||||||||||||||||
423 | for (const QString &file : qAsConst(files)) { | - | ||||||||||||||||||
424 | const QFileInfo fi(file); | - | ||||||||||||||||||
425 | if (!fi.exists()
| 0-42 | ||||||||||||||||||
426 | continue; never executed: continue; | 0 | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | QQmlEngine engine; | - | ||||||||||||||||||
429 | for (const QString &path : qAsConst(imports)) | - | ||||||||||||||||||
430 | engine.addImportPath(path); never executed: engine.addImportPath(path); | 0 | ||||||||||||||||||
431 | for (const QString &path : qAsConst(pluginPaths)) | - | ||||||||||||||||||
432 | engine.addPluginPath(path); never executed: engine.addPluginPath(path); | 0 | ||||||||||||||||||
433 | - | |||||||||||||||||||
434 | if (!fileSelectors.isEmpty()
| 0-42 | ||||||||||||||||||
435 | QQmlFileSelector* const qmlFileSelector = new QQmlFileSelector(&engine, &engine); | - | ||||||||||||||||||
436 | qmlFileSelector->setExtraSelectors(fileSelectors); | - | ||||||||||||||||||
437 | } never executed: end of block | 0 | ||||||||||||||||||
438 | - | |||||||||||||||||||
439 | TestCaseCollector testCaseCollector(fi, &engine); | - | ||||||||||||||||||
440 | if (!testCaseCollector.errors().isEmpty()
| 0-42 | ||||||||||||||||||
441 | for (const QQmlError &error : testCaseCollector.errors()) | - | ||||||||||||||||||
442 | QMessageLogger(__FILE__, 508, __PRETTY_FUNCTION__).warning() << error; never executed: QMessageLogger(__FILE__, 508, __PRETTY_FUNCTION__).warning() << error; | 0 | ||||||||||||||||||
443 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||
444 | } | - | ||||||||||||||||||
445 | - | |||||||||||||||||||
446 | TestCaseCollector::TestCaseList availableTestFunctions = testCaseCollector.testCases(); | - | ||||||||||||||||||
447 | if (QTest::printAvailableFunctions
| 0-42 | ||||||||||||||||||
448 | for (const QString &function : availableTestFunctions) | - | ||||||||||||||||||
449 | QMessageLogger(__FILE__, 515, __PRETTY_FUNCTION__).debug("%s()", QtPrivate::asString(function).toLocal8Bit().constData()); never executed: QMessageLogger(__FILE__, 515, __PRETTY_FUNCTION__).debug("%s()", QtPrivate::asString(function).toLocal8Bit().constData()); | 0 | ||||||||||||||||||
450 | continue; never executed: continue; | 0 | ||||||||||||||||||
451 | } | - | ||||||||||||||||||
452 | - | |||||||||||||||||||
453 | const QSet<QString> availableTestSet = availableTestFunctions.toSet(); | - | ||||||||||||||||||
454 | if (filteringTestFunctions
| 10-22 | ||||||||||||||||||
455 | continue; executed 10 times by 1 test: continue; Executed by:
| 10 | ||||||||||||||||||
456 | commandLineTestFunctions.subtract(availableTestSet); | - | ||||||||||||||||||
457 | - | |||||||||||||||||||
458 | QQuickView view(&engine, nullptr); | - | ||||||||||||||||||
459 | view.setFlags(Qt::Window | Qt::WindowSystemMenuHint | - | ||||||||||||||||||
460 | | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | - | ||||||||||||||||||
461 | | Qt::WindowCloseButtonHint); | - | ||||||||||||||||||
462 | QEventLoop eventLoop; | - | ||||||||||||||||||
463 | QObject::connect(view.engine(), qFlagLocation("2""quit()" "\0" __FILE__ ":" "529"), | - | ||||||||||||||||||
464 | QTestRootObject::instance(), qFlagLocation("1""quit()" "\0" __FILE__ ":" "530")); | - | ||||||||||||||||||
465 | QObject::connect(view.engine(), qFlagLocation("2""quit()" "\0" __FILE__ ":" "531"), | - | ||||||||||||||||||
466 | &eventLoop, qFlagLocation("1""quit()" "\0" __FILE__ ":" "532")); | - | ||||||||||||||||||
467 | view.rootContext()->setContextProperty | - | ||||||||||||||||||
468 | (QLatin1String("qtest"), QTestRootObject::instance()); | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | - | |||||||||||||||||||
471 | - | |||||||||||||||||||
472 | if (setup
| 2-30 | ||||||||||||||||||
473 | - | |||||||||||||||||||
474 | - | |||||||||||||||||||
475 | QMetaObject::invokeMethod(setup, "qmlEngineAvailable", QArgument<QQmlEngine* >("QQmlEngine*", view.engine())); | - | ||||||||||||||||||
476 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
477 | - | |||||||||||||||||||
478 | view.setObjectName(fi.baseName()); | - | ||||||||||||||||||
479 | view.setTitle(view.objectName()); | - | ||||||||||||||||||
480 | QTestRootObject::instance()->init(); | - | ||||||||||||||||||
481 | QString path = fi.absoluteFilePath(); | - | ||||||||||||||||||
482 | if (path.startsWith(QLatin1String(":/"))
| 0-32 | ||||||||||||||||||
483 | view.setSource(QUrl(QLatin1String("qrc:") + path.midRef(1))); never executed: view.setSource(QUrl(QLatin1String("qrc:") + path.midRef(1))); | 0 | ||||||||||||||||||
484 | else | - | ||||||||||||||||||
485 | view.setSource(QUrl::fromLocalFile(path)); executed 32 times by 4 tests: view.setSource(QUrl::fromLocalFile(path)); Executed by:
| 32 | ||||||||||||||||||
486 | - | |||||||||||||||||||
487 | while (view.status() == QQuickView::Loading
| 0-32 | ||||||||||||||||||
488 | QTest::qWait(10); never executed: QTest::qWait(10); | 0 | ||||||||||||||||||
489 | if (view.status() == QQuickView::Error
| 0-32 | ||||||||||||||||||
490 | handleCompileErrors(fi, &view); | - | ||||||||||||||||||
491 | continue; never executed: continue; | 0 | ||||||||||||||||||
492 | } | - | ||||||||||||||||||
493 | if (!QTestRootObject::instance()->hasQuit
| 16 | ||||||||||||||||||
494 | - | |||||||||||||||||||
495 | - | |||||||||||||||||||
496 | - | |||||||||||||||||||
497 | - | |||||||||||||||||||
498 | - | |||||||||||||||||||
499 | view.setFramePosition(QPoint(50, 50)); | - | ||||||||||||||||||
500 | if (view.size().isEmpty()
| 0-16 | ||||||||||||||||||
501 | view.resize(200, 200); | - | ||||||||||||||||||
502 | } never executed: end of block | 0 | ||||||||||||||||||
503 | view.show(); | - | ||||||||||||||||||
504 | if (!QTest::qWaitForWindowExposed(&view)
| 0-16 | ||||||||||||||||||
505 | QMessageLogger(__FILE__, 571, __PRETTY_FUNCTION__).warning().nospace() | - | ||||||||||||||||||
506 | << "Test '" << QDir::toNativeSeparators(path) << "' window not exposed after show()."; | - | ||||||||||||||||||
507 | } never executed: end of block | 0 | ||||||||||||||||||
508 | view.requestActivate(); | - | ||||||||||||||||||
509 | if (!QTest::qWaitForWindowActive(&view)
| 0-16 | ||||||||||||||||||
510 | QMessageLogger(__FILE__, 576, __PRETTY_FUNCTION__).warning().nospace() | - | ||||||||||||||||||
511 | << "Test '" << QDir::toNativeSeparators(path) << "' window not active after requestActivate()."; | - | ||||||||||||||||||
512 | } never executed: end of block | 0 | ||||||||||||||||||
513 | if (view.isExposed()
| 0-16 | ||||||||||||||||||
514 | QTestRootObject::instance()->setWindowShown(true); | - | ||||||||||||||||||
515 | } executed 16 times by 2 tests: else {end of block Executed by:
| 16 | ||||||||||||||||||
516 | QMessageLogger(__FILE__, 582, __PRETTY_FUNCTION__).warning().nospace() | - | ||||||||||||||||||
517 | << "Test '" << QDir::toNativeSeparators(path) << "' window was never exposed! " | - | ||||||||||||||||||
518 | << "If the test case was expecting windowShown, it will hang."; | - | ||||||||||||||||||
519 | } never executed: end of block | 0 | ||||||||||||||||||
520 | if (!QTestRootObject::instance()->hasQuit
| 0-16 | ||||||||||||||||||
521 | eventLoop.exec(); never executed: eventLoop.exec(); | 0 | ||||||||||||||||||
522 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||||||||||||||
523 | } executed 32 times by 4 tests: end of block Executed by:
| 32 | ||||||||||||||||||
524 | - | |||||||||||||||||||
525 | - | |||||||||||||||||||
526 | QuickTestResult::setProgramName(nullptr); | - | ||||||||||||||||||
527 | delete app; | - | ||||||||||||||||||
528 | - | |||||||||||||||||||
529 | - | |||||||||||||||||||
530 | if (!commandLineTestFunctions.isEmpty()
| 4-14 | ||||||||||||||||||
531 | QMessageLogger(__FILE__, 597, __PRETTY_FUNCTION__).warning() << "Could not find the following test functions:"; | - | ||||||||||||||||||
532 | for (const QString &functionName : qAsConst(commandLineTestFunctions)) | - | ||||||||||||||||||
533 | QMessageLogger(__FILE__, 599, __PRETTY_FUNCTION__).warning(" %s()", QtPrivate::asString(functionName).toUtf8().constData()); executed 4 times by 1 test: QMessageLogger(__FILE__, 599, __PRETTY_FUNCTION__).warning(" %s()", QtPrivate::asString(functionName).toUtf8().constData()); Executed by:
| 4 | ||||||||||||||||||
534 | return executed 4 times by 1 test: commandLineTestFunctions.count();return commandLineTestFunctions.count(); Executed by:
executed 4 times by 1 test: return commandLineTestFunctions.count(); Executed by:
| 4 | ||||||||||||||||||
535 | } | - | ||||||||||||||||||
536 | - | |||||||||||||||||||
537 | - | |||||||||||||||||||
538 | return executed 14 times by 4 tests: QuickTestResult::exitCode();return QuickTestResult::exitCode(); Executed by:
executed 14 times by 4 tests: return QuickTestResult::exitCode(); Executed by:
| 14 | ||||||||||||||||||
539 | } | - | ||||||||||||||||||
540 | - | |||||||||||||||||||
541 | - | |||||||||||||||||||
542 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |