test/nbt_size_helpers: begin adding unit tests for lib/nbt's new nextTag size helpers

BodgeMaster-unfinished
BodgeMaster 2022-08-13 15:47:08 +02:00
parent 86f1ef596f
commit 0c92bdf8fd
3 changed files with 64 additions and 1 deletions

View File

@ -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/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_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_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 for command in ${!COMPILE_COMMANDS[@]}; do
echo "${COMPILE_COMMANDS[command]}" echo "${COMPILE_COMMANDS[command]}"

View File

@ -26,7 +26,7 @@
int main(){ int main(){
std::cout << "################################################################################" << std::endl; std::cout << "################################################################################" << std::endl;
std::cout << "NBT helper tests" << std::endl; std::cout << "NBT read/write helper tests" << std::endl;
std::cout << "################################################################################" << std::endl; std::cout << "################################################################################" << std::endl;
// used for all integer tests // used for all integer tests

View File

@ -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 <iostream>
#include <cstdint>
#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<uint64_t> totalSize = NBT::helper::nextTagTotalSize(endTestData, 34, 0);
ErrorOr<int32_t> 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;
}