Skip to content

Commit 67aeecc

Browse files
Bugfix/pool arrays resize engine calls (#320)
* test resize and set for pool arrays * Replace calls to remove when calling resize engine calls on pool arrays Co-authored-by: Richard Treier <richard.treier@gmail.com>
1 parent a519eb5 commit 67aeecc

9 files changed

Lines changed: 678 additions & 516 deletions

harness/tests/src/main/kotlin/godot/tests/Invocation.kt

Lines changed: 580 additions & 509 deletions
Large diffs are not rendered by default.

harness/tests/test/unit/test_pool_arrays.gd

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ func test_pool_byte_array_add_delete() -> void:
1010
assert_eq(invocation_script.pool_byte_array.size(), 3, "PoolByteArray have 3 elements")
1111
invocation_script.delete_byte_from_pool_array(0)
1212
assert_eq(invocation_script.pool_byte_array.size(), 2, "PoolByteArray have 2 elements")
13+
14+
# Test resize + set in particular
15+
invocation_script.resize_byte_pool_array(0)
16+
assert_eq(invocation_script.pool_byte_array.size(), 0, "PoolByteArray was emptied by resize(0)")
17+
invocation_script.resize_byte_pool_array(3)
18+
invocation_script.set_byte_in_pool_array(0, 1)
19+
invocation_script.set_byte_in_pool_array(1, 2)
20+
invocation_script.set_byte_in_pool_array(2, 3)
21+
assert_eq(invocation_script.pool_byte_array.size(), 3, "PoolByteArray has size 3 after resize(3) and 3x set(...)")
22+
assert_eq(invocation_script.get_byte_from_pool_array(0), 1, "First element of PoolByteArray after resize(3) and 3x set(...) should be 1.")
23+
assert_eq(invocation_script.get_byte_from_pool_array(1), 2, "Second element of PoolByteArray after resize(3) and 3x set(...) should be 2.")
24+
assert_eq(invocation_script.get_byte_from_pool_array(2), 3, "Third element of PoolByteArray after resize(3) and 3x set(...) should be 3.")
25+
1326
invocation_script.free()
1427

1528
func test_pool_color_array_add_delete() -> void:
@@ -24,6 +37,19 @@ func test_pool_color_array_add_delete() -> void:
2437
assert_eq(invocation_script.get_color_from_pool_array(2), Color(1, 2, 3), "Second element of PoolColorArray should be Color(1, 2, 3).")
2538
invocation_script.delete_color_from_pool_array(0)
2639
assert_eq(invocation_script.pool_color_array.size(), 2, "PoolColorArray have 2 elements")
40+
41+
# Test resize + set in particular
42+
invocation_script.resize_color_pool_array(0)
43+
assert_eq(invocation_script.pool_color_array.size(), 0, "PoolColorArray was emptied by resize(0)")
44+
invocation_script.resize_color_pool_array(3)
45+
invocation_script.set_color_in_pool_array(0, Color(1, 1, 9))
46+
invocation_script.set_color_in_pool_array(1, Color(2, 2, 9))
47+
invocation_script.set_color_in_pool_array(2, Color(3, 3, 9))
48+
assert_eq(invocation_script.pool_color_array.size(), 3, "PoolColorArray has size 3 after resize(3) and 3x set(...)")
49+
assert_eq(invocation_script.get_color_from_pool_array(0), Color(1, 1, 9), "First element of PoolColorArray after resize(3) and 3x set(...) should be Color(1, 1, 9).")
50+
assert_eq(invocation_script.get_color_from_pool_array(1), Color(2, 2, 9), "Second element of PoolColorArray after resize(3) and 3x set(...) should be Color(2, 2, 9).")
51+
assert_eq(invocation_script.get_color_from_pool_array(2), Color(3, 3, 9), "Third element of PoolColorArray after resize(3) and 3x set(...) should be Color(3, 3, 9).")
52+
2753
invocation_script.free()
2854

2955
func test_pool_int_array_add_delete() -> void:
@@ -38,6 +64,19 @@ func test_pool_int_array_add_delete() -> void:
3864
assert_eq(invocation_script.get_int_from_pool_array(2), 3, "Second element of PoolIntArray should be 3.")
3965
invocation_script.delete_int_from_pool_array(0)
4066
assert_eq(invocation_script.pool_int_array.size(), 2, "PoolIntArray have 2 elements")
67+
68+
# Test resize + set in particular
69+
invocation_script.resize_int_pool_array(0)
70+
assert_eq(invocation_script.pool_int_array.size(), 0, "PoolIntArray was emptied by resize(0)")
71+
invocation_script.resize_int_pool_array(3)
72+
invocation_script.set_int_in_pool_array(0, 1)
73+
invocation_script.set_int_in_pool_array(1, 2)
74+
invocation_script.set_int_in_pool_array(2, 3)
75+
assert_eq(invocation_script.pool_int_array.size(), 3, "PoolIntArray has size 3 after resize(3) and 3x set(...)")
76+
assert_eq(invocation_script.get_int_from_pool_array(0), 1, "First element of PoolIntArray after resize(3) and 3x set(...) should be 1.")
77+
assert_eq(invocation_script.get_int_from_pool_array(1), 2, "Second element of PoolIntArray after resize(3) and 3x set(...) should be 2.")
78+
assert_eq(invocation_script.get_int_from_pool_array(2), 3, "Third element of PoolIntArray after resize(3) and 3x set(...) should be 3.")
79+
4180
invocation_script.free()
4281

4382
func test_pool_real_array_add_delete() -> void:
@@ -52,6 +91,19 @@ func test_pool_real_array_add_delete() -> void:
5291
assert_eq(invocation_script.get_real_from_pool_array(2), 3.0, "Second element of PoolRealArray should be 3.0.")
5392
invocation_script.delete_real_from_pool_array(0)
5493
assert_eq(invocation_script.pool_real_array.size(), 2, "PoolRealArray have 2 elements")
94+
95+
# Test resize + set in particular
96+
invocation_script.resize_real_pool_array(0)
97+
assert_eq(invocation_script.pool_real_array.size(), 0, "PoolRealArray was emptied by resize(0)")
98+
invocation_script.resize_real_pool_array(3)
99+
invocation_script.set_real_in_pool_array(0, 1.0)
100+
invocation_script.set_real_in_pool_array(1, 2.0)
101+
invocation_script.set_real_in_pool_array(2, 3.0)
102+
assert_eq(invocation_script.pool_real_array.size(), 3, "PoolRealArray has size 3 after resize(3) and 3x set(...)")
103+
assert_eq(invocation_script.get_real_from_pool_array(0), 1.0, "First element of PoolRealArray after resize(3) and 3x set(...) should be 1.0.")
104+
assert_eq(invocation_script.get_real_from_pool_array(1), 2.0, "Second element of PoolRealArray after resize(3) and 3x set(...) should be 2.0.")
105+
assert_eq(invocation_script.get_real_from_pool_array(2), 3.0, "Third element of PoolRealArray after resize(3) and 3x set(...) should be 3.0.")
106+
55107
invocation_script.free()
56108

57109
func test_pool_string_array_add_delete() -> void:
@@ -66,6 +118,19 @@ func test_pool_string_array_add_delete() -> void:
66118
assert_eq(invocation_script.get_string_from_pool_array(2), "3", "Second element of PoolStringArray should be 3.")
67119
invocation_script.delete_string_from_pool_array(0)
68120
assert_eq(invocation_script.pool_string_array.size(), 2, "PoolStringArray have 2 elements")
121+
122+
# Test resize + set in particular
123+
invocation_script.resize_string_pool_array(0)
124+
assert_eq(invocation_script.pool_string_array.size(), 0, "PoolStringArray was emptied by resize(0)")
125+
invocation_script.resize_string_pool_array(3)
126+
invocation_script.set_string_in_pool_array(0, "1")
127+
invocation_script.set_string_in_pool_array(1, "2")
128+
invocation_script.set_string_in_pool_array(2, "3")
129+
assert_eq(invocation_script.pool_string_array.size(), 3, "PoolStringArray has size 3 after resize(3) and 3x set(...)")
130+
assert_eq(invocation_script.get_string_from_pool_array(0), "1", "First element of PoolStringArray after resize(3) and 3x set(...) should be 1.")
131+
assert_eq(invocation_script.get_string_from_pool_array(1), "2", "Second element of PoolStringArray after resize(3) and 3x set(...) should be 2.")
132+
assert_eq(invocation_script.get_string_from_pool_array(2), "3", "Third element of PoolStringArray after resize(3) and 3x set(...) should be 3.")
133+
69134
invocation_script.free()
70135

71136
func test_pool_vector2_array_add_delete() -> void:
@@ -80,6 +145,19 @@ func test_pool_vector2_array_add_delete() -> void:
80145
assert_eq(invocation_script.get_vector2_from_pool_array(2), Vector2(3, 1), "Second element of PoolVector2Array should be Vector2(3, 1).")
81146
invocation_script.delete_vector2_from_pool_array(0)
82147
assert_eq(invocation_script.pool_vector2_array.size(), 2, "PoolVector2Array have 2 elements")
148+
149+
# Test resize + set in particular
150+
invocation_script.resize_vector2_pool_array(0)
151+
assert_eq(invocation_script.pool_vector2_array.size(), 0, "PoolVector2Array was emptied by resize(0)")
152+
invocation_script.resize_vector2_pool_array(3)
153+
invocation_script.set_vector2_in_pool_array(0, Vector2(1, 1))
154+
invocation_script.set_vector2_in_pool_array(1, Vector2(2, 2))
155+
invocation_script.set_vector2_in_pool_array(2, Vector2(3, 3))
156+
assert_eq(invocation_script.pool_vector2_array.size(), 3, "PoolVector2Array has size 3 after resize(3) and 3x set(...)")
157+
assert_eq(invocation_script.get_vector2_from_pool_array(0), Vector2(1, 1), "First element of PoolVector2Array after resize(3) and 3x set(...) should be Vector2(1, 1).")
158+
assert_eq(invocation_script.get_vector2_from_pool_array(1), Vector2(2, 2), "Second element of PoolVector2Array after resize(3) and 3x set(...) should be Vector2(2, 2).")
159+
assert_eq(invocation_script.get_vector2_from_pool_array(2), Vector2(3, 3), "Third element of PoolVector2Array after resize(3) and 3x set(...) should be Vector2(3, 3).")
160+
83161
invocation_script.free()
84162

85163
func test_pool_vector3_array_add_delete() -> void:
@@ -94,6 +172,19 @@ func test_pool_vector3_array_add_delete() -> void:
94172
assert_eq(invocation_script.get_vector3_from_pool_array(2), Vector3(3, 1, 1), "Second element of PoolVector3Array should be Vector3(3, 1).")
95173
invocation_script.delete_vector3_from_pool_array(0)
96174
assert_eq(invocation_script.pool_vector3_array.size(), 2, "PoolVector3Array have 2 elements")
175+
176+
# Test resize + set in particular
177+
invocation_script.resize_vector3_pool_array(0)
178+
assert_eq(invocation_script.pool_vector3_array.size(), 0, "PoolVector3Array was emptied by resize(0)")
179+
invocation_script.resize_vector3_pool_array(3)
180+
invocation_script.set_vector3_in_pool_array(0, Vector3(1, 1, 9))
181+
invocation_script.set_vector3_in_pool_array(1, Vector3(2, 2, 9))
182+
invocation_script.set_vector3_in_pool_array(2, Vector3(3, 3, 9))
183+
assert_eq(invocation_script.pool_vector3_array.size(), 3, "PoolVector3Array has size 3 after resize(3) and 3x set(...)")
184+
assert_eq(invocation_script.get_vector3_from_pool_array(0), Vector3(1, 1, 9), "First element of PoolVector3Array after resize(3) and 3x set(...) should be Vector3(1, 1, 9).")
185+
assert_eq(invocation_script.get_vector3_from_pool_array(1), Vector3(2, 2, 9), "Second element of PoolVector3Array after resize(3) and 3x set(...) should be Vector3(2, 2, 9).")
186+
assert_eq(invocation_script.get_vector3_from_pool_array(2), Vector3(3, 3, 9), "Third element of PoolVector3Array after resize(3) and 3x set(...) should be Vector3(3, 3, 9).")
187+
97188
invocation_script.free()
98189

99190
func test_pool_byte_array_string_conversion() -> void:

src/bridges/pool_byte_array_bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ void PoolByteArrayBridge::engine_call_resize(JNIEnv* p_raw_env, jobject p_instan
262262
Variant args[1] = {};
263263
TransferContext* transfer_context{GDKotlin::get_instance().transfer_context};
264264
transfer_context->read_args(env, args);
265-
from_uint_to_ptr<PoolByteArray>(p_raw_ptr)->remove(args[0].operator unsigned int());
265+
from_uint_to_ptr<PoolByteArray>(p_raw_ptr)->resize(args[0].operator unsigned int());
266266
}
267267

268268
void PoolByteArrayBridge::engine_call_set(JNIEnv* p_raw_env, jobject p_instance, jlong p_raw_ptr) {

src/bridges/pool_color_array_bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void PoolColorArrayBridge::engine_call_resize(JNIEnv* p_raw_env, jobject p_insta
159159
Variant args[1] = {};
160160
TransferContext* transfer_context{GDKotlin::get_instance().transfer_context};
161161
transfer_context->read_args(env, args);
162-
from_uint_to_ptr<PoolColorArray>(p_raw_ptr)->remove(args[0].operator unsigned int());
162+
from_uint_to_ptr<PoolColorArray>(p_raw_ptr)->resize(args[0].operator unsigned int());
163163
}
164164

165165
void PoolColorArrayBridge::engine_call_set(JNIEnv* p_raw_env, jobject p_instance, jlong p_raw_ptr) {

src/bridges/pool_int_array_bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void PoolIntArrayBridge::engine_call_resize(JNIEnv* p_raw_env, jobject p_instanc
159159
Variant args[1] = {};
160160
TransferContext* transfer_context{GDKotlin::get_instance().transfer_context};
161161
transfer_context->read_args(env, args);
162-
from_uint_to_ptr<PoolIntArray>(p_raw_ptr)->remove(args[0].operator unsigned int());
162+
from_uint_to_ptr<PoolIntArray>(p_raw_ptr)->resize(args[0].operator unsigned int());
163163
}
164164

165165
void PoolIntArrayBridge::engine_call_set(JNIEnv* p_raw_env, jobject p_instance, jlong p_raw_ptr) {

src/bridges/pool_real_array_bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void PoolRealArrayBridge::engine_call_resize(JNIEnv* p_raw_env, jobject p_instan
159159
Variant args[1] = {};
160160
TransferContext* transfer_context{GDKotlin::get_instance().transfer_context};
161161
transfer_context->read_args(env, args);
162-
from_uint_to_ptr<PoolRealArray>(p_raw_ptr)->remove(args[0].operator unsigned int());
162+
from_uint_to_ptr<PoolRealArray>(p_raw_ptr)->resize(args[0].operator unsigned int());
163163
}
164164

165165
void PoolRealArrayBridge::engine_call_set(JNIEnv* p_raw_env, jobject p_instance, jlong p_raw_ptr) {

src/bridges/pool_string_array_bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void PoolStringArrayBridge::engine_call_resize(JNIEnv* p_raw_env, jobject p_inst
174174
Variant args[1] = {};
175175
TransferContext* transfer_context{GDKotlin::get_instance().transfer_context};
176176
transfer_context->read_args(env, args);
177-
from_uint_to_ptr<PoolStringArray>(p_raw_ptr)->remove(args[0].operator unsigned int());
177+
from_uint_to_ptr<PoolStringArray>(p_raw_ptr)->resize(args[0].operator unsigned int());
178178
}
179179

180180
void PoolStringArrayBridge::engine_call_set(JNIEnv* p_raw_env, jobject p_instance, jlong p_raw_ptr) {

src/bridges/pool_vector2_array_bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void PoolVector2ArrayBridge::engine_call_resize(JNIEnv* p_raw_env, jobject p_ins
159159
Variant args[1] = {};
160160
TransferContext* transfer_context{GDKotlin::get_instance().transfer_context};
161161
transfer_context->read_args(env, args);
162-
from_uint_to_ptr<PoolVector2Array>(p_raw_ptr)->remove(args[0].operator unsigned int());
162+
from_uint_to_ptr<PoolVector2Array>(p_raw_ptr)->resize(args[0].operator unsigned int());
163163
}
164164

165165
void PoolVector2ArrayBridge::engine_call_set(JNIEnv* p_raw_env, jobject p_instance, jlong p_raw_ptr) {

src/bridges/pool_vector3_array_bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void PoolVector3ArrayBridge::engine_call_resize(JNIEnv* p_raw_env, jobject p_ins
159159
Variant args[1] = {};
160160
TransferContext* transfer_context{GDKotlin::get_instance().transfer_context};
161161
transfer_context->read_args(env, args);
162-
from_uint_to_ptr<PoolVector3Array>(p_raw_ptr)->remove(args[0].operator unsigned int());
162+
from_uint_to_ptr<PoolVector3Array>(p_raw_ptr)->resize(args[0].operator unsigned int());
163163
}
164164

165165
void PoolVector3ArrayBridge::engine_call_set(JNIEnv* p_raw_env, jobject p_instance, jlong p_raw_ptr) {

0 commit comments

Comments
 (0)