diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-02-01 20:56:03 +0100 |
---|---|---|
committer | Aleksi Lindeman <aleksi_888@hotmail.com> | 2018-02-01 20:56:11 +0100 |
commit | 91418b32d7b67c335eb3baffc0bf381c04f68035 (patch) | |
tree | 37afbd00ee237b039baa83042567d7be9ec0f742 /tests | |
parent | d6f8d63dc4ed077fa986a78d6390fa4497110152 (diff) |
Initial commit0.1.0
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 |