|
@@ -2,6 +2,9 @@
|
|
|
#include "tests/Test.h"
|
|
|
#include "utils/Buffer.h"
|
|
|
|
|
|
+static constexpr int SIZE_TYPES =
|
|
|
+ sizeof(int) + sizeof(long) + sizeof(float) + sizeof(double);
|
|
|
+
|
|
|
static void testAdd(Test& test) {
|
|
|
Buffer buffer(10);
|
|
|
for(int i = 0; i < 100000; i++) {
|
|
@@ -10,12 +13,61 @@ static void testAdd(Test& test) {
|
|
|
buffer.add(5.0f);
|
|
|
buffer.add(5.0);
|
|
|
}
|
|
|
- test.checkEqual(static_cast<int> ((sizeof (int) + sizeof (long) + sizeof (float) + sizeof (double)) * 100000),
|
|
|
- buffer.getLength(), "add increments length");
|
|
|
+ test.checkEqual(SIZE_TYPES * 100000, buffer.getLength(),
|
|
|
+ "add increments length");
|
|
|
+}
|
|
|
+
|
|
|
+static void testCopy(Test& test) {
|
|
|
+ Buffer buffer(10);
|
|
|
+ for(int i = 0; i < 10; i++) {
|
|
|
+ buffer.add(5);
|
|
|
+ buffer.add(5L);
|
|
|
+ buffer.add(5.0f);
|
|
|
+ buffer.add(5.0);
|
|
|
+ }
|
|
|
+ Buffer buffer2(buffer);
|
|
|
+ Buffer buffer3(2);
|
|
|
+ buffer3 = buffer;
|
|
|
+
|
|
|
+ test.checkEqual(SIZE_TYPES * 10, buffer.getLength(), "copy");
|
|
|
+ test.checkEqual(SIZE_TYPES * 10, buffer2.getLength(), "copy");
|
|
|
+ test.checkEqual(SIZE_TYPES * 10, buffer3.getLength(), "copy");
|
|
|
+}
|
|
|
+
|
|
|
+static void testMoveConstruct(Test& test) {
|
|
|
+ Buffer buffer(10);
|
|
|
+ for(int i = 0; i < 10; i++) {
|
|
|
+ buffer.add(5);
|
|
|
+ buffer.add(5L);
|
|
|
+ buffer.add(5.0f);
|
|
|
+ buffer.add(5.0);
|
|
|
+ }
|
|
|
+ Buffer buffer2(std::move(buffer));
|
|
|
+
|
|
|
+ test.checkEqual(0, buffer.getLength(), "move");
|
|
|
+ test.checkEqual(SIZE_TYPES * 10, buffer2.getLength(), "move");
|
|
|
+}
|
|
|
+
|
|
|
+static void testMove(Test& test) {
|
|
|
+ Buffer buffer(10);
|
|
|
+ for(int i = 0; i < 10; i++) {
|
|
|
+ buffer.add(5);
|
|
|
+ buffer.add(5L);
|
|
|
+ buffer.add(5.0f);
|
|
|
+ buffer.add(5.0);
|
|
|
+ }
|
|
|
+ Buffer buffer2(3);
|
|
|
+ buffer2 = std::move(buffer);
|
|
|
+
|
|
|
+ test.checkEqual(0, buffer.getLength(), "move");
|
|
|
+ test.checkEqual(SIZE_TYPES * 10, buffer2.getLength(), "move");
|
|
|
}
|
|
|
|
|
|
void BufferTests::test() {
|
|
|
Test test("Buffer");
|
|
|
testAdd(test);
|
|
|
+ testCopy(test);
|
|
|
+ testMoveConstruct(test);
|
|
|
+ testMove(test);
|
|
|
test.finalize();
|
|
|
}
|