lib/error.hpp: fix merge conflicts

Soda
Shwoomple 2022-09-19 16:21:25 +05:30
commit e8d41efeef
9 changed files with 214 additions and 281 deletions

View File

@ -1,12 +0,0 @@
all: build
build:
bash ./scripts/build.sh
clean:
bash ./scripts/clean.sh
mrproper:
bash ./scripts/clean.sh
bash ./scripts/clean_dependencies.sh
setup:
bash ./scripts/setup_project.sh
test:
bash ./scripts/test.sh

Binary file not shown.

Binary file not shown.

View File

@ -89,10 +89,7 @@ namespace ErrorCodes {
const uint8_t NOT_YET_KNOWN = 7; const uint8_t NOT_YET_KNOWN = 7;
//file errors const uint8_t INVALID_TYPE = 8;
const uint8_t FILE_READ_FAILED = 8;
const uint8_t FILE_WRITE_FAILED = 9;
const uint8_t FILE_NOT_FOUND = 10;
const uint8_t UNIMPLEMENTED = 254; const uint8_t UNIMPLEMENTED = 254;

View File

@ -36,7 +36,7 @@
#endif #endif
namespace NBT { namespace NBT {
namespace helper { namespace Helper {
ErrorOr<int8_t> readInt8(uint8_t data[], uint64_t dataSize, uint64_t currentPosition) { ErrorOr<int8_t> readInt8(uint8_t data[], uint64_t dataSize, uint64_t currentPosition) {
if (currentPosition>=dataSize) return ErrorOr<int8_t>(true, ErrorCodes::OUT_OF_RANGE); if (currentPosition>=dataSize) return ErrorOr<int8_t>(true, ErrorCodes::OUT_OF_RANGE);
return ErrorOr<int8_t>((int8_t) data[currentPosition]); return ErrorOr<int8_t>((int8_t) data[currentPosition]);
@ -92,7 +92,7 @@ namespace NBT {
*(valueAsBytes+2) = data[currentPosition+1]; *(valueAsBytes+2) = data[currentPosition+1];
*(valueAsBytes+3) = data[currentPosition]; *(valueAsBytes+3) = data[currentPosition];
#else #else
#error "NBT::helper::readFloat: An implementation for your endianness is unavailable." #error "NBT::Helper::readFloat: An implementation for your endianness is unavailable."
#endif #endif
#endif #endif
float dereferencedValue = *value; float dereferencedValue = *value;
@ -126,7 +126,7 @@ namespace NBT {
*(valueAsBytes+6) = data[currentPosition+1]; *(valueAsBytes+6) = data[currentPosition+1];
*(valueAsBytes+7) = data[currentPosition]; *(valueAsBytes+7) = data[currentPosition];
#else #else
#error "NBT::helper::readDouble: An implementation for your endianness is unavailable." #error "NBT::Helper::readDouble: An implementation for your endianness is unavailable."
#endif #endif
#endif #endif
double dereferencedValue = *value; double dereferencedValue = *value;
@ -232,7 +232,7 @@ namespace NBT {
destination->push_back(*(valueAsBytes+1)); destination->push_back(*(valueAsBytes+1));
destination->push_back(*valueAsBytes); destination->push_back(*valueAsBytes);
#else #else
#error "NBT::helper::writeInt16: An implementation for your endianness is unavailable." #error "NBT::Helper::writeInt16: An implementation for your endianness is unavailable."
#endif #endif
#endif #endif
delete value; delete value;
@ -255,7 +255,7 @@ namespace NBT {
destination->push_back(*(valueAsBytes+1)); destination->push_back(*(valueAsBytes+1));
destination->push_back(*valueAsBytes); destination->push_back(*valueAsBytes);
#else #else
#error "NBT::helper::writeInt16: An implementation for your endianness is unavailable." #error "NBT::Helper::writeInt16: An implementation for your endianness is unavailable."
#endif #endif
#endif #endif
delete value; delete value;
@ -286,7 +286,7 @@ namespace NBT {
destination->push_back(*(valueAsBytes+1)); destination->push_back(*(valueAsBytes+1));
destination->push_back(*valueAsBytes); destination->push_back(*valueAsBytes);
#else #else
#error "NBT::helper::writeInt16: An implementation for your endianness is unavailable." #error "NBT::Helper::writeInt16: An implementation for your endianness is unavailable."
#endif #endif
#endif #endif
delete value; delete value;
@ -309,7 +309,7 @@ namespace NBT {
destination->push_back(*(valueAsBytes+1)); destination->push_back(*(valueAsBytes+1));
destination->push_back(*valueAsBytes); destination->push_back(*valueAsBytes);
#else #else
#error "NBT::helper::writeInt16: An implementation for your endianness is unavailable." #error "NBT::Helper::writeInt16: An implementation for your endianness is unavailable."
#endif #endif
#endif #endif
delete value; delete value;
@ -340,7 +340,7 @@ namespace NBT {
destination->push_back(*(valueAsBytes+1)); destination->push_back(*(valueAsBytes+1));
destination->push_back(*valueAsBytes); destination->push_back(*valueAsBytes);
#else #else
#error "NBT::helper::writeInt16: An implementation for your endianness is unavailable." #error "NBT::Helper::writeInt16: An implementation for your endianness is unavailable."
#endif #endif
#endif #endif
delete value; delete value;
@ -363,7 +363,7 @@ namespace NBT {
void writeString(std::vector<uint8_t>* destination, tiny_utf8::string data) { void writeString(std::vector<uint8_t>* destination, tiny_utf8::string data) {
ErrorOr<std::vector<uint8_t>> exportedString = JavaCompat::exportJavaString(data); ErrorOr<std::vector<uint8_t>> exportedString = JavaCompat::exportJavaString(data);
if(exportedString.isError){ if(exportedString.isError){
std::cerr << "NBT::helpers::writeString encountered an error: " << (int) exportedString.errorCode << std::endl; std::cerr << "NBT::Helpers::writeString encountered an error: " << (int) exportedString.errorCode << std::endl;
std::abort(); std::abort();
} }
*destination = exportedString.value; *destination = exportedString.value;
@ -426,7 +426,7 @@ namespace NBT {
// deal with end tag before trying to access the name // deal with end tag before trying to access the name
if (nextTag == TagType::END) return ErrorOr<uint64_t>(1); if (nextTag == TagType::END) return ErrorOr<uint64_t>(1);
ErrorOr<int16_t> nameSize = helper::readInt16(data, dataSize, currentPosition+1); ErrorOr<int16_t> nameSize = Helper::readInt16(data, dataSize, currentPosition+1);
if (nameSize.isError) { if (nameSize.isError) {
return ErrorOr<uint64_t>(true, nameSize.errorCode); return ErrorOr<uint64_t>(true, nameSize.errorCode);
} }
@ -446,28 +446,28 @@ namespace NBT {
case TagType::DOUBLE: case TagType::DOUBLE:
return ErrorOr<uint64_t>(prefixSize+8); return ErrorOr<uint64_t>(prefixSize+8);
case TagType::INT8_ARRAY: { case TagType::INT8_ARRAY: {
ErrorOr<int32_t> arrayLength = helper::readInt32(data, dataSize, currentPosition+prefixSize); ErrorOr<int32_t> arrayLength = Helper::readInt32(data, dataSize, currentPosition+prefixSize);
if (arrayLength.isError) { if (arrayLength.isError) {
return ErrorOr<uint64_t>(true, arrayLength.errorCode); return ErrorOr<uint64_t>(true, arrayLength.errorCode);
} }
return ErrorOr<uint64_t>((uint64_t) arrayLength.value + prefixSize + 4); return ErrorOr<uint64_t>((uint64_t) arrayLength.value + prefixSize + 4);
} }
case TagType::STRING: { case TagType::STRING: {
ErrorOr<int16_t> stringSize = helper::readInt16(data, dataSize, currentPosition+prefixSize); ErrorOr<int16_t> stringSize = Helper::readInt16(data, dataSize, currentPosition+prefixSize);
if (stringSize.isError) { if (stringSize.isError) {
return ErrorOr<uint64_t>(true, stringSize.errorCode); return ErrorOr<uint64_t>(true, stringSize.errorCode);
} }
return ErrorOr<uint64_t>((uint64_t) stringSize.value + prefixSize + 2); return ErrorOr<uint64_t>((uint64_t) stringSize.value + prefixSize + 2);
} }
case TagType::INT32_ARRAY: { case TagType::INT32_ARRAY: {
ErrorOr<int32_t> arrayLength = helper::readInt32(data, dataSize, currentPosition+prefixSize); ErrorOr<int32_t> arrayLength = Helper::readInt32(data, dataSize, currentPosition+prefixSize);
if (arrayLength.isError) { if (arrayLength.isError) {
return ErrorOr<uint64_t>(true, arrayLength.errorCode); return ErrorOr<uint64_t>(true, arrayLength.errorCode);
} }
return ErrorOr<uint64_t>((uint64_t) arrayLength.value*4 + prefixSize + 4); return ErrorOr<uint64_t>((uint64_t) arrayLength.value*4 + prefixSize + 4);
} }
case TagType::INT64_ARRAY: { case TagType::INT64_ARRAY: {
ErrorOr<int32_t> arrayLength = helper::readInt32(data, dataSize, currentPosition+prefixSize); ErrorOr<int32_t> arrayLength = Helper::readInt32(data, dataSize, currentPosition+prefixSize);
if (arrayLength.isError) { if (arrayLength.isError) {
return ErrorOr<uint64_t>(true, arrayLength.errorCode); return ErrorOr<uint64_t>(true, arrayLength.errorCode);
} }
@ -509,7 +509,7 @@ namespace NBT {
return ErrorOr<int32_t>(1); return ErrorOr<int32_t>(1);
} }
ErrorOr<int16_t> nameSize = helper::readInt16(data, dataSize, currentPosition+1); ErrorOr<int16_t> nameSize = Helper::readInt16(data, dataSize, currentPosition+1);
if (nameSize.isError) { if (nameSize.isError) {
return ErrorOr<int32_t>(true, nameSize.errorCode); return ErrorOr<int32_t>(true, nameSize.errorCode);
} }
@ -517,10 +517,10 @@ namespace NBT {
uint64_t prefixSize = (uint64_t) nameSize.value + 3; uint64_t prefixSize = (uint64_t) nameSize.value + 3;
switch (nextTag) { switch (nextTag) {
case TagType::INT8_ARRAY: { case TagType::INT8_ARRAY: {
return helper::readInt32(data, dataSize, currentPosition+prefixSize); return Helper::readInt32(data, dataSize, currentPosition+prefixSize);
} }
case TagType::STRING: { case TagType::STRING: {
ErrorOr<int16_t> stringSize = helper::readInt16(data, dataSize, currentPosition+prefixSize); ErrorOr<int16_t> stringSize = Helper::readInt16(data, dataSize, currentPosition+prefixSize);
if (stringSize.isError) { if (stringSize.isError) {
return ErrorOr<int32_t>(true, stringSize.errorCode); return ErrorOr<int32_t>(true, stringSize.errorCode);
} }
@ -528,13 +528,13 @@ namespace NBT {
} }
case TagType::LIST: { case TagType::LIST: {
// add an additional byte for the contained data type // add an additional byte for the contained data type
return helper::readInt32(data, dataSize, currentPosition+prefixSize+1); return Helper::readInt32(data, dataSize, currentPosition+prefixSize+1);
} }
case TagType::INT32_ARRAY: { case TagType::INT32_ARRAY: {
return helper::readInt32(data, dataSize, currentPosition+prefixSize); return Helper::readInt32(data, dataSize, currentPosition+prefixSize);
} }
case TagType::INT64_ARRAY: { case TagType::INT64_ARRAY: {
return helper::readInt32(data, dataSize, currentPosition+prefixSize); return Helper::readInt32(data, dataSize, currentPosition+prefixSize);
} }
default: default:
// unknown tag or parsing error // unknown tag or parsing error
@ -543,56 +543,15 @@ namespace NBT {
} }
} }
//Tag constructors // generic class that all tag types are derived from
template <typename T>
Tag<T>::Tag() {
}
template <typename T> template <typename T>
Tag<T>::Tag(uint8_t tagType, tiny_utf8::string name, uint16_t nameSize, T content, uint32_t size) ErrorOr<std::vector<uint8_t>> Tag<T>::toRawData() {
: tagType(tagType), name(name), nameSize(nameSize), content(content) ,size(size) return ErrorOr<std::vector<uint8_t>>(true, ErrorCodes::INVALID_TYPE);
{}
End::End() : Tag::Tag(0, "", 0, 0, 0) {}
Byte::Byte(tiny_utf8::string name, uint16_t nameSize, int8_t content)
: Tag::Tag(1, name, nameSize, content, 1)
{}
Byte::Byte(uint8_t data[]){
if(validate(data)){
this->tagType = 1;
uint8_t nameSizeSlice[] = {data[1], data[2]};
ErrorOr<int16_t> readIntResult = helper::readInt16(nameSizeSlice, 2, 0);
if(!readIntResult.isError){
this->nameSize = readIntResult.value;
}else{
throw readIntResult.errorCode;
}
uint8_t nameSlice[this->nameSize+2];
for(int i=0; i<this->nameSize+2; i++){
nameSlice[i] = data[i+1];
}
ErrorOr<tiny_utf8::string> readStringResult = helper::readString(nameSlice, this->nameSize, 0);
if(!readStringResult.isError){
this->name = readStringResult.value;
}else{
throw readStringResult.errorCode;
}
//int8 needs only one byte
this->content = data[this->nameSize+4];
}
}
//more conditions will be added
bool Byte::validate(uint8_t data[]){
if(data[0] == 0x01){
return true;
}else{
return false;
}
} }
bool validateRawListContents(uint8_t data[], uint64_t dataSize, uint64_t initialPosition, uint64_t* processedDataSize) { bool validateRawListContents(uint8_t data[], uint64_t dataSize, uint64_t initialPosition, uint64_t* processedDataSize) {
@ -601,7 +560,7 @@ namespace NBT {
// headerless tags // headerless tags
// //
// add one byte to position to skip the type byte // add one byte to position to skip the type byte
ErrorOr<int32_t> elementCount = helper::readInt32(data, dataSize, initialPosition+1); ErrorOr<int32_t> elementCount = Helper::readInt32(data, dataSize, initialPosition+1);
if (elementCount.isError) { if (elementCount.isError) {
return false; return false;
} }
@ -634,7 +593,7 @@ namespace NBT {
} }
case TagType::INT8_ARRAY: { case TagType::INT8_ARRAY: {
for (int32_t i=0; i<elementCount.value; i++) { for (int32_t i=0; i<elementCount.value; i++) {
ErrorOr<std::vector<int8_t>> nextArray = helper::readInt8Array(data, dataSize, initialPosition+*processedDataSize); ErrorOr<std::vector<int8_t>> nextArray = Helper::readInt8Array(data, dataSize, initialPosition+*processedDataSize);
if (nextArray.isError) { if (nextArray.isError) {
return false; return false;
} }
@ -644,12 +603,12 @@ namespace NBT {
} }
case TagType::STRING: { case TagType::STRING: {
for (int32_t i=0; i<elementCount.value; i++) { for (int32_t i=0; i<elementCount.value; i++) {
ErrorOr<tiny_utf8::string> nextString = helper::readString(data, dataSize, initialPosition+*processedDataSize); ErrorOr<tiny_utf8::string> nextString = Helper::readString(data, dataSize, initialPosition+*processedDataSize);
if (nextString.isError) { if (nextString.isError) {
return false; return false;
} }
// this cannot be an error because it just got checked // this cannot be an error because it just got checked
int16_t nextStringSize = helper::readInt16(data, dataSize, initialPosition+*processedDataSize).value; int16_t nextStringSize = Helper::readInt16(data, dataSize, initialPosition+*processedDataSize).value;
*processedDataSize += (uint64_t) nextStringSize + 2; *processedDataSize += (uint64_t) nextStringSize + 2;
} }
return true; return true;
@ -685,7 +644,7 @@ namespace NBT {
} }
case TagType::INT32_ARRAY: { case TagType::INT32_ARRAY: {
for (int32_t i=0; i<elementCount.value; i++) { for (int32_t i=0; i<elementCount.value; i++) {
ErrorOr<std::vector<int32_t>> nextArray = helper::readInt32Array(data, dataSize, initialPosition+*processedDataSize); ErrorOr<std::vector<int32_t>> nextArray = Helper::readInt32Array(data, dataSize, initialPosition+*processedDataSize);
if (nextArray.isError) { if (nextArray.isError) {
return false; return false;
} }
@ -695,7 +654,7 @@ namespace NBT {
} }
case TagType::INT64_ARRAY: { case TagType::INT64_ARRAY: {
for (int32_t i=0; i<elementCount.value; i++) { for (int32_t i=0; i<elementCount.value; i++) {
ErrorOr<std::vector<int64_t>> nextArray = helper::readInt64Array(data, dataSize, initialPosition+*processedDataSize); ErrorOr<std::vector<int64_t>> nextArray = Helper::readInt64Array(data, dataSize, initialPosition+*processedDataSize);
if (nextArray.isError) { if (nextArray.isError) {
return false; return false;
} }
@ -737,11 +696,11 @@ namespace NBT {
uint64_t currentPosition = initialPosition; uint64_t currentPosition = initialPosition;
#define return if (processedDataSize!=nullptr) *processedDataSize = currentPosition-initialPosition; return #define return if (processedDataSize!=nullptr) *processedDataSize = currentPosition-initialPosition; return
while (currentPosition<dataSize) { while (currentPosition<dataSize) {
ErrorOr<uint64_t> nextTagSize = helper::totalTagSize(data, dataSize, currentPosition); ErrorOr<uint64_t> nextTagSize = Helper::totalTagSize(data, dataSize, currentPosition);
if (nextTagSize.isError) { if (nextTagSize.isError) {
if (nextTagSize.errorCode == ErrorCodes::NOT_YET_KNOWN) { if (nextTagSize.errorCode == ErrorCodes::NOT_YET_KNOWN) {
// attempt parsing the name // attempt parsing the name
ErrorOr<tiny_utf8::string> tagName = helper::readString(data, dataSize, currentPosition+1); ErrorOr<tiny_utf8::string> tagName = Helper::readString(data, dataSize, currentPosition+1);
if (tagName.isError) { if (tagName.isError) {
return false; return false;
} }
@ -750,7 +709,7 @@ namespace NBT {
// //
// there is no way this is an error bc it gets // there is no way this is an error bc it gets
// checked while trying to parse the string above // checked while trying to parse the string above
int16_t nameSize = helper::readInt16(data, dataSize, currentPosition+1).value; int16_t nameSize = Helper::readInt16(data, dataSize, currentPosition+1).value;
uint64_t* processedTagSize = new uint64_t; uint64_t* processedTagSize = new uint64_t;
*processedTagSize = 0; *processedTagSize = 0;
@ -791,7 +750,7 @@ namespace NBT {
// nameSize cannot be an error here bc it got checked in // nameSize cannot be an error here bc it got checked in
// nextTagSize() already // nextTagSize() already
int16_t nameSize = helper::readInt16(data, dataSize, currentPosition+1).value; int16_t nameSize = Helper::readInt16(data, dataSize, currentPosition+1).value;
// attempt parsing the name // attempt parsing the name
// //
@ -800,7 +759,7 @@ namespace NBT {
// being guarded against with // being guarded against with
// if (currentPosition + nextTagSize.value > dataSize) return false; // if (currentPosition + nextTagSize.value > dataSize) return false;
// It might, however, turn out to be a useful check in the future. // It might, however, turn out to be a useful check in the future.
ErrorOr<tiny_utf8::string> name = helper::readString(data, dataSize, currentPosition+1); ErrorOr<tiny_utf8::string> name = Helper::readString(data, dataSize, currentPosition+1);
if (name.isError) { if (name.isError) {
return false; return false;
} }
@ -825,7 +784,7 @@ namespace NBT {
// in the future. // in the future.
// //
// type byte + two name size bytes = 3 // type byte + two name size bytes = 3
ErrorOr<tiny_utf8::string> content = helper::readString(data, dataSize, currentPosition+nameSize+3); ErrorOr<tiny_utf8::string> content = Helper::readString(data, dataSize, currentPosition+nameSize+3);
if (content.isError) { if (content.isError) {
return false; return false;
} }

View File

@ -41,7 +41,7 @@
#include "error.hpp" #include "error.hpp"
namespace NBT { namespace NBT {
namespace helper { namespace Helper {
ErrorOr<int8_t> readInt8(uint8_t data[], uint64_t dataSize, uint64_t currentPosition); ErrorOr<int8_t> readInt8(uint8_t data[], uint64_t dataSize, uint64_t currentPosition);
ErrorOr<int16_t> readInt16(uint8_t data[], uint64_t dataSize, uint64_t currentPosition); ErrorOr<int16_t> readInt16(uint8_t data[], uint64_t dataSize, uint64_t currentPosition);
ErrorOr<int32_t> readInt32(uint8_t data[], uint64_t dataSize, uint64_t currentPosition); ErrorOr<int32_t> readInt32(uint8_t data[], uint64_t dataSize, uint64_t currentPosition);
@ -85,32 +85,21 @@ namespace NBT {
const uint8_t COMPOUND = 10; const uint8_t COMPOUND = 10;
const uint8_t INT32_ARRAY= 11; const uint8_t INT32_ARRAY= 11;
const uint8_t INT64_ARRAY= 12; const uint8_t INT64_ARRAY= 12;
// This is a workaround that's not part of the spec.
const uint8_t INVALID = 255;
// This class is used as a placeholder for implementing the end tag.
class End {};
} }
//Generic parent class to make declaration easier // generic class that all tag types are derived from
template <typename T> template <typename T>
class Tag{ struct Tag {
public: const uint8_t type = TagType::INVALID;
uint8_t tagType; T* containedData;
tiny_utf8::string name;
uint16_t nameSize;
T content;
int32_t size;
Tag(){} Tag();
Tag(uint8_t tagType, tiny_utf8::string name, uint16_t nameSize, T content, uint32_t size); ErrorOr<std::vector<uint8_t>> toRawData();
};
class End: public Tag<uint8_t>{
public:
End();
};
class Byte: public Tag<int8_t>{
public:
Byte(tiny_utf8::string name, uint16_t nameSize, int8_t content);
Byte(uint8_t data[]);
bool validate(uint8_t data[]);
}; };
bool validateRawNBTData(uint8_t data[], uint64_t dataSize, uint64_t initialPosition=0, uint64_t* processedDataSize=nullptr); bool validateRawNBTData(uint8_t data[], uint64_t dataSize, uint64_t initialPosition=0, uint64_t* processedDataSize=nullptr);

View File

@ -41,29 +41,29 @@ int main(){
// int8 ############################################################ // int8 ############################################################
// read successfully // read successfully
currentPosition = 5; currentPosition = 5;
ASSERT(NBT::helper::readInt8(dataForIntTest, dataSize, currentPosition).value == 35); ASSERT(NBT::Helper::readInt8(dataForIntTest, dataSize, currentPosition).value == 35);
ASSERT(NBT::helper::readInt8(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt8(dataForIntTest, dataSize, currentPosition).isError == false);
// begin of data // begin of data
currentPosition = 0; currentPosition = 0;
ASSERT(NBT::helper::readInt8(dataForIntTest, dataSize, currentPosition).value == 30); ASSERT(NBT::Helper::readInt8(dataForIntTest, dataSize, currentPosition).value == 30);
ASSERT(NBT::helper::readInt8(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt8(dataForIntTest, dataSize, currentPosition).isError == false);
// end of data // end of data
currentPosition = 9; currentPosition = 9;
ASSERT(NBT::helper::readInt8(dataForIntTest, dataSize, currentPosition).value == 39); ASSERT(NBT::Helper::readInt8(dataForIntTest, dataSize, currentPosition).value == 39);
ASSERT(NBT::helper::readInt8(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt8(dataForIntTest, dataSize, currentPosition).isError == false);
// out of bounds // out of bounds
currentPosition = 10; currentPosition = 10;
ASSERT(NBT::helper::readInt8(dataForIntTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt8(dataForIntTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt8(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE); ASSERT(NBT::Helper::readInt8(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE);
// read from a bigger blob // read from a bigger blob
currentPositionInBlob = 0x13A; currentPositionInBlob = 0x13A;
ASSERT(NBT::helper::readInt8(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false); ASSERT(NBT::Helper::readInt8(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false);
ASSERT(NBT::helper::readInt8(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 100); ASSERT(NBT::Helper::readInt8(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 100);
std::cout << "Passed readInt8 NBT helper test" << std::endl; std::cout << "Passed readInt8 NBT helper test" << std::endl;
std::vector<uint8_t>* writeInt8TestResult = new std::vector<uint8_t>(); std::vector<uint8_t>* writeInt8TestResult = new std::vector<uint8_t>();
NBT::helper::writeInt8(writeInt8TestResult, (int8_t) 8); NBT::Helper::writeInt8(writeInt8TestResult, (int8_t) 8);
std::vector<uint8_t> dereferencedWriteInt8TestResult = *writeInt8TestResult; std::vector<uint8_t> dereferencedWriteInt8TestResult = *writeInt8TestResult;
delete writeInt8TestResult; delete writeInt8TestResult;
ASSERT(dereferencedWriteInt8TestResult.back() == (uint8_t) 8); ASSERT(dereferencedWriteInt8TestResult.back() == (uint8_t) 8);
@ -73,33 +73,33 @@ int main(){
// int16 ########################################################### // int16 ###########################################################
// read successfully // read successfully
currentPosition = 5; currentPosition = 5;
ASSERT(NBT::helper::readInt16(dataForIntTest, dataSize, currentPosition).value == 8996); ASSERT(NBT::Helper::readInt16(dataForIntTest, dataSize, currentPosition).value == 8996);
ASSERT(NBT::helper::readInt16(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt16(dataForIntTest, dataSize, currentPosition).isError == false);
// begin of data // begin of data
currentPosition = 0; currentPosition = 0;
ASSERT(NBT::helper::readInt16(dataForIntTest, dataSize, currentPosition).value == 7711); ASSERT(NBT::Helper::readInt16(dataForIntTest, dataSize, currentPosition).value == 7711);
ASSERT(NBT::helper::readInt16(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt16(dataForIntTest, dataSize, currentPosition).isError == false);
// end of data // end of data
currentPosition = 8; currentPosition = 8;
ASSERT(NBT::helper::readInt16(dataForIntTest, dataSize, currentPosition).value == 9767); ASSERT(NBT::Helper::readInt16(dataForIntTest, dataSize, currentPosition).value == 9767);
ASSERT(NBT::helper::readInt16(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt16(dataForIntTest, dataSize, currentPosition).isError == false);
// partially out of bounds // partially out of bounds
currentPosition = 9; currentPosition = 9;
ASSERT(NBT::helper::readInt16(dataForIntTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt16(dataForIntTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt16(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readInt16(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN);
// fully out of bounds // fully out of bounds
currentPosition = 10; currentPosition = 10;
ASSERT(NBT::helper::readInt16(dataForIntTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt16(dataForIntTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt16(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE); ASSERT(NBT::Helper::readInt16(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE);
// read from a bigger blob // read from a bigger blob
currentPositionInBlob = 0xb9; currentPositionInBlob = 0xb9;
ASSERT(NBT::helper::readInt16(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false); ASSERT(NBT::Helper::readInt16(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false);
ASSERT(NBT::helper::readInt16(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 2000); ASSERT(NBT::Helper::readInt16(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 2000);
std::cout << "Passed readInt16 NBT helper test" << std::endl; std::cout << "Passed readInt16 NBT helper test" << std::endl;
std::vector<uint8_t>* writeInt16TestResult = new std::vector<uint8_t>(); std::vector<uint8_t>* writeInt16TestResult = new std::vector<uint8_t>();
NBT::helper::writeInt16(writeInt16TestResult, (int16_t) 0xABCD); NBT::Helper::writeInt16(writeInt16TestResult, (int16_t) 0xABCD);
std::vector<uint8_t> dereferencedWriteInt16TestResult = *writeInt16TestResult; std::vector<uint8_t> dereferencedWriteInt16TestResult = *writeInt16TestResult;
delete writeInt16TestResult; delete writeInt16TestResult;
ASSERT(dereferencedWriteInt16TestResult[0] == (uint8_t) 0xAB && dereferencedWriteInt16TestResult[1] == (uint8_t) 0xCD); ASSERT(dereferencedWriteInt16TestResult[0] == (uint8_t) 0xAB && dereferencedWriteInt16TestResult[1] == (uint8_t) 0xCD);
@ -109,33 +109,33 @@ int main(){
// int32 ########################################################### // int32 ###########################################################
// read successfully // read successfully
currentPosition = 5; currentPosition = 5;
ASSERT(NBT::helper::readInt32(dataForIntTest, dataSize, currentPosition).value == 589571366); ASSERT(NBT::Helper::readInt32(dataForIntTest, dataSize, currentPosition).value == 589571366);
ASSERT(NBT::helper::readInt32(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt32(dataForIntTest, dataSize, currentPosition).isError == false);
// begin of data // begin of data
currentPosition = 0; currentPosition = 0;
ASSERT(NBT::helper::readInt32(dataForIntTest, dataSize, currentPosition).value == 505356321); ASSERT(NBT::Helper::readInt32(dataForIntTest, dataSize, currentPosition).value == 505356321);
ASSERT(NBT::helper::readInt32(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt32(dataForIntTest, dataSize, currentPosition).isError == false);
// end of data // end of data
currentPosition = 6; currentPosition = 6;
ASSERT(NBT::helper::readInt32(dataForIntTest, dataSize, currentPosition).value == 606414375); ASSERT(NBT::Helper::readInt32(dataForIntTest, dataSize, currentPosition).value == 606414375);
ASSERT(NBT::helper::readInt32(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt32(dataForIntTest, dataSize, currentPosition).isError == false);
// partially out of bounds // partially out of bounds
currentPosition = 7; currentPosition = 7;
ASSERT(NBT::helper::readInt32(dataForIntTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt32(dataForIntTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt32(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readInt32(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN);
// fully out of bounds // fully out of bounds
currentPosition = 10; currentPosition = 10;
ASSERT(NBT::helper::readInt32(dataForIntTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt32(dataForIntTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt32(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE); ASSERT(NBT::Helper::readInt32(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE);
// read from a bigger blob // read from a bigger blob
currentPositionInBlob = 0xc3; currentPositionInBlob = 0xc3;
ASSERT(NBT::helper::readInt32(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false); ASSERT(NBT::Helper::readInt32(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false);
ASSERT(NBT::helper::readInt32(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 10101010); ASSERT(NBT::Helper::readInt32(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 10101010);
std::cout << "Passed readInt32 NBT helper test" << std::endl; std::cout << "Passed readInt32 NBT helper test" << std::endl;
std::vector<uint8_t>* writeInt32TestResult = new std::vector<uint8_t>(); std::vector<uint8_t>* writeInt32TestResult = new std::vector<uint8_t>();
NBT::helper::writeInt32(writeInt32TestResult, (int32_t) 0x12345678); NBT::Helper::writeInt32(writeInt32TestResult, (int32_t) 0x12345678);
// delete before checking assertions so we don't leak // delete before checking assertions so we don't leak
std::vector<uint8_t> dereferencedWriteInt32TestResult = *writeInt32TestResult; std::vector<uint8_t> dereferencedWriteInt32TestResult = *writeInt32TestResult;
delete writeInt32TestResult; delete writeInt32TestResult;
@ -151,33 +151,33 @@ int main(){
// int64 ########################################################### // int64 ###########################################################
// read successfully // read successfully
currentPosition = 1; currentPosition = 1;
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).value == 2242829044932683046); ASSERT(NBT::Helper::readInt64(dataForIntTest, dataSize, currentPosition).value == 2242829044932683046);
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == false);
// begin of data // begin of data
currentPosition = 0; currentPosition = 0;
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).value == 2170488872094606373); ASSERT(NBT::Helper::readInt64(dataForIntTest, dataSize, currentPosition).value == 2170488872094606373);
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == false);
// end of data // end of data
currentPosition = 2; currentPosition = 2;
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).value == 2315169217770759719); ASSERT(NBT::Helper::readInt64(dataForIntTest, dataSize, currentPosition).value == 2315169217770759719);
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == false);
// partially out of bounds // partially out of bounds
currentPosition = 3; currentPosition = 3;
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readInt64(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN);
// fully out of bounds // fully out of bounds
currentPosition = 10; currentPosition = 10;
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt64(dataForIntTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt64(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE); ASSERT(NBT::Helper::readInt64(dataForIntTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE);
// read from a bigger blob // read from a bigger blob
currentPositionInBlob = 0xf1; currentPositionInBlob = 0xf1;
ASSERT(NBT::helper::readInt64(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false); ASSERT(NBT::Helper::readInt64(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false);
ASSERT(NBT::helper::readInt64(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 810001800766); ASSERT(NBT::Helper::readInt64(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 810001800766);
std::cout << "Passed readInt64 NBT helper test" << std::endl; std::cout << "Passed readInt64 NBT helper test" << std::endl;
std::vector<uint8_t>* writeInt64TestResult = new std::vector<uint8_t>(); std::vector<uint8_t>* writeInt64TestResult = new std::vector<uint8_t>();
NBT::helper::writeInt64(writeInt64TestResult, (int64_t) 0x0123456789ABCDEF); NBT::Helper::writeInt64(writeInt64TestResult, (int64_t) 0x0123456789ABCDEF);
// delete before checking assertions so we don't leak // delete before checking assertions so we don't leak
std::vector<uint8_t> dereferencedWriteInt64TestResult = *writeInt64TestResult; std::vector<uint8_t> dereferencedWriteInt64TestResult = *writeInt64TestResult;
delete writeInt64TestResult; delete writeInt64TestResult;
@ -213,34 +213,34 @@ int main(){
// int8 "array" #################################################### // int8 "array" ####################################################
// read successfully // read successfully
currentPosition = 0; currentPosition = 0;
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int8_t>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20})); ASSERT(NBT::Helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int8_t>({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}));
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == false);
// read empty // read empty
currentPosition = 112; currentPosition = 112;
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int8_t>()); ASSERT(NBT::Helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int8_t>());
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == false);
// read overrun // read overrun
currentPosition = 20; currentPosition = 20;
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN);
// read with size partially out of bounds // read with size partially out of bounds
currentPosition = 114; currentPosition = 114;
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN);
// read out of bounds // read out of bounds
currentPosition = 200; currentPosition = 200;
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE); ASSERT(NBT::Helper::readInt8Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE);
// read from a bigger blob // read from a bigger blob
currentPositionInBlob = 0x148; currentPositionInBlob = 0x148;
ASSERT(NBT::helper::readInt8Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false); ASSERT(NBT::Helper::readInt8Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false);
ASSERT(NBT::helper::readInt8Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == std::vector<int8_t>({(int8_t) 0x71, (int8_t) 0x35, (int8_t) 0x77, (int8_t) 0x62, (int8_t) 0x54, (int8_t) 0x64, (int8_t) 0xf5, (int8_t) 0x32})); ASSERT(NBT::Helper::readInt8Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == std::vector<int8_t>({(int8_t) 0x71, (int8_t) 0x35, (int8_t) 0x77, (int8_t) 0x62, (int8_t) 0x54, (int8_t) 0x64, (int8_t) 0xf5, (int8_t) 0x32}));
std::cout << "Passed readInt8Array NBT helper test" << std::endl; std::cout << "Passed readInt8Array NBT helper test" << std::endl;
std::vector<uint8_t>* int8ArrayTestOutput = new std::vector<uint8_t>(); std::vector<uint8_t>* int8ArrayTestOutput = new std::vector<uint8_t>();
int8_t writeDataTest[] = {1,2,3,4}; int8_t writeDataTest[] = {1,2,3,4};
NBT::helper::writeInt8Array(int8ArrayTestOutput, writeDataTest, (uint32_t)4); NBT::Helper::writeInt8Array(int8ArrayTestOutput, writeDataTest, (uint32_t)4);
ASSERT( ASSERT(
int8ArrayTestOutput->at(0) == 0 && int8ArrayTestOutput->at(0) == 0 &&
int8ArrayTestOutput->at(1) == 0 && int8ArrayTestOutput->at(1) == 0 &&
@ -252,7 +252,7 @@ int main(){
int8ArrayTestOutput->at(7) == 4 int8ArrayTestOutput->at(7) == 4
); );
int8ArrayTestOutput->clear(); int8ArrayTestOutput->clear();
NBT::helper::writeInt8Array(int8ArrayTestOutput, std::vector<int8_t>({1,2,3,4})); NBT::Helper::writeInt8Array(int8ArrayTestOutput, std::vector<int8_t>({1,2,3,4}));
ASSERT( ASSERT(
int8ArrayTestOutput->at(0) == 0 && int8ArrayTestOutput->at(0) == 0 &&
int8ArrayTestOutput->at(1) == 0 && int8ArrayTestOutput->at(1) == 0 &&
@ -269,34 +269,34 @@ int main(){
// int32 "array" ################################################### // int32 "array" ###################################################
// read successfully // read successfully
currentPosition = 68; currentPosition = 68;
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int32_t>({1027489600, 1094861636, 1162233672, 1229605708, 1296977744, 1364349780, 1431721816, 1499093852, 1566465888, 1633837924})); ASSERT(NBT::Helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int32_t>({1027489600, 1094861636, 1162233672, 1229605708, 1296977744, 1364349780, 1431721816, 1499093852, 1566465888, 1633837924}));
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == false);
// read empty // read empty
currentPosition = 112; currentPosition = 112;
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int32_t>()); ASSERT(NBT::Helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int32_t>());
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == false);
// read overrun // read overrun
currentPosition = 20; currentPosition = 20;
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN);
// read with size partially out of bounds // read with size partially out of bounds
currentPosition = 114; currentPosition = 114;
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN);
// read out of bounds // read out of bounds
currentPosition = 200; currentPosition = 200;
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE); ASSERT(NBT::Helper::readInt32Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE);
// read from a bigger blob // read from a bigger blob
currentPositionInBlob = 0xd5; currentPositionInBlob = 0xd5;
ASSERT(NBT::helper::readInt32Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false); ASSERT(NBT::Helper::readInt32Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false);
ASSERT(NBT::helper::readInt32Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == std::vector<int32_t>({(int32_t) 0x17bfe83c, (int32_t) 0xa8fb, (int32_t) 0x7fffffff, (int32_t) 0x61727261})); ASSERT(NBT::Helper::readInt32Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == std::vector<int32_t>({(int32_t) 0x17bfe83c, (int32_t) 0xa8fb, (int32_t) 0x7fffffff, (int32_t) 0x61727261}));
std::cout << "Passed readInt32Array NBT helper test" << std::endl; std::cout << "Passed readInt32Array NBT helper test" << std::endl;
std::vector<uint8_t>* int32ArrayTestOutput = new std::vector<uint8_t>(); std::vector<uint8_t>* int32ArrayTestOutput = new std::vector<uint8_t>();
int32_t input32[] = {0x01234567, 0x01234567}; int32_t input32[] = {0x01234567, 0x01234567};
NBT::helper::writeInt32Array(int32ArrayTestOutput, input32, 2); NBT::Helper::writeInt32Array(int32ArrayTestOutput, input32, 2);
ASSERT( ASSERT(
int32ArrayTestOutput->at(0) == 0x00 && int32ArrayTestOutput->at(0) == 0x00 &&
int32ArrayTestOutput->at(1) == 0x00 && int32ArrayTestOutput->at(1) == 0x00 &&
@ -312,7 +312,7 @@ int main(){
int32ArrayTestOutput->at(11) == 0x67 int32ArrayTestOutput->at(11) == 0x67
); );
int32ArrayTestOutput->clear(); int32ArrayTestOutput->clear();
NBT::helper::writeInt32Array(int32ArrayTestOutput, std::vector<int32_t>({0x01234567, 0x01234567})); NBT::Helper::writeInt32Array(int32ArrayTestOutput, std::vector<int32_t>({0x01234567, 0x01234567}));
ASSERT( ASSERT(
int32ArrayTestOutput->at(0) == 0x00 && int32ArrayTestOutput->at(0) == 0x00 &&
int32ArrayTestOutput->at(1) == 0x00 && int32ArrayTestOutput->at(1) == 0x00 &&
@ -334,34 +334,34 @@ int main(){
// int64 "array" ################################################### // int64 "array" ###################################################
// read successfully // read successfully
currentPosition = 44; currentPosition = 44;
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int64_t>({2966230773313449776, 3544952156018063160, 4123673537695186954, 4413034230074983236, 4991755612779596620})); ASSERT(NBT::Helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int64_t>({2966230773313449776, 3544952156018063160, 4123673537695186954, 4413034230074983236, 4991755612779596620}));
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == false);
// read empty // read empty
currentPosition = 112; currentPosition = 112;
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int64_t>()); ASSERT(NBT::Helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).value == std::vector<int64_t>());
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == false);
// read overrun // read overrun
currentPosition = 20; currentPosition = 20;
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN);
// read with size partially out of bounds // read with size partially out of bounds
currentPosition = 114; currentPosition = 114;
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN);
// read out of bounds // read out of bounds
currentPosition = 200; currentPosition = 200;
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE); ASSERT(NBT::Helper::readInt64Array(dataForIntArrayTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE);
// read from a bigger blob // read from a bigger blob
currentPositionInBlob = 0x107; currentPositionInBlob = 0x107;
ASSERT(NBT::helper::readInt64Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false); ASSERT(NBT::Helper::readInt64Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false);
ASSERT(NBT::helper::readInt64Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == std::vector<int64_t>({(int64_t) 239865, (int64_t) 23586749, (int64_t) 9223372036854775807, (int64_t) 188944201329624, (int64_t) 3116157694992754})); ASSERT(NBT::Helper::readInt64Array(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == std::vector<int64_t>({(int64_t) 239865, (int64_t) 23586749, (int64_t) 9223372036854775807, (int64_t) 188944201329624, (int64_t) 3116157694992754}));
std::cout << "Passed readInt64Array NBT helper test" << std::endl; std::cout << "Passed readInt64Array NBT helper test" << std::endl;
std::vector<uint8_t>* int64ArrayTestOutput = new std::vector<uint8_t>(); std::vector<uint8_t>* int64ArrayTestOutput = new std::vector<uint8_t>();
int64_t input64[] = {0x0123456789ABCDEF, 0x0123456789ABCDEF}; int64_t input64[] = {0x0123456789ABCDEF, 0x0123456789ABCDEF};
NBT::helper::writeInt64Array(int64ArrayTestOutput, input64, 2); NBT::Helper::writeInt64Array(int64ArrayTestOutput, input64, 2);
ASSERT( ASSERT(
int64ArrayTestOutput->at(0) == 0x00 && int64ArrayTestOutput->at(0) == 0x00 &&
int64ArrayTestOutput->at(1) == 0x00 && int64ArrayTestOutput->at(1) == 0x00 &&
@ -385,7 +385,7 @@ int main(){
int64ArrayTestOutput->at(19) == 0xEF int64ArrayTestOutput->at(19) == 0xEF
); );
int64ArrayTestOutput->clear(); int64ArrayTestOutput->clear();
NBT::helper::writeInt64Array(int64ArrayTestOutput, std::vector<int64_t>({0x0123456789ABCDEF, 0x0123456789ABCDEF})); NBT::Helper::writeInt64Array(int64ArrayTestOutput, std::vector<int64_t>({0x0123456789ABCDEF, 0x0123456789ABCDEF}));
ASSERT( ASSERT(
int64ArrayTestOutput->at(0) == 0x00 && int64ArrayTestOutput->at(0) == 0x00 &&
int64ArrayTestOutput->at(1) == 0x00 && int64ArrayTestOutput->at(1) == 0x00 &&
@ -418,25 +418,25 @@ int main(){
dataSize = 4; dataSize = 4;
currentPosition = 0; currentPosition = 0;
// read successfully // read successfully
ASSERT(NBT::helper::readFloat(dataForFloatTest, dataSize, currentPosition).value == -63351.46484375f); ASSERT(NBT::Helper::readFloat(dataForFloatTest, dataSize, currentPosition).value == -63351.46484375f);
ASSERT(NBT::helper::readFloat(dataForFloatTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readFloat(dataForFloatTest, dataSize, currentPosition).isError == false);
// read overrun // read overrun
currentPosition = 1; currentPosition = 1;
ASSERT(NBT::helper::readFloat(dataForFloatTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readFloat(dataForFloatTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readFloat(dataForFloatTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readFloat(dataForFloatTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN);
// read out of bounds // read out of bounds
currentPosition = 4; currentPosition = 4;
ASSERT(NBT::helper::readFloat(dataForFloatTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readFloat(dataForFloatTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readFloat(dataForFloatTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE); ASSERT(NBT::Helper::readFloat(dataForFloatTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE);
// read from a bigger blob // read from a bigger blob
currentPositionInBlob = 0xad; currentPositionInBlob = 0xad;
ASSERT(NBT::helper::readFloat(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false); ASSERT(NBT::Helper::readFloat(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false);
ASSERT(NBT::helper::readFloat(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 35.2678337097168); ASSERT(NBT::Helper::readFloat(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 35.2678337097168);
std::cout << "Passed readFloat NBT helper test" << std::endl; std::cout << "Passed readFloat NBT helper test" << std::endl;
std::vector<uint8_t>* writeFloatTestResult = new std::vector<uint8_t>(); std::vector<uint8_t>* writeFloatTestResult = new std::vector<uint8_t>();
NBT::helper::writeFloat(writeFloatTestResult, (float) -63351.46484375f); NBT::Helper::writeFloat(writeFloatTestResult, (float) -63351.46484375f);
std::vector<uint8_t> dereferencedWriteFloatTestResult = *writeFloatTestResult; std::vector<uint8_t> dereferencedWriteFloatTestResult = *writeFloatTestResult;
delete writeFloatTestResult; delete writeFloatTestResult;
ASSERT( ASSERT(
@ -453,25 +453,25 @@ int main(){
dataSize = 8; dataSize = 8;
currentPosition = 0; currentPosition = 0;
// read successfully // read successfully
ASSERT(NBT::helper::readDouble(dataForDoubleTest, dataSize, currentPosition).value == -20.015625476837158203125); ASSERT(NBT::Helper::readDouble(dataForDoubleTest, dataSize, currentPosition).value == -20.015625476837158203125);
ASSERT(NBT::helper::readDouble(dataForDoubleTest, dataSize, currentPosition).isError == false); ASSERT(NBT::Helper::readDouble(dataForDoubleTest, dataSize, currentPosition).isError == false);
// read overrun // read overrun
currentPosition = 1; currentPosition = 1;
ASSERT(NBT::helper::readDouble(dataForDoubleTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readDouble(dataForDoubleTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readDouble(dataForDoubleTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readDouble(dataForDoubleTest, dataSize, currentPosition).errorCode == ErrorCodes::OVERRUN);
// read out of bounds // read out of bounds
currentPosition = 8; currentPosition = 8;
ASSERT(NBT::helper::readDouble(dataForDoubleTest, dataSize, currentPosition).isError == true); ASSERT(NBT::Helper::readDouble(dataForDoubleTest, dataSize, currentPosition).isError == true);
ASSERT(NBT::helper::readDouble(dataForDoubleTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE); ASSERT(NBT::Helper::readDouble(dataForDoubleTest, dataSize, currentPosition).errorCode == ErrorCodes::OUT_OF_RANGE);
// read from a bigger blob // read from a bigger blob
currentPositionInBlob = 0x9d; currentPositionInBlob = 0x9d;
ASSERT(NBT::helper::readDouble(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false); ASSERT(NBT::Helper::readDouble(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false);
ASSERT(NBT::helper::readDouble(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 623593.6542742235); ASSERT(NBT::Helper::readDouble(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == 623593.6542742235);
std::cout << "Passed readDouble NBT helper test" << std::endl; std::cout << "Passed readDouble NBT helper test" << std::endl;
std::vector<uint8_t>* writeDoubleTestResult = new std::vector<uint8_t>(); std::vector<uint8_t>* writeDoubleTestResult = new std::vector<uint8_t>();
NBT::helper::writeDouble(writeDoubleTestResult, (double) -20.015625476837158203125); NBT::Helper::writeDouble(writeDoubleTestResult, (double) -20.015625476837158203125);
std::vector<uint8_t> dereferencedWriteDoubleTestResult = *writeDoubleTestResult; std::vector<uint8_t> dereferencedWriteDoubleTestResult = *writeDoubleTestResult;
delete writeDoubleTestResult; delete writeDoubleTestResult;
ASSERT( ASSERT(
@ -533,16 +533,16 @@ int main(){
tiny_utf8::string normalString = tiny_utf8::string(normalStdString); tiny_utf8::string normalString = tiny_utf8::string(normalStdString);
delete nextChar; delete nextChar;
ASSERT(normalString == NBT::helper::readString(reinterpret_cast<uint8_t*>(javaStdString.data()), javaStdString.size(), 0).value) ASSERT(normalString == NBT::Helper::readString(reinterpret_cast<uint8_t*>(javaStdString.data()), javaStdString.size(), 0).value)
javaStdString[0] = '1'; javaStdString[0] = '1';
ASSERT(NBT::helper::readString(reinterpret_cast<uint8_t*>(javaStdString.data()), javaStdString.size(), 0).errorCode == ErrorCodes::OVERRUN); ASSERT(NBT::Helper::readString(reinterpret_cast<uint8_t*>(javaStdString.data()), javaStdString.size(), 0).errorCode == ErrorCodes::OVERRUN);
ASSERT(NBT::helper::readString(reinterpret_cast<uint8_t*>(javaStdString.data()), javaStdString.size(), javaStdString.size()).errorCode == ErrorCodes::OUT_OF_RANGE); ASSERT(NBT::Helper::readString(reinterpret_cast<uint8_t*>(javaStdString.data()), javaStdString.size(), javaStdString.size()).errorCode == ErrorCodes::OUT_OF_RANGE);
//reading data from the blob at the top of this file //reading data from the blob at the top of this file
currentPositionInBlob = 0x1cf; currentPositionInBlob = 0x1cf;
ASSERT(NBT::helper::readString(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false); ASSERT(NBT::Helper::readString(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).isError == false);
ASSERT(NBT::helper::readString(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == "Hello World!"); ASSERT(NBT::Helper::readString(validNBTDataBlob, validNBTDataBlobSize, currentPositionInBlob).value == "Hello World!");
std::cout << "Passed readString NBT helper test." << std::endl; std::cout << "Passed readString NBT helper test." << std::endl;
@ -570,7 +570,7 @@ int main(){
delete nextChar1; delete nextChar1;
std::vector<uint8_t>* exportedString = new std::vector<uint8_t>(); std::vector<uint8_t>* exportedString = new std::vector<uint8_t>();
NBT::helper::writeString(exportedString, normalString); NBT::Helper::writeString(exportedString, normalString);
ASSERT(javaStdString1 == *exportedString); ASSERT(javaStdString1 == *exportedString);
std::cout << "Passed writeString NBT helper test." << std::endl; std::cout << "Passed writeString NBT helper test." << std::endl;

View File

@ -101,16 +101,16 @@ int main() {
// Basic valid data tests // Basic valid data tests
//################################################################## //##################################################################
// const uint8_t END = 0; // const uint8_t END = 0;
ErrorOr<uint64_t> totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x93); ErrorOr<uint64_t> totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x93);
ErrorOr<int32_t> dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x93); ErrorOr<int32_t> dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x93);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 1); ASSERT(totalSize.value == 1);
ASSERT(!dataLength.isError); ASSERT(!dataLength.isError);
ASSERT(dataLength.value == 0); ASSERT(dataLength.value == 0);
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 477); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 477);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 477); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 477);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 1); ASSERT(totalSize.value == 1);
@ -118,8 +118,8 @@ int main() {
ASSERT(dataLength.value == 0); ASSERT(dataLength.value == 0);
//const uint8_t INT8 = 1; //const uint8_t INT8 = 1;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x133); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x133);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x133); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x133);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 8); ASSERT(totalSize.value == 8);
@ -127,8 +127,8 @@ int main() {
ASSERT(dataLength.value == 1); ASSERT(dataLength.value == 1);
//const uint8_t INT16 = 2; //const uint8_t INT16 = 2;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xb1); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xb1);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xb1); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xb1);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 10); ASSERT(totalSize.value == 10);
@ -136,16 +136,16 @@ int main() {
ASSERT(dataLength.value == 1); ASSERT(dataLength.value == 1);
//const uint8_t INT32 = 3; //const uint8_t INT32 = 3;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xbb); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xbb);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xbb); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xbb);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 12); ASSERT(totalSize.value == 12);
ASSERT(!dataLength.isError); ASSERT(!dataLength.isError);
ASSERT(dataLength.value == 1); ASSERT(dataLength.value == 1);
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x67); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x67);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x67); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x67);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 18); ASSERT(totalSize.value == 18);
@ -153,8 +153,8 @@ int main() {
ASSERT(dataLength.value == 1); ASSERT(dataLength.value == 1);
//const uint8_t INT64 = 4; //const uint8_t INT64 = 4;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xe9); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xe9);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xe9); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xe9);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 16); ASSERT(totalSize.value == 16);
@ -162,8 +162,8 @@ int main() {
ASSERT(dataLength.value == 1); ASSERT(dataLength.value == 1);
//const uint8_t FLOAT = 5; //const uint8_t FLOAT = 5;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xa5); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xa5);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xa5); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xa5);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 12); ASSERT(totalSize.value == 12);
@ -171,8 +171,8 @@ int main() {
ASSERT(dataLength.value == 1); ASSERT(dataLength.value == 1);
//const uint8_t DOUBLE = 6; //const uint8_t DOUBLE = 6;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x94); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x94);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x94); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x94);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 17); ASSERT(totalSize.value == 17);
@ -180,8 +180,8 @@ int main() {
ASSERT(dataLength.value == 1); ASSERT(dataLength.value == 1);
//const uint8_t INT8_ARRAY = 7; //const uint8_t INT8_ARRAY = 7;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x13b); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x13b);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x13b); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x13b);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 25); ASSERT(totalSize.value == 25);
@ -189,16 +189,16 @@ int main() {
ASSERT(dataLength.value == 8); ASSERT(dataLength.value == 8);
//const uint8_t STRING = 8; //const uint8_t STRING = 8;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x1c6); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x1c6);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x1c6); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x1c6);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 23); ASSERT(totalSize.value == 23);
ASSERT(!dataLength.isError); ASSERT(!dataLength.isError);
ASSERT(dataLength.value == 12); ASSERT(dataLength.value == 12);
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x79); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x79);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x79); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x79);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 26); ASSERT(totalSize.value == 26);
@ -206,16 +206,16 @@ int main() {
ASSERT(dataLength.value == 12); ASSERT(dataLength.value == 12);
//const uint8_t LIST = 9; //const uint8_t LIST = 9;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x154); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x154);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x154); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x154);
ASSERT(totalSize.isError); ASSERT(totalSize.isError);
ASSERT(totalSize.errorCode == ErrorCodes::NOT_YET_KNOWN); ASSERT(totalSize.errorCode == ErrorCodes::NOT_YET_KNOWN);
ASSERT(!dataLength.isError); ASSERT(!dataLength.isError);
ASSERT(dataLength.value == 5); ASSERT(dataLength.value == 5);
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x16a); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x16a);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x16a); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x16a);
ASSERT(totalSize.isError); ASSERT(totalSize.isError);
ASSERT(totalSize.errorCode == ErrorCodes::NOT_YET_KNOWN); ASSERT(totalSize.errorCode == ErrorCodes::NOT_YET_KNOWN);
@ -223,8 +223,8 @@ int main() {
ASSERT(dataLength.value == 12); ASSERT(dataLength.value == 12);
//const uint8_t COMPOUND = 10; //const uint8_t COMPOUND = 10;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x5c); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0x5c);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x5c); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0x5c);
ASSERT(totalSize.isError); ASSERT(totalSize.isError);
ASSERT(totalSize.errorCode == ErrorCodes::NOT_YET_KNOWN); ASSERT(totalSize.errorCode == ErrorCodes::NOT_YET_KNOWN);
@ -232,8 +232,8 @@ int main() {
ASSERT(dataLength.errorCode == ErrorCodes::NOT_YET_KNOWN); ASSERT(dataLength.errorCode == ErrorCodes::NOT_YET_KNOWN);
//const uint8_t INT32_ARRAY= 11; //const uint8_t INT32_ARRAY= 11;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xc7); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xc7);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xc7); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xc7);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 34); ASSERT(totalSize.value == 34);
@ -241,8 +241,8 @@ int main() {
ASSERT(dataLength.value == 4); ASSERT(dataLength.value == 4);
//const uint8_t INT64_ARRAY= 12; //const uint8_t INT64_ARRAY= 12;
totalSize = NBT::helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xf9); totalSize = NBT::Helper::totalTagSize(simpleNBTData, simpleNBTDataSize, 0xf9);
dataLength = NBT::helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xf9); dataLength = NBT::Helper::containedDataLength(simpleNBTData, simpleNBTDataSize, 0xf9);
ASSERT(!totalSize.isError); ASSERT(!totalSize.isError);
ASSERT(totalSize.value == 58); ASSERT(totalSize.value == 58);

View File

@ -27,5 +27,5 @@ int main() {
std::cout << "This is supposed to abort." << std::endl; std::cout << "This is supposed to abort." << std::endl;
std::vector<uint8_t>* exportedString = new std::vector<uint8_t>(); std::vector<uint8_t>* exportedString = new std::vector<uint8_t>();
std::string overrunString = std::string(0xFFFFF, '.'); std::string overrunString = std::string(0xFFFFF, '.');
NBT::helper::writeString(exportedString, tiny_utf8::string(overrunString)); NBT::Helper::writeString(exportedString, tiny_utf8::string(overrunString));
} }