1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QTest>
30#include <qbackendnodetester.h>
31#include <Qt3DRender/private/rendercapture_p.h>
32#include <Qt3DRender/qrendercapture.h>
33#include <Qt3DCore/private/qbackendnode_p.h>
34#include "testpostmanarbiter.h"
35#include "testrenderer.h"
36
37class tst_RenderCapture : public Qt3DCore::QBackendNodeTester
38{
39 Q_OBJECT
40private Q_SLOTS:
41
42 void checkInitialState()
43 {
44 // GIVEN
45 TestRenderer renderer;
46 Qt3DRender::QRenderCapture frontend;
47 Qt3DRender::Render::RenderCapture backend;
48
49 // WHEN
50 backend.setRenderer(&renderer);
51 simulateInitializationSync(frontend: &frontend, backend: &backend);
52
53 // THEN
54 QVERIFY(!backend.peerId().isNull());
55 QCOMPARE(backend.wasCaptureRequested(), false);
56 QCOMPARE(backend.isEnabled(), true);
57 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
58 }
59
60 void checkEnabledPropertyChange()
61 {
62 // GIVEN
63 Qt3DRender::QRenderCapture frontend;
64 Qt3DRender::Render::RenderCapture renderCapture;
65 TestRenderer renderer;
66 renderCapture.setRenderer(&renderer);
67 simulateInitializationSync(frontend: &frontend, backend: &renderCapture);
68
69 // WHEN
70 frontend.setEnabled(false);
71 renderCapture.syncFromFrontEnd(frontEnd: &frontend, firstTime: false);
72
73 // THEN
74 QCOMPARE(renderCapture.isEnabled(), false);
75 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
76 }
77
78 void checkReceiveRenderCaptureRequest()
79 {
80 // GIVEN
81 Qt3DRender::QRenderCapture frontend;
82 Qt3DRender::Render::RenderCapture renderCapture;
83 TestRenderer renderer;
84 renderCapture.setRenderer(&renderer);
85 simulateInitializationSync(frontend: &frontend, backend: &renderCapture);
86
87 // WHEN
88 frontend.requestCapture();
89 renderCapture.syncFromFrontEnd(frontEnd: &frontend, firstTime: false);
90
91 // THEN
92 QCOMPARE(renderCapture.wasCaptureRequested(), true);
93 }
94
95 void checkTakeCaptureRequest()
96 {
97 // GIVEN
98 Qt3DRender::Render::RenderCapture renderCapture;
99 TestRenderer renderer;
100 renderCapture.setRenderer(&renderer);
101 renderCapture.setEnabled(true);
102
103 // WHEN
104 renderCapture.requestCapture(request: { .captureId: 2, .rect: QRect(10, 10, 20, 20) });
105 renderCapture.requestCapture(request: { .captureId: 4, .rect: QRect(15, 15, 30, 30) });
106
107 // THEN
108 QCOMPARE(renderCapture.wasCaptureRequested(), true);
109
110 // WHEN
111 Qt3DRender::QRenderCaptureRequest r1 = renderCapture.takeCaptureRequest();
112
113 // THEN
114 QCOMPARE(r1.captureId, 2);
115 QCOMPARE(r1.rect, QRect(10, 10, 20, 20));
116 QCOMPARE(renderCapture.wasCaptureRequested(), true);
117
118 // WHEN
119 Qt3DRender::QRenderCaptureRequest r2 = renderCapture.takeCaptureRequest();
120
121 // THEN
122 QCOMPARE(r2.captureId, 4);
123 QCOMPARE(r2.rect, QRect(15, 15, 30, 30));
124 QCOMPARE(renderCapture.wasCaptureRequested(), false);
125 }
126};
127
128
129QTEST_APPLESS_MAIN(tst_RenderCapture)
130
131#include "tst_rendercapture.moc"
132

source code of qt3d/tests/auto/render/rendercapture/tst_rendercapture.cpp