test/nbt_tags: Partially implement compound test

Soda
BodgeMaster 2022-10-14 20:33:43 +02:00
parent 374466f26c
commit fd5fe3967f
1 changed files with 35 additions and 0 deletions

View File

@ -873,5 +873,40 @@ int main(){
vector.clear(); vector.clear();
std::cout << "Passed List test." << std::endl; std::cout << "Passed List test." << std::endl;
// COMPOUND ################################################################
// Things to put in the compound
std::vector<NBT::Tag::Generic*> compoundDataVector = std::vector<NBT::Tag::Generic*>();
compoundDataVector.push_back(new NBT::Tag::Int8("0", 0));
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::String("2", "Hello World!"));
NBT::Tag::Compound compound_0 = NBT::Tag::Compound();
compound_0.name = "compound_0";
NBT::Tag::Compound compound_1 = NBT::Tag::Compound("compound_1");
NBT::Tag::Compound compound_2 = NBT::Tag::Compound("compound_2", compoundDataVector);
ASSERT(!compound_1.appendPointer(new NBT::Tag::Int32("0", 69420)).isError);
ASSERT(!compound_1.appendPointer(new NBT::Tag::Int8("1", 1)).isError);
ASSERT(compound_1.appendPointer(new NBT::Tag::End()).isError && compound_1.appendPointer(new NBT::Tag::End()).errorCode == ErrorCodes::NOT_ALLOWED);
ASSERT(!compound_0.getElementPointer(0).isError && compound_0.getElementPointer(0).value->getTagType() == NBT::TagType::END);
ASSERT(compound_0.getElementPointer(1).isError && compound_0.getElementPointer(1).errorCode == ErrorCodes::OUT_OF_RANGE);
ASSERT(!compound_1.getElementPointer(0).isError && compound_1.getElementPointer(0).value->getTagType() == NBT::TagType::INT32);
ASSERT(!compound_1.getElementPointer(1).isError && compound_1.getElementPointer(1).value->getTagType() == NBT::TagType::INT8);
ASSERT(!compound_0.setElementPointerAt(0, new NBT::Tag::End()).isError);
ASSERT(!compound_1.setElementPointerAt(1, new NBT::Tag::Int16("set_element", 0xFFF)).isError);
ErrorOrVoid resultNotAllowed = compound_0.setElementPointerAt(0, new NBT::Tag::Int64());
ASSERT(resultNotAllowed.isError && resultNotAllowed.errorCode==ErrorCodes::NOT_ALLOWED);
resultNotAllowed = compound_1.setElementPointerAt(0, new NBT::Tag::End());
ASSERT(resultNotAllowed.isError && resultNotAllowed.errorCode==ErrorCodes::NOT_ALLOWED);
ASSERT(compound_0.setElementPointerAt(1, new NBT::Tag::Int8()).isError && compound_0.setElementPointerAt(1, new NBT::Tag::Int8()).errorCode == ErrorCodes::OUT_OF_RANGE);
ASSERT(!compound_2.deleteElement(1).isError);
ASSERT(compound_0.deleteElement(0).isError && compound_0.deleteElement(0).errorCode == ErrorCodes::NOT_ALLOWED);
ASSERT(compound_0.deleteElement(1).isError && compound_0.deleteElement(1).errorCode == ErrorCodes::OUT_OF_RANGE);
ASSERT(compound_0.length() == 1);
ASSERT(compound_1.length() == 3);
ASSERT(compound_2.length() == 4);
//TODO: test serialization
return 0; return 0;
} }