Merge pull request #1277 from dsnopek/variant-iter-tests

Add an automated test using a Variant iterator
pull/1288/head
Rémi Verschelde 2023-10-24 22:30:42 +02:00 committed by GitHub
commit 1ab94699c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 0 deletions

View File

@ -187,6 +187,10 @@ func _ready():
assert_equal(example.test_bitfield(0), 0) assert_equal(example.test_bitfield(0), 0)
assert_equal(example.test_bitfield(Example.FLAG_ONE | Example.FLAG_TWO), 3) assert_equal(example.test_bitfield(Example.FLAG_ONE | Example.FLAG_TWO), 3)
# Test variant iterator.
assert_equal(example.test_variant_iterator([10, 20, 30]), [15, 25, 35])
assert_equal(example.test_variant_iterator(null), "iter_init: not valid")
# RPCs. # RPCs.
assert_equal(example.return_last_rpc_arg(), 0) assert_equal(example.return_last_rpc_arg(), 0)
example.test_rpc(42) example.test_rpc(42)

View File

@ -171,6 +171,8 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield); ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield);
ClassDB::bind_method(D_METHOD("test_variant_iterator", "input"), &Example::test_variant_iterator);
ClassDB::bind_method(D_METHOD("test_rpc", "value"), &Example::test_rpc); ClassDB::bind_method(D_METHOD("test_rpc", "value"), &Example::test_rpc);
ClassDB::bind_method(D_METHOD("test_send_rpc", "value"), &Example::test_send_rpc); ClassDB::bind_method(D_METHOD("test_send_rpc", "value"), &Example::test_send_rpc);
ClassDB::bind_method(D_METHOD("return_last_rpc_arg"), &Example::return_last_rpc_arg); ClassDB::bind_method(D_METHOD("return_last_rpc_arg"), &Example::return_last_rpc_arg);
@ -485,6 +487,41 @@ BitField<Example::Flags> Example::test_bitfield(BitField<Flags> flags) {
return flags; return flags;
} }
Variant Example::test_variant_iterator(const Variant &p_input) {
Array output;
Variant iter;
bool is_init_valid = true;
if (!p_input.iter_init(iter, is_init_valid)) {
if (!is_init_valid) {
return "iter_init: not valid";
}
return output;
}
bool is_iter_next_valid = true;
bool is_iter_get_valid = true;
do {
if (!is_iter_next_valid) {
return "iter_next: not valid";
}
Variant value = p_input.iter_get(iter, is_iter_get_valid);
if (!is_iter_get_valid) {
return "iter_get: not valid";
}
output.push_back(((int)value) + 5);
} while (p_input.iter_next(iter, is_iter_next_valid));
if (!is_iter_next_valid) {
return "iter_next: not valid";
}
return output;
}
void Example::test_rpc(int p_value) { void Example::test_rpc(int p_value) {
last_rpc_arg = p_value; last_rpc_arg = p_value;
} }

View File

@ -152,6 +152,8 @@ public:
BitField<Flags> test_bitfield(BitField<Flags> flags); BitField<Flags> test_bitfield(BitField<Flags> flags);
Variant test_variant_iterator(const Variant &p_input);
// RPC // RPC
void test_rpc(int p_value); void test_rpc(int p_value);
void test_send_rpc(int p_value); void test_send_rpc(int p_value);