Skip to content

Commit 0c3bc51

Browse files
committed
ENH: add test for commonly used circular buffer functionality.
1 parent 665f536 commit 0c3bc51

File tree

1 file changed

+108
-3
lines changed

1 file changed

+108
-3
lines changed

testframes/test_utils_circularbuffer/test_utils_circularbuffer.cpp

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,116 @@
3232
*
3333
*/
3434

35+
//=============================================================================================================
36+
// INCLUDES
37+
//=============================================================================================================
38+
39+
#include <utils/generics/circularbuffer.h>
40+
41+
//=============================================================================================================
42+
// QT INCLUDES
43+
//=============================================================================================================
44+
3545
#include <QCoreApplication>
46+
#include <QObject>
47+
#include <QDebug>
48+
#include <QTest>
3649

37-
int main(int argc, char *argv[])
50+
//=============================================================================================================
51+
// USED NAMESPACES
52+
//=============================================================================================================
53+
54+
using namespace UTILSLIB;
55+
56+
//=============================================================================================================
57+
/**
58+
* DECLARE CLASS TestCircularBuffer
59+
*
60+
* @brief The TestCircularBuffer class provides tests for verifying circular buffer functionality
61+
*
62+
*/
63+
64+
class TestCircularBuffer : public QObject
3865
{
39-
QCoreApplication a(argc, argv);
66+
Q_OBJECT
67+
68+
private slots:
69+
void testBufferCreationDestruction();
70+
void testBufferPushingPopping();
71+
void testBufferCapacity();
72+
};
73+
74+
//=============================================================================================================
4075

41-
return a.exec();
76+
void TestCircularBuffer::testBufferCreationDestruction()
77+
{
78+
//Test Constructors/Destructors
79+
{
80+
CircularBuffer<float> testBuffer(10);
81+
}
82+
{
83+
CircularBuffer<int> *testBuffer = new CircularBuffer<int>(10);
84+
delete testBuffer;
85+
}
4286
}
87+
88+
//=============================================================================================================
89+
90+
void TestCircularBuffer::testBufferPushingPopping()
91+
{
92+
CircularBuffer<int> testBuffer(10);
93+
94+
int testVal = 5;
95+
int testArray[3] = {1, 2, 3};
96+
97+
//Verify Push
98+
QVERIFY(testBuffer.push(testVal));
99+
QVERIFY(testBuffer.push(testArray, 3));
100+
101+
int resultVal = 0;
102+
int resultArray[3] = {0, 0, 0};
103+
104+
QVERIFY(testBuffer.pop(resultVal));
105+
for (int i = 0; i < 3; ++i){
106+
QVERIFY(testBuffer.pop(resultArray[i]));
107+
}
108+
109+
QVERIFY(resultVal == testVal);
110+
for (int i = 0; i < 3; ++i){
111+
QVERIFY(resultArray[i] == resultArray[i]);
112+
}
113+
}
114+
115+
//=============================================================================================================
116+
117+
void TestCircularBuffer::testBufferCapacity()
118+
{
119+
CircularBuffer<int> testBuffer(2);
120+
int testSink = 0;
121+
122+
QVERIFY(!testBuffer.pop(testSink));
123+
124+
testBuffer.push(5);
125+
testBuffer.push(10);
126+
127+
QVERIFY(!testBuffer.push(15));
128+
129+
testBuffer.clear();
130+
131+
QVERIFY(!testBuffer.pop(testSink));
132+
133+
QVERIFY(testBuffer.push(20));
134+
135+
QVERIFY(testBuffer.pop(testSink));
136+
137+
QVERIFY(testSink == 20);
138+
139+
QVERIFY(!testBuffer.pop(testSink));
140+
}
141+
142+
//=============================================================================================================
143+
// MAIN
144+
//=============================================================================================================
145+
146+
QTEST_GUILESS_MAIN(TestCircularBuffer);
147+
#include "test_utils_circularbuffer.moc"

0 commit comments

Comments
 (0)