mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 10:31:50 +00:00
add StructMapper read/write methods
This commit is contained in:
parent
2b1db0b075
commit
c67b867a31
3 changed files with 224 additions and 1 deletions
23
test/data/StructMapper.cpp
Normal file
23
test/data/StructMapper.cpp
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue