2026-11-30 03:43:42 +08:00
|
|
|
local ____lualib = require("lualib_bundle")
|
|
|
|
|
local __TS__New = ____lualib.__TS__New
|
|
|
|
|
local ____exports = __module.env
|
|
|
|
|
local M__framework_context_game_context = __MODULE__.Import("framework.context.game_context", __module)
|
|
|
|
|
local GetGameInstanceContext = M__framework_context_game_context.GetGameInstanceContext
|
|
|
|
|
local Json = __MODULE__.Import("framework.core.json", __module)
|
|
|
|
|
local M__framework_resource_asset_catalog = __MODULE__.Import("framework.resource.asset_catalog", __module)
|
|
|
|
|
local ASSET_KEYS = M__framework_resource_asset_catalog.ASSET_KEYS
|
|
|
|
|
local BASE_ASSET_PATHS = M__framework_resource_asset_catalog.BASE_ASSET_PATHS
|
|
|
|
|
local M__framework_storage_local_save = __MODULE__.Import("framework.storage.local_save", __module)
|
|
|
|
|
local LocalSaveManager = M__framework_storage_local_save.LocalSaveManager
|
|
|
|
|
local M__framework_storage_storage_backend = __MODULE__.Import("framework.storage.storage_backend", __module)
|
|
|
|
|
local UEStorageBackend = M__framework_storage_storage_backend.UEStorageBackend
|
|
|
|
|
local M__game_setting_mini_settings_window = __MODULE__.Import("game.setting.mini_settings_window", __module)
|
|
|
|
|
local MiniSettingsWindow = M__game_setting_mini_settings_window.MiniSettingsWindow
|
|
|
|
|
local M__game_setting_setting_service = __MODULE__.Import("game.setting.setting_service", __module)
|
|
|
|
|
local SettingService = M__game_setting_setting_service.SettingService
|
2026-12-01 03:13:35 +08:00
|
|
|
local M__game_demo_demo_hub_window = __MODULE__.Import("game.demo.demo_hub_window", __module)
|
|
|
|
|
local DemoHubWindow = M__game_demo_demo_hub_window.DemoHubWindow
|
|
|
|
|
local M__game_demo_demo_router = __MODULE__.Import("game.demo.demo_router", __module)
|
|
|
|
|
local OpenDemoHub = M__game_demo_demo_router.OpenDemoHub
|
|
|
|
|
local OpenUIDemoMain = M__game_demo_demo_router.OpenUIDemoMain
|
|
|
|
|
local M__game_demo_ui_demo_ui_demo_windows = __MODULE__.Import("game.demo.ui_demo.ui_demo_windows", __module)
|
|
|
|
|
local UIDemoCachedWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoCachedWindow
|
|
|
|
|
local UIDemoFullscreenWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoFullscreenWindow
|
|
|
|
|
local UIDemoModalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoModalWindow
|
|
|
|
|
local UIDemoMultiWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoMultiWindow
|
|
|
|
|
local UIDemoNormalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoNormalWindow
|
|
|
|
|
local UIDemoSystemWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoSystemWindow
|
|
|
|
|
local UIDemoToastWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoToastWindow
|
2026-11-30 03:43:42 +08:00
|
|
|
local M__game_startup = __MODULE__.Import("game.startup", __module)
|
|
|
|
|
local GetPrimaryUIManager = M__game_startup.GetPrimaryUIManager
|
|
|
|
|
local M__share_base_scoped_object = __MODULE__.Import("share.base.scoped_object", __module)
|
|
|
|
|
local ScopedObject = M__share_base_scoped_object.ScopedObject
|
|
|
|
|
local M__tests_harness_test_runner = __MODULE__.Import("tests.harness.test_runner", __module)
|
|
|
|
|
local Assert = M__tests_harness_test_runner.Assert
|
|
|
|
|
local AssertEqual = M__tests_harness_test_runner.AssertEqual
|
|
|
|
|
local FormatReport = M__tests_harness_test_runner.FormatReport
|
|
|
|
|
local RunSuites = M__tests_harness_test_runner.RunSuites
|
|
|
|
|
local function PumpUEFrames(frames, dt)
|
|
|
|
|
if dt == nil then
|
|
|
|
|
dt = 0.02
|
|
|
|
|
end
|
|
|
|
|
if __UE_TEST_TICK == nil then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
do
|
|
|
|
|
local i = 0
|
|
|
|
|
while i < frames do
|
|
|
|
|
__UE_TEST_TICK(dt)
|
|
|
|
|
i = i + 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
function ____exports.RunAllUETests(gameInstance, world)
|
|
|
|
|
local suites = {
|
|
|
|
|
{
|
|
|
|
|
name = "UE.NativeJson",
|
|
|
|
|
cases = {{
|
|
|
|
|
name = "ue_json native C++ module is active and preserves 64-bit integers and UTF-8",
|
|
|
|
|
fn = function()
|
|
|
|
|
Assert(
|
|
|
|
|
Json.IsNativeBackend(),
|
|
|
|
|
"expected native ue_json backend inside UE"
|
|
|
|
|
)
|
|
|
|
|
local bigInt = tonumber("9007199254740993")
|
|
|
|
|
AssertEqual(
|
|
|
|
|
math.type(bigInt),
|
|
|
|
|
"integer",
|
|
|
|
|
"bigInt is Lua 5.4 integer"
|
|
|
|
|
)
|
|
|
|
|
local input = {
|
|
|
|
|
version = 2,
|
|
|
|
|
roleId = bigInt,
|
|
|
|
|
title = "UE5.8中文测试",
|
|
|
|
|
enabled = true,
|
|
|
|
|
list = {10, 20, 30},
|
|
|
|
|
empty = Json.GetEmptyArray()
|
|
|
|
|
}
|
|
|
|
|
local encoded, encErr = Json.Encode(input)
|
|
|
|
|
AssertEqual(encErr, nil, "encode error")
|
|
|
|
|
Assert(
|
|
|
|
|
type(encoded) == "string",
|
|
|
|
|
"encoded string"
|
|
|
|
|
)
|
|
|
|
|
local decoded, decErr = Json.Decode(encoded)
|
|
|
|
|
AssertEqual(decErr, nil, "decode error")
|
|
|
|
|
local obj = decoded
|
|
|
|
|
AssertEqual(obj.version, 2)
|
|
|
|
|
AssertEqual(obj.roleId, bigInt, "int64 lossless round-trip")
|
|
|
|
|
AssertEqual(obj.title, "UE5.8中文测试")
|
|
|
|
|
AssertEqual(obj.enabled, true)
|
|
|
|
|
local list = obj.list
|
|
|
|
|
AssertEqual(list[1], 10)
|
|
|
|
|
AssertEqual(list[3], 30)
|
|
|
|
|
local badVal, badErr = Json.Decode("{broken")
|
|
|
|
|
AssertEqual(badVal, nil)
|
|
|
|
|
Assert(badErr ~= nil and badErr ~= "", "malformed JSON returns error")
|
|
|
|
|
end
|
|
|
|
|
}}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "UE.LocalStorage",
|
|
|
|
|
cases = {{
|
|
|
|
|
name = "ULuaStorageLibrary + ULuaSaveGame: debounce save, cold-start readback, and corruption recovery",
|
|
|
|
|
fn = function()
|
|
|
|
|
Assert(gameInstance ~= nil, "gameInstance required")
|
|
|
|
|
local ctx = GetGameInstanceContext(gameInstance)
|
|
|
|
|
Assert(ctx ~= nil, "GameInstanceContext must be initialized")
|
|
|
|
|
local slotId = "ue_test_slot"
|
|
|
|
|
local fullSlotName = "sdata_" .. slotId
|
|
|
|
|
UE.ULuaStorageLibrary.DeleteSlot(fullSlotName, 0, true)
|
|
|
|
|
local backend = __TS__New(UEStorageBackend)
|
|
|
|
|
local saveMgr = __TS__New(LocalSaveManager, backend, ctx.scheduler)
|
|
|
|
|
local settings = __TS__New(SettingService, saveMgr, slotId)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
settings:GetStore():GetLastLoadStatus(),
|
|
|
|
|
"not_found"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
settings:GetSoundEnabled(),
|
|
|
|
|
true,
|
|
|
|
|
"missing slot returns default"
|
|
|
|
|
)
|
|
|
|
|
settings:SetSoundEnabled(false)
|
|
|
|
|
PumpUEFrames(8, 0.02)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
settings:GetStore():IsDirty(),
|
|
|
|
|
false,
|
|
|
|
|
"debounced save flushed to UE SaveGame"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaStorageLibrary.DoesSlotExist(fullSlotName, 0),
|
|
|
|
|
"SaveGame file created on disk"
|
|
|
|
|
)
|
|
|
|
|
settings:SetSoundEnabled(true)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
settings:Flush(),
|
|
|
|
|
"ok"
|
|
|
|
|
)
|
|
|
|
|
settings:Dispose()
|
|
|
|
|
saveMgr:Dispose()
|
|
|
|
|
local saveMgr2 = __TS__New(LocalSaveManager, backend, ctx.scheduler)
|
|
|
|
|
local settings2 = __TS__New(SettingService, saveMgr2, slotId)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
settings2:GetStore():GetLastLoadStatus(),
|
|
|
|
|
"ok"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
settings2:GetSoundEnabled(),
|
|
|
|
|
true,
|
|
|
|
|
"cold-start reads latest value"
|
|
|
|
|
)
|
|
|
|
|
settings2:Dispose()
|
|
|
|
|
saveMgr2:Dispose()
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaStorageLibrary.WriteCorruptRawSlotForTest(fullSlotName, "CORRUPTED_SAV_DATA", 0),
|
|
|
|
|
"corrupt injection succeeded"
|
|
|
|
|
)
|
|
|
|
|
local saveMgr3 = __TS__New(LocalSaveManager, backend, ctx.scheduler)
|
|
|
|
|
local settings3 = __TS__New(SettingService, saveMgr3, slotId)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
settings3:GetStore():GetLastLoadStatus(),
|
|
|
|
|
"ok"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
settings3:GetStore():WasRecoveredFromBackup(),
|
|
|
|
|
"recovered from .bak"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
settings3:GetSoundEnabled(),
|
|
|
|
|
false,
|
|
|
|
|
"recovered previous valid value"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaStorageLibrary.DoesCorruptBackupExist(fullSlotName, 0),
|
|
|
|
|
".corrupt evidence preserved"
|
|
|
|
|
)
|
|
|
|
|
settings3:Dispose()
|
|
|
|
|
saveMgr3:Dispose()
|
|
|
|
|
UE.ULuaStorageLibrary.DeleteSlot(fullSlotName, 0, true)
|
|
|
|
|
end
|
|
|
|
|
}}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "UE.ResourceManager",
|
|
|
|
|
cases = {{
|
|
|
|
|
name = "ULuaResourceSubsystem: PIE Content load, PatchManifest override, coalesced cancel, and GC ref-count",
|
|
|
|
|
fn = function()
|
|
|
|
|
Assert(gameInstance ~= nil, "gameInstance required")
|
|
|
|
|
local ctx = GetGameInstanceContext(gameInstance)
|
|
|
|
|
local resSvc = ctx:GetService("resource")
|
|
|
|
|
local sub = UE.ULuaResourceSubsystem.GetFromGameInstance(gameInstance)
|
|
|
|
|
Assert(resSvc ~= nil and sub ~= nil, "ResourceService & Subsystem ready")
|
|
|
|
|
Assert(
|
|
|
|
|
resSvc:DoesAssetExist(ASSET_KEYS.MINI_SETTINGS_ICON),
|
|
|
|
|
"T_MiniSettingsIcon exists"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
resSvc:DoesAssetExist(ASSET_KEYS.MINI_SETTINGS_WIDGET),
|
|
|
|
|
"WBP_MiniSettings exists"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
not resSvc:DoesAssetExist("/Game/DoesNotExist/MissingAsset"),
|
|
|
|
|
"missing asset returns false"
|
|
|
|
|
)
|
|
|
|
|
local aliasKey = "tex.patch_alias_icon"
|
|
|
|
|
Assert(
|
|
|
|
|
sub:ApplyPatchManifest(string.format("{\"%s\":\"%s\"}", aliasKey, BASE_ASSET_PATHS[ASSET_KEYS.MINI_SETTINGS_ICON])),
|
|
|
|
|
"ApplyPatchManifest succeeded"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
resSvc:ResolveAssetPath(aliasKey),
|
|
|
|
|
BASE_ASSET_PATHS[ASSET_KEYS.MINI_SETTINGS_ICON],
|
|
|
|
|
"PatchOverlay resolves alias key"
|
|
|
|
|
)
|
|
|
|
|
local owner1 = __TS__New(ScopedObject)
|
|
|
|
|
local owner2 = __TS__New(ScopedObject)
|
|
|
|
|
local owner3 = __TS__New(ScopedObject)
|
|
|
|
|
local tex1
|
|
|
|
|
local tex2
|
|
|
|
|
local cancelledFired = false
|
|
|
|
|
local widgetCls
|
|
|
|
|
local missingCalls = 0
|
|
|
|
|
local missingOk = true
|
|
|
|
|
resSvc:LoadTextureAsync(
|
|
|
|
|
ASSET_KEYS.MINI_SETTINGS_ICON,
|
|
|
|
|
owner1,
|
|
|
|
|
function(ok, asset)
|
|
|
|
|
if ok then
|
|
|
|
|
tex1 = asset
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
)
|
|
|
|
|
local hCancel = resSvc:LoadTextureAsync(
|
|
|
|
|
aliasKey,
|
|
|
|
|
owner3,
|
|
|
|
|
function()
|
|
|
|
|
cancelledFired = true
|
|
|
|
|
end
|
|
|
|
|
)
|
|
|
|
|
resSvc:LoadTextureAsync(
|
|
|
|
|
aliasKey,
|
|
|
|
|
owner2,
|
|
|
|
|
function(ok, asset)
|
|
|
|
|
if ok then
|
|
|
|
|
tex2 = asset
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
)
|
|
|
|
|
resSvc:LoadClassAsync(
|
|
|
|
|
ASSET_KEYS.MINI_SETTINGS_WIDGET,
|
|
|
|
|
owner1,
|
|
|
|
|
function(ok, cls)
|
|
|
|
|
if ok then
|
|
|
|
|
widgetCls = cls
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
)
|
|
|
|
|
resSvc:LoadObjectAsync(
|
|
|
|
|
"/Game/DoesNotExist/MissingAsset",
|
|
|
|
|
owner1,
|
|
|
|
|
function(ok)
|
|
|
|
|
missingCalls = missingCalls + 1
|
|
|
|
|
missingOk = ok
|
|
|
|
|
end
|
|
|
|
|
)
|
|
|
|
|
hCancel:Cancel()
|
|
|
|
|
PumpUEFrames(15, 0.02)
|
|
|
|
|
Assert(not cancelledFired, "cancelled caller must not receive callback")
|
|
|
|
|
Assert(
|
|
|
|
|
tex1 ~= nil and UE.UKismetSystemLibrary.IsValid(tex1),
|
|
|
|
|
"tex1 loaded & valid"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
tex2 ~= nil and UE.UKismetSystemLibrary.IsValid(tex2),
|
|
|
|
|
"tex2 loaded & valid"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
widgetCls ~= nil and UE.UKismetSystemLibrary.IsValid(widgetCls),
|
|
|
|
|
"WBP_MiniSettings class loaded"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(missingCalls, 1, "missing asset delivers exactly once")
|
|
|
|
|
AssertEqual(missingOk, false, "missing asset reports ok=false")
|
|
|
|
|
owner1:Dispose()
|
|
|
|
|
if __UE_TEST_GC ~= nil then
|
|
|
|
|
__UE_TEST_GC()
|
|
|
|
|
end
|
|
|
|
|
Assert(
|
|
|
|
|
UE.UKismetSystemLibrary.IsValid(tex2),
|
|
|
|
|
"tex2 survives GC while owner2 holds ref"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
sub:GetAssetRefCount(ASSET_KEYS.MINI_SETTINGS_ICON),
|
|
|
|
|
1,
|
|
|
|
|
"refcount decremented to 1"
|
|
|
|
|
)
|
|
|
|
|
owner2:Dispose()
|
|
|
|
|
owner3:Dispose()
|
|
|
|
|
sub:ClearPatchManifest()
|
|
|
|
|
if __UE_TEST_GC ~= nil then
|
|
|
|
|
__UE_TEST_GC()
|
|
|
|
|
end
|
|
|
|
|
local diag = resSvc:GetDiagnostics()
|
|
|
|
|
AssertEqual(diag.tsPendingRequests, 0, "tsPending back to 0")
|
|
|
|
|
AssertEqual(diag.nativeInFlight, 0, "nativeInFlight back to 0")
|
|
|
|
|
AssertEqual(diag.nativeRetainedAssets, 0, "nativeRetained back to 0")
|
|
|
|
|
AssertEqual(diag.nativeTotalRefCount, 0, "nativeTotalRefCount back to 0")
|
|
|
|
|
end
|
|
|
|
|
}}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "UE.MiniSettingsUMG",
|
|
|
|
|
cases = {{
|
|
|
|
|
name = "Real WBP_MiniSettings open, async icon, button click delegate, SaveGame persist, and clean baseline teardown",
|
|
|
|
|
fn = function()
|
|
|
|
|
Assert(gameInstance ~= nil and world ~= nil, "GI & World required")
|
|
|
|
|
local ctx = GetGameInstanceContext(gameInstance)
|
|
|
|
|
local uiMgr = GetPrimaryUIManager(ctx)
|
|
|
|
|
local settingSvc = ctx:GetService("setting")
|
|
|
|
|
local resSvc = ctx:GetService("resource")
|
|
|
|
|
local uiBridge = ctx:GetService("uiDelegateBridge")
|
|
|
|
|
UE.ULuaStorageLibrary.DeleteSlot("sdata", 0, true)
|
|
|
|
|
settingSvc:GetStore():Reload()
|
|
|
|
|
AssertEqual(
|
|
|
|
|
settingSvc:GetSoundEnabled(),
|
|
|
|
|
true,
|
|
|
|
|
"initial sound ON"
|
|
|
|
|
)
|
|
|
|
|
ctx:OnWorldCleanup(world)
|
|
|
|
|
local openedOk = false
|
|
|
|
|
local win = uiMgr:ShowUI(
|
|
|
|
|
MiniSettingsWindow,
|
|
|
|
|
nil,
|
|
|
|
|
function(ok)
|
|
|
|
|
openedOk = ok
|
|
|
|
|
end
|
|
|
|
|
)
|
|
|
|
|
Assert(win ~= nil, "MiniSettingsWindow controller created")
|
|
|
|
|
PumpUEFrames(20, 0.02)
|
|
|
|
|
Assert(openedOk, "MiniSettingsWindow opened callback fired")
|
|
|
|
|
Assert(
|
|
|
|
|
win:IsLoaded(),
|
|
|
|
|
"widget loaded"
|
|
|
|
|
)
|
|
|
|
|
Assert(win.iconLoaded, "T_MiniSettingsIcon loaded and applied to ImgIcon")
|
|
|
|
|
Assert(win.btnToggle ~= nil and win.btnClose ~= nil, "named UMG buttons bound")
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateButtonClick(win.btnToggle),
|
|
|
|
|
"SimulateButtonClick BtnToggle"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(win.toggleClickCount, 1, "toggle click handled exactly once")
|
|
|
|
|
AssertEqual(
|
|
|
|
|
settingSvc:GetSoundEnabled(),
|
|
|
|
|
false,
|
|
|
|
|
"sound toggled OFF"
|
|
|
|
|
)
|
|
|
|
|
PumpUEFrames(8, 0.02)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
settingSvc:GetStore():IsDirty(),
|
|
|
|
|
false,
|
|
|
|
|
"setting persisted to UE SaveGame"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateButtonClick(win.btnClose),
|
|
|
|
|
"SimulateButtonClick BtnClose"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
win:IsDisposed(),
|
|
|
|
|
"MiniSettingsWindow disposed after close"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
uiMgr:GetDiagnostics().openWindows,
|
|
|
|
|
0,
|
|
|
|
|
"openWindows back to 0"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
uiBridge:GetActiveBindingCount(),
|
|
|
|
|
0,
|
|
|
|
|
"button delegate bindings back to 0"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
resSvc:GetDiagnostics().nativeTotalRefCount,
|
|
|
|
|
0,
|
|
|
|
|
"resource refcount back to 0"
|
|
|
|
|
)
|
|
|
|
|
local freshStore = __TS__New(
|
|
|
|
|
LocalSaveManager,
|
|
|
|
|
__TS__New(UEStorageBackend),
|
|
|
|
|
ctx.scheduler
|
|
|
|
|
)
|
|
|
|
|
local freshSettings = __TS__New(SettingService, freshStore)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
freshSettings:GetSoundEnabled(),
|
|
|
|
|
false,
|
|
|
|
|
"cold readback reads OFF"
|
|
|
|
|
)
|
|
|
|
|
freshSettings:Dispose()
|
|
|
|
|
freshStore:Dispose()
|
|
|
|
|
UE.ULuaStorageLibrary.DeleteSlot("sdata", 0, true)
|
|
|
|
|
end
|
|
|
|
|
}}
|
2026-12-01 03:13:35 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "UE.DemoHubAndUIDemo",
|
|
|
|
|
cases = {
|
|
|
|
|
{
|
|
|
|
|
name = "Bootstrap DemoHubWindow loads Chinese UMG cards and cleans up with zero leaks",
|
|
|
|
|
fn = function()
|
|
|
|
|
Assert(gameInstance ~= nil and world ~= nil, "GI & World required")
|
|
|
|
|
local ctx = GetGameInstanceContext(gameInstance)
|
|
|
|
|
local uiMgr = GetPrimaryUIManager(ctx)
|
|
|
|
|
local resSvc = ctx:GetService("resource")
|
|
|
|
|
local uiBridge = ctx:GetService("uiDelegateBridge")
|
|
|
|
|
ctx:OnWorldCleanup(world)
|
|
|
|
|
local hubOpened = false
|
|
|
|
|
local hub = OpenDemoHub(
|
|
|
|
|
ctx,
|
|
|
|
|
function(ok)
|
|
|
|
|
hubOpened = ok
|
|
|
|
|
end
|
|
|
|
|
)
|
|
|
|
|
Assert(hub ~= nil, "DemoHubWindow controller created")
|
|
|
|
|
PumpUEFrames(25, 0.02)
|
|
|
|
|
Assert(
|
|
|
|
|
hubOpened and hub:IsLoaded(),
|
|
|
|
|
"DemoHubWindow loaded"
|
|
|
|
|
)
|
|
|
|
|
Assert(#hub.itemWidgets >= 1, "DemoHub dynamically populated demo cards")
|
|
|
|
|
Assert(hub.itemEnterButtons.ui_demo ~= nil, "UI Demo entry button created")
|
|
|
|
|
hub:Close()
|
|
|
|
|
Assert(
|
|
|
|
|
hub:IsDisposed(),
|
|
|
|
|
"DemoHubWindow disposed cleanly"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
uiMgr:GetDiagnostics().openWindows,
|
|
|
|
|
0,
|
|
|
|
|
"openWindows back to 0"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
uiBridge:GetActiveBindingCount(),
|
|
|
|
|
0,
|
|
|
|
|
"delegate bindings back to 0"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
resSvc:GetDiagnostics().nativeTotalRefCount,
|
|
|
|
|
0,
|
|
|
|
|
"resource refs back to 0"
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name = "UIDemoMainWindow exercises all UMG widgets and all 7 window types with zero leaks",
|
|
|
|
|
fn = function()
|
|
|
|
|
Assert(gameInstance ~= nil and world ~= nil, "GI & World required")
|
|
|
|
|
local ctx = GetGameInstanceContext(gameInstance)
|
|
|
|
|
local uiMgr = GetPrimaryUIManager(ctx)
|
|
|
|
|
local resSvc = ctx:GetService("resource")
|
|
|
|
|
local uiBridge = ctx:GetService("uiDelegateBridge")
|
|
|
|
|
ctx:OnWorldCleanup(world)
|
|
|
|
|
local mainOpened = false
|
|
|
|
|
local mainWin = OpenUIDemoMain(
|
|
|
|
|
ctx,
|
|
|
|
|
function(ok)
|
|
|
|
|
mainOpened = ok
|
|
|
|
|
end
|
|
|
|
|
)
|
|
|
|
|
Assert(mainWin ~= nil, "UIDemoMainWindow created")
|
|
|
|
|
PumpUEFrames(30, 0.02)
|
|
|
|
|
Assert(
|
|
|
|
|
mainOpened and mainWin:IsLoaded(),
|
|
|
|
|
"UIDemoMainWindow loaded"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateButtonClick(mainWin.btnDemoAction),
|
|
|
|
|
"Button click"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateButtonHover(mainWin.btnDemoAction, true),
|
|
|
|
|
"Button hover"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(mainWin.actionClickCount, 1)
|
|
|
|
|
AssertEqual(mainWin.actionHovered, true)
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateCheckBoxToggle(mainWin.chkFeature, true),
|
|
|
|
|
"CheckBox toggle"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(mainWin.checkboxChecked, true)
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateSliderValue(mainWin.sliderDemo, 0.75),
|
|
|
|
|
"Slider value"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
math.abs(mainWin.sliderValue - 0.75) < 0.001,
|
|
|
|
|
"sliderValue updated"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateSpinBoxValue(mainWin.spinDemo, 250),
|
|
|
|
|
"SpinBox value"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(mainWin.spinValue, 250)
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateEditableTextChange(mainWin.inputNickname, "星河骑士"),
|
|
|
|
|
"EditableText change"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(mainWin.draftNickname, "星河骑士")
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateEditableTextCommit(mainWin.inputNickname, "星河骑士", 1),
|
|
|
|
|
"EditableText commit"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(mainWin.currentNickname, "星河骑士")
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateComboBoxSelect(mainWin.comboTheme, "翡翠绿(稀有)"),
|
|
|
|
|
"ComboBox select"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(mainWin.selectedTheme, "翡翠绿(稀有)")
|
|
|
|
|
local bindingsBeforeList = uiBridge:GetActiveBindingCount()
|
|
|
|
|
mainWin:AddDynamicListItems(3)
|
|
|
|
|
AssertEqual(mainWin.dynamicItemCount, 3, "3 dynamic items added")
|
|
|
|
|
Assert(
|
|
|
|
|
uiBridge:GetActiveBindingCount() > bindingsBeforeList,
|
|
|
|
|
"list item button delegates bound"
|
|
|
|
|
)
|
|
|
|
|
mainWin:ClearDynamicListItems()
|
|
|
|
|
AssertEqual(mainWin.dynamicItemCount, 0, "dynamic items cleared")
|
|
|
|
|
AssertEqual(
|
|
|
|
|
uiBridge:GetActiveBindingCount(),
|
|
|
|
|
bindingsBeforeList,
|
|
|
|
|
"list item delegates fully unbound"
|
|
|
|
|
)
|
|
|
|
|
local norm1 = mainWin:OpenNormalDemoWindow()
|
|
|
|
|
local norm2 = mainWin:OpenNormalDemoWindow()
|
|
|
|
|
AssertEqual(norm1, norm2, "Normal window is singleton")
|
|
|
|
|
local fullWin = mainWin:OpenFullscreenDemoWindow()
|
|
|
|
|
local modalConfirmed = false
|
|
|
|
|
local modalWin = uiMgr:ShowUI(
|
|
|
|
|
UIDemoModalWindow,
|
|
|
|
|
{
|
|
|
|
|
title = "测试弹窗",
|
|
|
|
|
message = "测试模态确认",
|
|
|
|
|
onConfirm = function()
|
|
|
|
|
modalConfirmed = true
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
local cachedWin = mainWin:OpenCachedDemoWindow()
|
|
|
|
|
local multi1 = mainWin:OpenMultiDemoWindow()
|
|
|
|
|
local multi2 = mainWin:OpenMultiDemoWindow()
|
|
|
|
|
Assert(multi1 ~= multi2, "Multi-instance creates distinct windows")
|
|
|
|
|
local sysWin = mainWin:OpenSystemDemoWindow()
|
|
|
|
|
local toastWin = mainWin:ShowToast("自动测试飘字", 0.1)
|
|
|
|
|
PumpUEFrames(30, 0.02)
|
|
|
|
|
Assert(
|
|
|
|
|
toastWin:IsDisposed(),
|
|
|
|
|
"Toast auto-closed via WorldTimer"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
not mainWin:IsVisible(),
|
|
|
|
|
"MainWindow hidden while Fullscreen is open"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
uiMgr:GetDiagnostics().topWindowName,
|
|
|
|
|
"UIDemoSystemWindow",
|
|
|
|
|
"System window on top"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
uiMgr:GetDiagnostics().inputMode,
|
|
|
|
|
"ui",
|
|
|
|
|
"Input mode stays UI"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateButtonClick(modalWin.btnModalConfirm),
|
|
|
|
|
"Click Modal Confirm"
|
|
|
|
|
)
|
|
|
|
|
Assert(modalConfirmed, "Modal confirm callback fired")
|
|
|
|
|
Assert(
|
|
|
|
|
modalWin:IsDisposed(),
|
|
|
|
|
"Modal disposed after confirm"
|
|
|
|
|
)
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateButtonClick(cachedWin.btnCachedAction),
|
|
|
|
|
"Cached click #1"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(cachedWin.clickCount, 1)
|
|
|
|
|
cachedWin:Close()
|
|
|
|
|
Assert(
|
|
|
|
|
cachedWin:IsCached(),
|
|
|
|
|
"Cached window moved to cache"
|
|
|
|
|
)
|
|
|
|
|
local cachedReused = mainWin:OpenCachedDemoWindow()
|
|
|
|
|
AssertEqual(cachedReused, cachedWin, "Cached window reused")
|
|
|
|
|
AssertEqual(cachedReused.reuseCount, 1, "OnReuseUI invoked once")
|
|
|
|
|
Assert(
|
|
|
|
|
UE.ULuaUIEventSubsystem.SimulateButtonClick(cachedReused.btnCachedAction),
|
|
|
|
|
"Cached click #2"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(cachedReused.clickCount, 2, "Cached click after reuse increments by exactly 1")
|
|
|
|
|
fullWin:Close()
|
|
|
|
|
Assert(
|
|
|
|
|
mainWin:IsVisible(),
|
|
|
|
|
"MainWindow automatically restored after Fullscreen closed"
|
|
|
|
|
)
|
|
|
|
|
uiMgr:CloseAll(true)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
uiMgr:GetDiagnostics().openWindows,
|
|
|
|
|
0,
|
|
|
|
|
"openWindows back to 0"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
uiMgr:GetDiagnostics().cachedWindows,
|
|
|
|
|
0,
|
|
|
|
|
"cachedWindows back to 0"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
uiBridge:GetActiveBindingCount(),
|
|
|
|
|
0,
|
|
|
|
|
"delegate bindings back to 0"
|
|
|
|
|
)
|
|
|
|
|
AssertEqual(
|
|
|
|
|
resSvc:GetDiagnostics().nativeTotalRefCount,
|
|
|
|
|
0,
|
|
|
|
|
"resource refcount back to 0"
|
|
|
|
|
)
|
|
|
|
|
Assert(DemoHubWindow ~= nil and UIDemoNormalWindow ~= nil and UIDemoFullscreenWindow ~= nil and UIDemoCachedWindow ~= nil and UIDemoMultiWindow ~= nil and UIDemoToastWindow ~= nil and UIDemoSystemWindow ~= nil, "all demo window classes registered")
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-30 03:43:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
local summary = RunSuites(suites)
|
|
|
|
|
print(FormatReport(summary))
|
|
|
|
|
return summary
|
|
|
|
|
end
|
|
|
|
|
function __module.UpdateImports()
|
|
|
|
|
GetGameInstanceContext = M__framework_context_game_context.GetGameInstanceContext
|
|
|
|
|
ASSET_KEYS = M__framework_resource_asset_catalog.ASSET_KEYS
|
|
|
|
|
BASE_ASSET_PATHS = M__framework_resource_asset_catalog.BASE_ASSET_PATHS
|
|
|
|
|
LocalSaveManager = M__framework_storage_local_save.LocalSaveManager
|
|
|
|
|
UEStorageBackend = M__framework_storage_storage_backend.UEStorageBackend
|
|
|
|
|
MiniSettingsWindow = M__game_setting_mini_settings_window.MiniSettingsWindow
|
|
|
|
|
SettingService = M__game_setting_setting_service.SettingService
|
2026-12-01 03:13:35 +08:00
|
|
|
DemoHubWindow = M__game_demo_demo_hub_window.DemoHubWindow
|
|
|
|
|
OpenDemoHub = M__game_demo_demo_router.OpenDemoHub
|
|
|
|
|
OpenUIDemoMain = M__game_demo_demo_router.OpenUIDemoMain
|
|
|
|
|
UIDemoCachedWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoCachedWindow
|
|
|
|
|
UIDemoFullscreenWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoFullscreenWindow
|
|
|
|
|
UIDemoModalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoModalWindow
|
|
|
|
|
UIDemoMultiWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoMultiWindow
|
|
|
|
|
UIDemoNormalWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoNormalWindow
|
|
|
|
|
UIDemoSystemWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoSystemWindow
|
|
|
|
|
UIDemoToastWindow = M__game_demo_ui_demo_ui_demo_windows.UIDemoToastWindow
|
2026-11-30 03:43:42 +08:00
|
|
|
GetPrimaryUIManager = M__game_startup.GetPrimaryUIManager
|
|
|
|
|
ScopedObject = M__share_base_scoped_object.ScopedObject
|
|
|
|
|
Assert = M__tests_harness_test_runner.Assert
|
|
|
|
|
AssertEqual = M__tests_harness_test_runner.AssertEqual
|
|
|
|
|
FormatReport = M__tests_harness_test_runner.FormatReport
|
|
|
|
|
RunSuites = M__tests_harness_test_runner.RunSuites
|
|
|
|
|
end
|