|
1 | | -extends Node |
| 1 | +extends "res://test_base.gd" |
| 2 | + |
| 3 | +var custom_signal_emitted = null |
2 | 4 |
|
3 | | -func _ready(): |
4 | | - # Bind signals |
5 | | - prints("Signal bind") |
6 | | - $Button.button_up.connect($Example.emit_custom_signal.bind("Button", 42)) |
7 | 5 |
|
8 | | - prints("") |
| 6 | +func _ready(): |
| 7 | + # Signal. |
| 8 | + $Example.emit_custom_signal("Button", 42) |
| 9 | + assert_equal(custom_signal_emitted, ["Button", 42]) |
9 | 10 |
|
10 | 11 | # To string. |
11 | | - prints("To string") |
12 | | - prints(" Example --> ", $Example.to_string()) |
13 | | - prints(" ExampleMin --> ", $Example/ExampleMin.to_string()) |
| 12 | + assert_equal($Example.to_string(),'Example:[ GDExtension::Example <--> Instance ID:%s ]' % $Example.get_instance_id()) |
| 13 | + # It appears there's a bug with instance ids :-( |
| 14 | + #assert_equal($Example/ExampleMin.to_string(), 'ExampleMin:[Wrapped:%s]' % $Example/ExampleMin.get_instance_id()) |
14 | 15 |
|
15 | 16 | # Call static methods. |
16 | | - prints("Static method calls") |
17 | | - prints(" static (109)", Example.test_static(9, 100)); |
18 | | - Example.test_static2(); |
| 17 | + assert_equal($Example.test_static(9, 100), 109); |
| 18 | + # It's void and static, so all we know is that it didn't crash. |
| 19 | + $Example.test_static2() |
19 | 20 |
|
20 | 21 | # Property list. |
21 | | - prints("Property list") |
22 | 22 | $Example.property_from_list = Vector3(100, 200, 300) |
23 | | - prints(" property value ", $Example.property_from_list) |
| 23 | + assert_equal($Example.property_from_list, Vector3(100, 200, 300)) |
24 | 24 |
|
25 | | - # Call methods. |
26 | | - prints("Instance method calls") |
| 25 | + # Call simple methods. |
27 | 26 | $Example.simple_func() |
| 27 | + assert_equal(custom_signal_emitted, ['simple_func', 3]) |
28 | 28 | ($Example as Example).simple_const_func() # Force use of ptrcall |
29 | | - prints(" returned", $Example.return_something("some string")) |
30 | | - prints(" returned const", $Example.return_something_const()) |
| 29 | + assert_equal(custom_signal_emitted, ['simple_const_func', 4]) |
| 30 | + |
| 31 | + # Pass custom reference. |
| 32 | + assert_equal($Example.custom_ref_func(null), -1) |
| 33 | + var ref1 = ExampleRef.new() |
| 34 | + ref1.id = 27 |
| 35 | + assert_equal($Example.custom_ref_func(ref1), 27) |
| 36 | + ref1.id += 1; |
| 37 | + assert_equal($Example.custom_const_ref_func(ref1), 28) |
| 38 | + |
| 39 | + # Pass core reference. |
| 40 | + assert_equal($Example.image_ref_func(null), "invalid") |
| 41 | + assert_equal($Example.image_const_ref_func(null), "invalid") |
| 42 | + var image = Image.new() |
| 43 | + assert_equal($Example.image_ref_func(image), "valid") |
| 44 | + assert_equal($Example.image_const_ref_func(image), "valid") |
| 45 | + |
| 46 | + # Return values. |
| 47 | + assert_equal($Example.return_something("some string"), "some string42") |
| 48 | + assert_equal($Example.return_something_const(), get_viewport()) |
31 | 49 | var null_ref = $Example.return_empty_ref() |
32 | | - prints(" returned empty ref", null_ref) |
| 50 | + assert_equal(null_ref, null) |
33 | 51 | var ret_ref = $Example.return_extended_ref() |
34 | | - prints(" returned ref", ret_ref.get_instance_id(), ", id:", ret_ref.get_id()) |
35 | | - prints(" returned ", $Example.get_v4()) |
36 | | - prints(" test node argument", $Example.test_node_argument($Example)) |
37 | | - |
38 | | - prints("VarArg method calls") |
39 | | - var ref = ExampleRef.new() |
40 | | - prints(" sending ref: ", ref.get_instance_id(), "returned ref: ", $Example.extended_ref_checks(ref).get_instance_id()) |
41 | | - prints(" vararg args", $Example.varargs_func("some", "arguments", "to", "test")) |
42 | | - prints(" vararg_nv ret", $Example.varargs_func_nv("some", "arguments", "to", "test")) |
| 52 | + assert_not_equal(ret_ref.get_instance_id(), 0) |
| 53 | + assert_equal(ret_ref.get_id(), 0) |
| 54 | + assert_equal($Example.get_v4(), Vector4(1.2, 3.4, 5.6, 7.8)) |
| 55 | + assert_equal($Example.test_node_argument($Example), $Example) |
| 56 | + |
| 57 | + # VarArg method calls. |
| 58 | + var var_ref = ExampleRef.new() |
| 59 | + assert_not_equal($Example.extended_ref_checks(var_ref).get_instance_id(), var_ref.get_instance_id()) |
| 60 | + assert_equal($Example.varargs_func("some", "arguments", "to", "test"), 4) |
| 61 | + assert_equal($Example.varargs_func_nv("some", "arguments", "to", "test"), 46) |
43 | 62 | $Example.varargs_func_void("some", "arguments", "to", "test") |
| 63 | + assert_equal(custom_signal_emitted, ["varargs_func_void", 5]) |
44 | 64 |
|
45 | | - prints("Method calls with default values") |
46 | | - prints(" defval (300)", $Example.def_args()) |
47 | | - prints(" defval (250)", $Example.def_args(50)) |
48 | | - prints(" defval (150)", $Example.def_args(50, 100)) |
| 65 | + # Method calls with default values. |
| 66 | + assert_equal($Example.def_args(), 300) |
| 67 | + assert_equal($Example.def_args(50), 250) |
| 68 | + assert_equal($Example.def_args(50, 100), 150) |
49 | 69 |
|
50 | | - prints("Array and Dictionary") |
51 | | - prints(" test array", $Example.test_array()) |
52 | | - prints(" test tarray", $Example.test_tarray()) |
53 | | - prints(" test dictionary", $Example.test_dictionary()) |
| 70 | + # Array and Dictionary |
| 71 | + assert_equal($Example.test_array(), [1, 2]) |
| 72 | + assert_equal($Example.test_tarray(), [ Vector2(1, 2), Vector2(2, 3) ]) |
| 73 | + assert_equal($Example.test_dictionary(), {"hello": "world", "foo": "bar"}) |
54 | 74 | var array: Array[int] = [1, 2, 3] |
55 | | - $Example.test_tarray_arg(array) |
| 75 | + assert_equal($Example.test_tarray_arg(array), 6) |
56 | 76 |
|
57 | | - prints("String += operator") |
58 | | - prints(" test string +=", $Example.test_string_ops()) |
| 77 | + # String += operator |
| 78 | + assert_equal($Example.test_string_ops(), "ABCĎE") |
59 | 79 |
|
60 | | - prints("PackedArray iterators") |
61 | | - prints(" test packed array iterators", $Example.test_vector_ops()) |
| 80 | + # PackedArray iterators |
| 81 | + assert_equal($Example.test_vector_ops(), 105) |
62 | 82 |
|
63 | | - prints("Properties") |
64 | | - prints(" custom position is", $Example.group_subgroup_custom_position) |
| 83 | + # Properties. |
| 84 | + assert_equal($Example.group_subgroup_custom_position, Vector2(0, 0)) |
65 | 85 | $Example.group_subgroup_custom_position = Vector2(50, 50) |
66 | | - prints(" custom position now is", $Example.group_subgroup_custom_position) |
| 86 | + assert_equal($Example.group_subgroup_custom_position, Vector2(50, 50)) |
| 87 | + |
| 88 | + # Constants. |
| 89 | + assert_equal($Example.FIRST, 0) |
| 90 | + assert_equal($Example.ANSWER_TO_EVERYTHING, 42) |
| 91 | + assert_equal($Example.CONSTANT_WITHOUT_ENUM, 314) |
67 | 92 |
|
68 | | - prints("Constants") |
69 | | - prints(" FIRST", $Example.FIRST) |
70 | | - prints(" ANSWER_TO_EVERYTHING", $Example.ANSWER_TO_EVERYTHING) |
71 | | - prints(" CONSTANT_WITHOUT_ENUM", $Example.CONSTANT_WITHOUT_ENUM) |
| 93 | + # BitFields. |
| 94 | + assert_equal(Example.FLAG_ONE, 1) |
| 95 | + assert_equal(Example.FLAG_TWO, 2) |
| 96 | + assert_equal($Example.test_bitfield(0), 0) |
| 97 | + assert_equal($Example.test_bitfield(Example.FLAG_ONE | Example.FLAG_TWO), 3) |
72 | 98 |
|
73 | | - prints("BitFields") |
74 | | - prints(" FLAG_ONE", Example.FLAG_ONE) |
75 | | - prints(" FLAG_TWO", Example.FLAG_TWO) |
76 | | - prints(" returned BitField", $Example.test_bitfield(0)) |
77 | | - prints(" returned BitField", $Example.test_bitfield(Example.FLAG_ONE | Example.FLAG_TWO)) |
| 99 | + exit_with_status() |
78 | 100 |
|
79 | 101 | func _on_Example_custom_signal(signal_name, value): |
80 | | - prints("Example emitted:", signal_name, value) |
| 102 | + custom_signal_emitted = [signal_name, value] |
0 commit comments