diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/SConstruct | 1 | ||||
-rw-r--r-- | test/project/main.gd | 11 | ||||
-rw-r--r-- | test/src/example.cpp | 27 | ||||
-rw-r--r-- | test/src/example.h | 12 | ||||
-rw-r--r-- | test/src/register_types.cpp | 1 |
6 files changed, 51 insertions, 2 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 42ea6e0..f1c4c0d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -38,6 +38,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # using Visual Studio C++ set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /WX") # /GF /MP set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /DTYPED_METHOD_BIND") + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /utf-8") if(CMAKE_BUILD_TYPE MATCHES Debug) set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MDd") # /Od /RTC1 /Zi diff --git a/test/SConstruct b/test/SConstruct index 1f1db0f..b949bca 100644 --- a/test/SConstruct +++ b/test/SConstruct @@ -42,4 +42,5 @@ else: source=sources, ) +env.NoCache(library) Default(library) diff --git a/test/project/main.gd b/test/project/main.gd index 864c3d5..e5a3b95 100644 --- a/test/project/main.gd +++ b/test/project/main.gd @@ -81,10 +81,13 @@ func _ready(): # Array and Dictionary assert_equal(example.test_array(), [1, 2]) - assert_equal(example.test_tarray(), [ Vector2(1, 2), Vector2(2, 3) ]) - assert_equal(example.test_dictionary(), {"hello": "world", "foo": "bar"}) + assert_equal(example.test_tarray(), [Vector2(1, 2), Vector2(2, 3)]) var array: Array[int] = [1, 2, 3] assert_equal(example.test_tarray_arg(array), 6) + assert_equal(example.test_dictionary(), { "hello": "world", "foo": "bar" }) + assert_equal(example.test_tdictionary(), { Vector2(1, 2): Vector2i(2, 3) }) + var dictionary: Dictionary[String, int] = { "1": 1, "2": 2, "3": 3 } + assert_equal(example.test_tdictionary_arg(dictionary), 6) example.callable_bind() assert_equal(custom_signal_emitted, ["bound", 11]) @@ -282,6 +285,10 @@ func _ready(): assert_equal(library_path, ProjectSettings.globalize_path(library_path)) assert_equal(FileAccess.file_exists(library_path), true) + # Test a class with a unicode name. + var przykład = ExamplePrzykład.new() + assert_equal(przykład.get_the_word(), "słowo to przykład") + exit_with_status() func _on_Example_custom_signal(signal_name, value): diff --git a/test/src/example.cpp b/test/src/example.cpp index f49a230..22739b2 100644 --- a/test/src/example.cpp +++ b/test/src/example.cpp @@ -199,6 +199,8 @@ void Example::_bind_methods() { ClassDB::bind_method(D_METHOD("test_tarray_arg", "array"), &Example::test_tarray_arg); ClassDB::bind_method(D_METHOD("test_tarray"), &Example::test_tarray); ClassDB::bind_method(D_METHOD("test_dictionary"), &Example::test_dictionary); + ClassDB::bind_method(D_METHOD("test_tdictionary_arg", "dictionary"), &Example::test_tdictionary_arg); + ClassDB::bind_method(D_METHOD("test_tdictionary"), &Example::test_tdictionary); ClassDB::bind_method(D_METHOD("test_node_argument"), &Example::test_node_argument); ClassDB::bind_method(D_METHOD("test_string_ops"), &Example::test_string_ops); ClassDB::bind_method(D_METHOD("test_str_utility"), &Example::test_str_utility); @@ -552,6 +554,23 @@ Dictionary Example::test_dictionary() const { return dict; } +int Example::test_tdictionary_arg(const TypedDictionary<String, int64_t> &p_dictionary) { + int sum = 0; + TypedArray<int64_t> values = p_dictionary.values(); + for (int i = 0; i < p_dictionary.size(); i++) { + sum += (int)values[i]; + } + return sum; +} + +TypedDictionary<Vector2, Vector2i> Example::test_tdictionary() const { + TypedDictionary<Vector2, Vector2i> dict; + + dict[Vector2(1, 2)] = Vector2i(2, 3); + + return dict; +} + Example *Example::test_node_argument(Example *p_node) const { return p_node; } @@ -741,3 +760,11 @@ ExampleRuntime::ExampleRuntime() { ExampleRuntime::~ExampleRuntime() { } + +void ExamplePrzykład::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_the_word"), &ExamplePrzykład::get_the_word); +} + +String ExamplePrzykład::get_the_word() const { + return U"słowo to przykład"; +} diff --git a/test/src/example.h b/test/src/example.h index 40f934f..a7ae54c 100644 --- a/test/src/example.h +++ b/test/src/example.h @@ -129,6 +129,8 @@ public: int test_tarray_arg(const TypedArray<int64_t> &p_array); TypedArray<Vector2> test_tarray() const; Dictionary test_dictionary() const; + int test_tdictionary_arg(const TypedDictionary<String, int64_t> &p_dictionary); + TypedDictionary<Vector2, Vector2i> test_tdictionary() const; Example *test_node_argument(Example *p_node) const; String test_string_ops() const; String test_str_utility() const; @@ -274,4 +276,14 @@ public: ~ExampleRuntime(); }; +class ExamplePrzykład : public RefCounted { + GDCLASS(ExamplePrzykład, RefCounted); + +protected: + static void _bind_methods(); + +public: + String get_the_word() const; +}; + #endif // EXAMPLE_CLASS_H diff --git a/test/src/register_types.cpp b/test/src/register_types.cpp index 7cfe689..d9290c8 100644 --- a/test/src/register_types.cpp +++ b/test/src/register_types.cpp @@ -30,6 +30,7 @@ void initialize_example_module(ModuleInitializationLevel p_level) { GDREGISTER_CLASS(ExampleBase); GDREGISTER_CLASS(ExampleChild); GDREGISTER_RUNTIME_CLASS(ExampleRuntime); + GDREGISTER_CLASS(ExamplePrzykład); } void uninitialize_example_module(ModuleInitializationLevel p_level) { |