From 91418b32d7b67c335eb3baffc0bf381c04f68035 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 1 Feb 2018 20:56:03 +0100 Subject: Initial commit --- tests/main.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/main.cpp (limited to 'tests') 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 +#include +#include +#include +#include + +#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() == 3563634); + REQUIRE(deserializer.extract() == 204232532533423632); + REQUIRE(deserializer.extract() == 2); + char str[6]; + str[5] = '\0'; + deserializer.extract((uint8_t*)str, 5); + REQUIRE(strcmp(str, "hello") == 0); + REQUIRE(deserializer.empty()); + + try + { + deserializer.extract(); + FAIL("Expected extract to fail since we have extracted all data"); + } + catch (sibs::DeserializeException &e) + { + + } + + return 0; +} \ No newline at end of file -- cgit v1.2.3