summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/WorldStorage/FastNBT.cpp7
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/WorldStorage/CMakeLists.txt5
-rw-r--r--tests/WorldStorage/FastNBT/CMakeLists.txt18
-rw-r--r--tests/WorldStorage/FastNBT/Parse.cpp26
-rw-r--r--tests/WorldStorage/FastNBT/creatable.cpp7
6 files changed, 64 insertions, 0 deletions
diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp
index 1a81a6469..d4e781af1 100644
--- a/src/WorldStorage/FastNBT.cpp
+++ b/src/WorldStorage/FastNBT.cpp
@@ -64,6 +64,13 @@ bool cParsedNBT::Parse(void)
// Data too short
return false;
}
+
+ if (m_Data == nullptr)
+ {
+ // Invalid Data
+ return false;
+ }
+
if (m_Data[0] != TAG_Compound)
{
// The top-level tag must be a Compound
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index bdab4bc58..81f0da471 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -11,3 +11,4 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(ChunkData)
add_subdirectory(Network)
add_subdirectory(LoadablePieces)
+add_subdirectory(WorldStorage)
diff --git a/tests/WorldStorage/CMakeLists.txt b/tests/WorldStorage/CMakeLists.txt
new file mode 100644
index 000000000..bdb61688d
--- /dev/null
+++ b/tests/WorldStorage/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required (VERSION 2.6)
+
+enable_testing()
+
+add_subdirectory(FastNBT)
diff --git a/tests/WorldStorage/FastNBT/CMakeLists.txt b/tests/WorldStorage/FastNBT/CMakeLists.txt
new file mode 100644
index 000000000..1f6f0ef8d
--- /dev/null
+++ b/tests/WorldStorage/FastNBT/CMakeLists.txt
@@ -0,0 +1,18 @@
+cmake_minimum_required (VERSION 2.6)
+
+enable_testing()
+
+include_directories(${CMAKE_SOURCE_DIR}/src/)
+
+
+add_definitions(-DTEST_GLOBALS=1)
+add_library(TestFastNBT ${CMAKE_SOURCE_DIR}/src/WorldStorage/FastNBT.cpp ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp)
+
+add_executable(fastnbt-creatable-exe creatable.cpp)
+target_link_libraries(fastnbt-creatable-exe TestFastNBT)
+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)
diff --git a/tests/WorldStorage/FastNBT/Parse.cpp b/tests/WorldStorage/FastNBT/Parse.cpp
new file mode 100644
index 000000000..a57e5861e
--- /dev/null
+++ b/tests/WorldStorage/FastNBT/Parse.cpp
@@ -0,0 +1,26 @@
+#include "Globals.h"
+#include "WorldStorage/FastNBT.h"
+
+int main() {
+ {
+ cParsedNBT nbt{nullptr, 0};
+
+ testassert(!nbt.IsValid());
+ }
+
+ {
+ cParsedNBT nbt{nullptr, 2};
+
+ testassert(!nbt.IsValid());
+ }
+ {
+ cParsedNBT nbt{"", 3};
+
+ testassert(!nbt.IsValid());
+ }
+ {
+ cParsedNBT nbt{nullptr, 3};
+
+ testassert(!nbt.IsValid());
+ }
+}
diff --git a/tests/WorldStorage/FastNBT/creatable.cpp b/tests/WorldStorage/FastNBT/creatable.cpp
new file mode 100644
index 000000000..677071c3d
--- /dev/null
+++ b/tests/WorldStorage/FastNBT/creatable.cpp
@@ -0,0 +1,7 @@
+#include "Globals.h"
+#include "WorldStorage/FastNBT.h"
+
+int main() {
+ cParsedNBT{};
+ cFastNBTWriter test{};
+}