tests cleanup, NBT UTF

The UTF8 implementaion is ripped from openjdk-source's java source code, adapted by me for c++
v1
Brett 2023-01-29 15:24:33 -05:00
parent 33b0b7bbbb
commit 483713b265
15 changed files with 449 additions and 103 deletions

View File

@ -26,10 +26,13 @@ else()
set(NBT_FILES "")
endif()
#include parallel hashmaps if the user decided to download the submodule.
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/libraries/parallel-hashmap/CMakeLists.txt)
set(USE_PHMAPS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libraries/parallel-hashmap/)
#include zlib if the user has it.
find_package(ZLIB QUIET)
if (${ZLIB_FOUND})
include_directories(${ZLIB_INCLUDE_DIRS})
else()
message("ZLIB was not found, this is fine however if you wish you use gzip with NBT it is required.")
endif()
include_directories(include/)
@ -39,12 +42,16 @@ message("Profiler Files ${PROFILING_FILES}")
message("Source: ${CMAKE_SOURCE_DIR}")
message("Current Source: ${CMAKE_CURRENT_SOURCE_DIR}")
add_library(BLT ${STD_FILES} ${PROFILING_FILES} ${NBT_FILES})
target_include_directories(BLT PUBLIC include/)
configure_file(include/blt/config.h.in config/blt/config.h @ONLY)
if(${USE_PHMAPS})
target_link_libraries(BLT phmap)
add_library(BLT ${STD_FILES} ${PROFILING_FILES} ${NBT_FILES})
target_include_directories(BLT PUBLIC include/)
target_include_directories(BLT PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/config/)
if(${ZLIB_FOUND})
target_link_libraries(BLT PUBLIC ZLIB::ZLIB)
endif()
message("BLT ${CMAKE_PROJECT_VERSION} Successfully included!")
if(${BUILD_TESTS})

View File

@ -266,6 +266,15 @@ PHMAP_BUILD_TESTS:BOOL=OFF
//Enable installation
PHMAP_INSTALL:BOOL=OFF
//Path to a file.
ZLIB_INCLUDE_DIR:PATH=/usr/include
//Path to a library.
ZLIB_LIBRARY_DEBUG:FILEPATH=ZLIB_LIBRARY_DEBUG-NOTFOUND
//Path to a library.
ZLIB_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/libz.so
//Value Computed by CMake
phmap_BINARY_DIR:STATIC=/home/brett/Documents/code/c++/BLT/cmake-build-release/libraries/parallel-hashmap
@ -419,6 +428,14 @@ CMAKE_STRIP-ADVANCED:INTERNAL=1
CMAKE_UNAME:INTERNAL=/usr/bin/uname
//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE
CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1
//Details about finding ZLIB
FIND_PACKAGE_MESSAGE_DETAILS_ZLIB:INTERNAL=[/usr/lib/x86_64-linux-gnu/libz.so][/usr/include][v1.2.13()]
//ADVANCED property for variable: ZLIB_INCLUDE_DIR
ZLIB_INCLUDE_DIR-ADVANCED:INTERNAL=1
//ADVANCED property for variable: ZLIB_LIBRARY_DEBUG
ZLIB_LIBRARY_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: ZLIB_LIBRARY_RELEASE
ZLIB_LIBRARY_RELEASE-ADVANCED:INTERNAL=1
//linker supports push/pop state
_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED:INTERNAL=TRUE

View File

@ -52,35 +52,42 @@ build cmake_object_order_depends_target_BLT: phony || CMakeFiles/BLT.dir
build CMakeFiles/BLT.dir/src/blt/std/format.cpp.o: CXX_COMPILER__BLT_Release /home/brett/Documents/code/c++/BLT/src/blt/std/format.cpp || cmake_object_order_depends_target_BLT
DEP_FILE = CMakeFiles/BLT.dir/src/blt/std/format.cpp.o.d
FLAGS = -O3 -DNDEBUG -fdiagnostics-color=always
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include -I/home/brett/Documents/code/c++/BLT/cmake-build-release/config
OBJECT_DIR = CMakeFiles/BLT.dir
OBJECT_FILE_DIR = CMakeFiles/BLT.dir/src/blt/std
build CMakeFiles/BLT.dir/src/blt/std/logging.cpp.o: CXX_COMPILER__BLT_Release /home/brett/Documents/code/c++/BLT/src/blt/std/logging.cpp || cmake_object_order_depends_target_BLT
DEP_FILE = CMakeFiles/BLT.dir/src/blt/std/logging.cpp.o.d
FLAGS = -O3 -DNDEBUG -fdiagnostics-color=always
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include -I/home/brett/Documents/code/c++/BLT/cmake-build-release/config
OBJECT_DIR = CMakeFiles/BLT.dir
OBJECT_FILE_DIR = CMakeFiles/BLT.dir/src/blt/std
build CMakeFiles/BLT.dir/src/blt/std/system.cpp.o: CXX_COMPILER__BLT_Release /home/brett/Documents/code/c++/BLT/src/blt/std/system.cpp || cmake_object_order_depends_target_BLT
DEP_FILE = CMakeFiles/BLT.dir/src/blt/std/system.cpp.o.d
FLAGS = -O3 -DNDEBUG -fdiagnostics-color=always
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include -I/home/brett/Documents/code/c++/BLT/cmake-build-release/config
OBJECT_DIR = CMakeFiles/BLT.dir
OBJECT_FILE_DIR = CMakeFiles/BLT.dir/src/blt/std
build CMakeFiles/BLT.dir/src/blt/profiling/profiler.cpp.o: CXX_COMPILER__BLT_Release /home/brett/Documents/code/c++/BLT/src/blt/profiling/profiler.cpp || cmake_object_order_depends_target_BLT
DEP_FILE = CMakeFiles/BLT.dir/src/blt/profiling/profiler.cpp.o.d
FLAGS = -O3 -DNDEBUG -fdiagnostics-color=always
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include -I/home/brett/Documents/code/c++/BLT/cmake-build-release/config
OBJECT_DIR = CMakeFiles/BLT.dir
OBJECT_FILE_DIR = CMakeFiles/BLT.dir/src/blt/profiling
build CMakeFiles/BLT.dir/src/blt/nbt/nbt.cpp.o: CXX_COMPILER__BLT_Release /home/brett/Documents/code/c++/BLT/src/blt/nbt/nbt.cpp || cmake_object_order_depends_target_BLT
DEP_FILE = CMakeFiles/BLT.dir/src/blt/nbt/nbt.cpp.o.d
FLAGS = -O3 -DNDEBUG -fdiagnostics-color=always
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include -I/home/brett/Documents/code/c++/BLT/cmake-build-release/config
OBJECT_DIR = CMakeFiles/BLT.dir
OBJECT_FILE_DIR = CMakeFiles/BLT.dir/src/blt/nbt
build CMakeFiles/BLT.dir/src/blt/nbt/nbt_block.cpp.o: CXX_COMPILER__BLT_Release /home/brett/Documents/code/c++/BLT/src/blt/nbt/nbt_block.cpp || cmake_object_order_depends_target_BLT
DEP_FILE = CMakeFiles/BLT.dir/src/blt/nbt/nbt_block.cpp.o.d
FLAGS = -O3 -DNDEBUG -fdiagnostics-color=always
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include -I/home/brett/Documents/code/c++/BLT/cmake-build-release/config
OBJECT_DIR = CMakeFiles/BLT.dir
OBJECT_FILE_DIR = CMakeFiles/BLT.dir/src/blt/nbt
@ -92,7 +99,7 @@ build CMakeFiles/BLT.dir/src/blt/nbt/nbt_block.cpp.o: CXX_COMPILER__BLT_Release
#############################################
# Link the static library libBLT.a
build libBLT.a: CXX_STATIC_LIBRARY_LINKER__BLT_Release CMakeFiles/BLT.dir/src/blt/std/format.cpp.o CMakeFiles/BLT.dir/src/blt/std/logging.cpp.o CMakeFiles/BLT.dir/src/blt/std/system.cpp.o CMakeFiles/BLT.dir/src/blt/profiling/profiler.cpp.o CMakeFiles/BLT.dir/src/blt/nbt/nbt_block.cpp.o
build libBLT.a: CXX_STATIC_LIBRARY_LINKER__BLT_Release CMakeFiles/BLT.dir/src/blt/std/format.cpp.o CMakeFiles/BLT.dir/src/blt/std/logging.cpp.o CMakeFiles/BLT.dir/src/blt/std/system.cpp.o CMakeFiles/BLT.dir/src/blt/profiling/profiler.cpp.o CMakeFiles/BLT.dir/src/blt/nbt/nbt.cpp.o CMakeFiles/BLT.dir/src/blt/nbt/nbt_block.cpp.o
LANGUAGE_COMPILE_FLAGS = -O3 -DNDEBUG
OBJECT_DIR = CMakeFiles/BLT.dir
POST_BUILD = :
@ -112,7 +119,7 @@ build cmake_object_order_depends_target_BLT_TESTS: phony || cmake_object_order_d
build CMakeFiles/BLT_TESTS.dir/src/tests/main.cpp.o: CXX_COMPILER__BLT_TESTS_Release /home/brett/Documents/code/c++/BLT/src/tests/main.cpp || cmake_object_order_depends_target_BLT_TESTS
DEP_FILE = CMakeFiles/BLT_TESTS.dir/src/tests/main.cpp.o.d
FLAGS = -O3 -DNDEBUG -fdiagnostics-color=always -fsanitize=address
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include
INCLUDES = -I/home/brett/Documents/code/c++/BLT/include -I/home/brett/Documents/code/c++/BLT/cmake-build-release/config
OBJECT_DIR = CMakeFiles/BLT_TESTS.dir
OBJECT_FILE_DIR = CMakeFiles/BLT_TESTS.dir/src/tests
@ -124,10 +131,10 @@ build CMakeFiles/BLT_TESTS.dir/src/tests/main.cpp.o: CXX_COMPILER__BLT_TESTS_Rel
#############################################
# Link the executable BLT_TESTS
build BLT_TESTS: CXX_EXECUTABLE_LINKER__BLT_TESTS_Release CMakeFiles/BLT_TESTS.dir/src/tests/main.cpp.o | libBLT.a || libBLT.a
build BLT_TESTS: CXX_EXECUTABLE_LINKER__BLT_TESTS_Release CMakeFiles/BLT_TESTS.dir/src/tests/main.cpp.o | libBLT.a /usr/lib/x86_64-linux-gnu/libz.so || libBLT.a
FLAGS = -O3 -DNDEBUG
LINK_FLAGS = -fsanitize=address
LINK_LIBRARIES = libBLT.a
LINK_LIBRARIES = libBLT.a /usr/lib/x86_64-linux-gnu/libz.so
OBJECT_DIR = CMakeFiles/BLT_TESTS.dir
POST_BUILD = :
PRE_LINK = :
@ -179,14 +186,14 @@ build all: phony libBLT.a BLT_TESTS
#############################################
# Re-run CMake if any of its inputs changed.
build build.ninja: RERUN_CMAKE | /home/brett/Documents/code/c++/BLT/CMakeLists.txt /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCXXInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCommonLanguageInclude.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeGenericSystem.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeInitializeConfigs.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeLanguageInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeSystemSpecificInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeSystemSpecificInitialize.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/CMakeCommonCompilerMacros.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU-C.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU-CXX.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU-C.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU-CXX.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/UnixPaths.cmake CMakeCache.txt CMakeFiles/3.24.2/CMakeCCompiler.cmake CMakeFiles/3.24.2/CMakeCXXCompiler.cmake CMakeFiles/3.24.2/CMakeSystem.cmake
build build.ninja: RERUN_CMAKE | /home/brett/Documents/code/c++/BLT/CMakeLists.txt /home/brett/Documents/code/c++/BLT/include/blt/config.h.in /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCXXInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCommonLanguageInclude.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeGenericSystem.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeInitializeConfigs.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeLanguageInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeSystemSpecificInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeSystemSpecificInitialize.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/CMakeCommonCompilerMacros.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU-C.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU-CXX.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/FindPackageMessage.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/FindZLIB.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU-C.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU-CXX.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/UnixPaths.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/SelectLibraryConfigurations.cmake CMakeCache.txt CMakeFiles/3.24.2/CMakeCCompiler.cmake CMakeFiles/3.24.2/CMakeCXXCompiler.cmake CMakeFiles/3.24.2/CMakeSystem.cmake
pool = console
#############################################
# A missing CMake input file is not an error.
build /home/brett/Documents/code/c++/BLT/CMakeLists.txt /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCXXInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCommonLanguageInclude.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeGenericSystem.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeInitializeConfigs.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeLanguageInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeSystemSpecificInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeSystemSpecificInitialize.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/CMakeCommonCompilerMacros.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU-C.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU-CXX.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU-C.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU-CXX.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/UnixPaths.cmake CMakeCache.txt CMakeFiles/3.24.2/CMakeCCompiler.cmake CMakeFiles/3.24.2/CMakeCXXCompiler.cmake CMakeFiles/3.24.2/CMakeSystem.cmake: phony
build /home/brett/Documents/code/c++/BLT/CMakeLists.txt /home/brett/Documents/code/c++/BLT/include/blt/config.h.in /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCXXInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeCommonLanguageInclude.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeGenericSystem.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeInitializeConfigs.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeLanguageInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeSystemSpecificInformation.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/CMakeSystemSpecificInitialize.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/CMakeCommonCompilerMacros.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU-C.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU-CXX.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Compiler/GNU.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/FindPackageMessage.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/FindZLIB.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU-C.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU-CXX.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux-GNU.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/Linux.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/Platform/UnixPaths.cmake /opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.24/Modules/SelectLibraryConfigurations.cmake CMakeCache.txt CMakeFiles/3.24.2/CMakeCCompiler.cmake CMakeFiles/3.24.2/CMakeCXXCompiler.cmake CMakeFiles/3.24.2/CMakeSystem.cmake: phony
#############################################

2
include/blt/config.h.in Normal file
View File

@ -0,0 +1,2 @@
#cmakedefine ZLIB_FOUND

View File

@ -7,6 +7,63 @@
#ifndef BLT_TESTS_NBT_H
#define BLT_TESTS_NBT_H
#include <blt/nbt/nbt_block.h>
#include <fstream>
#include <ios>
#include "blt/std/format.h"
namespace blt::nbt {
void writeUTF8String(std::fstream& stream, const std::string& str);
std::string readUTF8String(std::fstream& stream);
class NBTByteReader {
public:
virtual void readBytes(char* buffer, size_t bytes) = 0;
};
class NBTByteFStreamReader : public NBTByteReader {
private:
std::fstream& m_stream;
size_t m_bufferSize;
char* m_buffer;
size_t readIndex = 0;
public:
explicit NBTByteFStreamReader(std::fstream& stream, size_t bufferSize):
m_stream(stream), m_bufferSize(bufferSize), m_buffer(new char[bufferSize]) {}
explicit NBTByteFStreamReader(NBTByteFStreamReader& copy) = delete;
explicit NBTByteFStreamReader(NBTByteFStreamReader&& move) = delete;
NBTByteFStreamReader& operator=(const NBTByteFStreamReader& copy) = delete;
void readBytes(char* buffer, size_t bytes) override;
~NBTByteFStreamReader() {
delete[] m_buffer;
}
};
class NBTDecoder {
private:
NBTByteReader* m_reader;
public:
explicit NBTDecoder(NBTByteReader* reader): m_reader(reader) {}
};
/**
* Reads the entire NBT file when the read() function is called.
*/
class NBTReader {
private:
std::string m_file;
public:
explicit NBTReader(std::string file): m_file(std::move(file)) {}
};
}
#endif //BLT_TESTS_NBT_H

View File

@ -62,3 +62,6 @@ namespace blt::profiling {
#define BLT_PRINT_PROFILE(profileName, ...) blt::profiling::printProfile(profileName, ##__VA_ARGS__);
#define BLT_PRINT_ORDERED(profileName, ...) blt::profiling::printOrderedProfile(profileName, ##__VA_ARGS__);
#endif
#define BLT_INTERVAL_START(profileName, intervalName) BLT_START_INTERVAL(profileName, intervalName)
#define BLT_INTERVAL_END(profileName, intervalName) BLT_END_INTERVAL(profileName, intervalName)

View File

@ -44,6 +44,123 @@ namespace blt::string {
return paddedString;
}
struct utf8_string {
char* characters;
unsigned int size;
};
// taken from java, adapted for c++.
static inline utf8_string createUTFString(const std::string& str) {
const unsigned int strlen = str.size();
unsigned int utflen = strlen;
for (int i = 0; i < strlen; i++) {
unsigned char c = str[i];
if (c >= 0x80 || c == 0)
utflen += (c >= 0x800) ? 2 : 1;
}
if (utflen > 65535 || /* overflow */ utflen < strlen)
throw "UTF Error";
utf8_string chars{};
chars.size = utflen + 2;
chars.characters = new char[chars.size];
int count = 0;
chars.characters[count++] = (char) ((utflen >> 0) & 0xFF);
chars.characters[count++] = (char) ((utflen >> 8) & 0xFF);
int i = 0;
for (i = 0; i < strlen; i++) { // optimized for initial run of ASCII
int c = (unsigned char) str[i];
if (c >= 0x80 || c == 0) break;
chars.characters[count++] = (char) c;
}
for (; i < strlen; i++) {
int c = (unsigned char) str[i];
if (c < 0x80 && c != 0) {
chars.characters[count++] = (char) c;
} else if (c >= 0x800) {
chars.characters[count++] = (char) (0xE0 | ((c >> 12) & 0x0F));
chars.characters[count++] = (char) (0x80 | ((c >> 6) & 0x3F));
chars.characters[count++] = (char) (0x80 | ((c >> 0) & 0x3F));
} else {
chars.characters[count++] = (char) (0xC0 | ((c >> 6) & 0x1F));
chars.characters[count++] = (char) (0x80 | ((c >> 0) & 0x3F));
}
}
return chars;
}
static inline std::string getStringFromUTF8(const utf8_string& str) {
auto utflen = str.size;
int c, char2, char3;
int count = 0;
int chararr_count = 0;
auto chararr = new char[utflen + 1];
while (count < utflen) {
c = (int) str.characters[count] & 0xff;
if (c > 127) break;
count++;
chararr[chararr_count++] = (char) c;
}
while (count < utflen) {
c = (int) str.characters[count] & 0xff;
switch (c >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
/* 0xxxxxxx*/
count++;
chararr[chararr_count++] = (char) c;
break;
case 12:
case 13:
/* 110x xxxx 10xx xxxx*/
count += 2;
if (count > utflen)
throw "malformed input: partial character at end";
char2 = (int) str.characters[count - 1];
if ((char2 & 0xC0) != 0x80)
throw "malformed input around byte " + std::to_string(count);
chararr[chararr_count++] = (char) (((c & 0x1F) << 6) |
(char2 & 0x3F));
case 14:
/* 1110 xxxx 10xx xxxx 10xx xxxx */
count += 3;
if (count > utflen)
throw "malformed input: partial character at end";
char2 = (int) str.characters[count - 2];
char3 = (int) str.characters[count - 1];
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
throw "malformed input around byte " + std::to_string(count - 1);
chararr[chararr_count++] = (char) (((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
break;
default:
/* 10xx xxxx, 1111 xxxx */
throw "malformed input around byte " + std::to_string(count);
break;
}
}
chararr[utflen] = '\0';
std::string strs {chararr};
delete[] chararr;
return strs;
}
struct TableColumn {
std::string columnName;
size_t maxColumnLength = 0;

View File

@ -4,8 +4,8 @@
* See LICENSE file for license detail
*/
#ifndef BLT_TESTS_LOGGING_H
#define BLT_TESTS_LOGGING_H
#ifndef BLT_LOGGING_H
#define BLT_LOGGING_H
#include <string>
@ -19,7 +19,7 @@ namespace blt::logging {
bool m_useColor = true;
bool m_logToConsole = true;
bool m_logToFile = true;
const char* m_directory = "./";
const char* m_directory = "./log/";
LOG_LEVEL minLevel = TRACE;
explicit constexpr LOG_PROPERTIES(bool useColor, bool logToConsole, bool logToFile, const char* directory):

49
src/blt/nbt/nbt.cpp Normal file
View File

@ -0,0 +1,49 @@
/*
* Created by Brett on 29/01/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#include <blt/nbt/nbt.h>
#include <cstring>
namespace blt::nbt {
void writeUTF8String(std::fstream& stream, const std::string& str) {
blt::string::utf8_string str8 = blt::string::createUTFString(str);
stream.write(str8.characters, str8.size);
delete[] str8.characters;
}
std::string readUTF8String(std::fstream& stream) {
unsigned short utflen;
stream.read(reinterpret_cast<char*>(&utflen), sizeof(utflen));
blt::string::utf8_string str{};
str.size = utflen;
str.characters = new char[str.size];
stream.read(str.characters, str.size);
auto strOut = std::move(blt::string::getStringFromUTF8(str));
delete[] str.characters;
return std::move(strOut);
}
void NBTByteFStreamReader::readBytes(char* buffer, size_t bytes) {
if (readIndex == 0)
m_stream.read(m_buffer, (long) m_bufferSize);
if (readIndex + bytes >= m_bufferSize) {
auto bytesLeft = m_bufferSize - readIndex;
memcpy(buffer, m_buffer + readIndex, bytesLeft);
readIndex = 0;
bytes -= bytesLeft;
readBytes(buffer + bytesLeft, bytes);
// m_stream.read(m_buffer, (long) m_bufferSize);
// memcpy(buffer + bytesLeft, m_buffer, bytes);
// readIndex += bytes;
} else {
std::memcpy(buffer, m_buffer + readIndex, bytes);
readIndex += bytes;
}
}
}

View File

@ -8,14 +8,5 @@
#include <fstream>
namespace blt::nbt {
/**
* Reads the entire NBT file when the read() function is called.
*/
class NBTReader {
private:
std::string m_file;
public:
explicit NBTReader(std::string file): m_file(std::move(file)) {}
};
}

View File

@ -84,7 +84,7 @@ namespace blt::logging {
};
// by default everything is enabled
LOG_PROPERTIES BLT_LOGGING_PROPERTIES{true, true, true, "./"};
LOG_PROPERTIES BLT_LOGGING_PROPERTIES{true, true, true, "./log/"};
LogFileWriter writer{"./"};
void init(LOG_PROPERTIES properties) {

30
src/tests/logging.h Normal file
View File

@ -0,0 +1,30 @@
/*
* Created by Brett on 29/01/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#ifndef BLT_TESTS_LOGGING_TEST_H
#define BLT_TESTS_LOGGING_TEST_H
void run_logging() {
BLT_TRACE(10);
BLT_TRACE(10.5);
BLT_TRACE("Hello %d World!\n", 50);
BLT_DEBUG("Hello %E World!\n", 1205200.0);
BLT_INFO("Hello World!\n");
BLT_WARN("Hello World!\n");
BLT_ERROR("Hello World!\n");
BLT_FATAL("Hello World!\n");
blt::logging::tlog << "Hello! " << "Double stream insertion! " << 51 << 65 << " ";
blt::logging::tlog << "Same Line! ";
blt::logging::tlog << "Write the end!\n";
blt::logging::tlog << "Seeee\n Super\n";
std::string hello = "superSexyMax";
std::cout << "String starts with: " << blt::string::contains(hello, "superSexyMaxE") << "\n";
}
#endif //BLT_TESTS_LOGGING_H

View File

@ -1,80 +1,18 @@
#include <unordered_map>
#include "binary_trees.h"
#include "blt/std/string.h"
#include "blt/profiling/profiler.h"
#include "blt/std/logging.h"
#include "blt/std/time.h"
#include "blt/std/format.h"
#include <chrono>
#include <thread>
void print(const std::vector<std::string>& vtr) {
for (const auto& line : vtr)
BLT_TRACE(line);
}
#include "logging.h"
#include "profiling_tests.h"
#include "nbt_tests.h"
int main() {
binaryTreeTest();
BLT_START_INTERVAL("Help", "SuperSet");
run_logging();
BLT_TRACE(10);
BLT_TRACE(10.5);
runProfilingAndTableTests();
BLT_TRACE("Hello %d World!\n", 50);
BLT_DEBUG("Hello %E World!\n", 1205200.0);
BLT_INFO("Hello World!\n");
BLT_WARN("Hello World!\n");
BLT_ERROR("Hello World!\n");
BLT_FATAL("Hello World!\n");
blt::logging::tlog << "Hello! " << "Double stream insertion! " << 51 << 65 << " ";
blt::logging::tlog << "Same Line! ";
blt::logging::tlog << "Write the end!\n";
blt::logging::tlog << "Seeee\n Super\n";
std::string hello = "superSexyMax";
std::cout << "String starts with: " << blt::string::contains(hello, "superSexyMaxE") << "\n";
BLT_END_INTERVAL("Help", "SuperSet");
BLT_START_INTERVAL("Help", "SecondSet");
for (int i = 0; i < 1000; i++){
;;
}
BLT_END_INTERVAL("Help", "SecondSet");
BLT_START_INTERVAL("Help", "UnderSet");
for (int i = 0; i < 1000; i++){
;;
}
BLT_END_INTERVAL("Help", "UnderSet");
for (int i = 0; i < 15; i++) {
BLT_START_INTERVAL("Help", "UnderSet" + std::to_string(i));
BLT_END_INTERVAL("Help", "UnderSet" + std::to_string(i));
}
BLT_PRINT_PROFILE("Help", blt::logging::LOG_LEVEL::TRACE);
BLT_PRINT_ORDERED("Help", blt::logging::LOG_LEVEL::TRACE);
blt::string::TableFormatter formatter;
formatter.addColumn(blt::string::TableColumn{"Test1"});
formatter.addColumn(blt::string::TableColumn{"Test2"});
formatter.addColumn(blt::string::TableColumn{"Test Column"});
formatter.addColumn(blt::string::TableColumn{"Test3"});
formatter.addRow({"This", "This LARGE", "222", "5000"});
formatter.addRow({"OTHER", "LARGE", "6", "1"});
formatter.addRow({"hheee", "looo", "m8", "loser"});
print(formatter.createTable(true, true));
BLT_TRACE("");
print(formatter.createTable(false, true));
BLT_TRACE("");
print(formatter.createTable(true, false));
BLT_TRACE("");
print(formatter.createTable(false, false));
nbt_tests();
return 0;
}

62
src/tests/nbt_tests.h Normal file
View File

@ -0,0 +1,62 @@
/*
* Created by Brett on 29/01/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#ifndef BLT_TESTS_NBT_TESTS_H
#define BLT_TESTS_NBT_TESTS_H
#include <blt/nbt/nbt.h>
#include <blt/profiling/profiler.h>
#include <blt/std/logging.h>
#include <blt/std/format.h>
inline void nbt_tests(){
std::fstream testOutput("Hello.txt", std::ios::out | std::ios::binary);
char testByte[] = {3, 'A', 91};
short testShort = 6132;
int testInt = 6600099;
testOutput.write(testByte, 3);
testOutput.write(reinterpret_cast<char*>(&testShort), sizeof(short));
testOutput.write(reinterpret_cast<char*>(&testInt), sizeof(int));
blt::nbt::writeUTF8String(testOutput, "HelloHowManyCanWeFit!");
//testOutput.flush();
testOutput.close();
std::fstream testInput("Hello.txt", std::ios::in | std::ios::binary);
char testByteIn[3];
short testShortIn;
int testIntIn;
testInput.read(testByteIn, 3);
testInput.read(reinterpret_cast<char*>(&testShortIn), sizeof(short));
testInput.read(reinterpret_cast<char*>(&testIntIn), sizeof(int));
std::string strIn = blt::nbt::readUTF8String(testInput);
testInput.close();
BLT_INFO("%d, %c, %d, %d, %d, %s", testByteIn[0], testByteIn[1], testByteIn[2], testShortIn, testIntIn, strIn.c_str());
auto bufferSize = 1024 * 128;
char* buffer = new char[bufferSize];
char* read_buffer = new char[bufferSize];
char* read_block_buffer = new char[bufferSize];
for (int i = 0; i < bufferSize; i++)
buffer[i] = i+1;
BLT_START_INTERVAL("nbt", "Raw Write");
std::fstream largeOutput("HeyThere.txt", std::ios::in | std::ios::binary);
largeOutput.write(buffer, bufferSize);
BLT_END_INTERVAL("nbt", "Raw Write");
}
#endif //BLT_TESTS_NBT_TESTS_H

View File

@ -0,0 +1,66 @@
/*
* Created by Brett on 29/01/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#ifndef BLT_TESTS_PROFILING_TESTS_H
#define BLT_TESTS_PROFILING_TESTS_H
#include "blt/profiling/profiler.h"
#include "blt/std/logging.h"
#include "blt/std/time.h"
#include "blt/std/format.h"
void print(const std::vector<std::string>& vtr) {
for (const auto& line : vtr)
BLT_TRACE(line);
}
static void runProfilingAndTableTests() {
BLT_START_INTERVAL("Help", "SuperSet");
BLT_END_INTERVAL("Help", "SuperSet");
BLT_START_INTERVAL("Help", "SecondSet");
for (int i = 0; i < 1000; i++){
;;
}
BLT_END_INTERVAL("Help", "SecondSet");
BLT_START_INTERVAL("Help", "UnderSet");
for (int i = 0; i < 1000; i++){
;;
}
BLT_END_INTERVAL("Help", "UnderSet");
for (int i = 0; i < 15; i++) {
BLT_START_INTERVAL("Help", "UnderSet" + std::to_string(i));
BLT_END_INTERVAL("Help", "UnderSet" + std::to_string(i));
}
BLT_PRINT_PROFILE("Help", blt::logging::LOG_LEVEL::TRACE);
BLT_TRACE("");
BLT_PRINT_ORDERED("Help", blt::logging::LOG_LEVEL::TRACE);
BLT_TRACE("");
blt::string::TableFormatter formatter;
formatter.addColumn(blt::string::TableColumn{"Test1"});
formatter.addColumn(blt::string::TableColumn{"Test2"});
formatter.addColumn(blt::string::TableColumn{"Test Column"});
formatter.addColumn(blt::string::TableColumn{"Test3"});
formatter.addRow({"This", "This LARGE", "222", "5000"});
formatter.addRow({"OTHER", "LARGE", "6", "1"});
formatter.addRow({"hheee", "looo", "m8", "opsiedo"});
print(formatter.createTable(true, true));
BLT_TRACE("");
print(formatter.createTable(false, true));
BLT_TRACE("");
print(formatter.createTable(true, false));
BLT_TRACE("");
print(formatter.createTable(false, false));
BLT_TRACE("");
}
#endif //BLT_TESTS_PROFILING_TESTS_H