|
7 | 7 | use crate::{expect_panic, itest};
|
8 | 8 | use godot::bind::{godot_api, GodotClass, GodotExt};
|
9 | 9 | use godot::builtin::{FromVariant, GodotString, StringName, ToVariant, Variant, Vector3};
|
10 |
| -use godot::engine::{Node, Node3D, Object, RefCounted}; |
| 10 | +use godot::engine::{file_access, FileAccess, Node, Node3D, Object, RefCounted}; |
11 | 11 | use godot::obj::Share;
|
12 | 12 | use godot::obj::{Base, Gd, InstanceId};
|
13 | 13 | use godot::sys::GodotFfi;
|
@@ -38,6 +38,7 @@ pub fn run() -> bool {
|
38 | 38 | ok &= object_engine_convert_variant();
|
39 | 39 | ok &= object_user_convert_variant_refcount();
|
40 | 40 | ok &= object_engine_convert_variant_refcount();
|
| 41 | + ok &= object_engine_returned_refcount(); |
41 | 42 | ok &= object_engine_up_deref();
|
42 | 43 | ok &= object_engine_up_deref_mut();
|
43 | 44 | ok &= object_engine_upcast();
|
@@ -265,6 +266,17 @@ fn check_convert_variant_refcount(obj: Gd<RefCounted>) {
|
265 | 266 | assert_eq!(obj.get_reference_count(), 1);
|
266 | 267 | }
|
267 | 268 |
|
| 269 | +#[itest] |
| 270 | +fn object_engine_returned_refcount() { |
| 271 | + let Some(file) = FileAccess::open("res://itest.gdextension".into(), file_access::ModeFlags::READ) else { |
| 272 | + panic!("failed to open file used to test FileAccess") |
| 273 | + }; |
| 274 | + assert!(file.is_open()); |
| 275 | + |
| 276 | + // There was a bug which incremented ref-counts of just-returned objects, keep this as regression test. |
| 277 | + assert_eq!(file.get_reference_count(), 1); |
| 278 | +} |
| 279 | + |
268 | 280 | #[itest]
|
269 | 281 | fn object_engine_up_deref() {
|
270 | 282 | let node3d: Gd<Node3D> = Node3D::new_alloc();
|
|
0 commit comments