diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-03-07 02:52:28 +0100 |
---|---|---|
committer | Aleksi Lindeman <0xdec05eba@gmail.com> | 2018-03-07 02:52:35 +0100 |
commit | e96e47e4d1eb7217a0169013c9968b8eb52bbb4e (patch) | |
tree | 00a52f662e09634cad31b143c1ca99241536a9db /tests | |
parent | 91418b32d7b67c335eb3baffc0bf381c04f68035 (diff) |
Make serializer/deserializer endian independent0.2.0
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.cpp | 17 |
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 +} |