Skip to content

Commit ba02ea9

Browse files
committed
Add itest for adding node in init
1 parent 09d45bc commit ba02ea9

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

itest/rust/src/engine_tests/node_test.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
use std::str::FromStr;
99

1010
use godot::builtin::{vslice, NodePath};
11+
use godot::classes::notify::NodeNotification;
1112
use godot::classes::{Node, Node3D, PackedScene, SceneTree};
1213
use godot::global;
1314
use godot::obj::{NewAlloc, NewGd};
15+
use godot::prelude::*;
1416

1517
use crate::framework::{itest, TestContext};
1618

@@ -92,3 +94,46 @@ fn node_call_group(ctx: &TestContext) {
9294
node.add_to_group("group");
9395
tree.call_group("group", "set_name", vslice!["name"]);
9496
}
97+
98+
#[derive(GodotClass, Debug)]
99+
#[class(base=Node)]
100+
struct NodeChild {
101+
child: Gd<Node>,
102+
notifications: Vec<NodeNotification>,
103+
}
104+
105+
#[godot_api]
106+
impl INode for NodeChild {
107+
fn init(_: Base<Node>) -> Self {
108+
let child = Node::new_alloc();
109+
Self {
110+
child,
111+
notifications: vec![],
112+
}
113+
}
114+
115+
fn on_notification(&mut self, what: NodeNotification) {
116+
match what {
117+
NodeNotification::READY => self.notifications.push(NodeNotification::READY),
118+
NodeNotification::PARENTED => self.notifications.push(NodeNotification::PARENTED),
119+
NodeNotification::POSTINITIALIZE => {
120+
self.notifications.push(NodeNotification::POSTINITIALIZE)
121+
}
122+
_ => {}
123+
};
124+
}
125+
}
126+
127+
// https://github.com/godotengine/godot/issues/91023
128+
#[cfg(since_api = "4.4")]
129+
#[itest]
130+
fn node_add_child_in_init() {
131+
let node = NodeChild::new_alloc();
132+
let dup: Gd<NodeChild> = node.duplicate().unwrap().cast();
133+
assert_eq!(
134+
dup.bind().notifications,
135+
vec![NodeNotification::POSTINITIALIZE,]
136+
);
137+
node.free();
138+
dup.free();
139+
}

0 commit comments

Comments
 (0)