123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "../Tests.hpp"
- #include "core/utils/Buffer.hpp"
- static constexpr int SIZE_TYPES =
- sizeof(int) + sizeof(long) + sizeof(float) + sizeof(double);
- static void testAdd(bool light) {
- Core::Buffer buffer(10);
- int limit = light ? 1000 : 100000;
- for(int i = 0; i < limit; i++) {
- CORE_TEST_ERROR(buffer.add(5));
- CORE_TEST_ERROR(buffer.add(5L));
- CORE_TEST_ERROR(buffer.add(5.0f));
- CORE_TEST_ERROR(buffer.add(5.0));
- }
- CORE_TEST_EQUAL(SIZE_TYPES * limit, buffer.getLength());
- }
- static void testCopy() {
- Core::Buffer buffer(10);
- for(int i = 0; i < 10; i++) {
- CORE_TEST_ERROR(buffer.add(5));
- CORE_TEST_ERROR(buffer.add(5L));
- CORE_TEST_ERROR(buffer.add(5.0f));
- CORE_TEST_ERROR(buffer.add(5.0));
- }
- Core::Buffer buffer2;
- CORE_TEST_ERROR(buffer2.copyFrom(buffer));
- if(CORE_TEST_EQUAL(SIZE_TYPES * 10, buffer.getLength()) &&
- CORE_TEST_EQUAL(SIZE_TYPES * 10, buffer2.getLength())) {
- CORE_TEST_TRUE(Core::memoryCompare(buffer, buffer2, SIZE_TYPES * 10));
- }
- }
- static void testMoveConstruct() {
- Core::Buffer buffer(10);
- for(int i = 0; i < 10; i++) {
- CORE_TEST_ERROR(buffer.add(5));
- CORE_TEST_ERROR(buffer.add(5L));
- CORE_TEST_ERROR(buffer.add(5.0f));
- CORE_TEST_ERROR(buffer.add(5.0));
- }
- Core::Buffer buffer2(Core::move(buffer));
- CORE_TEST_EQUAL(0, buffer.getLength());
- CORE_TEST_EQUAL(SIZE_TYPES * 10, buffer2.getLength());
- }
- static void testMove() {
- Core::Buffer buffer(10);
- for(int i = 0; i < 10; i++) {
- CORE_TEST_ERROR(buffer.add(5));
- CORE_TEST_ERROR(buffer.add(5L));
- CORE_TEST_ERROR(buffer.add(5.0f));
- CORE_TEST_ERROR(buffer.add(5.0));
- }
- Core::Buffer buffer2(3);
- buffer2 = Core::move(buffer);
- CORE_TEST_EQUAL(0, buffer.getLength());
- CORE_TEST_EQUAL(SIZE_TYPES * 10, buffer2.getLength());
- }
- void Core::testBuffer(bool light) {
- testAdd(light);
- testCopy();
- testMoveConstruct();
- testMove();
- }
|