test/nbt_tags: Implement Int32Array test

Soda
BodgeMaster 2022-10-14 22:33:57 +02:00
parent 996154fbbc
commit 9b21dfaee5
1 changed files with 187 additions and 0 deletions

View File

@ -762,6 +762,7 @@ int main(){
vector.clear();
std::cout << "Passed String test." << std::endl;
// LIST ####################################################################
// Things to put in the list
NBT::Tag::Int8* pointer_1_0 = new NBT::Tag::Int8("entry_1_0", 6);
@ -873,6 +874,7 @@ int main(){
vector.clear();
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*>();
@ -1073,5 +1075,190 @@ int main(){
vector.clear();
std::cout << "Passed Compound test." << std::endl;
// INT32_ARRAY #############################################################
std::vector<int32_t> int32DataVector = std::vector<int32_t>();
int32DataVector.push_back(-2147483648);
int32DataVector.push_back(2147483647);
int32DataVector.push_back(0);
NBT::Tag::Int32Array int32a_0 = NBT::Tag::Int32Array();
int32a_0.name = "int32a_0";
int32a_0.setData(int32DataVector);
NBT::Tag::Int32Array int32a_1 = NBT::Tag::Int32Array("int32a_1", int32DataVector);
NBT::Tag::Int32Array int32a_2 = NBT::Tag::Int32Array("int32a_2", int32DataVector.size(), int32DataVector.data());
ASSERT(int32a_0.getTagType() == 11 && int32a_1.getTagType() == 11 && int32a_2.getTagType() == 11);
ASSERT(
int32a_0.getData() == int32a_1.getData() &&
int32a_1.getData() == int32a_2.getData()
);
ASSERT(
!int32a_0.getValue(0).isError &&
!int32a_1.getValue(1).isError &&
!int32a_2.getValue(2).isError
);
ASSERT(int32a_0.getValue(3).isError);
ASSERT(int32a_2.getValue(3).errorCode == ErrorCodes::OUT_OF_RANGE);
int32a_1.addElement(-2147483647);
resultGood = int32a_2.removeElement(1);
resultError = int32a_2.removeElement(2);
ASSERT(!resultGood.isError && resultError.isError && resultError.errorCode==ErrorCodes::OUT_OF_RANGE);
resultGood = int32a_2.setValue(1, 15);
resultError = int32a_2.setValue(2, 7);
ASSERT(!resultGood.isError && resultError.isError && resultError.errorCode==ErrorCodes::OUT_OF_RANGE);
ASSERT(
int32a_0.length()==3 &&
int32a_1.length()==4 &&
int32a_2.length()==2
);
ASSERT(
!int32a_0.serialize(&vector).isError &&
!int32a_1.serialize(&vector).isError &&
!int32a_2.serialize(&vector).isError
);
ASSERT(vector.size() == 81);
ASSERT(
vector.at( 0) == 11 &&
vector.at( 1) == 0 &&
vector.at( 2) == 8 &&
vector.at( 3) == 'i' &&
vector.at( 4) == 'n' &&
vector.at( 5) == 't' &&
vector.at( 6) == '3' &&
vector.at( 7) == '2' &&
vector.at( 8) == 'a' &&
vector.at( 9) == '_' &&
vector.at(10) == '0' &&
vector.at(11) == 0 &&
vector.at(12) == 0 &&
vector.at(13) == 0 &&
vector.at(14) == 3 &&
vector.at(15) == 0x80 &&
vector.at(16) == 0x00 &&
vector.at(17) == 0x00 &&
vector.at(18) == 0x00 &&
vector.at(19) == 0x7F &&
vector.at(20) == 0xFF &&
vector.at(21) == 0xFF &&
vector.at(22) == 0xFF &&
vector.at(23) == 0x00 &&
vector.at(24) == 0x00 &&
vector.at(25) == 0x00 &&
vector.at(26) == 0x00 &&
vector.at(27) == 11 &&
vector.at(28) == 0 &&
vector.at(29) == 8 &&
vector.at(30) == 'i' &&
vector.at(31) == 'n' &&
vector.at(32) == 't' &&
vector.at(33) == '3' &&
vector.at(34) == '2' &&
vector.at(35) == 'a' &&
vector.at(36) == '_' &&
vector.at(37) == '1' &&
vector.at(38) == 0 &&
vector.at(39) == 0 &&
vector.at(40) == 0 &&
vector.at(41) == 4 &&
vector.at(42) == 0x80 &&
vector.at(43) == 0x00 &&
vector.at(44) == 0x00 &&
vector.at(45) == 0x00 &&
vector.at(46) == 0x7F &&
vector.at(47) == 0xFF &&
vector.at(48) == 0xFF &&
vector.at(49) == 0xFF &&
vector.at(50) == 0x00 &&
vector.at(51) == 0x00 &&
vector.at(52) == 0x00 &&
vector.at(53) == 0x00 &&
vector.at(54) == 0x80 &&
vector.at(55) == 0x00 &&
vector.at(56) == 0x00 &&
vector.at(57) == 0x01 &&
vector.at(58) == 11 &&
vector.at(59) == 0 &&
vector.at(60) == 8 &&
vector.at(61) == 'i' &&
vector.at(62) == 'n' &&
vector.at(63) == 't' &&
vector.at(64) == '3' &&
vector.at(65) == '2' &&
vector.at(66) == 'a' &&
vector.at(67) == '_' &&
vector.at(68) == '2' &&
vector.at(69) == 0 &&
vector.at(70) == 0 &&
vector.at(71) == 0 &&
vector.at(72) == 2 &&
vector.at(73) == 0x80 &&
vector.at(74) == 0x00 &&
vector.at(75) == 0x00 &&
vector.at(76) == 0x00 &&
vector.at(77) == 0x00 &&
vector.at(78) == 0x00 &&
vector.at(70) == 0x00 &&
vector.at(80) == 0x0F
);
vector.clear();
ASSERT(
!int32a_0.serializeWithoutHeader(&vector).isError &&
!int32a_1.serializeWithoutHeader(&vector).isError &&
!int32a_2.serializeWithoutHeader(&vector).isError
);
ASSERT(vector.size() == 48);
ASSERT(
vector.at( 0) == 0 &&
vector.at( 1) == 0 &&
vector.at( 2) == 0 &&
vector.at( 3) == 3 &&
vector.at( 4) == 0x80 &&
vector.at( 5) == 0x00 &&
vector.at( 6) == 0x00 &&
vector.at( 7) == 0x00 &&
vector.at( 8) == 0x7F &&
vector.at( 9) == 0xFF &&
vector.at(10) == 0xFF &&
vector.at(11) == 0xFF &&
vector.at(12) == 0x00 &&
vector.at(13) == 0x00 &&
vector.at(14) == 0x00 &&
vector.at(15) == 0x00 &&
vector.at(16) == 0 &&
vector.at(17) == 0 &&
vector.at(18) == 0 &&
vector.at(19) == 4 &&
vector.at(20) == 0x80 &&
vector.at(21) == 0x00 &&
vector.at(22) == 0x00 &&
vector.at(23) == 0x00 &&
vector.at(24) == 0x7F &&
vector.at(25) == 0xFF &&
vector.at(26) == 0xFF &&
vector.at(27) == 0xFF &&
vector.at(28) == 0x00 &&
vector.at(29) == 0x00 &&
vector.at(30) == 0x00 &&
vector.at(31) == 0x00 &&
vector.at(32) == 0x80 &&
vector.at(33) == 0x00 &&
vector.at(34) == 0x00 &&
vector.at(35) == 0x01 &&
vector.at(36) == 0 &&
vector.at(37) == 0 &&
vector.at(38) == 0 &&
vector.at(39) == 2 &&
vector.at(40) == 0x80 &&
vector.at(41) == 0x00 &&
vector.at(42) == 0x00 &&
vector.at(43) == 0x00 &&
vector.at(44) == 0x00 &&
vector.at(45) == 0x00 &&
vector.at(46) == 0x00 &&
vector.at(47) == 0x0F
);
vector.clear();
std::cout << "Passed Int32Array test." << std::endl;
return 0;
}