add StructMapper read/write methods

This commit is contained in:
MihailRis
2024-08-29 11:57:05 +03:00
parent 2b1db0b075
commit c67b867a31
3 changed files with 224 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
#include "data/StructMapper.hpp"
#include <gtest/gtest.h>
using namespace data;
TEST(StructMapper, ReadWrite) {
ubyte buffer[16] {};
std::vector<Field> fields {
Field {FieldType::I8, "a", 1},
Field {FieldType::I32, "b", 1},
Field {FieldType::F32, "f", 1},
};
auto mapping = StructMapping::create(fields);
EXPECT_EQ(mapping.size(), 9);
mapping.setInteger(buffer, 42, "a");
EXPECT_EQ(mapping.getInteger(buffer, "a"), 42);
mapping.setNumber(buffer, 3.141592f, "f");
EXPECT_FLOAT_EQ(mapping.getNumber(buffer, "f"), 3.141592f);
}