diff --git a/scripts/test.sh b/scripts/test.sh index 0088c60..56a7c1c 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -38,6 +38,7 @@ COMPILE_COMMANDS=( "$CXX_WITH_FLAGS src/test/javacompat.cpp -I./include -Lbin/lib -l:javacompat.so -o bin/test/javacompat" "$CXX_WITH_FLAGS src/test/nbt_write_string_failure_mode.cpp -I./include -Lbin/lib -l:nbt.so -l:javacompat.so -o bin/test/nbt_write_string_failure_mode" "$CXX_WITH_FLAGS src/test/nbt_tags.cpp -I./include -Lbin/lib -l:nbt.so -l:javacompat.so -o bin/test/nbt_tags" + "$CXX_WITH_FLAGS src/test/nbt_size_helpers.cpp -I./include -Lbin/lib -l:nbt.so -l:javacompat.so -o bin/test/nbt_size_helpers" ) for command in ${!COMPILE_COMMANDS[@]}; do echo "${COMPILE_COMMANDS[command]}" diff --git a/src/test/nbt_read_write_helpers.cpp b/src/test/nbt_read_write_helpers.cpp index d01d91b..cd08330 100644 --- a/src/test/nbt_read_write_helpers.cpp +++ b/src/test/nbt_read_write_helpers.cpp @@ -26,7 +26,7 @@ int main(){ std::cout << "################################################################################" << std::endl; - std::cout << "NBT helper tests" << std::endl; + std::cout << "NBT read/write helper tests" << std::endl; std::cout << "################################################################################" << std::endl; // used for all integer tests diff --git a/src/test/nbt_size_helpers.cpp b/src/test/nbt_size_helpers.cpp new file mode 100644 index 0000000..01a8fea --- /dev/null +++ b/src/test/nbt_size_helpers.cpp @@ -0,0 +1,62 @@ +// Copyright 2022, FOSS-VG Developers and Contributers +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied +// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// version 3 along with this program. +// If not, see https://www.gnu.org/licenses/agpl-3.0.en.html + +#include +#include + +#include "assert.hpp" + +#include "../lib/nbt.hpp" +#include "../lib/error.hpp" + +int main() { + std::cout + << "################################################################################\n" + << "NBT size helper tests\n" + << "################################################################################" + << std::endl; + + // end tag ######################################################### + // const uint8_t END = 0; + uint8_t endTestData[] = { + 0x00, 0x0a, 0x00, 0x11, 0x63, 0x6f, 0x6d, 0x70, + 0x6f, 0x75, 0x6e, 0x64, 0x5f, 0x6c, 0x65, 0x76, + 0x65, 0x6c, 0x5f, 0x32, 0x62, 0x05, 0x00, 0x03, + 0x33, 0x30, 0x30, 0x6e, 0x75, 0x6f, 0x70, 0x09, + 0x00, 0x03 + }; + ErrorOr totalSize = NBT::helper::nextTagTotalSize(endTestData, 34, 0); + ErrorOr dataLength = NBT::helper::nextTagDataLength(endTestData, 34, 0); + + ASSERT(!totalSize.isError); + ASSERT(totalSize.value == 1); + ASSERT(!dataLength.isError); + ASSERT(dataLength.value == 0); + + //const uint8_t INT8 = 1; + //const uint8_t INT16 = 2; + //const uint8_t INT32 = 3; + //const uint8_t INT64 = 4; + //const uint8_t FLOAT = 5; + //const uint8_t DOUBLE = 6; + //const uint8_t INT8_ARRAY = 7; + //const uint8_t STRING = 8; + //const uint8_t LIST = 9; + //const uint8_t COMPOUND = 10; + //const uint8_t INT32_ARRAY= 11; + //const uint8_t INT64_ARRAY= 12; + + return 0; +}