12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include "tests/BufferTests.h"
- #include "test/Test.h"
- #include "utils/Buffer.h"
- static constexpr int SIZE_TYPES =
- sizeof(int) + sizeof(long) + sizeof(float) + sizeof(double);
- static void testAdd() {
- Core::Buffer buffer(10);
- for(int i = 0; i < 100000; 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 * 100000, 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::BufferTests::test() {
- testAdd();
- testCopy();
- testMoveConstruct();
- testMove();
- }
|