1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "test_RingBuffer.h"
27 #include "Common/RingBuffer.h"
29 using namespace Common
;
31 Q_DECLARE_METATYPE(QVector
<int>);
33 void RingBufferTest::testOne()
36 QFETCH(QVector
<int>, sourceData
);
37 QFETCH(QVector
<int>, expectedData
);
38 RingBuffer
<int> rb(size
);
39 Q_FOREACH(const int item
, sourceData
) {
44 for (RingBuffer
<int>::const_iterator it
= rb
.begin(); it
!= rb
.end(); ++it
) {
46 if (output
.size() >= size
* 2) {
47 QFAIL("Iterated way too many times");
52 // Correct amount of data received?
53 QCOMPARE(output
.size(), expectedData
.size());
56 QCOMPARE(expectedData
, output
);
58 // Did it overwrite a correct number of items?
59 QCOMPARE(static_cast<uint
>(sourceData
.size() - expectedData
.size()), rb
.skippedCount());
63 // Is it really empty?
64 // Yes, QVERIFY instead of QCOMPARE -- they can't be printed
65 QVERIFY(rb
.begin() == rb
.end());
68 void RingBufferTest::testOne_data()
70 QTest::addColumn
<int>("size");
71 QTest::addColumn
<QVector
<int> >("sourceData");
72 QTest::addColumn
<QVector
<int> >("expectedData");
75 QTest::newRow("empty") << 5 << data
<< data
;
79 QTest::newRow("one-value") << 5 << data
<< data
;
83 QTest::newRow("two-values") << 5 << data
<< data
;
86 data
<< 333 << 666 << 7;
87 QTest::newRow("three-values") << 5 << data
<< data
;
90 data
<< 333 << 666 << 7 << 15;
91 QTest::newRow("four-values") << 5 << data
<< data
;
94 data
<< 333 << 666 << 7 << 15 << 9;
95 QTest::newRow("five-values") << 5 << data
<< data
;
98 data
<< 333 << 666 << 7 << 15 << 9 << 13;
99 QVector
<int> expected
;
100 expected
<< 666 << 7 << 15 << 9 << 13;
101 QTest::newRow("six-wrapped") << 5 << data
<< expected
;
104 data
<< 333 << 666 << 7 << 15 << 9 << 13 << 0;
106 expected
<< 7 << 15 << 9 << 13 << 0;
107 QTest::newRow("seven-wrapped") << 5 << data
<< expected
;
110 data
<< 333 << 666 << 7 << 15 << 9 << 13 << 0 << 2;
112 expected
<< 15 << 9 << 13 << 0 << 2;
113 QTest::newRow("eight-wrapped") << 5 << data
<< expected
;
116 data
<< 333 << 666 << 7 << 15 << 9 << 13 << 0 << 2 << 1;
118 expected
<< 9 << 13 << 0 << 2 << 1;
119 QTest::newRow("nine-wrapped") << 5 << data
<< expected
;
122 data
<< 333 << 666 << 7 << 15 << 9 << 13 << 0 << 2 << 1 << 800500;
124 expected
<< 13 << 0 << 2 << 1 << 800500;
125 QTest::newRow("ten-wrapped") << 5 << data
<< expected
;
128 data
<< 333 << 666 << 7 << 15 << 9 << 13 << 0 << 2 << 1 << 800500 << 11;
130 expected
<< 0 << 2 << 1 << 800500 << 11;
131 QTest::newRow("eleven-wrapped") << 5 << data
<< expected
;
134 QTEST_GUILESS_MAIN( RingBufferTest
)