Skip to content

Commit f43d748

Browse files
committed
Add integration test for properties.
1 parent 69a6a23 commit f43d748

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

godot-macros/src/derive_godot_class.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,10 @@ fn make_godot_properties_impl(
319319
let variant_type = property_info.variant_type;
320320
quote! {
321321
let class_name = StringName::from(#class_name::CLASS_NAME);
322-
let property_info = PropertyInfo::new(
322+
let property_info = ::godot::builtin::meta::PropertyInfo::new(
323323
//#variant_type,
324-
::godot_ffi::VariantType::Int,
325-
::godot_core::builtin::meta::ClassName::new::<#class_name>(),
324+
::godot::sys::VariantType::Int,
325+
::godot::builtin::meta::ClassName::new::<#class_name>(),
326326
StringName::from(#name),
327327
);
328328
let property_info_sys = property_info.property_sys();

itest/godot/ManualFfiTests.gd

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,35 @@
44

55
extends Node
66

7+
78
func run() -> bool:
89
print("[GD] Test ManualFfi...")
910
var ok = true
1011
#ok = ok && test_missing_init()
1112
ok = ok && test_to_string()
13+
ok = ok && test_property()
1214

1315
print("[GD] ManualFfi tested (passed=", ok, ")")
1416
return ok
1517

18+
1619
func test_missing_init() -> bool:
1720
var obj = WithoutInit.new()
1821
print("[GD] WithoutInit is: ", obj)
1922
return true
2023

24+
25+
func test_property() -> bool:
26+
var obj = HasProperty.new()
27+
obj.val = 5
28+
print("[GD] HasProperty's property is: ", obj.val, " and should be 5")
29+
return obj.val == 5
30+
31+
2132
func test_to_string() -> bool:
2233
var ffi = VirtualMethodTest.new()
2334
var s = str(ffi)
2435

2536
print("to_string: ", s)
2637
print("to_string: ", ffi)
27-
return true
38+
return true

itest/rust/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod enum_test;
1414
mod gdscript_ffi_test;
1515
mod node_test;
1616
mod object_test;
17+
mod property_test;
1718
mod singleton_test;
1819
mod string_test;
1920
mod utilities_test;
@@ -27,6 +28,7 @@ fn run_tests() -> bool {
2728
ok &= node_test::run();
2829
ok &= enum_test::run();
2930
ok &= object_test::run();
31+
ok &= property_test::run();
3032
ok &= singleton_test::run();
3133
ok &= string_test::run();
3234
ok &= utilities_test::run();

itest/rust/src/property_test.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
use crate::itest;
8+
use godot::prelude::*;
9+
10+
pub(crate) fn run() -> bool {
11+
let mut ok = true;
12+
// No tests currently, tests using HasProperty are in Godot scripts.
13+
14+
ok
15+
}
16+
17+
#[derive(GodotClass)]
18+
#[class(base=Node)]
19+
#[property(name = "val", getter = "get_val", setter = "set_val")]
20+
struct HasProperty {
21+
val: i32,
22+
#[base]
23+
base: Base<Node>,
24+
}
25+
26+
#[godot_api]
27+
impl HasProperty {
28+
#[func]
29+
pub fn get_val(&self) -> i32 {
30+
return self.val;
31+
}
32+
33+
#[func]
34+
pub fn set_val(&mut self, val: i32) {
35+
self.val = val;
36+
}
37+
}
38+
39+
#[godot_api]
40+
impl GodotExt for HasProperty {
41+
fn init(base: Base<Node>) -> Self {
42+
HasProperty { val: 0, base }
43+
}
44+
}

0 commit comments

Comments
 (0)