yyl
2026-05-11 51b0f6ed9f4e1d3bb6f8144470b46908c7699a96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// ============================================================================
// 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"));
    }
}