summaryrefslogtreecommitdiffstats
path: root/tests/auto/render/qrendertarget/tst_qrendertarget.cpp
blob: 32c78fc80f024b808c442cf247ddf7bbb16edc74 (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
// Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include <QtTest/QTest>
#include <Qt3DRender/qrendertarget.h>
#include <Qt3DRender/qrendertargetoutput.h>
#include <Qt3DRender/private/qrendertarget_p.h>
#include <QObject>
#include <QSignalSpy>
#include "testarbiter.h"

class tst_QRenderTarget : public QObject
{
    Q_OBJECT

private Q_SLOTS:

    void checkDefaultConstruction()
    {
        // GIVEN
        Qt3DRender::QRenderTarget renderTarget;

        // THEN
        QVERIFY(renderTarget.outputs().empty());
    }

    void checkPropertyChanges()
    {
        // GIVEN
        Qt3DRender::QRenderTarget renderTarget;

        // WHEN
        Qt3DRender::QRenderTargetOutput output;

        renderTarget.addOutput(&output);

        // THEN
        QCOMPARE(renderTarget.outputs().size(), 1);

        // WHEN
        renderTarget.addOutput(&output);

        // THEN
        QCOMPARE(renderTarget.outputs().size(), 1);

        // WHEN
        renderTarget.removeOutput(&output);

        // THEN
        QCOMPARE(renderTarget.outputs().size(), 0);
    }

    void checkRenderTargetOutputBookkeeping()
    {
        // GIVEN
        Qt3DRender::QRenderTarget renderTarget;

        {
            // WHEN
            Qt3DRender::QRenderTargetOutput output;
            renderTarget.addOutput(&output);

            // THEN
            QCOMPARE(renderTarget.outputs().size(), 1);
        }

        // THEN -> should not crash
        QCOMPARE(renderTarget.outputs().size(), 0);
    }

    void checkRenderTargetOutputUpdate()
    {
        // GIVEN
        TestArbiter arbiter;
        Qt3DRender::QRenderTarget renderTarget;
        Qt3DRender::QRenderTargetOutput renderTargetOutput;
        arbiter.setArbiterOnNode(&renderTarget);

        {
            // WHEN
            renderTarget.addOutput(&renderTargetOutput);
            QCoreApplication::processEvents();

            // THEN
            QCOMPARE(arbiter.dirtyNodes().size(), 1);
            QCOMPARE(arbiter.dirtyNodes().front(), &renderTarget);

            arbiter.clear();
        }

        {
            // WHEN
            renderTarget.removeOutput(&renderTargetOutput);
            QCoreApplication::processEvents();

            // THEN
            QCOMPARE(arbiter.dirtyNodes().size(), 1);
            QCOMPARE(arbiter.dirtyNodes().front(), &renderTarget);

            arbiter.clear();
        }
    }
};

QTEST_MAIN(tst_QRenderTarget)

#include "tst_qrendertarget.moc"