mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 07:53:26 +00:00
Merge pull request #102587 from bruvzg/s_pa_tst
[Tests] Add `Packed*Array` `to_byte_array` variant call tests.
This commit is contained in:
commit
0d4d70d5a6
1 changed files with 148 additions and 0 deletions
|
@ -215,6 +215,154 @@ TEST_CASE("[Vector] Get, set") {
|
|||
CHECK(vector.get(4) == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("[Vector] To byte array (variant call)") {
|
||||
// PackedInt32Array.
|
||||
{
|
||||
PackedInt32Array vector[] = { { 0, -1, 2008 }, {} };
|
||||
PackedByteArray out[] = { { /* 0 */ 0x00, 0x00, 0x00, 0x00, /* -1 */ 0xFF, 0xFF, 0xFF, 0xFF, /* 2008 */ 0xD8, 0x07, 0x00, 0x00 }, {} };
|
||||
|
||||
for (size_t i = 0; i < std::size(vector); i++) {
|
||||
Callable::CallError err;
|
||||
Variant v_ret;
|
||||
Variant v_vector = vector[i];
|
||||
v_vector.callp("to_byte_array", nullptr, 0, v_ret, err);
|
||||
CHECK(v_ret.get_type() == Variant::PACKED_BYTE_ARRAY);
|
||||
CHECK(v_ret.operator PackedByteArray() == out[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// PackedInt64Array.
|
||||
{
|
||||
PackedInt64Array vector[] = { { 0, -1, 2008 }, {} };
|
||||
PackedByteArray out[] = { { /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* -1 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 2008 */ 0xD8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, {} };
|
||||
|
||||
for (size_t i = 0; i < std::size(vector); i++) {
|
||||
Callable::CallError err;
|
||||
Variant v_ret;
|
||||
Variant v_vector = vector[i];
|
||||
v_vector.callp("to_byte_array", nullptr, 0, v_ret, err);
|
||||
CHECK(v_ret.get_type() == Variant::PACKED_BYTE_ARRAY);
|
||||
CHECK(v_ret.operator PackedByteArray() == out[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// PackedFloat32Array.
|
||||
{
|
||||
PackedFloat32Array vector[] = { { 0.0, -1.0, 200e24 }, {} };
|
||||
PackedByteArray out[] = { { /* 0.0 */ 0x00, 0x00, 0x00, 0x00, /* -1.0 */ 0x00, 0x00, 0x80, 0xBF, /* 200e24 */ 0xA6, 0x6F, 0x25, 0x6B }, {} };
|
||||
|
||||
for (size_t i = 0; i < std::size(vector); i++) {
|
||||
Callable::CallError err;
|
||||
Variant v_ret;
|
||||
Variant v_vector = vector[i];
|
||||
v_vector.callp("to_byte_array", nullptr, 0, v_ret, err);
|
||||
CHECK(v_ret.get_type() == Variant::PACKED_BYTE_ARRAY);
|
||||
CHECK(v_ret.operator PackedByteArray() == out[i]);
|
||||
}
|
||||
}
|
||||
// PackedFloat64Array.
|
||||
{
|
||||
PackedFloat64Array vector[] = { { 0.0, -1.0, 200e24 }, {} };
|
||||
PackedByteArray out[] = { { /* 0.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* -1.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xBF, /* 200e24 */ 0x35, 0x03, 0x32, 0xB7, 0xF4, 0xAD, 0x64, 0x45 }, {} };
|
||||
|
||||
for (size_t i = 0; i < std::size(vector); i++) {
|
||||
Callable::CallError err;
|
||||
Variant v_ret;
|
||||
Variant v_vector = vector[i];
|
||||
v_vector.callp("to_byte_array", nullptr, 0, v_ret, err);
|
||||
CHECK(v_ret.get_type() == Variant::PACKED_BYTE_ARRAY);
|
||||
CHECK(v_ret.operator PackedByteArray() == out[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// PackedStringArray.
|
||||
{
|
||||
PackedStringArray vector[] = { { "test", "string" }, {}, { "", "test" } };
|
||||
PackedByteArray out[] = { { /* test */ 0x74, 0x65, 0x73, 0x74, /* null */ 0x00, /* string */ 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, /* null */ 0x00 }, {}, { /* null */ 0x00, /* test */ 0x74, 0x65, 0x73, 0x74, /* null */ 0x00 } };
|
||||
|
||||
for (size_t i = 0; i < std::size(vector); i++) {
|
||||
Callable::CallError err;
|
||||
Variant v_ret;
|
||||
Variant v_vector = vector[i];
|
||||
v_vector.callp("to_byte_array", nullptr, 0, v_ret, err);
|
||||
CHECK(v_ret.get_type() == Variant::PACKED_BYTE_ARRAY);
|
||||
CHECK(v_ret.operator PackedByteArray() == out[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// PackedVector2Array.
|
||||
{
|
||||
PackedVector2Array vector[] = { { Vector2(), Vector2(1, -1) }, {} };
|
||||
#ifdef REAL_T_IS_DOUBLE
|
||||
PackedByteArray out[] = { { /* X=0.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Y=0.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* X=1.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, /* Y=-1.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xBF }, {} };
|
||||
#else
|
||||
PackedByteArray out[] = { { /* X=0.0 */ 0x00, 0x00, 0x00, 0x00, /* Y=0.0 */ 0x00, 0x00, 0x00, 0x00, /* X=1.0 */ 0x00, 0x00, 0x80, 0x3F, /* Y=-1.0 */ 0x00, 0x00, 0x80, 0xBF }, {} };
|
||||
#endif
|
||||
|
||||
for (size_t i = 0; i < std::size(vector); i++) {
|
||||
Callable::CallError err;
|
||||
Variant v_ret;
|
||||
Variant v_vector = vector[i];
|
||||
v_vector.callp("to_byte_array", nullptr, 0, v_ret, err);
|
||||
CHECK(v_ret.get_type() == Variant::PACKED_BYTE_ARRAY);
|
||||
CHECK(v_ret.operator PackedByteArray() == out[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// PackedVector3Array.
|
||||
{
|
||||
PackedVector3Array vector[] = { { Vector3(), Vector3(1, 1, -1) }, {} };
|
||||
#ifdef REAL_T_IS_DOUBLE
|
||||
PackedByteArray out[] = { { /* X=0.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Y=0.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Z=0.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* X=1.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, /* Y=1.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, /* Z=-1.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xBF }, {} };
|
||||
#else
|
||||
PackedByteArray out[] = { { /* X=0.0 */ 0x00, 0x00, 0x00, 0x00, /* Y=0.0 */ 0x00, 0x00, 0x00, 0x00, /* Z=0.0 */ 0x00, 0x00, 0x00, 0x00, /* X=1.0 */ 0x00, 0x00, 0x80, 0x3F, /* Y=1.0 */ 0x00, 0x00, 0x80, 0x3F, /* Z=-1.0 */ 0x00, 0x00, 0x80, 0xBF }, {} };
|
||||
#endif
|
||||
|
||||
for (size_t i = 0; i < std::size(vector); i++) {
|
||||
Callable::CallError err;
|
||||
Variant v_ret;
|
||||
Variant v_vector = vector[i];
|
||||
v_vector.callp("to_byte_array", nullptr, 0, v_ret, err);
|
||||
CHECK(v_ret.get_type() == Variant::PACKED_BYTE_ARRAY);
|
||||
CHECK(v_ret.operator PackedByteArray() == out[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// PackedColorArray.
|
||||
{
|
||||
PackedColorArray vector[] = { { Color(), Color(1, 1, 1) }, {} };
|
||||
PackedByteArray out[] = { { /* R=0.0 */ 0x00, 0x00, 0x00, 0x00, /* G=0.0 */ 0x00, 0x00, 0x00, 0x00, /* B=0.0 */ 0x00, 0x00, 0x00, 0x00, /* A=1.0 */ 0x00, 0x00, 0x80, 0x3F, /* R=1.0 */ 0x00, 0x00, 0x80, 0x3F, /* G=1.0 */ 0x00, 0x00, 0x80, 0x3F, /* B=1.0 */ 0x00, 0x00, 0x80, 0x3F, /* A=1.0 */ 0x00, 0x00, 0x80, 0x3F }, {} };
|
||||
|
||||
for (size_t i = 0; i < std::size(vector); i++) {
|
||||
Callable::CallError err;
|
||||
Variant v_ret;
|
||||
Variant v_vector = vector[i];
|
||||
v_vector.callp("to_byte_array", nullptr, 0, v_ret, err);
|
||||
CHECK(v_ret.get_type() == Variant::PACKED_BYTE_ARRAY);
|
||||
CHECK(v_ret.operator PackedByteArray() == out[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// PackedVector4Array.
|
||||
{
|
||||
PackedVector4Array vector[] = { { Vector4(), Vector4(1, -1, 1, -1) }, {} };
|
||||
#ifdef REAL_T_IS_DOUBLE
|
||||
PackedByteArray out[] = { { /* X=0.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Y=0.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Z 0.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* W=0.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* X=1.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, /* Y=-1.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xBF, /* Z=1.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, /* W=-1.0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xBF }, {} };
|
||||
#else
|
||||
PackedByteArray out[] = { { /* X=0.0 */ 0x00, 0x00, 0x00, 0x00, /* Y=0.0 */ 0x00, 0x00, 0x00, 0x00, /* Z=0.0 */ 0x00, 0x00, 0x00, 0x00, /* W 0.0 */ 0x00, 0x00, 0x00, 0x00, /* X 1.0 */ 0x00, 0x00, 0x80, 0x3F, /* Y=-1.0 */ 0x00, 0x00, 0x80, 0xBF, /* Z=1.0 */ 0x00, 0x00, 0x80, 0x3F, /* W=-1.0 */ 0x00, 0x00, 0x80, 0xBF }, {} };
|
||||
#endif
|
||||
|
||||
for (size_t i = 0; i < std::size(vector); i++) {
|
||||
Callable::CallError err;
|
||||
Variant v_ret;
|
||||
Variant v_vector = vector[i];
|
||||
v_vector.callp("to_byte_array", nullptr, 0, v_ret, err);
|
||||
CHECK(v_ret.get_type() == Variant::PACKED_BYTE_ARRAY);
|
||||
CHECK(v_ret.operator PackedByteArray() == out[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Vector] To byte array") {
|
||||
Vector<int> vector;
|
||||
vector.push_back(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue