FOSS-VG/src/test/nbt_size_helpers.cpp

63 lines
2.2 KiB
C++

// 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::totalTagSize(endTestData, 34, 0);
ErrorOr<int32_t> dataLength = NBT::helper::containedDataLength(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;
}