-
-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathSpecialTests.gd
More file actions
73 lines (55 loc) · 3.12 KB
/
Copy pathSpecialTests.gd
File metadata and controls
73 lines (55 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright (c) godot-rust; Bromeon and contributors.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
extends TestSuiteSpecial
# Tests in here require specific setup/configuration that is not easily achievable through the standard
# integration testing API.
#
# Using the standard API if possible is highly preferred.
# Test that we can call `_input_event` on a class defined in rust, as a virtual method.
#
# This tests #267, which was caused by us incorrectly handing Objects when passed as arguments to virtual
# methods. `_input_event` is the easiest such method to test. However it can only be triggered by letting a
# full physics frame pass after calling `push_unhandled_input`. Thus we cannot use the standard API for
# testing this at the moment, since we don't have any way to let frames pass in between the start and end of
# an integration test.
func test_collision_object_2d_input_event():
if not IntegrationTests.is_full_codegen():
print("Skip in minimal codegen: test_collision_object_2d_input_event")
return
# Dynamic instantiation, to still parse if Rust class is disabled.
var collision_object: Variant = ClassDB.instantiate("CollisionObject2DTest")
collision_object.input_pickable = true
var collision_shape := CollisionShape2D.new()
collision_shape.shape = RectangleShape2D.new()
collision_object.add_child(collision_shape)
var window := Window.new()
window.physics_object_picking = true
window.add_child(collision_object)
var root: Node = Engine.get_main_loop().root
root.add_child(window)
assert_that(not collision_object.input_event_called(), "Input event should not be propagated")
assert_eq(collision_object.get_viewport(), null, "Collision viewport should be null")
var event := InputEventMouseMotion.new()
event.global_position = Vector2.ZERO
# FIXME: https://github.com/godotengine/godot/pull/88992 changed behavior here. Adjust code depending on resolution.
return
# Needed push_unhandled_input() in Godot 4.0; no longer supported.
window.push_input(event)
# Ensure we run a full physics frame.
await root.get_tree().physics_frame
assert_that(collision_object.input_event_called(), "Input event should be propagated")
assert_eq(collision_object.get_viewport(), window, "Collision viewport should be the (non-null) window")
window.queue_free()
func test_autoload():
var fetched = Engine.get_main_loop().get_root().get_node_or_null("/root/MyAutoload")
assert_that(fetched != null, "MyAutoload should be loaded")
var by_class: AutoloadClass = fetched
assert_eq(by_class.verify_works(), 787, "Autoload typed by class")
var by_class_symbol: AutoloadClass = MyAutoload
assert_eq(by_class_symbol.verify_works(), 787, "Autoload typed by class")
# Autoload in GDScript can be referenced by class name or autoload name, however autoload as a type is only available in Godot 4.3+.
# See https://github.com/godot-rust/gdext/pull/1381#issuecomment-3446111511.
# var by_name: MyAutoload = fetched
# assert_eq(by_name.verify_works(), 787, "Autoload typed by name")