Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate GoogleTest and refactor ByteBuffer and BoundingBox tests #5539

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMake/AddDependencies.cmake
Expand Up @@ -28,6 +28,8 @@ function(build_dependencies)
set(ENABLE_PROGRAMS OFF CACHE BOOL "Build mbed TLS programs.")
set(ENABLE_TESTING OFF CACHE BOOL "Build mbed TLS tests.")

set(MBEDTLS_AS_SUBPROJECT ON CACHE BOOL "Use mbed TLS as subproject")

# Enumerate all submodule libraries
# SQLiteCpp needs to be included before sqlite so the lsqlite target is available:
set(DEPENDENCIES expat fmt jsoncpp libdeflate libevent lua luaexpat mbedtls SQLiteCpp sqlite tolua++)
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -4,6 +4,7 @@

cmake_minimum_required (VERSION 3.13)
cmake_policy(VERSION 3.13...3.17.2)
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES} "; Coverage")
project(
Cuberite
DESCRIPTION "A lightweight, fast and extensible game server for Minecraft"
Expand Down
21 changes: 21 additions & 0 deletions src/ChunkData.cpp
Expand Up @@ -72,6 +72,12 @@ void ChunkDataStore<ElementType, ElementCount, DefaultValue>::Assign(const Chunk
template<class ElementType, size_t ElementCount, ElementType DefaultValue>
ElementType ChunkDataStore<ElementType, ElementCount, DefaultValue>::Get(const Vector3i a_Position) const
{
if (!cChunkDef::IsValidRelPos(a_Position))
{
ASSERT(false);
UnpackDefaultValue<ElementCount>(DefaultValue);
}

const auto Indices = IndicesFromRelPos(a_Position);
const auto & Section = Store[Indices.Section];

Expand All @@ -97,6 +103,11 @@ ElementType ChunkDataStore<ElementType, ElementCount, DefaultValue>::Get(const V
template<class ElementType, size_t ElementCount, ElementType DefaultValue>
typename ChunkDataStore<ElementType, ElementCount, DefaultValue>::Type * ChunkDataStore<ElementType, ElementCount, DefaultValue>::GetSection(const size_t a_Y) const
{
if (a_Y >= cChunkDef::NumSections)
{
return nullptr;
}

return Store[a_Y].get();
}

Expand All @@ -107,6 +118,11 @@ typename ChunkDataStore<ElementType, ElementCount, DefaultValue>::Type * ChunkDa
template<class ElementType, size_t ElementCount, ElementType DefaultValue>
void ChunkDataStore<ElementType, ElementCount, DefaultValue>::Set(const Vector3i a_Position, const ElementType a_Value)
{
if (!cChunkDef::IsValidRelPos(a_Position))
{
return;
}

const auto Indices = IndicesFromRelPos(a_Position);
auto & Section = Store[Indices.Section];

Expand Down Expand Up @@ -138,6 +154,11 @@ void ChunkDataStore<ElementType, ElementCount, DefaultValue>::Set(const Vector3i
template<class ElementType, size_t ElementCount, ElementType DefaultValue>
void ChunkDataStore<ElementType, ElementCount, DefaultValue>::SetSection(const ElementType (& a_Source)[ElementCount], const size_t a_Y)
{
if (a_Y >= cChunkDef::NumSections)
{
return;
}

auto & Section = Store[a_Y];
const auto SourceEnd = std::end(a_Source);

Expand Down
8 changes: 5 additions & 3 deletions src/ChunkDef.h
Expand Up @@ -343,18 +343,20 @@ class cChunkDef
}


inline static void PackNibble(NIBBLETYPE * const a_Buffer, const size_t a_Index, const NIBBLETYPE a_Nibble)
template<typename T>
inline static void PackNibble(T * const a_Buffer, const size_t a_Index, const T a_Nibble)
{
ASSERT((a_Nibble & 0xF) == a_Nibble); // Only the lower bits should be set

a_Buffer[a_Index / 2] = static_cast<NIBBLETYPE>(
a_Buffer[a_Index / 2] = static_cast<T>(
(a_Buffer[a_Index / 2] & (0xf0 >> ((a_Index & 1) * 4))) | // The untouched nibble
((a_Nibble & 0x0f) << ((a_Index & 1) * 4)) // The nibble being set
);
}


inline static NIBBLETYPE ExpandNibble(const NIBBLETYPE * const a_Buffer, const size_t a_Index)
template<typename T>
inline static T ExpandNibble(const T * const a_Buffer, const size_t a_Index)
{
return (a_Buffer[a_Index / 2] >> ((a_Index & 1) * 4)) & 0x0f;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/BlockTypeRegistry/CMakeLists.txt
Expand Up @@ -65,10 +65,10 @@ file (COPY

# Define individual tests:

add_test(NAME BlockStateTest COMMAND BlockStateTest)
add_test(NAME BlockTypeRegistryTest COMMAND BlockTypeRegistryTest)
add_test(NAME BlockTypePaletteTest COMMAND BlockTypePaletteTest)
add_test(NAME PalettedBlockAreaTest COMMAND PalettedBlockAreaTest)
add_test_executable(BlockStateTest)
add_test_executable(BlockTypeRegistryTest)
add_test_executable(BlockTypePaletteTest)
add_test_executable(PalettedBlockAreaTest)



Expand Down