test/nbt_tags: Implement tests for the first three tag types

Soda
BodgeMaster 2022-10-06 11:10:51 +02:00
parent 936def1a65
commit 6bdf99c897
1 changed files with 74 additions and 7 deletions

View File

@ -34,17 +34,84 @@ int main(){
NBT::Tag::Generic generic = NBT::Tag::Generic();
ASSERT(generic.getTagType() == NBT::TagType::INVALID);
ASSERT(generic.serialize(&vector).isError);
std::cout << vector.size() << std::endl;
ASSERT(generic.serialize(&vector).errorCode == ErrorCodes::INVALID_TYPE);
std::cout << vector.size() << std::endl;
ASSERT(generic.serializeWithoutHeader(&vector).isError);
std::cout << vector.size() << std::endl;
ASSERT(generic.serializeWithoutHeader(&vector).errorCode == ErrorCodes::INVALID_TYPE);
std::cout << vector.size() << std::endl;
ASSERT(vector.size() == 10);
std::cout << "Passed Generic (super type) test" << std::endl;
ASSERT(vector.size() == 6);
ASSERT(
vector.at(0) == 255 &&
vector.at(1) == 0 &&
vector.at(2) == 0 &&
vector.at(3) == 255 &&
vector.at(4) == 0 &&
vector.at(5) == 0
);
vector.clear();
std::cout << "Passed Generic (super type) test." << std::endl;
//?????????
NBT::Tag::End end = NBT::Tag::End();
ASSERT(end.getTagType() == NBT::TagType::END);
ASSERT(!end.serialize(&vector).isError);
ASSERT(!end.serializeWithoutHeader(&vector).isError);
ASSERT(vector.size() == 1);
ASSERT(vector.at(0) == 0);
vector.clear();
std::cout << "Passed End test." << std::endl;
NBT::Tag::Int8 int8_0 = NBT::Tag::Int8();
int8_0.setValue(69);
int8_0.name = "int8_0";
NBT::Tag::Int8 int8_1 = NBT::Tag::Int8("int8_1", 127);
ASSERT(int8_0.getValue() == 69);
ASSERT(int8_1.getValue() == 127);
ASSERT(int8_0.getTagType() == 1 && int8_1.getTagType() == 1);
ASSERT(!int8_0.serialize(&vector).isError);
ASSERT(!int8_1.serialize(&vector).isError);
ASSERT(vector.size() == 20);
ASSERT(
vector.at( 0) == 1 &&
vector.at( 1) == 0 &&
vector.at( 2) == 6 &&
vector.at( 3) == 'i' &&
vector.at( 4) == 'n' &&
vector.at( 5) == 't' &&
vector.at( 6) == '8' &&
vector.at( 7) == '_' &&
vector.at( 8) == '0' &&
vector.at( 9) == 69 &&
vector.at(10) == 1 &&
vector.at(11) == 0 &&
vector.at(12) == 6 &&
vector.at(13) == 'i' &&
vector.at(14) == 'n' &&
vector.at(15) == 't' &&
vector.at(16) == '8' &&
vector.at(17) == '_' &&
vector.at(18) == '1' &&
vector.at(19) == 127
);
vector.clear();
int8_0.name = "";
ASSERT(!int8_0.serialize(&vector).isError);
ASSERT(vector.size() == 4);
ASSERT(
vector.at(0) == 1 &&
vector.at(1) == 0 &&
vector.at(2) == 0 &&
vector.at(3) == 69
);
vector.clear();
ASSERT(!int8_0.serializeWithoutHeader(&vector).isError);
ASSERT(!int8_1.serializeWithoutHeader(&vector).isError);
ASSERT(vector.size() == 2);
ASSERT(
vector.at(0) == 69 &&
vector.at(1) == 127
);
vector.clear();
std::cout << "Passed Int8 test." << std::endl;
//TODO: Check that we actually get overrun when trying to store a name that's too long
return 0;
}