diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/SchematicFileSerializer/CMakeLists.txt | 93 | ||||
-rw-r--r-- | tests/SchematicFileSerializer/SchematicFileSerializerTest.cpp | 43 | ||||
-rw-r--r-- | tests/SchematicFileSerializer/Stubs.cpp | 193 |
4 files changed, 330 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 61f34d9fb..17ad2baa4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,3 +14,4 @@ add_subdirectory(CompositeChat) add_subdirectory(HTTP) add_subdirectory(LoadablePieces) add_subdirectory(Network) +add_subdirectory(SchematicFileSerializer) diff --git a/tests/SchematicFileSerializer/CMakeLists.txt b/tests/SchematicFileSerializer/CMakeLists.txt new file mode 100644 index 000000000..43b19e4c3 --- /dev/null +++ b/tests/SchematicFileSerializer/CMakeLists.txt @@ -0,0 +1,93 @@ +cmake_minimum_required (VERSION 2.6) + +enable_testing() + +include_directories(${CMAKE_SOURCE_DIR}/src/) +include_directories(${CMAKE_SOURCE_DIR}/lib/) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +add_definitions(-DTEST_GLOBALS=1) + +set (SHARED_SRCS + ${CMAKE_SOURCE_DIR}/src/BiomeDef.cpp + ${CMAKE_SOURCE_DIR}/src/BlockArea.cpp + ${CMAKE_SOURCE_DIR}/src/Cuboid.cpp + ${CMAKE_SOURCE_DIR}/src/ChunkData.cpp + ${CMAKE_SOURCE_DIR}/src/StringCompression.cpp + ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp + + ${CMAKE_SOURCE_DIR}/src/Noise/Noise.cpp + + ${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.cpp + ${CMAKE_SOURCE_DIR}/src/OSSupport/Event.cpp + ${CMAKE_SOURCE_DIR}/src/OSSupport/File.cpp + ${CMAKE_SOURCE_DIR}/src/OSSupport/GZipFile.cpp + ${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp + + ${CMAKE_SOURCE_DIR}/src/WorldStorage/FastNBT.cpp + ${CMAKE_SOURCE_DIR}/src/WorldStorage/SchematicFileSerializer.cpp +) + +set (SHARED_HDRS + ${CMAKE_SOURCE_DIR}/src/BiomeDef.h + ${CMAKE_SOURCE_DIR}/src/BlockArea.h + ${CMAKE_SOURCE_DIR}/src/Cuboid.h + ${CMAKE_SOURCE_DIR}/src/ChunkData.h + ${CMAKE_SOURCE_DIR}/src/Globals.h + ${CMAKE_SOURCE_DIR}/src/StringCompression.h + ${CMAKE_SOURCE_DIR}/src/StringUtils.h + + ${CMAKE_SOURCE_DIR}/src/Bindings/LuaState.h + + ${CMAKE_SOURCE_DIR}/src/Generating/ChunkDesc.h + ${CMAKE_SOURCE_DIR}/src/Generating/PieceGenerator.h + ${CMAKE_SOURCE_DIR}/src/Generating/Prefab.h + ${CMAKE_SOURCE_DIR}/src/Generating/PrefabPiecePool.h + ${CMAKE_SOURCE_DIR}/src/Generating/VerticalLimit.h + ${CMAKE_SOURCE_DIR}/src/Generating/VerticalStrategy.h + + ${CMAKE_SOURCE_DIR}/src/Noise/Noise.h + + ${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.h + ${CMAKE_SOURCE_DIR}/src/OSSupport/Event.h + ${CMAKE_SOURCE_DIR}/src/OSSupport/File.h + ${CMAKE_SOURCE_DIR}/src/OSSupport/GZipFile.h + ${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.h + + ${CMAKE_SOURCE_DIR}/src/WorldStorage/FastNBT.h + ${CMAKE_SOURCE_DIR}/src/WorldStorage/SchematicFileSerializer.h +) + +set (SRCS + SchematicFileSerializerTest.cpp + Stubs.cpp +) + + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_flags_cxx("-Wno-error=conversion -Wno-error=old-style-cast") + add_flags_cxx("-Wno-error=global-constructors") + add_flags_cxx("-Wno-error=switch-enum") +endif() + + +if (MSVC) + # Add the MSVC-specific LeakFinder sources: + list (APPEND SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/LeakFinder.cpp ${CMAKE_SOURCE_DIR}/src/StackWalker.cpp) + list (APPEND SHARED_HDRS ${CMAKE_SOURCE_DIR}/src/LeakFinder.h ${CMAKE_SOURCE_DIR}/src/StackWalker.h) +endif() + +source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS}) +source_group("Sources" FILES ${SRCS}) +add_executable(SchematicFileSerializer-exe ${SRCS} ${SHARED_SRCS} ${SHARED_HDRS}) +target_link_libraries(SchematicFileSerializer-exe zlib) +add_test(NAME SchematicFileSerializer-test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND SchematicFileSerializer-exe) + + + + +# Put the projects into solution folders (MSVC): +set_target_properties( + SchematicFileSerializer-exe + PROPERTIES FOLDER Tests +) diff --git a/tests/SchematicFileSerializer/SchematicFileSerializerTest.cpp b/tests/SchematicFileSerializer/SchematicFileSerializerTest.cpp new file mode 100644 index 000000000..fc18daf93 --- /dev/null +++ b/tests/SchematicFileSerializer/SchematicFileSerializerTest.cpp @@ -0,0 +1,43 @@ + +// SchematicFileSerializerTest.cpp + +// Implements the SchematicFileSerializer test main entrypoint + +#include "Globals.h" +#include "WorldStorage/SchematicFileSerializer.h" + + + + + +static void DoTest(void) +{ + cBlockArea ba; + ba.Create(21, 256, 21); + ba.RelLine(0, 0, 0, 9, 8, 7, cBlockArea::baTypes | cBlockArea::baMetas, E_BLOCK_WOODEN_STAIRS, 1); + AString Schematic; + if (!cSchematicFileSerializer::SaveToSchematicString(ba, Schematic)) + { + assert_test(!"Schematic failed to save!"); + } + cBlockArea ba2; + if (!cSchematicFileSerializer::LoadFromSchematicString(ba2, Schematic)) + { + assert_test(!"Schematic failed to load!"); + } +} + + + + + +int main(int argc, char * argv[]) +{ + DoTest(); + LOG("SchematicFileSerializer test done."); + return 0; +} + + + + diff --git a/tests/SchematicFileSerializer/Stubs.cpp b/tests/SchematicFileSerializer/Stubs.cpp new file mode 100644 index 000000000..2fb500436 --- /dev/null +++ b/tests/SchematicFileSerializer/Stubs.cpp @@ -0,0 +1,193 @@ + +// Stubs.cpp + +// Implements stubs of various Cuberite methods that are needed for linking but not for runtime +// This is required so that we don't bring in the entire Cuberite via dependencies + +#include "Globals.h" +#include "BlockInfo.h" +#include "Blocks/BlockHandler.h" + + + + + +cBlockInfo::~cBlockInfo() +{ +} + + + + + +void cBlockInfo::Initialize(cBlockInfo::cBlockInfoArray & a_BlockInfos) +{ + // The piece-loading code uses the handlers for rotations, so we need valid handlers + // Insert dummy handlers: + for (size_t i = 0; i < ARRAYCOUNT(a_BlockInfos); i++) + { + a_BlockInfos[i].m_Handler = new cBlockHandler(static_cast<BLOCKTYPE>(i)); + } +} + + + + + +cBlockHandler::cBlockHandler(BLOCKTYPE a_BlockType) +{ +} + + + + + +bool cBlockHandler::GetPlacementBlockTypeMeta( + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta +) +{ + return true; +} + + + + + +void cBlockHandler::OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ) +{ +} + + + + + +void cBlockHandler::OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, const sSetBlock & a_BlockChange) +{ +} + + + + + +void cBlockHandler::OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) +{ +} + + + + + +void cBlockHandler::OnPlaced(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +{ +} + + + + + +void cBlockHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) +{ +} + + + + + +void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_WhichNeighbor) +{ +} + + + + + +void cBlockHandler::ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) +{ +} + + + + + +void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop) +{ +} + + + + + +bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, const cChunk & a_Chunk) +{ + return true; +} + + + + + +bool cBlockHandler::IsUseable() +{ + return false; +} + + + + + +bool cBlockHandler::IsClickedThrough(void) +{ + return false; +} + + + + + +bool cBlockHandler::DoesIgnoreBuildCollision(void) +{ + return (m_BlockType == E_BLOCK_AIR); +} + + + + + +bool cBlockHandler::DoesDropOnUnsuitable(void) +{ + return true; +} + + + + + +void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) +{ +} + + + + + +ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) +{ + return 0; +} + + + + + +bool cBlockHandler::IsInsideBlock(const Vector3d & a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) +{ + return true; +} + + + + + |