From e96e47e4d1eb7217a0169013c9968b8eb52bbb4e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 7 Mar 2018 02:52:28 +0100 Subject: Make serializer/deserializer endian independent --- tests/main.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'tests') 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() == 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(); + 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 +} -- cgit v1.2.3