test/nbt_tags: Add tests for constructing invalid lists/compounds

windows
BodgeMaster 2022-11-25 17:07:35 +01:00
parent 60a8ac9788
commit d392e080ca
1 changed files with 19 additions and 4 deletions

View File

@ -773,11 +773,16 @@ int main(){
NBT::Tag::Int8* pointer_2_1 = new NBT::Tag::Int8("entry_2_1", 28); NBT::Tag::Int8* pointer_2_1 = new NBT::Tag::Int8("entry_2_1", 28);
NBT::Tag::Int8* pointer_2_2 = new NBT::Tag::Int8("entry_2_2", 45); NBT::Tag::Int8* pointer_2_2 = new NBT::Tag::Int8("entry_2_2", 45);
NBT::Tag::Int8* pointer_2_3 = new NBT::Tag::Int8("entry_2_3", 78); NBT::Tag::Int8* pointer_2_3 = new NBT::Tag::Int8("entry_2_3", 78);
NBT::Tag::Int8* pointer_invalid_0 = new NBT::Tag::Int8("ayya", 78);
NBT::Tag::Int16* pointer_invalid_1 = new NBT::Tag::Int16("ellohhh", 78);
std::vector<NBT::Tag::Generic*> listDataVector; std::vector<NBT::Tag::Generic*> listDataVector;
listDataVector.push_back(pointer_2_0); listDataVector.push_back(pointer_2_0);
listDataVector.push_back(pointer_2_1); listDataVector.push_back(pointer_2_1);
listDataVector.push_back(pointer_2_2); listDataVector.push_back(pointer_2_2);
listDataVector.push_back(pointer_2_3); listDataVector.push_back(pointer_2_3);
std::vector<NBT::Tag::Generic*> invalidListDataVector;
invalidListDataVector.push_back(pointer_invalid_0);
invalidListDataVector.push_back(pointer_invalid_1);
NBT::Tag::List list_0 = NBT::Tag::List(); NBT::Tag::List list_0 = NBT::Tag::List();
ASSERT(list_0.serialize(&vector).isError); ASSERT(list_0.serialize(&vector).isError);
@ -792,8 +797,9 @@ int main(){
NBT::Tag::Int16* pointer_invalid = new NBT::Tag::Int16("invalid", 400); NBT::Tag::Int16* pointer_invalid = new NBT::Tag::Int16("invalid", 400);
resultError = list_1.appendPointer(pointer_invalid); resultError = list_1.appendPointer(pointer_invalid);
ASSERT(resultError.isError && resultError.errorCode == ErrorCodes::INVALID_TYPE); ASSERT(resultError.isError && resultError.errorCode == ErrorCodes::INVALID_TYPE);
//TODO: Check that constructing with a vector of mixed tags ErrorOr<NBT::Tag::List*> invalid_list_or_error = NBT::Tag::List::constructWithData("list_invalid", invalidListDataVector);
// results in a clearly defined failure mode (issue #60) ASSERT(invalid_list_or_error.isError);
ASSERT(invalid_list_or_error.errorCode == ErrorCodes::MIXED_TYPES);
ErrorOr<NBT::Tag::List*> list_2_or_error = NBT::Tag::List::constructWithData("list_2", listDataVector); ErrorOr<NBT::Tag::List*> list_2_or_error = NBT::Tag::List::constructWithData("list_2", listDataVector);
ASSERT(!list_2_or_error.isError); ASSERT(!list_2_or_error.isError);
NBT::Tag::List* list_2 = list_2_or_error.value; NBT::Tag::List* list_2 = list_2_or_error.value;
@ -886,12 +892,21 @@ int main(){
compoundDataVector.push_back(new NBT::Tag::Int16("will be deleted", 0x1337)); compoundDataVector.push_back(new NBT::Tag::Int16("will be deleted", 0x1337));
compoundDataVector.push_back(new NBT::Tag::Int16("1", 0x1337)); compoundDataVector.push_back(new NBT::Tag::Int16("1", 0x1337));
compoundDataVector.push_back(new NBT::Tag::String("2", "Hello World!")); compoundDataVector.push_back(new NBT::Tag::String("2", "Hello World!"));
std::vector<NBT::Tag::Generic*> invalidCompoundDataVector;
invalidCompoundDataVector.push_back(new NBT::Tag::End());
invalidCompoundDataVector.push_back(new NBT::Tag::End());
std::vector<NBT::Tag::Generic*> compoundDataVectorWithEnd;
compoundDataVectorWithEnd.push_back(new NBT::Tag::Int8("eeee", 25));
compoundDataVectorWithEnd.push_back(new NBT::Tag::End());
NBT::Tag::Compound compound_0 = NBT::Tag::Compound(); NBT::Tag::Compound compound_0 = NBT::Tag::Compound();
compound_0.name = "compound_0"; compound_0.name = "compound_0";
NBT::Tag::Compound compound_1 = NBT::Tag::Compound("compound_1"); NBT::Tag::Compound compound_1 = NBT::Tag::Compound("compound_1");
//TODO: Check that constructing with a vector containing an end tag that ErrorOr<NBT::Tag::Compound*> invalid_compound_or_error = NBT::Tag::Compound::constructWithData("iiiiii", invalidCompoundDataVector);
// isnt at the end results in a clearly defined failure mode (issue #60) ASSERT(invalid_compound_or_error.isError);
ASSERT(invalid_compound_or_error.errorCode == ErrorCodes::NOT_ALLOWED);
ErrorOr<NBT::Tag::Compound*> alternate_compound_or_error = NBT::Tag::Compound::constructWithData("iiiiii", compoundDataVectorWithEnd);
ASSERT(!alternate_compound_or_error.isError);
ErrorOr<NBT::Tag::Compound*> compound_2_or_error = NBT::Tag::Compound::constructWithData("compound_2", compoundDataVector); ErrorOr<NBT::Tag::Compound*> compound_2_or_error = NBT::Tag::Compound::constructWithData("compound_2", compoundDataVector);
ASSERT(!compound_2_or_error.isError); ASSERT(!compound_2_or_error.isError);
NBT::Tag::Compound* compound_2 = compound_2_or_error.value; NBT::Tag::Compound* compound_2 = compound_2_or_error.value;