feat(test): add real UE 5.8 RunLuaTests commandlet, Lua.RunTests command, and fix UnLua .d.ts math/UObject bugs
This commit is contained in:
1 parent
3dd61c32a9
commit
96e3f0d009
29 files changed
+1417
-134
No files matched your search
@@ -50,8 +50,7 @@ function ____exports.RunLifecycleAndMemoryTests()
|
||||
EventBus.Clear()
|
||||
local actor = CreateBoundInstance(LifecycleSafetyActor, "AActor")
|
||||
local asset = UE.UObject.Load("/Game/Data/DA_Config.DA_Config")
|
||||
local weak = UE.FWeakObjectPtr()
|
||||
weak:Set(actor)
|
||||
local weak = UE.FWeakObjectPtr(actor)
|
||||
actor:ReceiveBeginPlay()
|
||||
actor:HoldManualRef(asset)
|
||||
AssertEqual(
|
||||
|
||||
@@ -382,7 +382,16 @@ function ____exports.RunGameplayTests()
|
||||
runner:GetActiveTaskCount(),
|
||||
0
|
||||
)
|
||||
local ownerActor = CreateBoundInstance({}, "AActor")
|
||||
local world = _G.__UE_TEST_WORLD
|
||||
local ownerActor = world ~= nil and world:SpawnActor(
|
||||
UE.AActor.StaticClass(),
|
||||
UE.FTransform(
|
||||
UE.FRotator(0, 0, 0):ToQuat(),
|
||||
UE.FVector(0, 0, 0),
|
||||
UE.FVector(1, 1, 1)
|
||||
),
|
||||
UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn
|
||||
) or CreateBoundInstance({}, "AActor")
|
||||
local postDestroyExecuted = false
|
||||
runner:Start(
|
||||
function()
|
||||
|
||||
@@ -281,7 +281,7 @@ local function CreateMockTArray()
|
||||
local i = 0
|
||||
while i < #data do
|
||||
if data[i + 1] == item then
|
||||
return 0
|
||||
return i + 1
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
@@ -566,27 +566,47 @@ local function CreateMockFVector(x, y, z)
|
||||
end,
|
||||
Add = function(self, other)
|
||||
if type(other) == "number" then
|
||||
return CreateMockFVector(self.X + other, self.Y + other, self.Z + other)
|
||||
self.X = self.X + other
|
||||
self.Y = self.Y + other
|
||||
self.Z = self.Z + other
|
||||
else
|
||||
self.X = self.X + other.X
|
||||
self.Y = self.Y + other.Y
|
||||
self.Z = self.Z + other.Z
|
||||
end
|
||||
return CreateMockFVector(self.X + other.X, self.Y + other.Y, self.Z + other.Z)
|
||||
end,
|
||||
Sub = function(self, other)
|
||||
if type(other) == "number" then
|
||||
return CreateMockFVector(self.X - other, self.Y - other, self.Z - other)
|
||||
self.X = self.X - other
|
||||
self.Y = self.Y - other
|
||||
self.Z = self.Z - other
|
||||
else
|
||||
self.X = self.X - other.X
|
||||
self.Y = self.Y - other.Y
|
||||
self.Z = self.Z - other.Z
|
||||
end
|
||||
return CreateMockFVector(self.X - other.X, self.Y - other.Y, self.Z - other.Z)
|
||||
end,
|
||||
Mul = function(self, other)
|
||||
if type(other) == "number" then
|
||||
return CreateMockFVector(self.X * other, self.Y * other, self.Z * other)
|
||||
self.X = self.X * other
|
||||
self.Y = self.Y * other
|
||||
self.Z = self.Z * other
|
||||
else
|
||||
self.X = self.X * other.X
|
||||
self.Y = self.Y * other.Y
|
||||
self.Z = self.Z * other.Z
|
||||
end
|
||||
return CreateMockFVector(self.X * other.X, self.Y * other.Y, self.Z * other.Z)
|
||||
end,
|
||||
Div = function(self, other)
|
||||
if type(other) == "number" then
|
||||
return CreateMockFVector(self.X / other, self.Y / other, self.Z / other)
|
||||
self.X = self.X / other
|
||||
self.Y = self.Y / other
|
||||
self.Z = self.Z / other
|
||||
else
|
||||
self.X = self.X / other.X
|
||||
self.Y = self.Y / other.Y
|
||||
self.Z = self.Z / other.Z
|
||||
end
|
||||
return CreateMockFVector(self.X / other.X, self.Y / other.Y, self.Z / other.Z)
|
||||
end,
|
||||
Dot = function(self, other)
|
||||
return self.X * other.X + self.Y * other.Y + self.Z * other.Z
|
||||
@@ -880,8 +900,8 @@ function ____exports.InstallIfNeeded()
|
||||
Normal = CreateMockFVector(0, 0, 1)
|
||||
} end,
|
||||
FActorSpawnParameters = function() return {Name = "", bNoFail = false, SpawnCollisionHandlingOverride = 0} end,
|
||||
FWeakObjectPtr = function()
|
||||
local refObj = nil
|
||||
FWeakObjectPtr = function(initialObj)
|
||||
local refObj = initialObj
|
||||
return {
|
||||
Set = function(self, o)
|
||||
refObj = o
|
||||
@@ -1050,6 +1070,9 @@ function ____exports.InstallIfNeeded()
|
||||
hit.Distance = dist * 0.5
|
||||
hit.Location = CreateMockFVector((startVec.X + endVec.X) * 0.5, (startVec.Y + endVec.Y) * 0.5, (startVec.Z + endVec.Z) * 0.5)
|
||||
hit.ImpactPoint = hit.Location
|
||||
if outHit ~= nil then
|
||||
return bHit, nil
|
||||
end
|
||||
return bHit, hit
|
||||
end
|
||||
}
|
||||
|
||||
@@ -127,26 +127,36 @@ function ____exports.GetSummary()
|
||||
end
|
||||
return {total = #results, passed = passed, failed = failed, results = results}
|
||||
end
|
||||
function ____exports.PrintReport()
|
||||
local summary = ____exports.GetSummary()
|
||||
function ____exports.FormatReport(summary)
|
||||
local s = summary or ____exports.GetSummary()
|
||||
local lines = {}
|
||||
local lastSuite = ""
|
||||
do
|
||||
local i = 0
|
||||
while i < #summary.results do
|
||||
local r = summary.results[i + 1]
|
||||
while i < #s.results do
|
||||
local r = s.results[i + 1]
|
||||
if r.suite ~= lastSuite then
|
||||
lastSuite = r.suite
|
||||
print(string.format("\n[%s]", r.suite))
|
||||
lines[#lines + 1] = ""
|
||||
lines[#lines + 1] = string.format("[%s]", r.suite)
|
||||
end
|
||||
if r.passed then
|
||||
print(string.format(" PASS %s", r.name))
|
||||
lines[#lines + 1] = string.format(" PASS %s", r.name)
|
||||
else
|
||||
print(string.format(" FAIL %s\n -> %s", r.name, r.errorMessage or "unknown error"))
|
||||
lines[#lines + 1] = string.format(" FAIL %s\n -> %s", r.name, r.errorMessage or "unknown error")
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
print(string.format("\n========================================\nTotal: %d | Passed: %d | Failed: %d\n========================================", summary.total, summary.passed, summary.failed))
|
||||
lines[#lines + 1] = ""
|
||||
lines[#lines + 1] = "========================================"
|
||||
lines[#lines + 1] = string.format("Total: %d | Passed: %d | Failed: %d", s.total, s.passed, s.failed)
|
||||
lines[#lines + 1] = "========================================"
|
||||
return table.concat(lines, "\n")
|
||||
end
|
||||
function ____exports.PrintReport()
|
||||
local summary = ____exports.GetSummary()
|
||||
print(____exports.FormatReport(summary))
|
||||
return summary
|
||||
end
|
||||
return ____exports
|
||||
@@ -0,0 +1,462 @@
|
||||
local ____exports = {}
|
||||
local ____TestRunner = require("Tests.Harness.TestRunner")
|
||||
local Reset = ____TestRunner.Reset
|
||||
local PrintReport = ____TestRunner.PrintReport
|
||||
local Suite = ____TestRunner.Suite
|
||||
local Test = ____TestRunner.Test
|
||||
local AssertEqual = ____TestRunner.AssertEqual
|
||||
local AssertNear = ____TestRunner.AssertNear
|
||||
local AssertTrue = ____TestRunner.AssertTrue
|
||||
local AssertFalse = ____TestRunner.AssertFalse
|
||||
local AssertNotNil = ____TestRunner.AssertNotNil
|
||||
local AssertNil = ____TestRunner.AssertNil
|
||||
local AssertArrayEqual = ____TestRunner.AssertArrayEqual
|
||||
local ____BasicTypesAndControlFlow = require("Tests.Syntax.BasicTypesAndControlFlow")
|
||||
local RunBasicTypesAndControlFlowTests = ____BasicTypesAndControlFlow.RunBasicTypesAndControlFlowTests
|
||||
local ____FunctionsClosuresAndTuples = require("Tests.Syntax.FunctionsClosuresAndTuples")
|
||||
local RunFunctionsClosuresAndTuplesTests = ____FunctionsClosuresAndTuples.RunFunctionsClosuresAndTuplesTests
|
||||
local ____PureClassesAndGenerics = require("Tests.Syntax.PureClassesAndGenerics")
|
||||
local RunPureClassesAndGenericsTests = ____PureClassesAndGenerics.RunPureClassesAndGenericsTests
|
||||
local ____GameplaySuite = require("Tests.Gameplay.GameplaySuite")
|
||||
local RunGameplayTests = ____GameplaySuite.RunGameplayTests
|
||||
local ____Lua54PitfallsTest = require("Tests.Extra.Lua54PitfallsTest")
|
||||
local RunLua54PitfallsTests = ____Lua54PitfallsTest.RunLua54PitfallsTests
|
||||
local EventBus = require("Framework.EventBus")
|
||||
local HotReload = require("Framework.HotReload")
|
||||
local ____Ex06_NativeContainers = require("Tests.UnLuaExamples.Ex06_NativeContainers")
|
||||
local VerifyTArrayOperations = ____Ex06_NativeContainers.VerifyTArrayOperations
|
||||
local VerifyTMapOperations = ____Ex06_NativeContainers.VerifyTMapOperations
|
||||
local VerifyTSetOperations = ____Ex06_NativeContainers.VerifyTSetOperations
|
||||
local UnLuaBaseActorClass = require("Tests.Syntax.UnLuaBaseActor")
|
||||
local function TickUEWorld(steps, deltaSeconds)
|
||||
local tickFn = _G.__UE_TEST_TICK
|
||||
if tickFn == nil then
|
||||
return
|
||||
end
|
||||
do
|
||||
local i = 0
|
||||
while i < steps do
|
||||
tickFn(deltaSeconds)
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
function ____exports.RunUERuntimeSuite(world)
|
||||
local canTickWorld = _G.__UE_TEST_TICK ~= nil
|
||||
Suite(
|
||||
"UE.RealEngineIntegration",
|
||||
function()
|
||||
Test(
|
||||
"Real UE C++ TArray / TMap / TSet containers & native __pairs iteration",
|
||||
function()
|
||||
VerifyTArrayOperations()
|
||||
VerifyTMapOperations()
|
||||
VerifyTSetOperations()
|
||||
end
|
||||
)
|
||||
Test(
|
||||
"Real UE SpawnActor + @unlua UnLuaBaseActor (Overridden, static methods, destructuring)",
|
||||
function()
|
||||
local actor = world:SpawnActor(
|
||||
UE.ATargetPoint.StaticClass(),
|
||||
UE.FTransform(
|
||||
UE.FRotator(0, 0, 0):ToQuat(),
|
||||
UE.FVector(0, 0, 0),
|
||||
UE.FVector(1, 1, 1)
|
||||
),
|
||||
UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn,
|
||||
nil,
|
||||
nil,
|
||||
"Tests.Syntax.UnLuaBaseActor"
|
||||
)
|
||||
AssertNotNil(actor)
|
||||
AssertTrue(UE.UKismetSystemLibrary.IsValid(actor))
|
||||
AssertTrue(actor:IsA(UE.AActor.StaticClass()))
|
||||
AssertEqual(
|
||||
actor:GetHp(),
|
||||
100
|
||||
)
|
||||
AssertArrayEqual(
|
||||
actor:GetTrace(),
|
||||
{"Base.ReceiveBeginPlay"}
|
||||
)
|
||||
AssertEqual(
|
||||
actor:ApplyConfig({name = "UEHero"}),
|
||||
"UEHero:100"
|
||||
)
|
||||
AssertEqual(
|
||||
actor:ApplyConfig({name = "UEBoss", hp = 888}),
|
||||
"UEBoss:888"
|
||||
)
|
||||
AssertEqual(
|
||||
actor:SumScores({10}),
|
||||
15
|
||||
)
|
||||
AssertEqual(
|
||||
actor:SumScores({1, 2, 3, 4}),
|
||||
10
|
||||
)
|
||||
AssertEqual(
|
||||
UnLuaBaseActorClass:StaticWithSelf(25),
|
||||
125
|
||||
)
|
||||
AssertEqual(
|
||||
UnLuaBaseActorClass.StaticNoSelf(7, 8),
|
||||
15
|
||||
)
|
||||
AssertEqual(
|
||||
UnLuaBaseActorClass.StaticDocNoSelf(9),
|
||||
27
|
||||
)
|
||||
actor:K2_DestroyActor()
|
||||
end
|
||||
)
|
||||
Test(
|
||||
"Real UE SpawnActor + 3-level @unlua inheritance (GrandChild -> Sub -> Base -> AActor)",
|
||||
function()
|
||||
local grand = world:SpawnActor(
|
||||
UE.ATriggerBox.StaticClass(),
|
||||
UE.FTransform(
|
||||
UE.FRotator(0, 0, 0):ToQuat(),
|
||||
UE.FVector(0, 0, 0),
|
||||
UE.FVector(1, 1, 1)
|
||||
),
|
||||
UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn,
|
||||
nil,
|
||||
nil,
|
||||
"Tests.Syntax.UnLuaGrandChildActor"
|
||||
)
|
||||
AssertNotNil(grand)
|
||||
AssertArrayEqual(
|
||||
grand:GetTrace(),
|
||||
{"Base.ReceiveBeginPlay", "Sub.ReceiveBeginPlay", "GrandChild.ReceiveBeginPlay"}
|
||||
)
|
||||
AssertEqual(
|
||||
grand:GetFaction(),
|
||||
"Ally"
|
||||
)
|
||||
AssertEqual(
|
||||
grand:GetTier(),
|
||||
3
|
||||
)
|
||||
AssertEqual(
|
||||
grand:ComputeBonus(10),
|
||||
33
|
||||
)
|
||||
AssertEqual(
|
||||
grand:SetupWithFaction({name = "Knight", hp = 250}, "Enemy"),
|
||||
"Knight:250[Enemy]"
|
||||
)
|
||||
grand:K2_DestroyActor()
|
||||
end
|
||||
)
|
||||
Test(
|
||||
"Real UE Ex01_HelloWorld & Ex02_OverrideBlueprintEvents lifecycle",
|
||||
function()
|
||||
local hello = world:SpawnActor(
|
||||
UE.ATriggerSphere.StaticClass(),
|
||||
UE.FTransform(
|
||||
UE.FRotator(0, 0, 0):ToQuat(),
|
||||
UE.FVector(0, 0, 0),
|
||||
UE.FVector(1, 1, 1)
|
||||
),
|
||||
UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn,
|
||||
nil,
|
||||
nil,
|
||||
"Tests.UnLuaExamples.Ex01_HelloWorld"
|
||||
)
|
||||
AssertNotNil(hello)
|
||||
AssertTrue((string.find(
|
||||
hello:GetGreeting(),
|
||||
"Hello UnLua from TypeScript",
|
||||
1,
|
||||
true
|
||||
)) ~= nil)
|
||||
hello:K2_DestroyActor()
|
||||
local eventsActor = world:SpawnActor(
|
||||
UE.ATriggerCapsule.StaticClass(),
|
||||
UE.FTransform(
|
||||
UE.FRotator(0, 0, 0):ToQuat(),
|
||||
UE.FVector(0, 0, 0),
|
||||
UE.FVector(1, 1, 1)
|
||||
),
|
||||
UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn,
|
||||
nil,
|
||||
nil,
|
||||
"Tests.UnLuaExamples.Ex02_OverrideBlueprintEvents"
|
||||
)
|
||||
AssertNotNil(eventsActor)
|
||||
local events = eventsActor:GetEvents()
|
||||
AssertTrue(#events >= 2)
|
||||
AssertEqual(events[1], "Initialize")
|
||||
eventsActor:K2_DestroyActor()
|
||||
end
|
||||
)
|
||||
Test(
|
||||
"Real UE Ex04 DynamicBinding: SpawnActor, SpawnActorEx & UE.NewObject with Initializer",
|
||||
function()
|
||||
local spawned = world:SpawnActor(
|
||||
UE.APlayerStart.StaticClass(),
|
||||
UE.FTransform(
|
||||
UE.FRotator(0, 90, 0):ToQuat(),
|
||||
UE.FVector(100, 200, 300),
|
||||
UE.FVector(1, 1, 1)
|
||||
),
|
||||
UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn,
|
||||
nil,
|
||||
nil,
|
||||
"Tests.UnLuaExamples.Ex04_DynamicSpawnedActor",
|
||||
{InitTag = "RealUESpawn", InitPower = 555}
|
||||
)
|
||||
AssertNotNil(spawned)
|
||||
AssertEqual(
|
||||
spawned:GetInitTag(),
|
||||
"RealUESpawn"
|
||||
)
|
||||
AssertEqual(
|
||||
spawned:GetInitPower(),
|
||||
555
|
||||
)
|
||||
AssertTrue(spawned:IsBeginPlayCalled())
|
||||
spawned:K2_DestroyActor()
|
||||
local params = UE.FActorSpawnParameters()
|
||||
params.bNoFail = true
|
||||
params.SpawnCollisionHandlingOverride = UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn
|
||||
local spawnedEx = world:SpawnActorEx(
|
||||
UE.APlayerStart.StaticClass(),
|
||||
UE.FTransform(
|
||||
UE.FRotator(0, 0, 0):ToQuat(),
|
||||
UE.FVector(10, 20, 30),
|
||||
UE.FVector(1, 1, 1)
|
||||
),
|
||||
{InitTag = "RealUESpawnEx", InitPower = 777},
|
||||
"Tests.UnLuaExamples.Ex04_DynamicSpawnedActor",
|
||||
params
|
||||
)
|
||||
AssertNotNil(spawnedEx)
|
||||
AssertEqual(
|
||||
spawnedEx:GetInitTag(),
|
||||
"RealUESpawnEx"
|
||||
)
|
||||
AssertEqual(
|
||||
spawnedEx:GetInitPower(),
|
||||
777
|
||||
)
|
||||
spawnedEx:K2_DestroyActor()
|
||||
local dynObj = UE.NewObject(
|
||||
UE.ULuaBundleAsset.StaticClass(),
|
||||
world,
|
||||
"RealUEDynObj",
|
||||
"Tests.UnLuaExamples.Ex04_DynamicObject",
|
||||
{Seed = 10}
|
||||
)
|
||||
AssertNotNil(dynObj)
|
||||
AssertEqual(
|
||||
dynObj:GetSeed(),
|
||||
10
|
||||
)
|
||||
AssertEqual(
|
||||
dynObj:NextValue(),
|
||||
21
|
||||
)
|
||||
AssertEqual(
|
||||
dynObj:NextValue(),
|
||||
43
|
||||
)
|
||||
end
|
||||
)
|
||||
Test(
|
||||
"Real UE Ex08 Struct math, K2_SetActorLocation & LineTraceSingle multi-return",
|
||||
function()
|
||||
local actor = world:SpawnActor(
|
||||
UE.ATextRenderActor.StaticClass(),
|
||||
UE.FTransform(
|
||||
UE.FRotator(0, 0, 0):ToQuat(),
|
||||
UE.FVector(0, 0, 0),
|
||||
UE.FVector(1, 1, 1)
|
||||
),
|
||||
UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn,
|
||||
nil,
|
||||
nil,
|
||||
"Tests.UnLuaExamples.Ex08_StructAndTrace"
|
||||
)
|
||||
AssertNotNil(actor)
|
||||
local size, dot, dist = actor:ComputeVectorMath()
|
||||
AssertNear(size, 13, 0.001)
|
||||
AssertNear(dot, 0, 0.001)
|
||||
AssertNear(dist, 13, 0.001)
|
||||
local bHit, hitDist, impact = actor:TraceForward(500)
|
||||
AssertFalse(bHit)
|
||||
AssertEqual(
|
||||
type(hitDist),
|
||||
"number"
|
||||
)
|
||||
AssertNotNil(impact)
|
||||
local bHit2, outHit2 = actor:TraceForwardMultiReturn(500)
|
||||
AssertFalse(bHit2)
|
||||
AssertNotNil(outHit2)
|
||||
actor:K2_DestroyActor()
|
||||
end
|
||||
)
|
||||
Test(
|
||||
"Real UE UnLua.Ref / UnLua.Unref & FWeakObjectPtr validity",
|
||||
function()
|
||||
local obj = UE.NewObject(
|
||||
UE.UObjectLibrary.StaticClass(),
|
||||
world,
|
||||
"WeakRefTarget"
|
||||
)
|
||||
AssertTrue(UE.UKismetSystemLibrary.IsValid(obj))
|
||||
local refProxy = UnLua.Ref(obj)
|
||||
AssertNotNil(refProxy)
|
||||
local weak = UE.FWeakObjectPtr(obj)
|
||||
AssertTrue(weak:IsValid())
|
||||
AssertNotNil(weak:Get())
|
||||
weak:Reset()
|
||||
AssertFalse(weak:IsValid())
|
||||
AssertNil(weak:Get())
|
||||
UnLua.Unref(obj)
|
||||
end
|
||||
)
|
||||
Test(
|
||||
"Real UE ALuaDemoActor (IUnLuaInterface static binding) + EventBus + Tick + EndPlay",
|
||||
function()
|
||||
EventBus.Clear()
|
||||
local demoActor = world:SpawnActor(
|
||||
UE.ALuaDemoActor.StaticClass(),
|
||||
UE.FTransform(
|
||||
UE.FRotator(0, 0, 0):ToQuat(),
|
||||
UE.FVector(0, 0, 100),
|
||||
UE.FVector(1, 1, 1)
|
||||
),
|
||||
UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn
|
||||
)
|
||||
AssertNotNil(demoActor)
|
||||
AssertTrue(demoActor:IsA(UE.ALuaDemoActor.StaticClass()))
|
||||
local initText = demoActor:GetStatusTextString()
|
||||
AssertTrue((string.find(initText, "UnLua Active", 1, true)) ~= nil)
|
||||
AssertTrue((string.find(initText, "Pings: 0", 1, true)) ~= nil)
|
||||
if canTickWorld then
|
||||
TickUEWorld(5, 0.05)
|
||||
end
|
||||
EventBus.Emit("Demo.Ping", "UERealEngineTest")
|
||||
local pingedText = demoActor:GetStatusTextString()
|
||||
AssertTrue((string.find(pingedText, "Pings: 1", 1, true)) ~= nil)
|
||||
AssertTrue((string.find(pingedText, "Color: Gold", 1, true)) ~= nil)
|
||||
local bMoved = demoActor:K2_SetActorLocation(
|
||||
UE.FVector(120, 240, 360),
|
||||
false,
|
||||
nil,
|
||||
true
|
||||
)
|
||||
AssertTrue(bMoved)
|
||||
local loc = demoActor:K2_GetActorLocation()
|
||||
AssertNear(loc.X, 120, 0.01)
|
||||
AssertNear(loc.Y, 240, 0.01)
|
||||
AssertNear(loc.Z, 360, 0.01)
|
||||
demoActor:K2_DestroyActor()
|
||||
EventBus.Clear()
|
||||
end
|
||||
)
|
||||
if canTickWorld then
|
||||
Test(
|
||||
"Real UE FTimerManager + K2_SetTimerDelegate(UnLua.Delegate) ticked by UWorld",
|
||||
function()
|
||||
local timerActor = world:SpawnActor(
|
||||
UE.ACameraActor.StaticClass(),
|
||||
UE.FTransform(
|
||||
UE.FRotator(0, 0, 0):ToQuat(),
|
||||
UE.FVector(0, 0, 0),
|
||||
UE.FVector(1, 1, 1)
|
||||
),
|
||||
UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn,
|
||||
nil,
|
||||
nil,
|
||||
"Tests.UE.UETimerTestActor"
|
||||
)
|
||||
AssertNotNil(timerActor)
|
||||
AssertTrue(timerActor:IsTimerActive())
|
||||
AssertEqual(
|
||||
timerActor:GetTimerCount(),
|
||||
0
|
||||
)
|
||||
TickUEWorld(10, 0.05)
|
||||
AssertTrue(timerActor:GetTimerCount() >= 3)
|
||||
local countBeforeStop = timerActor:GetTimerCount()
|
||||
timerActor:StopTimer()
|
||||
AssertFalse(timerActor:IsTimerActive())
|
||||
TickUEWorld(6, 0.05)
|
||||
AssertEqual(
|
||||
timerActor:GetTimerCount(),
|
||||
countBeforeStop
|
||||
)
|
||||
timerActor:K2_DestroyActor()
|
||||
end
|
||||
)
|
||||
Test(
|
||||
"Real UE FLatentActionManager + UKismetSystemLibrary.Delay coroutine (Ex07)",
|
||||
function()
|
||||
local latentActor = world:SpawnActor(
|
||||
UE.ADecalActor.StaticClass(),
|
||||
UE.FTransform(
|
||||
UE.FRotator(0, 0, 0):ToQuat(),
|
||||
UE.FVector(0, 0, 0),
|
||||
UE.FVector(1, 1, 1)
|
||||
),
|
||||
UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn,
|
||||
nil,
|
||||
nil,
|
||||
"Tests.UnLuaExamples.Ex07_CallLatentFunction"
|
||||
)
|
||||
AssertNotNil(latentActor)
|
||||
AssertArrayEqual(
|
||||
latentActor:GetSteps(),
|
||||
{"Step1:Start"}
|
||||
)
|
||||
AssertFalse(latentActor:IsCompleted())
|
||||
TickUEWorld(6, 0.1)
|
||||
AssertArrayEqual(
|
||||
latentActor:GetSteps(),
|
||||
{"Step1:Start", "Step2:After0.5s"}
|
||||
)
|
||||
AssertFalse(latentActor:IsCompleted())
|
||||
TickUEWorld(11, 0.1)
|
||||
AssertArrayEqual(
|
||||
latentActor:GetSteps(),
|
||||
{"Step1:Start", "Step2:After0.5s", "Step3:Done"}
|
||||
)
|
||||
AssertTrue(latentActor:IsCompleted())
|
||||
latentActor:K2_DestroyActor()
|
||||
end
|
||||
)
|
||||
end
|
||||
Test(
|
||||
"Real UE HotReload.ReloadModule validates arguments and emits events",
|
||||
function()
|
||||
EventBus.Clear()
|
||||
local badOk = HotReload.ReloadModule("")
|
||||
AssertFalse(badOk)
|
||||
local ok = HotReload.ReloadModule("Framework.Log")
|
||||
AssertTrue(ok)
|
||||
EventBus.Clear()
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
end
|
||||
--- 在真实 UE 5.8 + UnLua 2.3.6 环境下运行的统一入口。
|
||||
-- 可由 RunLuaTestsCommandlet 或编辑器控制台命令 `Lua.RunTests` 调用。
|
||||
function ____exports.RunAllInUE(world)
|
||||
local targetWorld = world or _G.__UE_TEST_WORLD
|
||||
Reset()
|
||||
RunBasicTypesAndControlFlowTests()
|
||||
RunFunctionsClosuresAndTuplesTests()
|
||||
RunPureClassesAndGenericsTests()
|
||||
RunGameplayTests()
|
||||
RunLua54PitfallsTests()
|
||||
if targetWorld ~= nil then
|
||||
____exports.RunUERuntimeSuite(targetWorld)
|
||||
end
|
||||
return PrintReport()
|
||||
end
|
||||
return ____exports
|
||||
@@ -0,0 +1,26 @@
|
||||
local UETimerTestActor = UnLua.Class()
|
||||
function UETimerTestActor.ReceiveBeginPlay(self)
|
||||
self.Overridden.ReceiveBeginPlay(self)
|
||||
self.timerCount = 0
|
||||
self.timerHandle = UE.UKismetSystemLibrary.K2_SetTimerDelegate({self, self.OnTimerTick}, 0.1, true)
|
||||
end
|
||||
function UETimerTestActor.OnTimerTick(self)
|
||||
if not UE.UKismetSystemLibrary.IsValid(self) then
|
||||
return
|
||||
end
|
||||
self.timerCount = self.timerCount + 1
|
||||
end
|
||||
function UETimerTestActor.StopTimer(self)
|
||||
UE.UKismetSystemLibrary.K2_ClearAndInvalidateTimerHandle(self, self.timerHandle)
|
||||
end
|
||||
function UETimerTestActor.GetTimerCount(self)
|
||||
return self.timerCount
|
||||
end
|
||||
function UETimerTestActor.IsTimerActive(self)
|
||||
return UE.UKismetSystemLibrary.K2_IsTimerActiveHandle(self, self.timerHandle)
|
||||
end
|
||||
function UETimerTestActor.ReceiveEndPlay(self, EndPlayReason)
|
||||
self:StopTimer()
|
||||
self.Overridden.ReceiveEndPlay(self, EndPlayReason)
|
||||
end
|
||||
return UETimerTestActor
|
||||
@@ -63,7 +63,7 @@ function ____exports.VerifyTArrayOperations()
|
||||
AssertFalse(arr:Contains(999))
|
||||
AssertEqual(
|
||||
arr:AddUnique(25),
|
||||
0
|
||||
2
|
||||
)
|
||||
AssertEqual(
|
||||
arr:AddUnique(40),
|
||||
|
||||
@@ -10,19 +10,19 @@ end
|
||||
function Ex08_StructAndTrace.ComputeVectorMath(self)
|
||||
local a = UE.FVector(3, 4, 0)
|
||||
local b = UE.FVector(0, 0, 12)
|
||||
local c = a:Add(b)
|
||||
local dot = a:Dot(b)
|
||||
a:Add(b)
|
||||
local dist = UE.FVector.Dist(
|
||||
UE.FVector(0, 0, 0),
|
||||
c
|
||||
a
|
||||
)
|
||||
return c:Size(), dot, dist
|
||||
return a:Size(), dot, dist
|
||||
end
|
||||
function Ex08_StructAndTrace.TraceForward(self, distance)
|
||||
local origin = self:K2_GetActorLocation()
|
||||
self._tmpStart:Set(origin.X, origin.Y, origin.Z)
|
||||
self._tmpEnd:Set(origin.X + distance, origin.Y, origin.Z)
|
||||
local bHit, hit = UE.UKismetSystemLibrary.LineTraceSingle(
|
||||
local bHit, returnedHit = UE.UKismetSystemLibrary.LineTraceSingle(
|
||||
self,
|
||||
self._tmpStart,
|
||||
self._tmpEnd,
|
||||
@@ -33,8 +33,25 @@ function Ex08_StructAndTrace.TraceForward(self, distance)
|
||||
self._tmpHit,
|
||||
true
|
||||
)
|
||||
local hit = returnedHit or self._tmpHit
|
||||
return bHit, hit.Distance, hit.ImpactPoint
|
||||
end
|
||||
function Ex08_StructAndTrace.TraceForwardMultiReturn(self, distance)
|
||||
local origin = self:K2_GetActorLocation()
|
||||
self._tmpStart:Set(origin.X, origin.Y, origin.Z)
|
||||
self._tmpEnd:Set(origin.X + distance, origin.Y, origin.Z)
|
||||
return UE.UKismetSystemLibrary.LineTraceSingle(
|
||||
self,
|
||||
self._tmpStart,
|
||||
self._tmpEnd,
|
||||
UE.ETraceTypeQuery.TraceTypeQuery1,
|
||||
false,
|
||||
self._ignoreActors,
|
||||
UE.EDrawDebugTrace.None,
|
||||
nil,
|
||||
true
|
||||
)
|
||||
end
|
||||
function Ex08_StructAndTrace.TeleportTo(self, x, y, z)
|
||||
local target = UE.FVector(x, y, z)
|
||||
local bMoved = self:K2_SetActorLocation(target, false, self._tmpHit, true)
|
||||
|
||||
@@ -2,14 +2,14 @@ local Ex09_AssetRefAndUMG = UnLua.Class()
|
||||
function Ex09_AssetRefAndUMG.Initialize(self, _Initializer)
|
||||
self.isConstructed = false
|
||||
self.isDestructed = false
|
||||
self.weakRef = UE.FWeakObjectPtr()
|
||||
self.weakRef = nil
|
||||
end
|
||||
function Ex09_AssetRefAndUMG.Construct(self)
|
||||
self.isConstructed = true
|
||||
self.loadedAsset = UE.UObject.Load("/Game/UI/Textures/T_Icon.T_Icon")
|
||||
if self.loadedAsset ~= nil then
|
||||
self.refProxy = UnLua.Ref(self.loadedAsset)
|
||||
self.weakRef:Set(self.loadedAsset)
|
||||
self.weakRef = UE.FWeakObjectPtr(self.loadedAsset)
|
||||
end
|
||||
end
|
||||
function Ex09_AssetRefAndUMG.ShowOnScreen(self)
|
||||
@@ -30,10 +30,13 @@ function Ex09_AssetRefAndUMG.Destruct(self)
|
||||
self.refProxy = nil
|
||||
self.loadedAsset = nil
|
||||
end
|
||||
self.weakRef:Reset()
|
||||
if self.weakRef ~= nil then
|
||||
self.weakRef:Reset()
|
||||
self.weakRef = nil
|
||||
end
|
||||
end
|
||||
function Ex09_AssetRefAndUMG.HasValidWeakAsset(self)
|
||||
return self.weakRef:IsValid()
|
||||
return self.weakRef ~= nil and self.weakRef:IsValid()
|
||||
end
|
||||
function Ex09_AssetRefAndUMG.IsConstructed(self)
|
||||
return self.isConstructed
|
||||
|
||||
Reference in new issue
Block a user