diff --git a/src/test/nbt_tags.cpp b/src/test/nbt_tags.cpp index 24330ad..1019734 100644 --- a/src/test/nbt_tags.cpp +++ b/src/test/nbt_tags.cpp @@ -873,5 +873,40 @@ int main(){ vector.clear(); std::cout << "Passed List test." << std::endl; + // COMPOUND ################################################################ + // Things to put in the compound + std::vector compoundDataVector = std::vector(); + 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; }