diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-02-01 20:56:03 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-06 07:16:10 +0200 |
commit | 6fd8decb98ce81fd71cebd0226e30b0024ffd77c (patch) | |
tree | 7428c0f539af0a36f5ffe31e59757ae3027bb96d /tests | |
parent | bf9ff3ab31a996a0d6628eb23291d4a4b59543ec (diff) |
Initial commit
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 0000000..e495b3a --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,40 @@ +#include <cstdio> +#include <cstdlib> +#include <sibs/SafeSerializer.hpp> +#include <sibs/SafeDeserializer.hpp> +#include <cstdint> + +#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) + +int main() +{ + 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); + + sibs::SafeDeserializer deserializer(serializer.getBuffer().data(), serializer.getBuffer().size()); + REQUIRE(deserializer.extract<uint32_t>() == 3563634); + REQUIRE(deserializer.extract<uint64_t>() == 204232532533423632); + REQUIRE(deserializer.extract<uint8_t>() == 2); + char str[6]; + str[5] = '\0'; + deserializer.extract((uint8_t*)str, 5); + REQUIRE(strcmp(str, "hello") == 0); + REQUIRE(deserializer.empty()); + + try + { + deserializer.extract<uint8_t>(); + FAIL("Expected extract to fail since we have extracted all data"); + } + catch (sibs::DeserializeException &e) + { + + } + + return 0; +}
\ No newline at end of file |