summaryrefslogtreecommitdiffstats
path: root/tests/auto/slides/tst_q3dsslides.cpp
blob: f68835afce8a678f5ced956b6b283c9df985b72c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtTest>

#include <private/q3dsengine_p.h>
#include <private/q3dswindow_p.h>
#include <private/q3dsutils_p.h>
#include <private/q3dsuippresentation_p.h>
#include <private/q3dsscenemanager_p.h>
#include <private/q3dsslideplayer_p.h>
#include <Qt3DCore/QEntity>
#include <Qt3DRender/QLayer>

#include "../shared/shared.h"

class tst_Q3DSSlides : public QObject
{
    Q_OBJECT

public:
    tst_Q3DSSlides();
    ~tst_Q3DSSlides();
private Q_SLOTS:
    void initTestCase();
    void cleanupTestCase();
    void setPresentationSlides();
    void presentationRollback();
    void setComponentSlides();
    void componentRollback();
    void setDeepComponentSlides();
    void deepComponentRollback();
    void setNonVisibleComponentSlides();
    void testTimeLineVisibility();

private:
    Q3DSModelNode *getModelWithName(const QString &name, Q3DSGraphObject *parent);
    Q3DSComponentNode *getComponentWithName(const QString &name, Q3DSGraphObject *parent);
    Q3DSTextNode *getTextNodeWithName(const QString &name, Q3DSGraphObject *parent);

    bool isNodeVisible(Q3DSNode *node);

    Q3DSEngine *m_engine = nullptr;
    Q3DSWindow *m_view = nullptr;
    Q3DSUipPresentation *m_presentation = nullptr;
    Q3DSSceneManager *m_sceneManager = nullptr;
    Q3DSScene *m_scene = nullptr;

    // Slides
    // Presentation Slides
    Q3DSSlide *m_presentationMasterSlide = nullptr;
    Q3DSSlide *m_presentationSlide1 = nullptr;
    Q3DSSlide *m_presentationSlide2 = nullptr;
    Q3DSSlide *m_presentationSlide3 = nullptr;
    Q3DSSlide *m_presentationSlide4 = nullptr;
    Q3DSSlide *m_presentationSlide5 = nullptr;

    // Slide 3 ComponentSlides
    Q3DSSlide *m_componentMasterSlide = nullptr;
    Q3DSSlide *m_componentSlide1 = nullptr;
    Q3DSSlide *m_componentSlide2 = nullptr;
    Q3DSSlide *m_componentSlide3 = nullptr;

    // Deep Component Slides
    Q3DSSlide *m_deepComponentMasterSlide = nullptr;
    Q3DSSlide *m_deepComponentSlide1 = nullptr;
    Q3DSSlide *m_deepComponentSlide2 = nullptr;

    // Objects
    // Presentation Objects
    Q3DSModelNode *m_masterCylinder = nullptr;
    Q3DSModelNode *m_dynamicSphere = nullptr;
    Q3DSModelNode *m_slide1Rect = nullptr;
    Q3DSModelNode *m_slide2Sphere = nullptr;
    Q3DSComponentNode *m_slide3Component = nullptr;
    Q3DSModelNode *m_slide4Cone = nullptr;
    Q3DSModelNode *m_slide5Rect = nullptr;
    Q3DSModelNode *m_slide5Sphere = nullptr;
    Q3DSComponentNode *m_slide5Component = nullptr;

    // Component Objects
    Q3DSModelNode *m_componentMasterCube = nullptr;
    Q3DSModelNode *m_componentMasterCubeSlide5 = nullptr;
    Q3DSModelNode *m_componentSlide1Cone = nullptr;
    Q3DSTextNode *m_componentSlide2Text = nullptr;
    Q3DSComponentNode *m_componentSlide3Component = nullptr;

    // Deep Component Objects
    Q3DSModelNode *m_deepComponentSlide1Cylinder = nullptr;
    Q3DSModelNode *m_deepComponentSlide2Sphere = nullptr;
    Q3DSModelNode *m_deepComponentSlide2Moon = nullptr;
    Q3DSTextNode *m_deepComponentMasterText = nullptr;

};

tst_Q3DSSlides::tst_Q3DSSlides()
{
}

tst_Q3DSSlides::~tst_Q3DSSlides()
{
    delete m_engine;
    delete m_view;
}

void tst_Q3DSSlides::initTestCase()
{
    if (!isOpenGLGoodEnough())
        QSKIP("This platform does not support OpenGL proper");

    QSurfaceFormat::setDefaultFormat(Q3DS::surfaceFormat());
    m_engine = new Q3DSEngine;
    m_view = new Q3DSWindow;
    m_view->setEngine(m_engine);
    m_view->forceResize(640, 480);

    Q3DSUtils::setDialogsEnabled(false);
    // This tests the basic Presentation (top level) slide change
    m_view->engine()->setSource(QLatin1String(":/test3.uip"));
    QVERIFY(m_view->engine()->presentation());
    QVERIFY(m_view->engine()->sceneManager());

    m_presentation = m_view->engine()->presentation();
    m_sceneManager = m_view->engine()->sceneManager();
    m_scene = m_presentation->scene();

    // Presentation Slides
    m_presentationMasterSlide = m_presentation->masterSlide();
    QVERIFY(m_presentationMasterSlide->childCount() == 5);
    m_presentationSlide1 = static_cast<Q3DSSlide *>(m_presentationMasterSlide->firstChild());
    QVERIFY(m_presentationSlide1);
    m_presentationSlide2 = static_cast<Q3DSSlide *>(m_presentationSlide1->nextSibling());
    QVERIFY(m_presentationSlide2);
    m_presentationSlide3 = static_cast<Q3DSSlide *>(m_presentationSlide2->nextSibling());
    QVERIFY(m_presentationSlide3);
    m_presentationSlide4 = static_cast<Q3DSSlide *>(m_presentationSlide3->nextSibling());
    QVERIFY(m_presentationSlide4);
    m_presentationSlide5 = static_cast<Q3DSSlide *>(m_presentationSlide4->nextSibling());
    QVERIFY(m_presentationSlide5);

    // Presentation Objects
    auto sceneLayer = m_scene->firstChild();
    QVERIFY(sceneLayer->childCount() == 11);
    m_masterCylinder = getModelWithName(QStringLiteral("MasterCylinder"), sceneLayer);
    QVERIFY(m_masterCylinder);
    m_dynamicSphere = getModelWithName(QStringLiteral("DynamicSphere"), sceneLayer);
    QVERIFY(m_dynamicSphere);
    m_slide1Rect = getModelWithName(QStringLiteral("Slide1Rect"), sceneLayer);
    QVERIFY(m_slide1Rect);
    m_slide2Sphere = getModelWithName(QStringLiteral("Slide2Sphere"), sceneLayer);
    QVERIFY(m_slide2Sphere);
    m_slide3Component = getComponentWithName(QStringLiteral("Slide3Component"), sceneLayer);
    QVERIFY(m_slide3Component);
    m_slide4Cone = getModelWithName(QStringLiteral("Slide4Cone"), sceneLayer);
    QVERIFY(m_slide4Cone);
    m_slide5Rect = getModelWithName(QStringLiteral("Slide5Rect"), sceneLayer);
    QVERIFY(m_slide5Rect);
    m_slide5Sphere = getModelWithName(QStringLiteral("Slide5Sphere"), sceneLayer);
    QVERIFY(m_slide5Sphere);
    m_slide5Component = getComponentWithName(QStringLiteral("Slide5Component"), sceneLayer);
    QVERIFY(m_slide5Component);

    // Component Slides
    m_componentMasterSlide = m_slide3Component->masterSlide();
    QVERIFY(m_componentMasterSlide);
    m_componentSlide1 = static_cast<Q3DSSlide *>(m_componentMasterSlide->firstChild());
    QVERIFY(m_componentSlide1);
    m_componentSlide2 = static_cast<Q3DSSlide *>(m_componentSlide1->nextSibling());
    QVERIFY(m_componentSlide2);
    m_componentSlide3 = static_cast<Q3DSSlide *>(m_componentSlide2->nextSibling());
    QVERIFY(m_componentSlide3);

    // Component Objects
    m_componentMasterCube = getModelWithName(QStringLiteral("ComponentMasterCube"), m_slide3Component);
    QVERIFY(m_componentMasterCube);
    m_componentMasterCubeSlide5 = getModelWithName(QStringLiteral("ComponentMasterCube"), m_slide5Component);
    QVERIFY(m_componentMasterCubeSlide5);
    m_componentSlide1Cone = getModelWithName(QStringLiteral("ComponentSlide1Cone"), m_componentMasterCube);
    QVERIFY(m_componentSlide1Cone);
    m_componentSlide2Text = getTextNodeWithName(QStringLiteral("ComponentSlide2Text"), m_slide3Component);
    QVERIFY(m_componentSlide2Text);
    m_componentSlide3Component = getComponentWithName(QStringLiteral("ComponentSlide3Component"), m_slide3Component);
    QVERIFY(m_componentSlide3Component);

    // Deep Component Slides
    m_deepComponentMasterSlide = m_componentSlide3Component->masterSlide();
    QVERIFY(m_deepComponentMasterSlide);
    m_deepComponentSlide1 = static_cast<Q3DSSlide *>(m_deepComponentMasterSlide->firstChild());
    QVERIFY(m_deepComponentSlide1);
    m_deepComponentSlide2 = static_cast<Q3DSSlide *>(m_deepComponentSlide1->nextSibling());
    QVERIFY(m_deepComponentSlide2);

    // Deep Component Objects
    m_deepComponentSlide1Cylinder = getModelWithName(QStringLiteral("DeepComponentSlide1Cylinder"), m_componentSlide3Component);
    QVERIFY(m_deepComponentSlide1Cylinder);
    m_deepComponentSlide2Sphere = getModelWithName(QStringLiteral("DeepComponentSlide2Sphere"), m_componentSlide3Component);
    QVERIFY(m_deepComponentSlide2Sphere);
    m_deepComponentSlide2Moon = getModelWithName(QStringLiteral("DeepComponentSlide2Moon"), m_deepComponentSlide2Sphere);
    QVERIFY(m_deepComponentSlide2Moon);
    m_deepComponentMasterText = getTextNodeWithName(QStringLiteral("DeepComponentMasterText"), m_componentSlide3Component);
    QVERIFY(m_deepComponentMasterText);

    m_view->show();
    QVERIFY(QTest::qWaitForWindowExposed(m_view));
}

void tst_Q3DSSlides::cleanupTestCase()
{
    if (m_view)
        m_view->close();
}

void tst_Q3DSSlides::setPresentationSlides()
{
    QVERIFY(m_sceneManager->currentSlide() == m_presentationSlide1);
    // For the first check we have to wait from the first frame update
    QSignalSpy m_updateSpy(m_engine, SIGNAL(nextFrameStarting()));
    m_updateSpy.wait(30);

    Q3DSSlidePlayer *player = m_sceneManager->slidePlayer();
    player->stop();
    QVERIFY(player);

    // Check starting state
    QCOMPARE(player->duration(), 10000);
    // MasterCylinder should be visible
    QVERIFY(isNodeVisible(m_masterCylinder));
    // "Slide 1 Rect" should be visible
    QVERIFY(isNodeVisible(m_slide1Rect));
    QVERIFY(!isNodeVisible(m_slide4Cone));

    // Set second slide
    m_sceneManager->setCurrentSlide(m_presentationSlide2);
    // Verify second slide state
    QCOMPARE(player->duration(), 10000);
    // MasterCylinder should be visible
    QVERIFY(isNodeVisible(m_masterCylinder));
    // "Slide 2 Sphere" should be visible
    QVERIFY(isNodeVisible(m_slide2Sphere));
    // "Slide 1 Rect" should not be visible
    QVERIFY(!isNodeVisible(m_slide1Rect));

    // Go back to first slide
    m_sceneManager->setCurrentSlide(m_presentationSlide1);
    // Check first slide state
    QCOMPARE(player->duration(), 10000);
    // MasterCylinder should be visible
    QVERIFY(isNodeVisible(m_masterCylinder));
    // "Slide 1 Rect" should be visible
    QVERIFY(isNodeVisible(m_slide1Rect));
    QVERIFY(!isNodeVisible(m_slide4Cone));
    // "Slide 2 Sphere" should not be visible
    QVERIFY(!isNodeVisible(m_slide2Sphere));

    // Set 3rd Slide (with Component)
    m_sceneManager->setCurrentSlide(m_presentationSlide3);
    QCOMPARE(player->duration(), 10000);
    // MasterCylinder should be visible
    QVERIFY(isNodeVisible(m_masterCylinder));
    // Component Should be visible
    QVERIFY(isNodeVisible(m_slide3Component));
    // "Slide 2 Sphere" should not be visible
    QVERIFY(!isNodeVisible(m_slide2Sphere));
    // "Slide 1 Rect" should not be visible
    QVERIFY(!isNodeVisible(m_slide1Rect));

    // Set 4th Slide (from Component)
    m_sceneManager->setCurrentSlide(m_presentationSlide4);
    QCOMPARE(player->duration(), 12028);
    // MasterCylinder should be visible
    QVERIFY(isNodeVisible(m_masterCylinder));
    // Component Should not be visible
    QVERIFY(!isNodeVisible(m_slide3Component));
    // "Slide 2 Sphere" should not be visible
    QVERIFY(!isNodeVisible(m_slide2Sphere));
    // "Slide 1 Rect" should not be visible
    QVERIFY(!isNodeVisible(m_slide1Rect));
    // Slide 4 Cone should be visible
    QVERIFY(isNodeVisible(m_slide4Cone));

    // Set the same slide again
    m_sceneManager->setCurrentSlide(m_presentationSlide4);
    QCOMPARE(player->duration(), 12028);
    // MasterCylinder should be visible
    QVERIFY(isNodeVisible(m_masterCylinder));
    // Component Should not be visible
    QVERIFY(!isNodeVisible(m_slide3Component));
    // "Slide 2 Sphere" should not be visible
    QVERIFY(!isNodeVisible(m_slide2Sphere));
    // "Slide 1 Rect" should not be visible
    QVERIFY(!isNodeVisible(m_slide1Rect));
    // Slide 4 Cone should be visible
    QVERIFY(isNodeVisible(m_slide4Cone));
}

void tst_Q3DSSlides::presentationRollback()
{
    // Go back to first slide
    m_sceneManager->setCurrentSlide(m_presentationSlide1);

    // DynamicSphere exists on the master slide (visible by default)
    // DynamicSphere has eyeball set to false on Slides 2 and 4
    QVERIFY(isNodeVisible(m_dynamicSphere));

    // Go to Second Slide
    m_sceneManager->setCurrentSlide(m_presentationSlide2);
    QVERIFY(!isNodeVisible(m_dynamicSphere));

    // Go to Third Slide (requires rollback)
    m_sceneManager->setCurrentSlide(m_presentationSlide3);
    QVERIFY(isNodeVisible(m_dynamicSphere));

    // Go to Forth Slide
    m_sceneManager->setCurrentSlide(m_presentationSlide4);
    QVERIFY(!isNodeVisible(m_dynamicSphere));

    // Go to another slide with eyeball false (no rollback)
    m_sceneManager->setCurrentSlide(m_presentationSlide2);
    QVERIFY(!isNodeVisible(m_dynamicSphere));

    // Make sure rollback still works
    m_sceneManager->setCurrentSlide(m_presentationSlide1);
    QVERIFY(isNodeVisible(m_dynamicSphere));

}

void tst_Q3DSSlides::setComponentSlides()
{
    // Set the presentation slide to Slide3 (contains component)
    m_sceneManager->setCurrentSlide(m_presentationSlide3);
    QVERIFY(isNodeVisible(m_slide3Component));

    // Initial slide should be m_componentSlide1
    QVERIFY(isNodeVisible(m_componentMasterCube));
    QVERIFY(isNodeVisible(m_componentSlide1Cone));
    QVERIFY(!isNodeVisible(m_componentSlide2Text));
    QVERIFY(!isNodeVisible(m_componentSlide3Component));

    // Switch to Component Slide 2 (text)
    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide2);
    QVERIFY(!isNodeVisible(m_componentMasterCube));
    QVERIFY(!isNodeVisible(m_componentSlide1Cone));
    QVERIFY(isNodeVisible(m_componentSlide2Text));
    QVERIFY(!isNodeVisible(m_componentSlide3Component));

    // Switch back to Component Slide 1
    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide1);
    QVERIFY(isNodeVisible(m_componentMasterCube));
    QVERIFY(isNodeVisible(m_componentSlide1Cone));
    QVERIFY(!isNodeVisible(m_componentSlide2Text));
    QVERIFY(!isNodeVisible(m_componentSlide3Component));

    // Switch to Component Slide 3 (deep component)
    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide3);
    QVERIFY(isNodeVisible(m_componentMasterCube));
    QVERIFY(!isNodeVisible(m_componentSlide1Cone));
    QVERIFY(!isNodeVisible(m_componentSlide2Text));
    QVERIFY(isNodeVisible(m_componentSlide3Component));

    // Switch to same slide
    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide3);
    QVERIFY(isNodeVisible(m_componentMasterCube));
    QVERIFY(!isNodeVisible(m_componentSlide1Cone));
    QVERIFY(!isNodeVisible(m_componentSlide2Text));
    QVERIFY(isNodeVisible(m_componentSlide3Component));
}

void tst_Q3DSSlides::componentRollback()
{
    // Set the presentation slide to Slide3 (contains component)
    m_sceneManager->setCurrentSlide(m_presentationSlide3);
    QVERIFY(isNodeVisible(m_slide3Component));

    // Set first slide which contains "Master Cube"
    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide1);
    QVERIFY(isNodeVisible(m_componentMasterCube));

    // Second slide sets Master Cube eyeball to false
    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide2);
    QVERIFY(!isNodeVisible(m_componentMasterCube));

    // Switch back to first slide (requires rollback)
    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide1);
    QVERIFY(isNodeVisible(m_componentMasterCube));

    // Move to slide 3 (no change)
    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide3);
    QVERIFY(isNodeVisible(m_componentMasterCube));
}

void tst_Q3DSSlides::setDeepComponentSlides()
{
    // Deep Component is a nested component Slide
    // PresentationSlide3 -> ComponentSlide3 -> DeepComponentSlide[n]
    // Set the presentation slide to Slide3 (contains component)
    m_sceneManager->setCurrentSlide(m_presentationSlide3);
    QVERIFY(isNodeVisible(m_slide3Component));
    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide3);
    QVERIFY(isNodeVisible(m_componentSlide3Component));

    // At this point the first slide of deep component should be active
    QVERIFY(m_componentSlide3Component->currentSlide() == m_deepComponentSlide1);
    QVERIFY(isNodeVisible(m_deepComponentSlide1Cylinder));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Sphere));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Moon));

    // Switch to second deep component slide
    m_sceneManager->setComponentCurrentSlide(m_componentSlide3Component, m_deepComponentSlide2);
    QVERIFY(!isNodeVisible(m_deepComponentSlide1Cylinder));
    QVERIFY(isNodeVisible(m_deepComponentSlide2Sphere));
    QVERIFY(isNodeVisible(m_deepComponentSlide2Moon));

    // Switch back to deep component first slide
    m_sceneManager->setComponentCurrentSlide(m_componentSlide3Component, m_deepComponentSlide1);
    QVERIFY(isNodeVisible(m_deepComponentSlide1Cylinder));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Sphere));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Moon));

    // Set same slide again
    m_sceneManager->setComponentCurrentSlide(m_componentSlide3Component, m_deepComponentSlide1);
    QVERIFY(isNodeVisible(m_deepComponentSlide1Cylinder));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Sphere));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Moon));
}

void tst_Q3DSSlides::deepComponentRollback()
{
    // Deep Component is a nested component Slide
    // PresentationSlide3 -> ComponentSlide3 -> DeepComponentSlide[n]
    // Set the presentation slide to Slide3 (contains component)
    m_sceneManager->setCurrentSlide(m_presentationSlide3);
    QVERIFY(isNodeVisible(m_slide3Component));
    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide3);
    QVERIFY(isNodeVisible(m_componentSlide3Component));

    // First slide has "master text" active
    m_sceneManager->setComponentCurrentSlide(m_componentSlide3Component, m_deepComponentSlide1);
    QVERIFY(isNodeVisible(m_deepComponentMasterText));

    // Second slide has eyeball set to false for master text
    m_sceneManager->setComponentCurrentSlide(m_componentSlide3Component, m_deepComponentSlide2);
    QVERIFY(!isNodeVisible(m_deepComponentMasterText));

    // Switch back to first slide to perform rollback
    m_sceneManager->setComponentCurrentSlide(m_componentSlide3Component, m_deepComponentSlide1);
    QVERIFY(isNodeVisible(m_deepComponentMasterText));
}

void tst_Q3DSSlides::setNonVisibleComponentSlides()
{
    // It is possible to change component slides even though components
    // are not visible.  This is useful because when you do switch to a
    // slide where components contents are shown they will be in the
    // correct state. We have to make sure that changing component slides
    // does not have un-intended side effects for the active slides.

    // Select a presentation slide that does not have a component
    m_sceneManager->setCurrentSlide(m_presentationSlide1);
    QVERIFY(!isNodeVisible(m_slide3Component));

    // m_slide3Component is only visible on m_presentationSlide3
    // change m_slide3Component's slides and make sure the contents
    // do not become visible.
    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide1);
    QVERIFY(!isNodeVisible(m_componentMasterCube));
    QVERIFY(!isNodeVisible(m_componentSlide1Cone));
    QVERIFY(!isNodeVisible(m_componentSlide2Text));
    QVERIFY(!isNodeVisible(m_componentSlide3Component));
    QVERIFY(!isNodeVisible(m_deepComponentSlide1Cylinder));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Sphere));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Moon));
    QVERIFY(!isNodeVisible(m_deepComponentMasterText));

    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide2);
    QVERIFY(!isNodeVisible(m_componentMasterCube));
    QVERIFY(!isNodeVisible(m_componentSlide1Cone));
    QVERIFY(!isNodeVisible(m_componentSlide2Text));
    QVERIFY(!isNodeVisible(m_componentSlide3Component));
    QVERIFY(!isNodeVisible(m_deepComponentSlide1Cylinder));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Sphere));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Moon));
    QVERIFY(!isNodeVisible(m_deepComponentMasterText));

    m_sceneManager->setComponentCurrentSlide(m_slide3Component, m_componentSlide3);
    QVERIFY(!isNodeVisible(m_componentMasterCube));
    QVERIFY(!isNodeVisible(m_componentSlide1Cone));
    QVERIFY(!isNodeVisible(m_componentSlide2Text));
    QVERIFY(!isNodeVisible(m_componentSlide3Component));
    QVERIFY(!isNodeVisible(m_deepComponentSlide1Cylinder));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Sphere));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Moon));
    QVERIFY(!isNodeVisible(m_deepComponentMasterText));

    // also change deep compoents slides (now active in component slide3)
    m_sceneManager->setComponentCurrentSlide(m_componentSlide3Component, m_deepComponentSlide1);
    QVERIFY(!isNodeVisible(m_componentMasterCube));
    QVERIFY(!isNodeVisible(m_componentSlide1Cone));
    QVERIFY(!isNodeVisible(m_componentSlide2Text));
    QVERIFY(!isNodeVisible(m_componentSlide3Component));
    QVERIFY(!isNodeVisible(m_deepComponentSlide1Cylinder));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Sphere));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Moon));
    QVERIFY(!isNodeVisible(m_deepComponentMasterText));

    m_sceneManager->setComponentCurrentSlide(m_componentSlide3Component, m_deepComponentSlide2);
    QVERIFY(!isNodeVisible(m_componentMasterCube));
    QVERIFY(!isNodeVisible(m_componentSlide1Cone));
    QVERIFY(!isNodeVisible(m_componentSlide2Text));
    QVERIFY(!isNodeVisible(m_componentSlide3Component));
    QVERIFY(!isNodeVisible(m_deepComponentSlide1Cylinder));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Sphere));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Moon));
    QVERIFY(!isNodeVisible(m_deepComponentMasterText));

    // Now make component visible by switching to slide 3
    m_sceneManager->setCurrentSlide(m_presentationSlide3);
    QVERIFY(isNodeVisible(m_slide3Component));
    QVERIFY(isNodeVisible(m_componentMasterCube));
    QVERIFY(!isNodeVisible(m_componentSlide1Cone));
    QVERIFY(!isNodeVisible(m_componentSlide2Text));
    QVERIFY(isNodeVisible(m_componentSlide3Component));
    QVERIFY(!isNodeVisible(m_deepComponentSlide1Cylinder));
    QVERIFY(isNodeVisible(m_deepComponentSlide2Sphere));
    QVERIFY(isNodeVisible(m_deepComponentSlide2Moon));
    QVERIFY(!isNodeVisible(m_deepComponentMasterText));

    // make sure that they go away again
    m_sceneManager->setCurrentSlide(m_presentationSlide1);
    QVERIFY(!isNodeVisible(m_slide3Component));
    QVERIFY(!isNodeVisible(m_componentMasterCube));
    QVERIFY(!isNodeVisible(m_componentSlide1Cone));
    QVERIFY(!isNodeVisible(m_componentSlide2Text));
    QVERIFY(!isNodeVisible(m_componentSlide3Component));
    QVERIFY(!isNodeVisible(m_deepComponentSlide1Cylinder));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Sphere));
    QVERIFY(!isNodeVisible(m_deepComponentSlide2Moon));
    QVERIFY(!isNodeVisible(m_deepComponentMasterText));
}

void tst_Q3DSSlides::testTimeLineVisibility()
{
    // Select a presentation slide that has items with different starttimes
    // and endtimes than the slide they are on
    m_sceneManager->setCurrentSlide(m_presentationSlide5);

    QVERIFY(isNodeVisible(m_masterCylinder));
    QVERIFY(isNodeVisible(m_dynamicSphere));
    QVERIFY(!isNodeVisible(m_slide5Rect));
    QVERIFY(isNodeVisible(m_slide5Sphere));

    Q3DSSlidePlayer *player = m_sceneManager->slidePlayer();
    player->stop();
    QVERIFY(player);

    QSignalSpy updateSpy(m_engine, SIGNAL(nextFrameStarting()));
    QSignalSpy positionChangedSpy(player, &Q3DSSlidePlayer::positionChanged);

    const auto seekAndWait = [player, &updateSpy, &positionChangedSpy](int value) {
        const float t = value;
        player->seek(t);
        QVERIFY(positionChangedSpy.wait(5000));
        QVERIFY(updateSpy.wait(5000));
    };

    Q3DSSlide *compMasterSlide = m_slide5Component->masterSlide();
    Q_ASSERT(compMasterSlide);
    Q3DSSlidePlayer *compPlayer = compMasterSlide->attached<Q3DSSlideAttached>()->slidePlayer;
    compPlayer->stop();
    QVERIFY(compPlayer);

    QSignalSpy compPositionChangedSpy(compPlayer, &Q3DSSlidePlayer::positionChanged);

    const auto seekAndWaitForComp = [player, &updateSpy, &compPositionChangedSpy](int value) {
        const float t = value;
        player->seek(t);
        QVERIFY(compPositionChangedSpy.wait(5000));
        QVERIFY(updateSpy.wait(5000));
    };

    seekAndWait(999);

    // Still invisible
    QVERIFY(isNodeVisible(m_masterCylinder));
    QVERIFY(isNodeVisible(m_dynamicSphere));
    QVERIFY(!isNodeVisible(m_slide5Rect));
    QVERIFY(isNodeVisible(m_slide5Sphere));
    QVERIFY(!isNodeVisible(m_slide5Component));
    QVERIFY(!isNodeVisible(m_componentMasterCubeSlide5));

    seekAndWait(1000);

    // Slide 5 component becomes visible, but not components objects
    QVERIFY(isNodeVisible(m_masterCylinder));
    QVERIFY(isNodeVisible(m_dynamicSphere));
    QVERIFY(isNodeVisible(m_slide5Rect));
    QVERIFY(isNodeVisible(m_slide5Sphere));
    QVERIFY(isNodeVisible(m_slide5Component));
    QVERIFY(!isNodeVisible(m_componentMasterCubeSlide5));

    seekAndWait(1500);

    // Everything now visible
    QVERIFY(isNodeVisible(m_masterCylinder));
    QVERIFY(isNodeVisible(m_dynamicSphere));
    QVERIFY(isNodeVisible(m_slide5Rect));
    QVERIFY(isNodeVisible(m_slide5Sphere));
    QVERIFY(isNodeVisible(m_slide5Component));
    QVERIFY(isNodeVisible(m_componentMasterCubeSlide5));

    // Verify a positionChanged signal coming from component slide player
    seekAndWaitForComp(1501);

    seekAndWait(2000);

    // Everything still visible
    QVERIFY(isNodeVisible(m_masterCylinder));
    QVERIFY(isNodeVisible(m_dynamicSphere));
    QVERIFY(isNodeVisible(m_slide5Rect));
    QVERIFY(isNodeVisible(m_slide5Sphere));
    QVERIFY(isNodeVisible(m_slide5Component));
    QVERIFY(isNodeVisible(m_componentMasterCubeSlide5));

    seekAndWait(2001);

    // Neither rect nor sphere are visible
    QVERIFY(isNodeVisible(m_masterCylinder));
    QVERIFY(isNodeVisible(m_dynamicSphere));
    QVERIFY(!isNodeVisible(m_slide5Rect));
    QVERIFY(!isNodeVisible(m_slide5Sphere));
    QVERIFY(isNodeVisible(m_slide5Component));
    QVERIFY(isNodeVisible(m_componentMasterCubeSlide5));

    seekAndWait(2885);

    // Neither rect nor sphere are visible
    QVERIFY(isNodeVisible(m_masterCylinder));
    QVERIFY(isNodeVisible(m_dynamicSphere));
    QVERIFY(!isNodeVisible(m_slide5Rect));
    QVERIFY(!isNodeVisible(m_slide5Sphere));
    QVERIFY(!isNodeVisible(m_slide5Component));
    QVERIFY(!isNodeVisible(m_componentMasterCubeSlide5));

    seekAndWait(0);

    // Back to the beginning
    QVERIFY(isNodeVisible(m_masterCylinder));
    QVERIFY(isNodeVisible(m_dynamicSphere));
    QVERIFY(!isNodeVisible(m_slide5Rect));
    QVERIFY(isNodeVisible(m_slide5Sphere));
    QVERIFY(!isNodeVisible(m_slide5Component));
    QVERIFY(!isNodeVisible(m_componentMasterCubeSlide5));
}

Q3DSModelNode *tst_Q3DSSlides::getModelWithName(const QString &name, Q3DSGraphObject *parent)
{
    Q3DSGraphObject *n = parent->firstChild();
    while (n) {
        if (n->type() == Q3DSGraphObject::Model) {
            auto model = static_cast<Q3DSModelNode *>(n);
            if (model->name() == name)
                return model;
        }
        n = n->nextSibling();
    }
    return nullptr;
}

Q3DSComponentNode *tst_Q3DSSlides::getComponentWithName(const QString &name, Q3DSGraphObject *parent)
{
    Q3DSGraphObject *n = parent->firstChild();
    while (n) {
        if (n->type() == Q3DSGraphObject::Component) {
            auto component = static_cast<Q3DSComponentNode *>(n);
            if (component->name() == name)
                return component;
        }
        n = n->nextSibling();
    }
    return nullptr;
}

Q3DSTextNode *tst_Q3DSSlides::getTextNodeWithName(const QString &name, Q3DSGraphObject *parent)
{
    Q3DSGraphObject *n = parent->firstChild();
    while (n) {
        if (n->type() == Q3DSGraphObject::Text) {
            auto text = static_cast<Q3DSTextNode *>(n);
            if (text->name() == name)
                return text;
        }
        n = n->nextSibling();
    }
    return nullptr;
}

bool tst_Q3DSSlides::isNodeVisible(Q3DSNode *node)
{
    if (!node) {
        return false;
    }

    auto nodeAttached = static_cast<Q3DSNodeAttached *>(node->attached());
    auto entity = nodeAttached->entity;
    if (!entity)
        return false;
    auto layerAttached = static_cast<Q3DSLayerAttached *>(nodeAttached->layer3DS->attached());

    if (entity->components().contains(layerAttached->opaqueTag) || entity->components().contains(layerAttached->transparentTag))
        return true;

    return false;
}

QTEST_MAIN(tst_Q3DSSlides);

#include "tst_q3dsslides.moc"