main.gd 4.1 KB

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