diff options
author | tycho <work.tycho@gmail.com> | 2015-12-22 18:43:54 +0100 |
---|---|---|
committer | tycho <work.tycho@gmail.com> | 2016-01-18 17:31:46 +0100 |
commit | 9dcc93cc7937a059f34d06df7eb3c60de7ae6af4 (patch) | |
tree | 6f778e8c60303d40666cefb856a74b5ff6cedb3c | |
parent | More tests (diff) | |
download | cuberite-9dcc93cc7937a059f34d06df7eb3c60de7ae6af4.tar cuberite-9dcc93cc7937a059f34d06df7eb3c60de7ae6af4.tar.gz cuberite-9dcc93cc7937a059f34d06df7eb3c60de7ae6af4.tar.bz2 cuberite-9dcc93cc7937a059f34d06df7eb3c60de7ae6af4.tar.lz cuberite-9dcc93cc7937a059f34d06df7eb3c60de7ae6af4.tar.xz cuberite-9dcc93cc7937a059f34d06df7eb3c60de7ae6af4.tar.zst cuberite-9dcc93cc7937a059f34d06df7eb3c60de7ae6af4.zip |
-rw-r--r-- | tests/WorldStorage/FastNBT/CMakeLists.txt | 10 | ||||
-rw-r--r-- | tests/WorldStorage/FastNBT/ReadList.cpp | 34 | ||||
-rw-r--r-- | tests/WorldStorage/FastNBT/ReadTag.cpp | 77 | ||||
-rw-r--r-- | tests/WorldStorage/FastNBT/creatable.cpp | 5 |
4 files changed, 124 insertions, 2 deletions
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{}; } |