// ============================================================================
|
// ResourcePreloaderTests.cs — 预加载管理器单元测试
|
// Feature: 001-async-resource-loading
|
// ============================================================================
|
|
using NUnit.Framework;
|
using ProjSG.Resource;
|
|
[TestFixture]
|
public class ResourcePreloaderTests
|
{
|
private ResourcePreloader _preloader;
|
|
[SetUp]
|
public void SetUp()
|
{
|
_preloader = ResourcePreloader.Instance;
|
}
|
|
// ====================================================================
|
// 配置注册
|
// ====================================================================
|
|
[Test]
|
public void RegisterConfig_AcceptsValidConfig()
|
{
|
var config = new PreloadConfig
|
{
|
ConfigName = "TestConfig",
|
Locations = new[] { "Assets/Test/a.png" },
|
IsPermanent = false,
|
};
|
|
Assert.DoesNotThrow(() => _preloader.RegisterConfig(config));
|
}
|
|
[Test]
|
public void RegisterConfig_RejectsNullConfig()
|
{
|
// Should log error but not throw
|
Assert.DoesNotThrow(() => _preloader.RegisterConfig(null));
|
}
|
|
[Test]
|
public void RegisterConfig_RejectsEmptyName()
|
{
|
var config = new PreloadConfig
|
{
|
ConfigName = "",
|
Locations = new[] { "Assets/Test/a.png" },
|
};
|
|
Assert.DoesNotThrow(() => _preloader.RegisterConfig(config));
|
}
|
|
// ====================================================================
|
// IsConfigLoaded
|
// ====================================================================
|
|
[Test]
|
public void IsConfigLoaded_ReturnsFalse_WhenNotLoaded()
|
{
|
Assert.IsFalse(_preloader.IsConfigLoaded("NotRegistered"));
|
}
|
|
[Test]
|
public void IsConfigLoaded_ReturnsFalse_ForNewConfig()
|
{
|
_preloader.RegisterConfig(new PreloadConfig
|
{
|
ConfigName = "NewConfig",
|
Locations = new[] { "Assets/Test/x.png" },
|
});
|
|
Assert.IsFalse(_preloader.IsConfigLoaded("NewConfig"));
|
}
|
|
// ====================================================================
|
// UnloadConfig
|
// ====================================================================
|
|
[Test]
|
public void UnloadConfig_DoesNotThrow_WhenNotRegistered()
|
{
|
Assert.DoesNotThrow(() => _preloader.UnloadConfig("NonExistent"));
|
}
|
|
[Test]
|
public void UnloadConfig_SkipsPermanentConfig()
|
{
|
_preloader.RegisterConfig(new PreloadConfig
|
{
|
ConfigName = "PermanentTest",
|
Locations = new[] { "Assets/Test/p.png" },
|
IsPermanent = true,
|
});
|
|
// Should not throw, should log warning
|
Assert.DoesNotThrow(() => _preloader.UnloadConfig("PermanentTest"));
|
}
|
}
|