aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-03-07 02:52:28 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:16:10 +0200
commitff9ea15709ba60008f46df9adae747b8c6e71d68 (patch)
tree4c2bce5309765194bb2614be92aac45db86aa0ea /tests
parent6fd8decb98ce81fd71cebd0226e30b0024ffd77c (diff)
Make serializer/deserializer endian independent
Diffstat (limited to 'tests')
-rw-r--r--tests/main.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index e495b3a..4b6c7a7 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -7,14 +7,25 @@
#define REQUIRE(statement) do { if(!(statement)) { fprintf(stderr, "Assertion failed:\n%s\n", #statement); exit(1); } } while(0)
#define FAIL(str) do { fprintf(stderr, "Failed:\n%s\n", (str)); exit(1); } while(0)
+struct TestStruct
+{
+ uint32_t a;
+ uint8_t b;
+};
+
int main()
{
+ TestStruct expectedTestStruct;
+ expectedTestStruct.a = 0x38956326;
+ expectedTestStruct.b = 0x34;
+
sibs::SafeSerializer serializer;
serializer.add((uint32_t)3563634);
serializer.add((uint64_t)204232532533423632);
serializer.add((uint8_t)2);
serializer.add((uint8_t*)"hello", 5);
- REQUIRE(serializer.getBuffer().size() == 18);
+ serializer.add(expectedTestStruct);
+ REQUIRE(serializer.getBuffer().size() == 18 + sizeof(expectedTestStruct));
sibs::SafeDeserializer deserializer(serializer.getBuffer().data(), serializer.getBuffer().size());
REQUIRE(deserializer.extract<uint32_t>() == 3563634);
@@ -24,6 +35,8 @@ int main()
str[5] = '\0';
deserializer.extract((uint8_t*)str, 5);
REQUIRE(strcmp(str, "hello") == 0);
+ TestStruct actualTestStruct = deserializer.extract<TestStruct>();
+ REQUIRE(actualTestStruct.a == expectedTestStruct.a && actualTestStruct.b == expectedTestStruct.b);
REQUIRE(deserializer.empty());
try
@@ -37,4 +50,4 @@ int main()
}
return 0;
-} \ No newline at end of file
+}