From 9dcc93cc7937a059f34d06df7eb3c60de7ae6af4 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 22 Dec 2015 17:43:54 +0000 Subject: More NBTTests --- tests/WorldStorage/FastNBT/CMakeLists.txt | 10 ++++ tests/WorldStorage/FastNBT/ReadList.cpp | 34 ++++++++++++++ tests/WorldStorage/FastNBT/ReadTag.cpp | 77 +++++++++++++++++++++++++++++++ tests/WorldStorage/FastNBT/creatable.cpp | 5 +- 4 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 tests/WorldStorage/FastNBT/ReadList.cpp create mode 100644 tests/WorldStorage/FastNBT/ReadTag.cpp diff --git a/tests/WorldStorage/FastNBT/CMakeLists.txt b/tests/WorldStorage/FastNBT/CMakeLists.txt index 1f6f0ef8d..520d41b10 100644 --- a/tests/WorldStorage/FastNBT/CMakeLists.txt +++ b/tests/WorldStorage/FastNBT/CMakeLists.txt @@ -16,3 +16,13 @@ add_test(NAME fastnbt-creatable-test COMMAND fastnbt-creatable-exe) add_executable(fastnbt-parse-exe Parse.cpp) target_link_libraries(fastnbt-parse-exe TestFastNBT) add_test(NAME fastnbt-parse-test COMMAND fastnbt-parse-exe) + + +add_executable(fastnbt-readlist-exe ReadList.cpp) +target_link_libraries(fastnbt-readlist-exe TestFastNBT) +add_test(NAME fastnbt-readlist-test COMMAND fastnbt-readlist-exe) + + +add_executable(fastnbt-readtag-exe ReadTag.cpp) +target_link_libraries(fastnbt-readtag-exe TestFastNBT) +add_test(NAME fastnbt-readtag-test COMMAND fastnbt-readtag-exe) diff --git a/tests/WorldStorage/FastNBT/ReadList.cpp b/tests/WorldStorage/FastNBT/ReadList.cpp new file mode 100644 index 000000000..718784524 --- /dev/null +++ b/tests/WorldStorage/FastNBT/ReadList.cpp @@ -0,0 +1,34 @@ + +#include "Globals.h" +#include "WorldStorage/FastNBT.h" + +int main() { + { + // -1 items + char data[] = {10, 0, 0, 9, 0, 0, 0, -0x1, -0x1, -0x1, -0x1}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(!nbt.IsValid()); + } + { + // 1001 items + char data[] = {10, 0, 0, 9, 0, 0, 0, 0, 0, 3, -0x68}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(!nbt.IsValid()); + } + { + // single invalid + char data[] = {10, 0, 0, 9, 0, 0, -1, 0, 0, 0, 1, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(!nbt.IsValid()); + } + { + // two valid + char data[] = {10, 0, 0, 9, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(nbt.IsValid()); + } +} diff --git a/tests/WorldStorage/FastNBT/ReadTag.cpp b/tests/WorldStorage/FastNBT/ReadTag.cpp new file mode 100644 index 000000000..385e2daf3 --- /dev/null +++ b/tests/WorldStorage/FastNBT/ReadTag.cpp @@ -0,0 +1,77 @@ + + +#include "Globals.h" +#include "WorldStorage/FastNBT.h" + +int main() { + { + // TAG_BYTE + char data[] = {10, 0, 0, 1, 0, 0, 0, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(nbt.IsValid()); + } + { + // TAG_SHORT + char data[] = {10, 0, 0, 2, 0, 0, 0, 0, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(nbt.IsValid()); + } + { + // TAG_INT + char data[] = {10, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(nbt.IsValid()); + } + { + // TAG_LONG + char data[] = {10, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(nbt.IsValid()); + } + { + // TAG_FLOAT + char data[] = {10, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(nbt.IsValid()); + } + { + // TAG_DOUBLE + char data[] = {10, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(nbt.IsValid()); + } + { + // TAG_ByteArray negative length + char data[] = {10, 0, 0, 7, 0, 0, -1, -1, -1, -1, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(!nbt.IsValid()); + } + { + // TAG_Compound + char data[] = {10, 0, 0, 10, 0, 0, 0, 0, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(nbt.IsValid()); + } + { + // TAG_IntArray negative length + char data[] = {10, 0, 0, 11, 0, 0, -1, -1, -1, -1, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(!nbt.IsValid()); + } + { + // TAG_IntArray zero length + char data[] = {10, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0}; + cParsedNBT nbt{data, sizeof(data)}; + + testassert(nbt.IsValid()); + } +} diff --git a/tests/WorldStorage/FastNBT/creatable.cpp b/tests/WorldStorage/FastNBT/creatable.cpp index 677071c3d..a7a93b2ba 100644 --- a/tests/WorldStorage/FastNBT/creatable.cpp +++ b/tests/WorldStorage/FastNBT/creatable.cpp @@ -2,6 +2,7 @@ #include "WorldStorage/FastNBT.h" int main() { - cParsedNBT{}; - cFastNBTWriter test{}; + std::string test = ""; + cParsedNBT reader{test.c_str(), test.size()}; + cFastNBTWriter writer{}; } -- cgit v1.2.3