| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). | 
| 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 <Qt3DCore/private/aspectcommanddebugger_p.h> | 
| 31 |  | 
| 32 | using namespace Qt3DCore::Debug; | 
| 33 |  | 
| 34 | class tst_AspectCommandDebugger : public QObject | 
| 35 | { | 
| 36 |     Q_OBJECT | 
| 37 |  | 
| 38 | private slots: | 
| 39 |     void checkReadBufferInitialState() | 
| 40 |     { | 
| 41 |         // GIVEN | 
| 42 |         AspectCommandDebugger::ReadBuffer buffer; | 
| 43 |  | 
| 44 |         // THEN | 
| 45 |         QCOMPARE(buffer.startIdx, 0); | 
| 46 |         QCOMPARE(buffer.endIdx, 0); | 
| 47 |     } | 
| 48 |  | 
| 49 |     void checkReadBufferInsert() | 
| 50 |     { | 
| 51 |         // GIVEN | 
| 52 |         AspectCommandDebugger::ReadBuffer buffer; | 
| 53 |  | 
| 54 |         // WHEN | 
| 55 |         QByteArray fakeData(1024, '8'); | 
| 56 |         buffer.insert(array: fakeData); | 
| 57 |  | 
| 58 |         // THEN | 
| 59 |         QCOMPARE(buffer.startIdx, 0); | 
| 60 |         QCOMPARE(buffer.endIdx, 1024); | 
| 61 |         QCOMPARE(buffer.buffer.size(), 1024); | 
| 62 |         QCOMPARE(fakeData, QByteArray(buffer.buffer.constData(), 1024)); | 
| 63 |  | 
| 64 |         // WHEN | 
| 65 |         QByteArray hugeFakeData(1024 * 16, '.'); | 
| 66 |         buffer.insert(array: hugeFakeData); | 
| 67 |  | 
| 68 |         // THEN | 
| 69 |         QCOMPARE(buffer.startIdx, 0); | 
| 70 |         QCOMPARE(buffer.endIdx, 1024 + 16 * 1024); | 
| 71 |         QCOMPARE(fakeData, QByteArray(buffer.buffer.constData(), 1024)); | 
| 72 |         QCOMPARE(hugeFakeData, QByteArray(buffer.buffer.constData() + 1024, 1024 * 16)); | 
| 73 |     } | 
| 74 |  | 
| 75 |     void checkBufferTrim() | 
| 76 |     { | 
| 77 |         // GIVEN | 
| 78 |         AspectCommandDebugger::ReadBuffer buffer; | 
| 79 |         QByteArray fakeData(1024, '9'); | 
| 80 |         QByteArray hugeFakeData(1024 * 16, '.'); | 
| 81 |         buffer.insert(array: fakeData); | 
| 82 |         buffer.insert(array: hugeFakeData); | 
| 83 |  | 
| 84 |         // WHEN | 
| 85 |         buffer.startIdx += 1024; | 
| 86 |         buffer.trim(); | 
| 87 |  | 
| 88 |         // THEN | 
| 89 |         QCOMPARE(buffer.size(), 16 * 1024); | 
| 90 |         QCOMPARE(hugeFakeData, QByteArray(buffer.buffer.constData(), 1024 * 16)); | 
| 91 |     } | 
| 92 | }; | 
| 93 |  | 
| 94 | QTEST_APPLESS_MAIN(tst_AspectCommandDebugger) | 
| 95 |  | 
| 96 | #include "tst_aspectcommanddebugger.moc" | 
| 97 |  |