Skip to content

Commit

Permalink
Merge SerializableProperty<Component> process (mr-456)
Browse files Browse the repository at this point in the history
823532a - feat(tests): add serializable component property test
54248b6 - fix(net): SerializableProperty<Component> process
  • Loading branch information
prikolium-cfx committed Aug 6, 2024
2 parents 10da6d8 + 823532a commit 8dcaedd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/components/net-base/include/SerializableProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace net
struct HasIsComponent
{
template <typename U>
static auto TestIsComponent(int) -> decltype(U::IsComponent, std::true_type());
static auto TestIsComponent(int) -> decltype(U::kIsComponent, std::true_type());

template <typename>
static auto TestIsComponent(...) -> std::false_type;
Expand Down
53 changes: 53 additions & 0 deletions code/tests/TestComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,56 @@ TEST_CASE("Components test")
uint64_t size = byteCounter.GetCapacity();
REQUIRE(size == uint64_t(917549));
}

namespace SerializableComponentPropertyTest {
class Component: public net::SerializableComponent
{
public:
net::SerializableProperty<uint32_t> value {};

template <typename T>
bool Process(T& stream)
{
return ProcessPropertiesInOrder<T>(
stream,
value
);
}
};

class ComponentHoldingClass : public net::SerializableComponent
{
public:
net::SerializableProperty<Component> component {};

template <typename T>
bool Process(T& stream)
{
return ProcessPropertiesInOrder<T>(
stream,
component
);
}
};
}

TEST_CASE("Serializable component property")
{
uint32_t random = fx::TestUtils::u64Random(UINT32_MAX);

SerializableComponentPropertyTest::ComponentHoldingClass instance;
instance.component.GetValue().value.SetValue(random);

uint8_t buffer[4];
net::ByteWriter writer(buffer, sizeof(buffer));
REQUIRE(instance.Process(writer));

REQUIRE(*reinterpret_cast<uint32_t*>(buffer) == random);

SerializableComponentPropertyTest::ComponentHoldingClass instanceRead;

net::ByteReader reader(buffer, sizeof(buffer));
REQUIRE(instanceRead.Process(reader));

REQUIRE(instanceRead.component.GetValue().value.GetValue() == random);
}

0 comments on commit 8dcaedd

Please sign in to comment.