123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include "tests/BufferTests.h"
- #include "tests/Test.h"
- #include "utils/Buffer.h"
- #include "utils/Utility.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++) {
- buffer.add(5);
- buffer.add(5L);
- buffer.add(5.0f);
- buffer.add(5.0);
- }
- 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(Core::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 = Core::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();
- }
|