From 3843e5c1dd6fd7f7e0534cfd944cc78a45b0721e Mon Sep 17 00:00:00 2001
From: gewuyou <95328647+GeWuYou@users.noreply.github.com>
Date: Mon, 27 Apr 2026 19:07:30 +0800
Subject: [PATCH] =?UTF-8?q?test(pool):=20=E6=8B=86=E5=88=86=20ObjectPoolTe?=
=?UTF-8?q?sts=20=E6=B1=A0=E5=8C=96=E8=BE=85=E5=8A=A9=E7=B1=BB=E5=9E=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 拆分 TestObjectPool 与 TestPoolableObject 到 Pool 同目录独立文件
- 保留并补充对象池测试辅助类型的 XML 文档与命名空间一致性
- 验证 GFramework.Core.Tests Release 构建通过且当前切片无新增 warning
---
GFramework.Core.Tests/Pool/ObjectPoolTests.cs | 80 -------------------
GFramework.Core.Tests/Pool/TestObjectPool.cs | 27 +++++++
.../Pool/TestPoolableObject.cs | 58 ++++++++++++++
3 files changed, 85 insertions(+), 80 deletions(-)
create mode 100644 GFramework.Core.Tests/Pool/TestObjectPool.cs
create mode 100644 GFramework.Core.Tests/Pool/TestPoolableObject.cs
diff --git a/GFramework.Core.Tests/Pool/ObjectPoolTests.cs b/GFramework.Core.Tests/Pool/ObjectPoolTests.cs
index bb7bd360..44ebc909 100644
--- a/GFramework.Core.Tests/Pool/ObjectPoolTests.cs
+++ b/GFramework.Core.Tests/Pool/ObjectPoolTests.cs
@@ -1,5 +1,3 @@
-using GFramework.Core.Abstractions.Pool;
-using GFramework.Core.Pool;
using NUnit.Framework;
namespace GFramework.Core.Tests.Pool;
@@ -285,81 +283,3 @@ public class ObjectPoolTests
Assert.That(_pool.GetActiveCount("key2"), Is.EqualTo(0));
}
}
-
-///
-/// 测试用对象池实现类,继承自AbstractObjectPoolSystem
-///
-public class TestObjectPool : AbstractObjectPoolSystem
-{
- ///
- /// 创建新的池化对象
- ///
- /// 用于标识对象的键
- /// 新创建的TestPoolableObject实例
- protected override TestPoolableObject Create(string key)
- {
- return new TestPoolableObject { PoolKey = key };
- }
-
- ///
- /// 初始化方法,用于对象池初始化时的操作
- ///
- protected override void OnInit()
- {
- }
-}
-
-///
-/// 测试用池化对象类,实现了IPoolableObject接口
-///
-public class TestPoolableObject : IPoolableObject
-{
- ///
- /// 获取或设置对象的池键
- ///
- public string PoolKey { get; set; } = string.Empty;
-
- ///
- /// 获取或设置测试用的整数值
- ///
- public int TestValue { get; set; }
-
- ///
- /// 获取或设置OnAcquire方法是否被调用的标志
- ///
- public bool OnAcquireCalled { get; set; }
-
- ///
- /// 获取或设置OnRelease方法是否被调用的标志
- ///
- public bool OnReleaseCalled { get; set; }
-
- ///
- /// 获取或设置OnPoolDestroy方法是否被调用的标志
- ///
- public bool OnPoolDestroyCalled { get; set; }
-
- ///
- /// 对象被获取时的回调方法
- ///
- public void OnAcquire()
- {
- OnAcquireCalled = true;
- }
-
- ///
- /// 对象被释放时的回调方法
- ///
- public void OnRelease()
- {
- OnReleaseCalled = true;
- }
-
- ///
- /// 对象被销毁时的回调方法
- ///
- public void OnPoolDestroy()
- {
- OnPoolDestroyCalled = true;
- }
-}
\ No newline at end of file
diff --git a/GFramework.Core.Tests/Pool/TestObjectPool.cs b/GFramework.Core.Tests/Pool/TestObjectPool.cs
new file mode 100644
index 00000000..303db8db
--- /dev/null
+++ b/GFramework.Core.Tests/Pool/TestObjectPool.cs
@@ -0,0 +1,27 @@
+using GFramework.Core.Pool;
+
+namespace GFramework.Core.Tests.Pool;
+
+///
+/// 测试用对象池实现类,继承自 ,
+/// 用于验证对象池的获取、释放和统计行为。
+///
+public class TestObjectPool : AbstractObjectPoolSystem
+{
+ ///
+ /// 根据池键创建新的测试对象。
+ ///
+ /// 用于标识对象所属池的键。
+ /// 带有对应 的测试对象实例。
+ protected override TestPoolableObject Create(string key)
+ {
+ return new TestPoolableObject { PoolKey = key };
+ }
+
+ ///
+ /// 执行对象池初始化。
+ ///
+ protected override void OnInit()
+ {
+ }
+}
diff --git a/GFramework.Core.Tests/Pool/TestPoolableObject.cs b/GFramework.Core.Tests/Pool/TestPoolableObject.cs
new file mode 100644
index 00000000..2b1f0750
--- /dev/null
+++ b/GFramework.Core.Tests/Pool/TestPoolableObject.cs
@@ -0,0 +1,58 @@
+using GFramework.Core.Abstractions.Pool;
+
+namespace GFramework.Core.Tests.Pool;
+
+///
+/// 供对象池测试使用的池化对象,记录生命周期回调是否被触发。
+///
+public class TestPoolableObject : IPoolableObject
+{
+ ///
+ /// 获取或设置对象所属的池键。
+ ///
+ public string PoolKey { get; set; } = string.Empty;
+
+ ///
+ /// 获取或设置测试中写入的整数值。
+ ///
+ public int TestValue { get; set; }
+
+ ///
+ /// 获取或设置对象获取回调是否已执行。
+ ///
+ public bool OnAcquireCalled { get; set; }
+
+ ///
+ /// 获取或设置对象释放回调是否已执行。
+ ///
+ public bool OnReleaseCalled { get; set; }
+
+ ///
+ /// 获取或设置对象销毁回调是否已执行。
+ ///
+ public bool OnPoolDestroyCalled { get; set; }
+
+ ///
+ /// 在对象被对象池取出时记录回调执行状态。
+ ///
+ public void OnAcquire()
+ {
+ OnAcquireCalled = true;
+ }
+
+ ///
+ /// 在对象被归还到对象池时记录回调执行状态。
+ ///
+ public void OnRelease()
+ {
+ OnReleaseCalled = true;
+ }
+
+ ///
+ /// 在对象因容量限制或清池而销毁时记录回调执行状态。
+ ///
+ public void OnPoolDestroy()
+ {
+ OnPoolDestroyCalled = true;
+ }
+}