| 1 |
/* |
| 2 |
* Copyright 2012 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 |
|
| 17 |
#include <QtCore/QCoreApplication> |
| 18 |
#include <QtCore/QDir> |
| 19 |
#include <QtCore/QFileInfo> |
| 20 |
#include <QtCore/QString> |
| 21 |
#include <QtCore/QThread> |
| 22 |
#include <QtQml/QQmlEngine> |
| 23 |
#include <QtQuick/QQuickItem> |
| 24 |
#include <QtQuick/QQuickView> |
| 25 |
#include <QtQuick/private/qquickanchors_p_p.h> |
| 26 |
#include <QtTest/QtTest> |
| 27 |
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 28 |
#include <LomiriToolkit-Qt6/private/ucunits_p.h> |
| 29 |
#else |
| 30 |
#include <LomiriToolkit/private/ucunits_p.h> |
| 31 |
#endif |
| 32 |
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 33 |
#include <LomiriToolkit-Qt6/private/uctheme_p.h> |
| 34 |
#else |
| 35 |
#include <LomiriToolkit/private/uctheme_p.h> |
| 36 |
#endif |
| 37 |
|
| 38 |
#include "uctestcase.h" |
| 39 |
#include "ullayouts.h" |
| 40 |
|
| 41 |
UT_USE_NAMESPACE |
| 42 |
|
| 43 |
#define QCOMPARE_RET(actual, expected) \ |
| 44 |
do {\ |
| 45 |
if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ |
| 46 |
return false;\ |
| 47 |
} while (0) |
| 48 |
|
| 49 |
#define QVERIFY_RET(statement, resturns) \ |
| 50 |
do {\ |
| 51 |
if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ |
| 52 |
return resturns;\ |
| 53 |
} while (0) |
| 54 |
|
| 55 |
|
| 56 |
class tst_Layouts : public QObject |
| 57 |
{ |
| 58 |
Q_OBJECT |
| 59 |
private: |
| 60 |
QString m_modulePath; |
| 61 |
|
| 62 |
public: |
| 63 |
|
| 64 |
tst_Layouts() |
| 65 |
{ |
| 66 |
} |
| 67 |
|
| 68 |
QQuickView * loadTest(const QString &file) |
| 69 |
{ |
| 70 |
LomiriTestCase* testCase = new LomiriTestCase(file); |
| 71 |
return qobject_cast<QQuickView*>(testCase); |
| 72 |
} |
| 73 |
|
| 74 |
QQuickItem *testItem(QQuickItem *that, const QString &identifier) |
| 75 |
{ |
| 76 |
if (that->property(identifier.toLocal8Bit()).isValid()) |
| 77 |
return that->property(identifier.toLocal8Bit()).value<QQuickItem*>(); |
| 78 |
|
| 79 |
QList<QQuickItem*> children = that->findChildren<QQuickItem*>(identifier); |
| 80 |
return (children.count() > 0) ? children[0] : 0; |
| 81 |
} |
| 82 |
|
| 83 |
bool hasChildItem(QQuickItem *child, QQuickItem *parent) |
| 84 |
{ |
| 85 |
QQuickItem *pl = child->parentItem(); |
| 86 |
while (pl) { |
| 87 |
if (pl == parent) { |
| 88 |
return true; |
| 89 |
} |
| 90 |
pl = pl->parentItem(); |
| 91 |
} |
| 92 |
return false; |
| 93 |
} |
| 94 |
|
| 95 |
QQuickItem *prevSibling(QQuickItem *item) |
| 96 |
{ |
| 97 |
QList<QQuickItem*> children = item->parentItem()->childItems(); |
| 98 |
int index = children.indexOf(item); |
| 99 |
return (index > 0) ? children.at(index - 1) : 0; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
private Q_SLOTS: |
| 104 |
void initTestCase() |
| 105 |
{ |
| 106 |
qputenv("SUPPRESS_DEPRECATED_NOTE", "yes"); |
| 107 |
} |
| 108 |
|
| 109 |
void cleanup() |
| 110 |
{ |
| 111 |
UCTheme::previousVersion = 0; |
| 112 |
} |
| 113 |
|
| 114 |
void testCase_NoLayouts() |
| 115 |
{ |
| 116 |
QScopedPointer<LomiriTestCase> testCase(new LomiriTestCase("NoLayouts.qml")); |
| 117 |
ULLayouts *layouts = testCase->findItem<ULLayouts*>("layouts"); |
| 118 |
QVERIFY(layouts->layoutList().isEmpty()); |
| 119 |
} |
| 120 |
|
| 121 |
void testCase_SimpleLayout() |
| 122 |
{ |
| 123 |
QScopedPointer<QQuickView> view(loadTest("SimpleLayouts.qml")); |
| 124 |
QVERIFY(view); |
| 125 |
QQuickItem *root = view->rootObject(); |
| 126 |
QVERIFY(root); |
| 127 |
|
| 128 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layouts")); |
| 129 |
QVERIFY(layouts); |
| 130 |
QVERIFY(!layouts->layoutList().isEmpty()); |
| 131 |
QSignalSpy currentLayout(layouts, SIGNAL(currentLayoutChanged())); |
| 132 |
currentLayout.wait(300); |
| 133 |
|
| 134 |
QCOMPARE(layouts->currentLayout(), QString("small")); |
| 135 |
|
| 136 |
QQuickItem *item = testItem(root, "item1"); |
| 137 |
QVERIFY(item); |
| 138 |
QVERIFY(item->parentItem()->parentItem()->inherits("QQuickColumn")); |
| 139 |
|
| 140 |
item = testItem(root, "item2"); |
| 141 |
QVERIFY(item); |
| 142 |
QVERIFY(item->parentItem()->parentItem()->inherits("QQuickColumn")); |
| 143 |
|
| 144 |
item = testItem(root, "item3"); |
| 145 |
QVERIFY(item); |
| 146 |
QVERIFY(item->parentItem()->parentItem()->inherits("QQuickColumn")); |
| 147 |
} |
| 148 |
|
| 149 |
void testCase_SimpleLayout_Medium() |
| 150 |
{ |
| 151 |
QScopedPointer<QQuickView> view(loadTest("SimpleLayouts.qml")); |
| 152 |
QVERIFY(view); |
| 153 |
QQuickItem *root = view->rootObject(); |
| 154 |
QVERIFY(root); |
| 155 |
|
| 156 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layouts")); |
| 157 |
QVERIFY(layouts); |
| 158 |
|
| 159 |
QVERIFY(!layouts->layoutList().isEmpty()); |
| 160 |
QSignalSpy layoutChangeSpy(layouts, SIGNAL(currentLayoutChanged())); |
| 161 |
|
| 162 |
root->setWidth(UCUnits::instance()->gu(55)); |
| 163 |
QCOMPARE(root->width(), UCUnits::instance()->gu(55)); |
| 164 |
layoutChangeSpy.wait(100); |
| 165 |
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 166 |
// When the width is changed, the condition for the active conditional |
| 167 |
// layout becomes false and we briefly return to the default layout |
| 168 |
// before the other conditional layout becomes active (hence 2 changes) |
| 169 |
QCOMPARE(layoutChangeSpy.count(), 2); |
| 170 |
#else |
| 171 |
QCOMPARE(layoutChangeSpy.count(), 1); |
| 172 |
#endif |
| 173 |
|
| 174 |
QCOMPARE(layouts->currentLayout(), QString("medium")); |
| 175 |
|
| 176 |
QQuickItem *item = testItem(root, "item1"); |
| 177 |
QVERIFY(item); |
| 178 |
QVERIFY(item->parentItem()->parentItem()->inherits("QQuickFlow")); |
| 179 |
|
| 180 |
item = testItem(root, "item2"); |
| 181 |
QVERIFY(item); |
| 182 |
QVERIFY(item->parentItem()->parentItem()->inherits("QQuickFlow")); |
| 183 |
|
| 184 |
item = testItem(root, "item3"); |
| 185 |
QVERIFY(item); |
| 186 |
QVERIFY(item->parentItem()->parentItem()->inherits("QQuickFlow")); |
| 187 |
} |
| 188 |
|
| 189 |
void testCase_SimpleLayout_Large() |
| 190 |
{ |
| 191 |
QScopedPointer<QQuickView> view(loadTest("SimpleLayouts.qml")); |
| 192 |
QVERIFY(view); |
| 193 |
QQuickItem *root = view->rootObject(); |
| 194 |
QVERIFY(root); |
| 195 |
|
| 196 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layouts")); |
| 197 |
QVERIFY(layouts); |
| 198 |
QVERIFY(!layouts->layoutList().isEmpty()); |
| 199 |
QSignalSpy layoutChangeSpy(layouts, SIGNAL(currentLayoutChanged())); |
| 200 |
|
| 201 |
root->setWidth(UCUnits::instance()->gu(65)); |
| 202 |
QCOMPARE(root->width(), UCUnits::instance()->gu(65)); |
| 203 |
layoutChangeSpy.wait(100); |
| 204 |
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 205 |
// When the width is changed, the condition for the active conditional |
| 206 |
// layout becomes false and we briefly return to the default layout |
| 207 |
// before the other conditional layout becomes active (hence 2 changes) |
| 208 |
QCOMPARE(layoutChangeSpy.count(), 2); |
| 209 |
#else |
| 210 |
QCOMPARE(layoutChangeSpy.count(), 1); |
| 211 |
#endif |
| 212 |
|
| 213 |
QCOMPARE(layouts->currentLayout(), QString("large")); |
| 214 |
|
| 215 |
QQuickItem *item = testItem(root, "item1"); |
| 216 |
QVERIFY(item); |
| 217 |
QVERIFY(item->parentItem()->parentItem()->inherits("QQuickRow")); |
| 218 |
|
| 219 |
item = testItem(root, "item2"); |
| 220 |
QVERIFY(item); |
| 221 |
QVERIFY(item->parentItem()->parentItem()->inherits("QQuickRow")); |
| 222 |
|
| 223 |
item = testItem(root, "item3"); |
| 224 |
QVERIFY(item); |
| 225 |
QVERIFY(item->parentItem()->parentItem()->inherits("QQuickRow")); |
| 226 |
} |
| 227 |
|
| 228 |
void testCase_OverlappingCondition() |
| 229 |
{ |
| 230 |
QScopedPointer<QQuickView> view(loadTest("OverlappingCondition.qml")); |
| 231 |
QVERIFY(view); |
| 232 |
QQuickItem *root = view->rootObject(); |
| 233 |
QVERIFY(root); |
| 234 |
|
| 235 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layouts")); |
| 236 |
QVERIFY(layouts); |
| 237 |
QVERIFY(!layouts->layoutList().isEmpty()); |
| 238 |
QSignalSpy currentLayout(layouts, SIGNAL(currentLayoutChanged())); |
| 239 |
currentLayout.wait(300); |
| 240 |
|
| 241 |
QCOMPARE(layouts->currentLayout(), QString("small")); |
| 242 |
} |
| 243 |
|
| 244 |
void testCase_ExternalLayouts() |
| 245 |
{ |
| 246 |
QScopedPointer<QQuickView> view(loadTest("ExternalLayouts.qml")); |
| 247 |
QVERIFY(view); |
| 248 |
QQuickItem *root = view->rootObject(); |
| 249 |
QVERIFY(root); |
| 250 |
|
| 251 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layouts")); |
| 252 |
QVERIFY(layouts); |
| 253 |
QVERIFY(!layouts->layoutList().isEmpty()); |
| 254 |
QSignalSpy currentLayout(layouts, SIGNAL(currentLayoutChanged())); |
| 255 |
currentLayout.wait(300); |
| 256 |
|
| 257 |
QCOMPARE(layouts->currentLayout(), QString("small")); |
| 258 |
} |
| 259 |
|
| 260 |
void testCase_ExternalLayouts_Medium() |
| 261 |
{ |
| 262 |
QScopedPointer<QQuickView> view(loadTest("ExternalLayouts.qml")); |
| 263 |
QVERIFY(view); |
| 264 |
QQuickItem *root = view->rootObject(); |
| 265 |
QVERIFY(root); |
| 266 |
|
| 267 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layouts")); |
| 268 |
QVERIFY(layouts); |
| 269 |
QVERIFY(!layouts->layoutList().isEmpty()); |
| 270 |
QSignalSpy layoutChangeSpy(layouts, SIGNAL(currentLayoutChanged())); |
| 271 |
|
| 272 |
root->setWidth(UCUnits::instance()->gu(55)); |
| 273 |
layoutChangeSpy.wait(100); |
| 274 |
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 275 |
// When the width is changed, the condition for the active conditional |
| 276 |
// layout becomes false and we briefly return to the default layout |
| 277 |
// before the other conditional layout becomes active (hence 2 changes) |
| 278 |
QCOMPARE(layoutChangeSpy.count(), 2); |
| 279 |
#else |
| 280 |
QCOMPARE(layoutChangeSpy.count(), 1); |
| 281 |
#endif |
| 282 |
|
| 283 |
QCOMPARE(layouts->currentLayout(), QString("medium")); |
| 284 |
} |
| 285 |
|
| 286 |
void testCase_ExternalLayouts_Large() |
| 287 |
{ |
| 288 |
QScopedPointer<QQuickView> view(loadTest("ExternalLayouts.qml")); |
| 289 |
QVERIFY(view); |
| 290 |
QQuickItem *root = view->rootObject(); |
| 291 |
QVERIFY(root); |
| 292 |
|
| 293 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layouts")); |
| 294 |
QVERIFY(layouts); |
| 295 |
QVERIFY(!layouts->layoutList().isEmpty()); |
| 296 |
QSignalSpy layoutChangeSpy(layouts, SIGNAL(currentLayoutChanged())); |
| 297 |
|
| 298 |
root->setWidth(UCUnits::instance()->gu(65)); |
| 299 |
layoutChangeSpy.wait(100); |
| 300 |
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 301 |
// When the width is changed, the condition for the active conditional |
| 302 |
// layout becomes false and we briefly return to the default layout |
| 303 |
// before the other conditional layout becomes active (hence 2 changes) |
| 304 |
QCOMPARE(layoutChangeSpy.count(), 2); |
| 305 |
#else |
| 306 |
QCOMPARE(layoutChangeSpy.count(), 1); |
| 307 |
#endif |
| 308 |
|
| 309 |
QCOMPARE(layouts->currentLayout(), QString("large")); |
| 310 |
} |
| 311 |
|
| 312 |
void testCase_NestedLayouts() |
| 313 |
{ |
| 314 |
QScopedPointer<QQuickView> view(loadTest("NestedLayouts.qml")); |
| 315 |
QVERIFY(view); |
| 316 |
QQuickItem *root = view->rootObject(); |
| 317 |
QVERIFY(root); |
| 318 |
|
| 319 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layouts")); |
| 320 |
QVERIFY(layouts); |
| 321 |
QVERIFY(!layouts->layoutList().isEmpty()); |
| 322 |
QSignalSpy currentLayout(layouts, SIGNAL(currentLayoutChanged())); |
| 323 |
currentLayout.wait(300); |
| 324 |
|
| 325 |
QCOMPARE(layouts->currentLayout(), QString("simple")); |
| 326 |
} |
| 327 |
|
| 328 |
void testCase_NestedLayouts_ExtraLarge() |
| 329 |
{ |
| 330 |
QScopedPointer<QQuickView> view(loadTest("NestedLayouts.qml")); |
| 331 |
QVERIFY(view); |
| 332 |
QQuickItem *root = view->rootObject(); |
| 333 |
QVERIFY(root); |
| 334 |
|
| 335 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layouts")); |
| 336 |
QVERIFY(layouts); |
| 337 |
QVERIFY(!layouts->layoutList().isEmpty()); |
| 338 |
QSignalSpy layoutChangeSpy(layouts, SIGNAL(currentLayoutChanged())); |
| 339 |
|
| 340 |
root->setWidth(UCUnits::instance()->gu(90)); |
| 341 |
layoutChangeSpy.wait(100); |
| 342 |
QCOMPARE(layoutChangeSpy.count(), 1); |
| 343 |
|
| 344 |
QCOMPARE(layouts->currentLayout(), QString("extra-large")); |
| 345 |
|
| 346 |
root->setWidth(UCUnits::instance()->gu(50)); |
| 347 |
layoutChangeSpy.wait(100); |
| 348 |
QCOMPARE(layoutChangeSpy.count(), 2); |
| 349 |
|
| 350 |
QCOMPARE(root->property("nestedLayout").toString(), QString("medium")); |
| 351 |
} |
| 352 |
|
| 353 |
void testCase_ResizingContainers() |
| 354 |
{ |
| 355 |
QScopedPointer<QQuickView> view(loadTest("ResizingContainers.qml")); |
| 356 |
QVERIFY(view); |
| 357 |
QQuickItem *root = view->rootObject(); |
| 358 |
QVERIFY(root); |
| 359 |
|
| 360 |
// fetch the current size of one item |
| 361 |
QQuickItem *item = testItem(root, "item1"); |
| 362 |
qreal width = item->width(); |
| 363 |
qreal height = item->height(); |
| 364 |
QQuickItem *item2 = testItem(root, "item2"); |
| 365 |
qreal width2 = item2->width(); |
| 366 |
qreal height2 = item2->height(); |
| 367 |
|
| 368 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layouts")); |
| 369 |
QVERIFY(layouts); |
| 370 |
QVERIFY(!layouts->layoutList().isEmpty()); |
| 371 |
QSignalSpy layoutChangeSpy(layouts, SIGNAL(currentLayoutChanged())); |
| 372 |
|
| 373 |
root->setWidth(UCUnits::instance()->gu(50)); |
| 374 |
layoutChangeSpy.wait(100); |
| 375 |
QCOMPARE(layouts->currentLayout(), QString("small")); |
| 376 |
QCOMPARE(item->width(), UCUnits::instance()->gu(10)); |
| 377 |
QCOMPARE(item->height(), UCUnits::instance()->gu(10)); |
| 378 |
|
| 379 |
root->setWidth(UCUnits::instance()->gu(60)); |
| 380 |
layoutChangeSpy.wait(100); |
| 381 |
QCOMPARE(layouts->currentLayout(), QString("large")); |
| 382 |
QCOMPARE(item->width(), UCUnits::instance()->gu(22)); |
| 383 |
QCOMPARE(item->height(), UCUnits::instance()->gu(22)); |
| 384 |
|
| 385 |
root->setWidth(UCUnits::instance()->gu(80)); |
| 386 |
layoutChangeSpy.wait(100); |
| 387 |
QCOMPARE(layouts->currentLayout(), QString("xlarge")); |
| 388 |
QCOMPARE(item->width(), UCUnits::instance()->gu(30)); |
| 389 |
QCOMPARE(item->height(), UCUnits::instance()->gu(30)); |
| 390 |
QCOMPARE(item2->width(), UCUnits::instance()->gu(40)); |
| 391 |
QCOMPARE(item2->height(), UCUnits::instance()->gu(50)); |
| 392 |
|
| 393 |
root->setWidth(UCUnits::instance()->gu(40)); |
| 394 |
layoutChangeSpy.wait(100); |
| 395 |
QCOMPARE(item->width(), width); |
| 396 |
QCOMPARE(item->height(), height); |
| 397 |
QCOMPARE(item2->width(), width2); |
| 398 |
QCOMPARE(item2->height(), height2); |
| 399 |
} |
| 400 |
|
| 401 |
void testCase_CurrentLayoutChange() |
| 402 |
{ |
| 403 |
LomiriTestCase::ignoreWarning("CurrentLayoutChange.qml", 30, 13, |
| 404 |
"QML ConditionalLayout: ERROR: no container specified for layout \"portrait\". ConditionalLayout cannot be activated without a container."); |
| 405 |
LomiriTestCase::ignoreWarning("CurrentLayoutChange.qml", 35, 13, |
| 406 |
"QML ConditionalLayout: ERROR: no container specified for layout \"landscape\". ConditionalLayout cannot be activated without a container."); |
| 407 |
LomiriTestCase::ignoreWarning("CurrentLayoutChange.qml", 30, 13, |
| 408 |
"QML ConditionalLayout: WARNING: Cannot activate layout \"portrait\" with no container specified. Falling back to default layout.", 3); |
| 409 |
QScopedPointer<QQuickView> view(loadTest("CurrentLayoutChange.qml")); |
| 410 |
QVERIFY(view); |
| 411 |
QQuickItem *root = view->rootObject(); |
| 412 |
QVERIFY(root); |
| 413 |
|
| 414 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layoutManager")); |
| 415 |
QVERIFY(layouts); |
| 416 |
|
| 417 |
QSignalSpy spy(layouts, SIGNAL(currentLayoutChanged())); |
| 418 |
root->setWidth(root->height() - 10); |
| 419 |
spy.wait(100); |
| 420 |
QEXPECT_FAIL(0, "Layout change should not happen when component is not defined", Continue); |
| 421 |
QCOMPARE(spy.count(), 1); |
| 422 |
} |
| 423 |
|
| 424 |
void testCase_PositioningOnLayoutChange() |
| 425 |
{ |
| 426 |
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 427 |
LomiriTestCase::ignoreWarning("PositioningOnLayoutChange.qml", 42, 13, |
| 428 |
"QML ConditionalLayout: WARNING: Cannot activate layout \"landscape\" with no container specified. Falling back to default layout.", 3); |
| 429 |
#else |
| 430 |
LomiriTestCase::ignoreWarning("PositioningOnLayoutChange.qml", 42, 13, |
| 431 |
"QML ConditionalLayout: WARNING: Cannot activate layout \"landscape\" with no container specified. Falling back to default layout.", 4); |
| 432 |
#endif |
| 433 |
LomiriTestCase::ignoreWarning("PositioningOnLayoutChange.qml", 42, 13, |
| 434 |
"QML ConditionalLayout: ERROR: no container specified for layout \"landscape\". ConditionalLayout cannot be activated without a container."); |
| 435 |
QScopedPointer<QQuickView> view(loadTest("PositioningOnLayoutChange.qml")); |
| 436 |
QVERIFY(view); |
| 437 |
QQuickItem *root = view->rootObject(); |
| 438 |
QVERIFY(root); |
| 439 |
|
| 440 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layoutManager")); |
| 441 |
QVERIFY(layouts); |
| 442 |
|
| 443 |
QSignalSpy spy(layouts, SIGNAL(currentLayoutChanged())); |
| 444 |
root->setWidth(root->height() + 10); |
| 445 |
spy.wait(100); |
| 446 |
QEXPECT_FAIL(0, "Layout change should not happen when component is not defined", Continue); |
| 447 |
QCOMPARE(spy.count(), 1); |
| 448 |
|
| 449 |
spy.clear(); |
| 450 |
root->setWidth(root->height() - 10); |
| 451 |
spy.wait(100); |
| 452 |
QCOMPARE(spy.count(), 1); |
| 453 |
} |
| 454 |
|
| 455 |
void testCase_LaidOutItemsOutsideOfLayout() |
| 456 |
{ |
| 457 |
LomiriTestCase::ignoreWarning("LaidOutItemsOutsideOfLayout.qml", 44, 5, |
| 458 |
"QML Rectangle: ERROR: Item that is not a child of a Layouts component will not be laid out."); |
| 459 |
QScopedPointer<QQuickView> view(loadTest("LaidOutItemsOutsideOfLayout.qml")); |
| 460 |
QVERIFY(view); |
| 461 |
QQuickItem *root = view->rootObject(); |
| 462 |
QVERIFY(root); |
| 463 |
|
| 464 |
QQuickItem *item = qobject_cast<QQuickItem*>(testItem(root, "itemLaidOut")); |
| 465 |
QVERIFY(item); |
| 466 |
|
| 467 |
ULLayoutsAttached *marker = qobject_cast<ULLayoutsAttached*>( |
| 468 |
qmlAttachedPropertiesObject<ULLayouts>(item, false)); |
| 469 |
QVERIFY(marker); |
| 470 |
QVERIFY(!marker->isValid()); |
| 471 |
} |
| 472 |
|
| 473 |
void testCase_OverlaidInItemLayout() |
| 474 |
{ |
| 475 |
QScopedPointer<QQuickView> view(loadTest("OverlaidInItemLayout.qml")); |
| 476 |
QVERIFY(view); |
| 477 |
QQuickItem *root = view->rootObject(); |
| 478 |
QVERIFY(root); |
| 479 |
|
| 480 |
ULLayouts *layouts = qobject_cast<ULLayouts*>(testItem(root, "layoutManager")); |
| 481 |
QVERIFY(layouts); |
| 482 |
QSignalSpy currentLayout(layouts, SIGNAL(currentLayoutChanged())); |
| 483 |
currentLayout.wait(300); |
| 484 |
|
| 485 |
QQuickItem *layout = qobject_cast<QQuickItem*>(testItem(root, "layout")); |
| 486 |
QVERIFY(layout); |
| 487 |
|
| 488 |
QQuickItem *item = qobject_cast<QQuickItem*>(testItem(root, "hostedItem")); |
| 489 |
QVERIFY(item); |
| 490 |
|
| 491 |
QCOMPARE(layout->childItems()[0], item); |
| 492 |
} |
| 493 |
|
| 494 |
void testCase_AnchorFilledReparenting() |
| 495 |
{ |
| 496 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorFilledReparenting.qml")); |
| 497 |
QVERIFY(view); |
| 498 |
QQuickItem *root = view->rootObject(); |
| 499 |
QVERIFY(root); |
| 500 |
|
| 501 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 502 |
QVERIFY(layout); |
| 503 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 504 |
|
| 505 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 506 |
QVERIFY(item); |
| 507 |
|
| 508 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 509 |
QVERIFY(anchors); |
| 510 |
|
| 511 |
root->setWidth(root->width() + 100); |
| 512 |
layoutChangeSpy.wait(100); |
| 513 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 514 |
QVERIFY(testLayout); |
| 515 |
QCOMPARE(anchors->fill(), testLayout); |
| 516 |
|
| 517 |
root->setWidth(root->width() - 100); |
| 518 |
layoutChangeSpy.wait(100); |
| 519 |
QCOMPARE(anchors->fill(), layout->contentItem()); |
| 520 |
} |
| 521 |
|
| 522 |
void testCase_AnchorFilledMargins() |
| 523 |
{ |
| 524 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorFilledMargins.qml")); |
| 525 |
QVERIFY(view); |
| 526 |
QQuickItem *root = view->rootObject(); |
| 527 |
QVERIFY(root); |
| 528 |
|
| 529 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 530 |
QVERIFY(layout); |
| 531 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 532 |
|
| 533 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 534 |
QVERIFY(item); |
| 535 |
|
| 536 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 537 |
QVERIFY(anchors); |
| 538 |
|
| 539 |
root->setWidth(root->width() + 100); |
| 540 |
layoutChangeSpy.wait(100); |
| 541 |
|
| 542 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 543 |
QVERIFY(testLayout); |
| 544 |
QCOMPARE(anchors->fill(), testLayout); |
| 545 |
QCOMPARE(anchors->margins(), 0.0); |
| 546 |
|
| 547 |
root->setWidth(root->width() - 100); |
| 548 |
layoutChangeSpy.wait(100); |
| 549 |
QCOMPARE(anchors->fill(), layout->contentItem()); |
| 550 |
QCOMPARE(anchors->margins(), 10.0); |
| 551 |
} |
| 552 |
|
| 553 |
void testCase_AnchorFilledSeparateMargins() |
| 554 |
{ |
| 555 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorFilledSeparateMargins.qml")); |
| 556 |
QVERIFY(view); |
| 557 |
QQuickItem *root = view->rootObject(); |
| 558 |
QVERIFY(root); |
| 559 |
|
| 560 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 561 |
QVERIFY(layout); |
| 562 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 563 |
|
| 564 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 565 |
QVERIFY(item); |
| 566 |
|
| 567 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 568 |
QVERIFY(anchors); |
| 569 |
|
| 570 |
root->setWidth(root->width() + 100); |
| 571 |
layoutChangeSpy.wait(100); |
| 572 |
|
| 573 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 574 |
QVERIFY(testLayout); |
| 575 |
QCOMPARE(anchors->fill(), testLayout); |
| 576 |
QCOMPARE(anchors->margins(), 0.0); |
| 577 |
QCOMPARE(anchors->leftMargin(), 0.0); |
| 578 |
QCOMPARE(anchors->rightMargin(), 0.0); |
| 579 |
QCOMPARE(anchors->topMargin(), 0.0); |
| 580 |
QCOMPARE(anchors->bottomMargin(), 0.0); |
| 581 |
|
| 582 |
root->setWidth(root->width() - 100); |
| 583 |
layoutChangeSpy.wait(100); |
| 584 |
QCOMPARE(anchors->fill(), layout->contentItem()); |
| 585 |
QCOMPARE(anchors->leftMargin(), 10.0); |
| 586 |
QCOMPARE(anchors->topMargin(), 20.0); |
| 587 |
QCOMPARE(anchors->rightMargin(), 30.0); |
| 588 |
QCOMPARE(anchors->bottomMargin(), 40.0); |
| 589 |
} |
| 590 |
|
| 591 |
void testCase_AnchorCenteredInDefault() |
| 592 |
{ |
| 593 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorCenteredInDefault.qml")); |
| 594 |
QVERIFY(view); |
| 595 |
QQuickItem *root = view->rootObject(); |
| 596 |
QVERIFY(root); |
| 597 |
|
| 598 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 599 |
QVERIFY(layout); |
| 600 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 601 |
|
| 602 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 603 |
QVERIFY(item); |
| 604 |
|
| 605 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 606 |
QVERIFY(anchors); |
| 607 |
|
| 608 |
root->setWidth(root->width() + 100); |
| 609 |
layoutChangeSpy.wait(100); |
| 610 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 611 |
QVERIFY(testLayout); |
| 612 |
QCOMPARE(anchors->fill(), testLayout); |
| 613 |
|
| 614 |
root->setWidth(root->width() - 100); |
| 615 |
layoutChangeSpy.wait(100); |
| 616 |
QCOMPARE(anchors->centerIn(), layout->contentItem()); |
| 617 |
} |
| 618 |
|
| 619 |
void testCase_AnchorVerticalCenter() |
| 620 |
{ |
| 621 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorVerticalCenter.qml")); |
| 622 |
QVERIFY(view); |
| 623 |
QQuickItem *root = view->rootObject(); |
| 624 |
QVERIFY(root); |
| 625 |
|
| 626 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 627 |
QVERIFY(layout); |
| 628 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 629 |
|
| 630 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 631 |
QVERIFY(item); |
| 632 |
|
| 633 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 634 |
QVERIFY(anchors); |
| 635 |
|
| 636 |
QCOMPARE(anchors->verticalCenter().item, layout->contentItem()); |
| 637 |
|
| 638 |
root->setWidth(root->width() + 100); |
| 639 |
layoutChangeSpy.wait(100); |
| 640 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 641 |
QVERIFY(testLayout); |
| 642 |
QCOMPARE(anchors->fill(), testLayout); |
| 643 |
|
| 644 |
root->setWidth(root->width() - 100); |
| 645 |
layoutChangeSpy.wait(100); |
| 646 |
QCOMPARE(anchors->verticalCenter().item, layout->contentItem()); |
| 647 |
} |
| 648 |
|
| 649 |
void testCase_AnchorVerticalCenterOffset() |
| 650 |
{ |
| 651 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorVerticalCenterOffset.qml")); |
| 652 |
QVERIFY(view); |
| 653 |
QQuickItem *root = view->rootObject(); |
| 654 |
QVERIFY(root); |
| 655 |
|
| 656 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 657 |
QVERIFY(layout); |
| 658 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 659 |
|
| 660 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 661 |
QVERIFY(item); |
| 662 |
|
| 663 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 664 |
QVERIFY(anchors); |
| 665 |
|
| 666 |
QCOMPARE(anchors->verticalCenter().item, layout->contentItem()); |
| 667 |
QCOMPARE(anchors->verticalCenterOffset(), 50.0); |
| 668 |
|
| 669 |
root->setWidth(root->width() + 100); |
| 670 |
layoutChangeSpy.wait(100); |
| 671 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 672 |
QVERIFY(testLayout); |
| 673 |
QCOMPARE(anchors->fill(), testLayout); |
| 674 |
// no need to check offset as it does not affect the fill |
| 675 |
|
| 676 |
root->setWidth(root->width() - 100); |
| 677 |
layoutChangeSpy.wait(100); |
| 678 |
QCOMPARE(anchors->verticalCenter().item, layout->contentItem()); |
| 679 |
QCOMPARE(anchors->verticalCenterOffset(), 50.0); |
| 680 |
} |
| 681 |
|
| 682 |
void testCase_AnchorHorizontalCenter() |
| 683 |
{ |
| 684 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorHorizontalCenter.qml")); |
| 685 |
QVERIFY(view); |
| 686 |
QQuickItem *root = view->rootObject(); |
| 687 |
QVERIFY(root); |
| 688 |
|
| 689 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 690 |
QVERIFY(layout); |
| 691 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 692 |
|
| 693 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 694 |
QVERIFY(item); |
| 695 |
|
| 696 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 697 |
QVERIFY(anchors); |
| 698 |
|
| 699 |
QCOMPARE(anchors->horizontalCenter().item, layout->contentItem()); |
| 700 |
|
| 701 |
root->setWidth(root->width() + 100); |
| 702 |
layoutChangeSpy.wait(100); |
| 703 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 704 |
QVERIFY(testLayout); |
| 705 |
QCOMPARE(anchors->fill(), testLayout); |
| 706 |
|
| 707 |
root->setWidth(root->width() - 100); |
| 708 |
layoutChangeSpy.wait(100); |
| 709 |
QCOMPARE(anchors->horizontalCenter().item, layout->contentItem()); |
| 710 |
} |
| 711 |
|
| 712 |
void testCase_AnchorHorizontalCenterOffset() |
| 713 |
{ |
| 714 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorHorizontalCenterOffset.qml")); |
| 715 |
QVERIFY(view); |
| 716 |
QQuickItem *root = view->rootObject(); |
| 717 |
QVERIFY(root); |
| 718 |
|
| 719 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 720 |
QVERIFY(layout); |
| 721 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 722 |
|
| 723 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 724 |
QVERIFY(item); |
| 725 |
|
| 726 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 727 |
QVERIFY(anchors); |
| 728 |
|
| 729 |
QCOMPARE(anchors->horizontalCenter().item, layout->contentItem()); |
| 730 |
QCOMPARE(anchors->horizontalCenterOffset(), 50.0); |
| 731 |
|
| 732 |
root->setWidth(root->width() + 100); |
| 733 |
layoutChangeSpy.wait(100); |
| 734 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 735 |
QVERIFY(testLayout); |
| 736 |
QCOMPARE(anchors->fill(), testLayout); |
| 737 |
// no need to check offset as it does not affect the fill |
| 738 |
|
| 739 |
root->setWidth(root->width() - 100); |
| 740 |
layoutChangeSpy.wait(100); |
| 741 |
QCOMPARE(anchors->horizontalCenter().item, layout->contentItem()); |
| 742 |
QCOMPARE(anchors->horizontalCenterOffset(), 50.0); |
| 743 |
} |
| 744 |
|
| 745 |
void testCase_AnchorCenterWithOffset() |
| 746 |
{ |
| 747 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorCenterWithOffset.qml")); |
| 748 |
QVERIFY(view); |
| 749 |
QQuickItem *root = view->rootObject(); |
| 750 |
QVERIFY(root); |
| 751 |
|
| 752 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 753 |
QVERIFY(layout); |
| 754 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 755 |
|
| 756 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 757 |
QVERIFY(item); |
| 758 |
|
| 759 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 760 |
QVERIFY(anchors); |
| 761 |
|
| 762 |
QCOMPARE(anchors->centerIn(), layout->contentItem()); |
| 763 |
QCOMPARE(anchors->verticalCenterOffset(), 50.0); |
| 764 |
QCOMPARE(anchors->horizontalCenterOffset(), 40.0); |
| 765 |
|
| 766 |
root->setWidth(root->width() + 100); |
| 767 |
layoutChangeSpy.wait(100); |
| 768 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 769 |
QVERIFY(testLayout); |
| 770 |
QCOMPARE(anchors->fill(), testLayout); |
| 771 |
// no need to check offsets as it does not affect the fill |
| 772 |
|
| 773 |
root->setWidth(root->width() - 100); |
| 774 |
layoutChangeSpy.wait(100); |
| 775 |
QCOMPARE(anchors->centerIn(), layout->contentItem()); |
| 776 |
QCOMPARE(anchors->verticalCenterOffset(), 50.0); |
| 777 |
QCOMPARE(anchors->horizontalCenterOffset(), 40.0); |
| 778 |
} |
| 779 |
|
| 780 |
void testCase_AnchorLeft() |
| 781 |
{ |
| 782 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorLeft.qml")); |
| 783 |
QVERIFY(view); |
| 784 |
QQuickItem *root = view->rootObject(); |
| 785 |
QVERIFY(root); |
| 786 |
|
| 787 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 788 |
QVERIFY(layout); |
| 789 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 790 |
|
| 791 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 792 |
QVERIFY(item); |
| 793 |
|
| 794 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 795 |
QVERIFY(anchors); |
| 796 |
|
| 797 |
QCOMPARE(anchors->left().item, layout->contentItem()); |
| 798 |
QCOMPARE(anchors->leftMargin(), 10.0); |
| 799 |
|
| 800 |
root->setWidth(root->width() + 100); |
| 801 |
layoutChangeSpy.wait(100); |
| 802 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 803 |
QVERIFY(testLayout); |
| 804 |
QCOMPARE(anchors->fill(), testLayout); |
| 805 |
QCOMPARE(anchors->leftMargin(), 0.0); |
| 806 |
|
| 807 |
root->setWidth(root->width() - 100); |
| 808 |
layoutChangeSpy.wait(100); |
| 809 |
QCOMPARE(anchors->left().item, layout->contentItem()); |
| 810 |
QCOMPARE(anchors->leftMargin(), 10.0); |
| 811 |
} |
| 812 |
|
| 813 |
void testCase_AnchorTop() |
| 814 |
{ |
| 815 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorTop.qml")); |
| 816 |
QVERIFY(view); |
| 817 |
QQuickItem *root = view->rootObject(); |
| 818 |
QVERIFY(root); |
| 819 |
|
| 820 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 821 |
QVERIFY(layout); |
| 822 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 823 |
|
| 824 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 825 |
QVERIFY(item); |
| 826 |
|
| 827 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 828 |
QVERIFY(anchors); |
| 829 |
|
| 830 |
QCOMPARE(anchors->top().item, layout->contentItem()); |
| 831 |
QCOMPARE(anchors->topMargin(), 10.0); |
| 832 |
|
| 833 |
root->setWidth(root->width() + 100); |
| 834 |
layoutChangeSpy.wait(100); |
| 835 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 836 |
QVERIFY(testLayout); |
| 837 |
QCOMPARE(anchors->fill(), testLayout); |
| 838 |
QCOMPARE(anchors->topMargin(), 0.0); |
| 839 |
|
| 840 |
root->setWidth(root->width() - 100); |
| 841 |
layoutChangeSpy.wait(100); |
| 842 |
QCOMPARE(anchors->top().item, layout->contentItem()); |
| 843 |
QCOMPARE(anchors->topMargin(), 10.0); |
| 844 |
} |
| 845 |
|
| 846 |
void testCase_AnchorRight() |
| 847 |
{ |
| 848 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorRight.qml")); |
| 849 |
QVERIFY(view); |
| 850 |
QQuickItem *root = view->rootObject(); |
| 851 |
QVERIFY(root); |
| 852 |
|
| 853 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 854 |
QVERIFY(layout); |
| 855 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 856 |
|
| 857 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 858 |
QVERIFY(item); |
| 859 |
|
| 860 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 861 |
QVERIFY(anchors); |
| 862 |
|
| 863 |
QCOMPARE(anchors->right().item, layout->contentItem()); |
| 864 |
QCOMPARE(anchors->rightMargin(), 10.0); |
| 865 |
|
| 866 |
root->setWidth(root->width() + 100); |
| 867 |
layoutChangeSpy.wait(100); |
| 868 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 869 |
QVERIFY(testLayout); |
| 870 |
QCOMPARE(anchors->fill(), testLayout); |
| 871 |
QCOMPARE(anchors->rightMargin(), 0.0); |
| 872 |
|
| 873 |
root->setWidth(root->width() - 100); |
| 874 |
layoutChangeSpy.wait(100); |
| 875 |
QCOMPARE(anchors->right().item, layout->contentItem()); |
| 876 |
QCOMPARE(anchors->rightMargin(), 10.0); |
| 877 |
} |
| 878 |
|
| 879 |
void testCase_AnchorBottom() |
| 880 |
{ |
| 881 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorBottom.qml")); |
| 882 |
QVERIFY(view); |
| 883 |
QQuickItem *root = view->rootObject(); |
| 884 |
QVERIFY(root); |
| 885 |
|
| 886 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 887 |
QVERIFY(layout); |
| 888 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 889 |
|
| 890 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 891 |
QVERIFY(item); |
| 892 |
|
| 893 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 894 |
QVERIFY(anchors); |
| 895 |
|
| 896 |
QCOMPARE(anchors->bottom().item, layout->contentItem()); |
| 897 |
QCOMPARE(anchors->bottomMargin(), 10.0); |
| 898 |
|
| 899 |
root->setWidth(root->width() + 100); |
| 900 |
layoutChangeSpy.wait(100); |
| 901 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 902 |
QVERIFY(testLayout); |
| 903 |
QCOMPARE(anchors->fill(), testLayout); |
| 904 |
QCOMPARE(anchors->bottomMargin(), 0.0); |
| 905 |
|
| 906 |
root->setWidth(root->width() - 100); |
| 907 |
layoutChangeSpy.wait(100); |
| 908 |
QCOMPARE(anchors->bottom().item, layout->contentItem()); |
| 909 |
QCOMPARE(anchors->bottomMargin(), 10.0); |
| 910 |
} |
| 911 |
|
| 912 |
void testCase_AnchorAll() |
| 913 |
{ |
| 914 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("AnchorAll.qml")); |
| 915 |
QVERIFY(view); |
| 916 |
QQuickItem *root = view->rootObject(); |
| 917 |
QVERIFY(root); |
| 918 |
|
| 919 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 920 |
QVERIFY(layout); |
| 921 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 922 |
|
| 923 |
QQuickItem *item = view->findItem<QQuickItem*>("testItem"); |
| 924 |
QVERIFY(item); |
| 925 |
|
| 926 |
QQuickAnchors *anchors = item->property("anchors").value<QQuickAnchors*>(); |
| 927 |
QVERIFY(anchors); |
| 928 |
|
| 929 |
QCOMPARE(anchors->left().item, layout->contentItem()); |
| 930 |
QCOMPARE(anchors->top().item, layout->contentItem()); |
| 931 |
QCOMPARE(anchors->right().item, layout->contentItem()); |
| 932 |
QCOMPARE(anchors->bottom().item, layout->contentItem()); |
| 933 |
QVERIFY(!anchors->fill()); |
| 934 |
QCOMPARE(anchors->margins(), 20.0); |
| 935 |
|
| 936 |
root->setWidth(root->width() + 100); |
| 937 |
layoutChangeSpy.wait(100); |
| 938 |
QQuickItem *testLayout = view->findItem<QQuickItem*>("testLayout"); |
| 939 |
QVERIFY(testLayout); |
| 940 |
QCOMPARE(anchors->fill(), testLayout); |
| 941 |
QVERIFY(!anchors->left().item); |
| 942 |
QVERIFY(!anchors->top().item); |
| 943 |
QVERIFY(!anchors->right().item); |
| 944 |
QVERIFY(!anchors->bottom().item); |
| 945 |
QCOMPARE(anchors->margins(), 0.0); |
| 946 |
|
| 947 |
root->setWidth(root->width() - 100); |
| 948 |
layoutChangeSpy.wait(100); |
| 949 |
QCOMPARE(anchors->left().item, layout->contentItem()); |
| 950 |
QCOMPARE(anchors->top().item, layout->contentItem()); |
| 951 |
QCOMPARE(anchors->right().item, layout->contentItem()); |
| 952 |
QCOMPARE(anchors->bottom().item, layout->contentItem()); |
| 953 |
QVERIFY(!anchors->fill()); |
| 954 |
QCOMPARE(anchors->margins(), 20.0); |
| 955 |
} |
| 956 |
|
| 957 |
// the following tests guard bug #1280359 |
| 958 |
void testCase_ItemInstanceAsProperty() |
| 959 |
{ |
| 960 |
LomiriTestCase::ignoreWarning("ItemInstanceAsProperty.qml", 45, 17, |
| 961 |
"QML ItemLayout: WARNING: item \"object2\" not specified or has been specified for layout by more than one active ItemLayout"); |
| 962 |
QScopedPointer<QQuickView> view(loadTest("ItemInstanceAsProperty.qml")); |
| 963 |
QVERIFY(view); |
| 964 |
QQuickItem *root = view->rootObject(); |
| 965 |
QVERIFY(root); |
| 966 |
|
| 967 |
QQuickItem *layout = testItem(root, "layoutManager"); |
| 968 |
QVERIFY(layout); |
| 969 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 970 |
|
| 971 |
// invoke layout change |
| 972 |
view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "changeLayout"); |
| 973 |
layoutChangeSpy.wait(); |
| 974 |
QCOMPARE(layoutChangeSpy.count(), 1); |
| 975 |
} |
| 976 |
|
| 977 |
void testCase_DialerCrash() |
| 978 |
{ |
| 979 |
LomiriTestCase::ignoreWarning("DialerCrash.qml", 45, 17, |
| 980 |
"QML ItemLayout: WARNING: item \"object2\" not specified or has been specified for layout by more than one active ItemLayout"); |
| 981 |
QScopedPointer<QQuickView> view(loadTest("DialerCrash.qml")); |
| 982 |
QVERIFY(view); |
| 983 |
QQuickItem *root = view->rootObject(); |
| 984 |
QVERIFY(root); |
| 985 |
|
| 986 |
QQuickItem *layout = testItem(root, "layoutManager"); |
| 987 |
QVERIFY(layout); |
| 988 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 989 |
|
| 990 |
// invoke layout change |
| 991 |
view->rootObject()->setProperty("wide", false); |
| 992 |
layoutChangeSpy.wait(); |
| 993 |
QCOMPARE(layoutChangeSpy.count(), 1); |
| 994 |
} |
| 995 |
|
| 996 |
void testCase_ExcludedItemDeleted() |
| 997 |
{ |
| 998 |
QScopedPointer<QQuickView> view(loadTest("ExcludedItemDeleted.qml")); |
| 999 |
QVERIFY(view); |
| 1000 |
QQuickItem *root = view->rootObject(); |
| 1001 |
QVERIFY(root); |
| 1002 |
|
| 1003 |
QQuickItem *layout = testItem(root, "layoutManager"); |
| 1004 |
QVERIFY(layout); |
| 1005 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 1006 |
|
| 1007 |
// invoke layout change |
| 1008 |
view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "changeLayout"); |
| 1009 |
layoutChangeSpy.wait(); |
| 1010 |
QCOMPARE(layoutChangeSpy.count(), 1); |
| 1011 |
} |
| 1012 |
|
| 1013 |
// guard bug #1204834 and #1300668 |
| 1014 |
void testCase_Visibility() |
| 1015 |
{ |
| 1016 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("Visibility.qml")); |
| 1017 |
QVERIFY(view); |
| 1018 |
QQuickItem *root = view->rootObject(); |
| 1019 |
QVERIFY(root); |
| 1020 |
|
| 1021 |
ULLayouts *layout = view->findItem<ULLayouts*>("layoutManager"); |
| 1022 |
QVERIFY(layout); |
| 1023 |
QSignalSpy layoutChangeSpy(layout, SIGNAL(currentLayoutChanged())); |
| 1024 |
|
| 1025 |
QQuickItem *defaultLayout = testItem(root, "DefaultLayout"); |
| 1026 |
QVERIFY(defaultLayout); |
| 1027 |
|
| 1028 |
// invoke layout change |
| 1029 |
view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "portraitLayout"); |
| 1030 |
layoutChangeSpy.wait(1000); |
| 1031 |
QCOMPARE(defaultLayout->parentItem(), layout->contentItem()); |
| 1032 |
// despite of visible property binding, the visibility of the component is false |
| 1033 |
// while its parent is set to invisible |
| 1034 |
QCOMPARE(defaultLayout->isVisible(), false); |
| 1035 |
QCOMPARE(layout->contentItem()->isVisible(), false); |
| 1036 |
|
| 1037 |
// change layout back |
| 1038 |
layoutChangeSpy.clear(); |
| 1039 |
view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "landscapeLayout"); |
| 1040 |
layoutChangeSpy.wait(1000); |
| 1041 |
QCOMPARE(defaultLayout->parentItem(), layout->contentItem()); |
| 1042 |
QCOMPARE(defaultLayout->isVisible(), true); |
| 1043 |
QCOMPARE(layout->contentItem()->isVisible(), true); |
| 1044 |
} |
| 1045 |
|
| 1046 |
void testCase_NestedVisibility_data() { |
| 1047 |
QTest::addColumn<QString>("layoutFunction"); |
| 1048 |
QTest::addColumn<QString>("layoutName"); |
| 1049 |
|
| 1050 |
QTest::newRow("portrait") << "tabletPortraitLayout" << "tabletPortrait"; |
| 1051 |
QTest::newRow("landscape") << "tabletLandscapeLayout" << "tabletLandscape"; |
| 1052 |
} |
| 1053 |
|
| 1054 |
void testCase_NestedVisibility() |
| 1055 |
{ |
| 1056 |
QFETCH(QString, layoutFunction); |
| 1057 |
QFETCH(QString, layoutName); |
| 1058 |
|
| 1059 |
QScopedPointer<LomiriTestCase> view(new LomiriTestCase("NestedVisibility.qml")); |
| 1060 |
QVERIFY(view); |
| 1061 |
QQuickItem *root = view->rootObject(); |
| 1062 |
QVERIFY(root); |
| 1063 |
|
| 1064 |
ULLayouts *mainLayout = view->findItem<ULLayouts*>("mainLayout"); |
| 1065 |
QVERIFY(mainLayout); |
| 1066 |
QQuickItem *red = testItem(mainLayout, "mainRed"); |
| 1067 |
QVERIFY(red); |
| 1068 |
QQuickItem *green = testItem(mainLayout, "mainGreen"); |
| 1069 |
QVERIFY(green); |
| 1070 |
QQuickItem *blue = testItem(mainLayout, "mainBlue"); |
| 1071 |
QVERIFY(blue); |
| 1072 |
QQuickItem *magenta = testItem(mainLayout, "mainMagenta"); |
| 1073 |
QVERIFY(magenta); |
| 1074 |
QQuickItem *hidden = testItem(mainLayout, "mainHidden"); |
| 1075 |
QVERIFY(hidden); |
| 1076 |
QCOMPARE(hidden->isVisible(), false); |
| 1077 |
// default is phone layout, get layd out items' neighbors |
| 1078 |
QQuickItem *greenPrev = prevSibling(green); |
| 1079 |
QQuickItem *magentaPrev = prevSibling(magenta); |
| 1080 |
QSizeF greenSize(green->width(), green->height()); |
| 1081 |
QSizeF magentaSize(magenta->width(), magenta->height()); |
| 1082 |
|
| 1083 |
// invoke tablet layout change |
| 1084 |
QSignalSpy mainLayoutChangeSpy(mainLayout, SIGNAL(currentLayoutChanged())); |
| 1085 |
view->rootObject()->metaObject()->invokeMethod(view->rootObject(), layoutFunction.toLocal8Bit().data()); |
| 1086 |
mainLayoutChangeSpy.wait(1000); |
| 1087 |
// get the nested layout |
| 1088 |
ULLayouts *nestedLayout = nullptr; |
| 1089 |
QTRY_VERIFY((nestedLayout = qobject_cast<ULLayouts*>(testItem(mainLayout, "nestedLayout")))); |
| 1090 |
QQuickItem *nestedActiveLayout = testItem(nestedLayout, layoutName); |
| 1091 |
QVERIFY(nestedActiveLayout); |
| 1092 |
QCOMPARE(red->isVisible(), false); |
| 1093 |
QCOMPARE(green->isVisible(), true); |
| 1094 |
QCOMPARE(blue->isVisible(), false); |
| 1095 |
QCOMPARE(magenta->isVisible(), true); |
| 1096 |
QCOMPARE(hidden->isVisible(), false); |
| 1097 |
// we cannot use findChild() to locate green and magenta boxes, as reparenting only |
| 1098 |
// changes the parentItem, not the parent object itself; therefore we only check if |
| 1099 |
// their container is in the layout |
| 1100 |
QVERIFY(hasChildItem(green, nestedActiveLayout)); |
| 1101 |
QVERIFY(hasChildItem(magenta, nestedActiveLayout)); |
| 1102 |
|
| 1103 |
// go back to default layout of main |
| 1104 |
mainLayoutChangeSpy.clear(); |
| 1105 |
view->rootObject()->metaObject()->invokeMethod(view->rootObject(), "phoneLayout"); |
| 1106 |
mainLayoutChangeSpy.wait(1000); |
| 1107 |
QCOMPARE(red->isVisible(), true); |
| 1108 |
QCOMPARE(green->isVisible(), true); |
| 1109 |
QCOMPARE(blue->isVisible(), true); |
| 1110 |
QCOMPARE(magenta->isVisible(), true); |
| 1111 |
QCOMPARE(hidden->isVisible(), false); |
| 1112 |
QCOMPARE(prevSibling(green), greenPrev); |
| 1113 |
QCOMPARE(prevSibling(magenta), magentaPrev); |
| 1114 |
QCOMPARE(green->width(), greenSize.width()); |
| 1115 |
QCOMPARE(green->height(), greenSize.height()); |
| 1116 |
QCOMPARE(magenta->width(), magentaSize.width()); |
| 1117 |
QCOMPARE(magenta->height(), magentaSize.height()); |
| 1118 |
QVERIFY(hasChildItem(green, mainLayout->contentItem())); |
| 1119 |
QVERIFY(hasChildItem(magenta, mainLayout->contentItem())); |
| 1120 |
} |
| 1121 |
|
| 1122 |
}; |
| 1123 |
|
| 1124 |
QTEST_MAIN(tst_Layouts) |
| 1125 |
|
| 1126 |
#include "tst_layouts.moc" |