Debian Codegraph @

tests/unit/statesaver11/tst_statesaver.cpp

raw symbols SCIP
1 /*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Zsombor Egri <[email protected]>
17 */
18
19 #include <signal.h>
20
21 #include <QtCore/QCoreApplication>
22 #include <QtCore/QProcess>
23 #include <QtCore/QProcessEnvironment>
24 #include <QtCore/QRegularExpression>
25 #include <QtGui/QMatrix4x4>
26 #include <QtGui/QQuaternion>
27 #include <QtGui/QVector3D>
28 #include <QtGui/QVector4D>
29 #include <QtQml/QQmlEngine>
30 #include <QtQml/QQmlProperty>
31 #include <QtQuick/QQuickItem>
32 #include <QtQuick/QQuickView>
33 #include <QtTest/QSignalSpy>
34 #include <QtTest/QtTest>
35 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
36 #include <LomiriToolkit-Qt6/lomiritoolkitmodule.h>
37 #else
38 #include <LomiriToolkit/lomiritoolkitmodule.h>
39 #endif
40 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
41 #include <LomiriToolkit-Qt6/private/quickutils_p.h>
42 #else
43 #include <LomiriToolkit/private/quickutils_p.h>
44 #endif
45 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
46 #include <LomiriToolkit-Qt6/private/ucapplication_p.h>
47 #else
48 #include <LomiriToolkit/private/ucapplication_p.h>
49 #endif
50 #define protected public
51 #define private public
52 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
53 #include <LomiriToolkit-Qt6/private/ucstatesaver_p.h>
54 #else
55 #include <LomiriToolkit/private/ucstatesaver_p.h>
56 #endif
57 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
58 #include <LomiriToolkit-Qt6/private/statesaverbackend_p.h>
59 #else
60 #include <LomiriToolkit/private/statesaverbackend_p.h>
61 #endif
62 #undef private
63 #undef protected
64
65 #include "uctestcase.h"
66
67 UT_USE_NAMESPACE
68
69 class tst_StateSaverTest : public QObject
70 {
71 Q_OBJECT
72 public:
73 tst_StateSaverTest() {}
74
75 private:
76 QTemporaryDir *tempDir = nullptr;
77 QString m_modulePath;
78 QQmlEngine *engine = nullptr;
79
80 QQuickView *createView(const QString &file)
81 {
82 LomiriTestCase* testCase = new LomiriTestCase(file);
83 return qobject_cast<QQuickView*>(testCase);
84 }
85
86 void resetView(QScopedPointer<LomiriTestCase> &view, const QString &file)
87 {
88 Q_EMIT StateSaverBackend::instance()->initiateStateSaving();
89 view.reset();
90 // Make sure that the state is reloaded from file
91 StateSaverBackend::instance()->m_archive.data()->sync();
92 view.reset(new LomiriTestCase(file));
93 }
94
95 void resetView(QScopedPointer<QQuickView> &view, const QString &file)
96 {
97 Q_EMIT StateSaverBackend::instance()->initiateStateSaving();
98 view.reset();
99 // Make sure that the state is reloaded from file
100 StateSaverBackend::instance()->m_archive.data()->sync();
101 view.reset(createView(file));
102 }
103
104 QString stateFile(const QString &appId)
105 {
106 return QString("%1/%2/statesaver.appstate")
107 .arg(QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation))
108 .arg(appId);
109 }
110
111 private Q_SLOTS:
112
113 void initTestCase()
114 {
115 QCoreApplication::setApplicationName("savedstate");
116 QCoreApplication::setOrganizationName("");
117 QDir modules (LOMIRI_QML_IMPORT_PATH);
118 QVERIFY(modules.exists());
119 m_modulePath = modules.absolutePath();
120 // XDG_RUNTIME_DIR may not be set in a test environment
121
122 tempDir = new QTemporaryDir();
123 QVERIFY(tempDir->isValid());
124 QString testRuntimeDir(tempDir->filePath("tst_statesaver"));
125 // Create manually to avoid wrong ownership
126 QDir(testRuntimeDir).mkdir("tst_statesaver");
127 setenv("XDG_RUNTIME_DIR", testRuntimeDir.toUtf8(), 1);
128 QFile::setPermissions(testRuntimeDir.toUtf8(), QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner);
129 }
130
131 void cleanupTestCase()
132 {
133 delete tempDir;
134 }
135
136 void init()
137 {
138 engine = new QQmlEngine;
139 LomiriToolkitModule::initializeContextProperties(engine);
140 // invoke initialization
141 StateSaverBackend::instance(engine);
142 }
143 void cleanup()
144 {
145 StateSaverBackend::instance()->reset();
146 delete engine;
147 }
148
149 void test_SaveArrays()
150 {
151 QScopedPointer<QQuickView> view(createView("SaveArrays.qml"));
152 QVERIFY(view);
153 QObject *testItem = view->rootObject();
154 QVERIFY(testItem);
155
156 QVariantList boolValues;
157 boolValues << true << true;
158 QVariantList intValues;
159 intValues << 100 << 200;
160 QVariantList realValues;
161 realValues << 123.45 << 678.9;
162 QVariantList stringValues;
163 stringValues << "one" << "two";
164 testItem->setProperty("boolArray", boolValues);
165 testItem->setProperty("intArray", intValues);
166 testItem->setProperty("realArray", realValues);
167 testItem->setProperty("stringArray", stringValues);
168
169 resetView(view, "SaveArrays.qml");
170 QVERIFY(view);
171 testItem = view->rootObject();
172 QVERIFY(testItem);
173 QCOMPARE(testItem->property("boolArray").value<QVariantList>(), boolValues);
174 QCOMPARE(testItem->property("intArray").value<QVariantList>(), intValues);
175 QCOMPARE(testItem->property("realArray").value<QVariantList>(), realValues);
176 QCOMPARE(testItem->property("stringArray").value<QVariantList>(), stringValues);
177 }
178
179 void test_SaveStructures()
180 {
181 QScopedPointer<QQuickView> view(createView("SaveSupportedTypes.qml"));
182 QVERIFY(view);
183 QObject *testItem = view->rootObject();
184 QVERIFY(testItem);
185
186 QVariantHash values;
187 values.insert("intValue", 1000);
188 values.insert("boolValue", true);
189 values.insert("realValue", 345.12);
190 values.insert("doubleValue", 65535.33244);
191 values.insert("string", "test string");
192 values.insert("url", QUrl::fromLocalFile("tst_statesaver.cpp"));
193 values.insert("date", QDateTime::currentDateTime().addDays(5));
194 values.insert("point", QPointF(100, 100));
195 values.insert("rect", QRectF(100, 100, 200, 200));
196 values.insert("size", QSizeF(345, 678));
197 values.insert("color", QColor("blue"));
198 values.insert("font", QFont("Noto Sans"));
199 values.insert("vector2d", QVector2D(100.0, 200.0));
200 values.insert("vector3d", QVector3D(100.0, 200.0, 300.0));
201 values.insert("vector4d", QVector4D(100.0, 200.0, 300.0, 400.0));
202 values.insert("quaternion", QQuaternion(1, 100.0, 200.0, 300.0));
203 values.insert("matrix4x4", QMatrix4x4(5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20));
204
205 QHashIterator<QString, QVariant> i(values);
206 while (i.hasNext()) {
207 i.next();
208 QVERIFY2(testItem->setProperty(i.key().toLocal8Bit().constData(), i.value()),
209 QString("set %1").arg(i.key()).toLocal8Bit().constData());
210 }
211
212 resetView(view, "SaveSupportedTypes.qml");
213 QVERIFY(view);
214 testItem = view->rootObject();
215 QVERIFY(testItem);
216
217 UCStateSaverAttached *stateSaver = qobject_cast<UCStateSaverAttached*>(qmlAttachedPropertiesObject<UCStateSaver>(testItem, false));
218 QVERIFY(stateSaver);
219
220 QStringList properties = stateSaver->properties().split(',');
221 Q_FOREACH(const QString &property, properties) {
222 QVERIFY2(testItem->property(property.toLocal8Bit().constData()) == values.value(property), QString("verifying %1").arg(property).toLocal8Bit().constData());
223 }
224 }
225
226 void test_SaveEnum()
227 {
228 /* This test is important because when saving the value of an enum
229 * property to QSettings, it is deserialized as a string. Setting that
230 * string value to an enum property fails and therefore the state
231 * restoration does not work.
232 * In most cases implicit type conversion from string to the appropriate
233 * type works.
234 */
235 QScopedPointer<QQuickView> view(createView("SaveEnum.qml"));
236 QVERIFY(view);
237 QObject *testItem = view->rootObject();
238 QVERIFY(testItem);
239
240 testItem->setProperty("horizontalAlignment", Qt::AlignRight);
241
242 resetView(view, "SaveEnum.qml");
243 QVERIFY(view);
244 testItem = view->rootObject();
245 QVERIFY(testItem);
246
247
248 QVERIFY(testItem->property("horizontalAlignment") == Qt::AlignRight);
249 }
250
251 void test_SavePropertyGroup()
252 {
253 QScopedPointer<QQuickView> view(createView("SavePropertyGroups.qml"));
254 QVERIFY(view);
255 QObject *testItem = view->rootObject();
256 QVERIFY(testItem);
257 QVERIFY(testItem->setProperty("color", QColor("red")));
258 // set property groups using QQmlProperty
259 QQmlProperty borderColor(testItem, "border.color");
260 borderColor.write(QColor("green"));
261 QQmlProperty propertyGroup(testItem, "propertyGroup.color");
262 propertyGroup.write(QColor("blue"));
263
264 resetView(view, "SavePropertyGroups.qml");
265 QVERIFY(view);
266 testItem = view->rootObject();
267 QVERIFY(testItem);
268 QCOMPARE(testItem->property("color"), QVariant(QColor("red")));
269 // read property groups using QQmlProperty
270 QQmlProperty verifyBorderColor(testItem, "border.color");
271 QCOMPARE(verifyBorderColor.read(), QVariant(QColor("green")));
272 QQmlProperty verifyPropertyGroup(testItem, "propertyGroup.color");
273 QCOMPARE(verifyPropertyGroup.read(), QVariant(QColor("blue")));
274 }
275
276 void test_SaveObject()
277 {
278 QScopedPointer<QQuickView> view(createView("SaveObject.qml"));
279 QVERIFY(view);
280 QObject *testItem = view->rootObject();
281 QVERIFY(testItem);
282
283 QScopedPointer<QQuickItem> obj(new QQuickItem);
284 obj->setObjectName("internal");
285 testItem->setProperty("object", QVariant::fromValue(obj.data()));
286
287 resetView(view, "SaveObject.qml");
288 QVERIFY(view);
289 testItem = view->rootObject();
290 QVERIFY(testItem);
291 QVERIFY(testItem->property("object").value<QQuickItem*>() != obj.data());
292 }
293
294 void test_ValidUID()
295 {
296 QScopedPointer<QQuickView> view(createView("ValidUID.qml"));
297 QVERIFY(view);
298 QObject *testItem = view->rootObject()->findChild<QObject*>("testItem");
299 QVERIFY(testItem);
300
301 testItem->setObjectName("updated");
302
303 resetView(view, "ValidUID.qml");
304 QVERIFY(view);
305 testItem = view->rootObject()->findChild<QObject*>("updated");
306 QVERIFY(testItem);
307 }
308
309 void test_InvalidUID()
310 {
311 QString filePath(QFileInfo("InvalidUID.qml").absoluteFilePath());
312 QString objectId(filePath.replace("/", "_") + ":21:5:testItem");
313
314 QRegularExpression warningRe(QStringLiteral(
315 ": QML (Item|InvalidUID): All the parents must have an id\\.\n"
316 "State saving disabled for %1, class (QQuickItem|InvalidUID)$"
317 ).arg(QRegularExpression::escape(objectId)));
318 // The warning happens twice.
319 QTest::ignoreMessage(QtWarningMsg, warningRe);
320 QTest::ignoreMessage(QtWarningMsg, warningRe);
321
322 QScopedPointer<LomiriTestCase> view(new LomiriTestCase("InvalidUID.qml"));
323 QObject *testItem = view->rootObject()->findChild<QObject*>("testItem");
324 QVERIFY(testItem);
325
326 testItem->setObjectName("updated");
327
328 resetView(view, "InvalidUID.qml");
329 QVERIFY(view);
330 testItem = view->rootObject()->findChild<QObject*>("updated");
331 QVERIFY(testItem == 0);
332 }
333
334 void test_ValidGroupProperty()
335 {
336 QScopedPointer<QQuickView> view(createView("ValidGroupProperty.qml"));
337 QVERIFY(view);
338 QObject *testItem = view->rootObject()->findChild<QObject*>("testItem");
339 QVERIFY(testItem);
340
341 testItem->setObjectName("group");
342
343 resetView(view, "ValidGroupProperty.qml");
344 QVERIFY(view);
345 testItem = view->rootObject()->findChild<QObject*>("group");
346 QVERIFY(testItem);
347 }
348
349 void test_InvalidGroupProperty()
350 {
351 LomiriTestCase::ignoreWarning("InvalidGroupProperty.qml", 24, 29,
352 "QML QtObject: Warning: attachee must have an ID. State will not be saved.", 2);
353 QScopedPointer<LomiriTestCase> view(new LomiriTestCase("InvalidGroupProperty.qml"));
354 QObject *testItem = view->rootObject()->findChild<QObject*>("testItem");
355 QVERIFY(testItem);
356
357 testItem->setObjectName("group");
358
359 resetView(view, "InvalidGroupProperty.qml");
360 testItem = view->rootObject()->findChild<QObject*>("group");
361 QVERIFY(testItem == 0);
362 }
363
364 void test_Dynamic()
365 {
366 QScopedPointer<QQuickView> view(createView("Dynamic.qml"));
367 QVERIFY(view);
368 QObject *testItem = view->rootObject()->findChild<QObject*>("testItem");
369 QVERIFY(testItem);
370
371 testItem->setObjectName("updated");
372
373 resetView(view, "Dynamic.qml");
374 QVERIFY(view);
375 testItem = view->rootObject()->findChild<QObject*>("updated");
376 QVERIFY(testItem);
377 }
378
379 void test_TwoDynamics()
380 {
381 QScopedPointer<QQuickView> view(createView("TwoDynamics.qml"));
382 QVERIFY(view);
383 QObject *testItem = view->rootObject()->findChild<QObject*>("testItem");
384 QVERIFY(testItem);
385
386 testItem->setObjectName("updated");
387
388 resetView(view, "TwoDynamics.qml");
389 QVERIFY(view);
390 testItem = view->rootObject()->findChild<QObject*>("updated");
391 QVERIFY(testItem);
392 }
393
394 void test_DisabledStateSaver()
395 {
396 QScopedPointer<QQuickView> view(createView("DisabledStateSaver.qml"));
397 QVERIFY(view);
398 QObject *testItem = view->rootObject()->findChild<QObject*>("testItem");
399 QVERIFY(testItem);
400
401 testItem->setObjectName("updated");
402
403 resetView(view, "DisabledStateSaver.qml");
404 QVERIFY(view);
405 testItem = view->rootObject()->findChild<QObject*>("updated");
406 QVERIFY(testItem == 0);
407 }
408
409 void test_SameIdsInDifferentComponents()
410 {
411 QSKIP("Failing on Qt 5.9 due to unknown parent missing ID.");
412 QScopedPointer<QQuickView> view(createView("SameIdsInDifferentComponents.qml"));
413 QVERIFY(view);
414 QObject *testItem = view->rootObject()->findChild<QObject*>("testItem");
415 QVERIFY(testItem);
416
417 testItem->setProperty("source", "SecondComponent.qml");
418 // check if the SecondComponent state saver is enabled
419 QObject *item = testItem->property("item").value<QObject*>();
420 QVERIFY(item);
421 QObject *innerItem = item->findChild<QObject*>("secondComponent");
422 UCStateSaverAttached *stateSaver = qobject_cast<UCStateSaverAttached*>(qmlAttachedPropertiesObject<UCStateSaver>(innerItem, false));
423 QVERIFY(stateSaver);
424 QVERIFY(stateSaver->enabled());
425
426 resetView(view, "SameIdsInDifferentComponents.qml");
427 QVERIFY(view);
428 testItem = view->rootObject()->findChild<QObject*>("secondComponent");
429 QVERIFY(testItem);
430 }
431
432 void test_ComponentsWithStateSavers()
433 {
434 QScopedPointer<QQuickView> view(createView("ComponentsWithStateSavers.qml"));
435 QVERIFY(view);
436 QObject *control1 = view->rootObject()->findChild<QObject*>("control1");
437 QVERIFY(control1);
438 QObject *control2 = view->rootObject()->findChild<QObject*>("control2");
439 QVERIFY(control2);
440 UCStateSaverAttached *stateSaver1 = qobject_cast<UCStateSaverAttached*>(qmlAttachedPropertiesObject<UCStateSaver>(control1, false));
441 QVERIFY(stateSaver1);
442 QVERIFY(stateSaver1->enabled());
443 UCStateSaverAttached *stateSaver2 = qobject_cast<UCStateSaverAttached*>(qmlAttachedPropertiesObject<UCStateSaver>(control2, false));
444 QVERIFY(stateSaver2);
445 QVERIFY(stateSaver2->enabled());
446
447 QVERIFY(control1->setProperty("color", QColor("green")));
448 QVERIFY(control2->setProperty("color", QColor("blue")));
449
450 resetView(view, "ComponentsWithStateSavers.qml");
451 control1 = view->rootObject()->findChild<QObject*>("control1");
452 QVERIFY(control1);
453 control2 = view->rootObject()->findChild<QObject*>("control2");
454 QVERIFY(control2);
455 stateSaver1 = qobject_cast<UCStateSaverAttached*>(qmlAttachedPropertiesObject<UCStateSaver>(control1, false));
456 QVERIFY(stateSaver1);
457 QVERIFY(stateSaver1->enabled());
458 stateSaver2 = qobject_cast<UCStateSaverAttached*>(qmlAttachedPropertiesObject<UCStateSaver>(control2, false));
459 QVERIFY(stateSaver2);
460 QVERIFY(stateSaver2->enabled());
461 QVERIFY(view);
462
463 QCOMPARE(control1->property("color"), QVariant(QColor("green")));
464 QCOMPARE(control2->property("color"), QVariant(QColor("blue")));
465 }
466
467 void test_ComponentsWithStateSaversNoId()
468 {
469 QRegularExpression warningRe(QStringLiteral(
470 ": QML (Rectangle|CustomControl): Warning: attachee must have an ID\\. State will not be saved\\.$"
471 ));
472 QTest::ignoreMessage(QtWarningMsg, warningRe);
473
474 QScopedPointer<LomiriTestCase> view(new LomiriTestCase("ComponentsWithStateSaversNoId.qml"));
475 QObject *control1 = view->rootObject()->findChild<QObject*>("control1");
476 QVERIFY(control1);
477 QObject *control2 = view->rootObject()->findChild<QObject*>("control2");
478 QVERIFY(control2);
479 UCStateSaverAttached *stateSaver1 = qobject_cast<UCStateSaverAttached*>(qmlAttachedPropertiesObject<UCStateSaver>(control1, false));
480 QVERIFY(stateSaver1);
481 QVERIFY(stateSaver1->enabled() == false);
482 UCStateSaverAttached *stateSaver2 = qobject_cast<UCStateSaverAttached*>(qmlAttachedPropertiesObject<UCStateSaver>(control2, false));
483 QVERIFY(stateSaver2);
484 QVERIFY(stateSaver2->enabled());
485 }
486
487 void test_nestedDynamics()
488 {
489 QSKIP("Failing on Qt 5.9 due to unknown parent missing ID.");
490 QScopedPointer<QQuickView> view(createView("NestedDynamics.qml"));
491 QVERIFY(view);
492 QObject *topLoader = view->rootObject()->findChild<QObject*>("outerLoader");
493 QVERIFY(topLoader);
494
495 topLoader->setProperty("source", "Dynamic.qml");
496 QCoreApplication::processEvents();
497
498 QObject *testItem = view->rootObject()->findChild<QObject*>("testItem");
499 QVERIFY(testItem);
500 testItem->setObjectName("updated");
501
502 resetView(view, "NestedDynamics.qml");
503 QVERIFY(view);
504 testItem = view->rootObject()->findChild<QObject*>("updated");
505 QVERIFY(testItem);
506 }
507
508 void test_repeaterStates()
509 {
510 QScopedPointer<QQuickView> view(createView("RepeaterStates.qml"));
511 QVERIFY(view);
512 QQuickItem *column = view->rootObject()->findChild<QQuickItem*>("column");
513 QVERIFY(column);
514
515 QList<QQuickItem*> items = column->childItems();
516 QCOMPARE(items.count(), 5); // 4 Rectangles + 1 Repeater
517
518 Q_FOREACH(QQuickItem *item, items) {
519 if (QuickUtils::instance()->className(item) == "QQuickRectangle") {
520 item->setHeight(25);
521 }
522 }
523
524 resetView(view, "RepeaterStates.qml");
525 QVERIFY(view);
526 column = view->rootObject()->findChild<QQuickItem*>("column");
527 QVERIFY(column);
528
529 items = column->childItems();
530 QCOMPARE(items.count(), 5); // 4 Rectangles + 1 Repeater
531
532 Q_FOREACH(QQuickItem *item, items) {
533 if (QuickUtils::instance()->className(item) == "QQuickRectangle") {
534 QCOMPARE(item->height(), 25.0);
535 }
536 }
537 }
538
539 void test_ListViewItemStates()
540 {
541 QScopedPointer<QQuickView> view(createView("ListViewItems.qml"));
542 QVERIFY(view);
543 QQuickItem *list = view->rootObject()->findChild<QQuickItem*>("list");
544 QVERIFY(list);
545 QQuickItem *contentItem = list->property("contentItem").value<QQuickItem*>();
546 QVERIFY(contentItem);
547 QList<QQuickItem*> items = contentItem->childItems();
548
549 int testItemCount = 0;
550 Q_FOREACH(QQuickItem *item, items) {
551 if (item->objectName() == "testItem") {
552 item->setHeight(25);
553 testItemCount++;
554 }
555 }
556 QCOMPARE(testItemCount, 2);
557
558 resetView(view, "ListViewItems.qml");
559 QVERIFY(view);
560 list = view->rootObject()->findChild<QQuickItem*>("list");
561 QVERIFY(list);
562 contentItem = list->property("contentItem").value<QQuickItem*>();
563 QVERIFY(contentItem);
564 items = contentItem->childItems();
565
566 Q_FOREACH(QQuickItem *item, items) {
567 if (item->objectName() == "testItem") {
568 QCOMPARE(item->height(), 25.0);
569 }
570 }
571 }
572
573 void test_GridViewItemStates()
574 {
575 QScopedPointer<QQuickView> view(createView("GridViewItems.qml"));
576 QVERIFY(view);
577 QQuickItem *list = view->rootObject()->findChild<QQuickItem*>("grid");
578 QVERIFY(list);
579 QQuickItem *contentItem = list->property("contentItem").value<QQuickItem*>();
580 QVERIFY(contentItem);
581 QList<QQuickItem*> items = contentItem->childItems();
582
583 int testItemCount = 0;
584 Q_FOREACH(QQuickItem *item, items) {
585 if (item->objectName() == "testItem") {
586 item->setHeight(25);
587 testItemCount++;
588 }
589 }
590 QCOMPARE(testItemCount, 2);
591
592 resetView(view, "GridViewItems.qml");
593 QVERIFY(view);
594 list = view->rootObject()->findChild<QQuickItem*>("grid");
595 QVERIFY(list);
596 contentItem = list->property("contentItem").value<QQuickItem*>();
597 QVERIFY(contentItem);
598 items = contentItem->childItems();
599
600 Q_FOREACH(QQuickItem *item, items) {
601 if (item->objectName() == "testItem") {
602 QCOMPARE(item->height(), 25.0);
603 }
604 }
605 }
606
607 void test_normalAppClose()
608 {
609 QProcess testApp;
610 testApp.start("qmlscene", QStringList() << "-I" << LOMIRI_QML_IMPORT_PATH << "NormalAppClose.qml");
611 testApp.waitForFinished();
612
613 QString fileName = stateFile("NormalAppClose");
614 QVERIFY(!QFile(fileName).exists());
615 }
616
617 void test_SigTerm()
618 {
619 QProcess testApp;
620 testApp.start("qmlscene",QStringList() << "-I" << LOMIRI_QML_IMPORT_PATH << "SimpleApp.qml");
621 testApp.waitForStarted();
622
623 // send SIGTERM signal to the process, use terminate() to do that.
624 testApp.terminate();
625 testApp.waitForFinished();
626
627 QString fileName = stateFile("SimpleApp");
628 QVERIFY(!QFile(fileName).exists());
629 }
630
631 void test_SigInt()
632 {
633 QProcess testApp;
634 testApp.start("qmlscene",QStringList() << "-I" << LOMIRI_QML_IMPORT_PATH << "SimpleApp.qml");
635 testApp.waitForStarted();
636
637 QTest::qWait(1000);
638
639 // make sure we are not killing the parent
640 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
641 QVERIFY(testApp.pid() != QCoreApplication::applicationPid());
642 #else
643 QVERIFY(testApp.processId() != QCoreApplication::applicationPid());
644 #endif
645 // skip tests if the application PID is zero => the child app PID seems to be zero as well
646 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
647 if (!testApp.pid()) {
648 #else
649 if (!testApp.processId()) {
650 #endif
651 // kill child process
652 testApp.close();
653 QSKIP("This test requires valid PID");
654 }
655 // send SIGINT
656 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
657 ::kill(testApp.pid(), SIGINT);
658 #else
659 ::kill(testApp.processId(), SIGINT);
660 #endif
661 testApp.waitForFinished();
662
663 QString fileName = stateFile("SimpleApp");
664 QVERIFY2(QFile(fileName).exists(), qPrintable(fileName));
665 // clean the file
666 QFile::remove(fileName);
667 }
668 };
669
670 QTEST_MAIN(tst_StateSaverTest)
671
672 #include "tst_statesaver.moc"
673
674
675