mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-18 06:03:47 +03:00
Upload
This commit is contained in:
22
lua/pac3/core/client/tests/all_parts.lua
Normal file
22
lua/pac3/core/client/tests/all_parts.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
function test.Run(done)
|
||||
local root = pac.CreatePart("group")
|
||||
|
||||
for class_name in pairs(pac.GetRegisteredParts()) do
|
||||
root:CreatePart(class_name)
|
||||
end
|
||||
|
||||
timer.Simple(0.5, function()
|
||||
root:Remove()
|
||||
done()
|
||||
end)
|
||||
end
|
||||
71
lua/pac3/core/client/tests/base_part.lua
Normal file
71
lua/pac3/core/client/tests/base_part.lua
Normal file
@@ -0,0 +1,71 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
local consume = test.EventConsumer({
|
||||
"init",
|
||||
"hide",
|
||||
"parent group",
|
||||
"shown from rendering",
|
||||
"draw",
|
||||
"hide",
|
||||
"remove",
|
||||
})
|
||||
|
||||
function test.Run(done)
|
||||
do
|
||||
local BUILDER, PART = pac.PartTemplate("base_drawable")
|
||||
|
||||
PART.FriendlyName = "test"
|
||||
PART.ClassName = "test"
|
||||
PART.Icon = 'icon16/cut.png'
|
||||
|
||||
function PART:Initialize()
|
||||
consume("init")
|
||||
end
|
||||
|
||||
function PART:OnShow(from_rendering)
|
||||
if from_rendering then
|
||||
consume("shown from rendering")
|
||||
end
|
||||
end
|
||||
|
||||
function PART:OnDraw()
|
||||
consume("draw")
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
function PART:OnThink()
|
||||
--consume("think")
|
||||
end
|
||||
|
||||
function PART:OnHide()
|
||||
consume("hide")
|
||||
end
|
||||
|
||||
function PART:OnRemove()
|
||||
consume("remove")
|
||||
done()
|
||||
end
|
||||
|
||||
function PART:OnParent(parent)
|
||||
consume("parent " .. tostring(parent.ClassName))
|
||||
end
|
||||
|
||||
function PART:OnUnparent()
|
||||
consume("unparent")
|
||||
end
|
||||
|
||||
pac.RegisterPart(PART)
|
||||
end
|
||||
|
||||
local root = pac.CreatePart("group")
|
||||
local part = root:CreatePart("test")
|
||||
end
|
||||
114
lua/pac3/core/client/tests/events.lua
Normal file
114
lua/pac3/core/client/tests/events.lua
Normal file
@@ -0,0 +1,114 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
local consume = test.EventConsumer({
|
||||
"shown from rendering",
|
||||
"event think",
|
||||
"event triggers hide",
|
||||
"hidden",
|
||||
"event triggers show",
|
||||
"shown from event",
|
||||
})
|
||||
|
||||
function test.Run(done)
|
||||
local stage = nil
|
||||
|
||||
do
|
||||
local BUILDER, PART = pac.PartTemplate("base_drawable")
|
||||
|
||||
PART.FriendlyName = "test"
|
||||
PART.ClassName = "test"
|
||||
PART.Icon = 'icon16/cut.png'
|
||||
|
||||
function PART:OnShow(from_rendering)
|
||||
if from_rendering then
|
||||
-- TODO: OnShow(true) triggers 2 times
|
||||
if stage == nil then
|
||||
-- 1
|
||||
|
||||
consume("shown from rendering")
|
||||
stage = "first event frame"
|
||||
end
|
||||
else
|
||||
if stage == "wait for trigger" then
|
||||
|
||||
-- 5
|
||||
|
||||
consume("shown from event")
|
||||
self:GetRootPart():Remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PART:OnHide()
|
||||
if stage == "hide from event" then
|
||||
|
||||
-- 3
|
||||
|
||||
consume("hidden")
|
||||
stage = "show trigger"
|
||||
end
|
||||
end
|
||||
|
||||
function PART:OnRemove()
|
||||
done()
|
||||
end
|
||||
|
||||
pac.RegisterPart(PART)
|
||||
end
|
||||
|
||||
do
|
||||
local event = pac.CreateEvent("test")
|
||||
|
||||
function event:Think(event, ent, ...)
|
||||
|
||||
if stage == "first event frame" then
|
||||
|
||||
-- 2
|
||||
|
||||
consume("event think")
|
||||
stage = "hide trigger"
|
||||
|
||||
|
||||
elseif stage == "hide trigger" then
|
||||
|
||||
|
||||
-- 3
|
||||
|
||||
consume("event triggers hide")
|
||||
stage = "hide from event"
|
||||
|
||||
return true -- hide
|
||||
elseif stage == "show trigger" then
|
||||
|
||||
-- 4
|
||||
|
||||
consume("event triggers show")
|
||||
stage = "wait for trigger"
|
||||
|
||||
|
||||
return false -- show
|
||||
end
|
||||
end
|
||||
|
||||
pac.RegisterEvent(event)
|
||||
end
|
||||
|
||||
local root = pac.CreatePart("group")
|
||||
|
||||
do
|
||||
local event = root:CreatePart("event")
|
||||
event:SetEvent("test")
|
||||
event:SetAffectChildrenOnly(true)
|
||||
|
||||
local child = event:CreatePart("test")
|
||||
end
|
||||
end
|
||||
65
lua/pac3/core/client/tests/model_modifier.lua
Normal file
65
lua/pac3/core/client/tests/model_modifier.lua
Normal file
@@ -0,0 +1,65 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local function equal(a,b, msg)
|
||||
if a ~= b then
|
||||
error(tostring(a) .. " != " .. tostring(b) .. ": " .. msg .. "\n", 2)
|
||||
end
|
||||
end
|
||||
|
||||
function test.Run(done)
|
||||
local owner = pac.LocalPlayer
|
||||
local prev = owner:GetModel()
|
||||
local mdl = "models/combine_helicopter/helicopter_bomb01.mdl"
|
||||
|
||||
if prev == mdl then
|
||||
owner:SetModel(test.RunLuaOnServer("return Entity(" .. owner:EntIndex() .. "):GetModel()"))
|
||||
prev = owner:GetModel()
|
||||
assert(prev ~= mdl, "something is wrong!!")
|
||||
end
|
||||
|
||||
for _, class in ipairs({"entity", "entity2"}) do
|
||||
local root = pac.CreatePart("group")
|
||||
local entity = root:CreatePart(class)
|
||||
|
||||
-- the owner is not valid right away, when the owner is valid, the changes are applied
|
||||
repeat yield() until entity:GetOwner():IsValid()
|
||||
|
||||
entity:SetModel(mdl)
|
||||
|
||||
equal(owner:GetModel(), mdl, " after "..class..":SetModel")
|
||||
root:Remove()
|
||||
equal(owner:GetModel(), prev, " after root is removed, the model should be reverted")
|
||||
end
|
||||
|
||||
RunConsoleCommand("pac_modifier_model", "1")
|
||||
repeat yield() until GetConVar("pac_modifier_model"):GetBool()
|
||||
|
||||
pac.emut.MutateEntity(owner, "model", owner, mdl)
|
||||
|
||||
equal(test.RunLuaOnServer("return Entity(" .. owner:EntIndex() .. "):GetModel()"), mdl, " server model differs")
|
||||
|
||||
RunConsoleCommand("pac_modifier_model", "0")
|
||||
repeat yield() until not GetConVar("pac_modifier_model"):GetBool()
|
||||
|
||||
equal(test.RunLuaOnServer("return Entity(" .. owner:EntIndex() .. "):GetModel()"), prev, " should be reverted")
|
||||
|
||||
pac.emut.RestoreMutations(owner, "model", owner)
|
||||
|
||||
RunConsoleCommand("pac_modifier_model", "1")
|
||||
repeat yield() until GetConVar("pac_modifier_model"):GetBool()
|
||||
|
||||
done()
|
||||
end
|
||||
|
||||
|
||||
function test.Teardown()
|
||||
timer.Remove("pac_test")
|
||||
end
|
||||
113
lua/pac3/core/client/tests/property_fuzz.lua
Normal file
113
lua/pac3/core/client/tests/property_fuzz.lua
Normal file
@@ -0,0 +1,113 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local function RandomModel()
|
||||
for _, tbl in RandomPairs(spawnmenu.GetPropTable()) do
|
||||
for _, val in RandomPairs(tbl.contents) do
|
||||
if val.model then
|
||||
return val.model
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function RandomMaterial()
|
||||
return table.Random(list.Get("OverrideMaterials"))
|
||||
end
|
||||
|
||||
function test.Run(done)
|
||||
local root = pac.CreatePart("group")
|
||||
local classes = {}
|
||||
for class_name in pairs(pac.GetRegisteredParts()) do
|
||||
local part = root:CreatePart(class_name)
|
||||
table.insert(classes, class_name)
|
||||
end
|
||||
|
||||
local run = true
|
||||
|
||||
timer.Simple(10, function()
|
||||
run = false
|
||||
root:Remove()
|
||||
done()
|
||||
end)
|
||||
|
||||
local file = file.Open("pac_test_log.txt", "w", "DATA")
|
||||
local function log(line)
|
||||
file:Write(line .. "\n")
|
||||
file:Flush()
|
||||
end
|
||||
|
||||
while run do
|
||||
local children = root:GetChildrenList()
|
||||
for _, part in RandomPairs(children) do
|
||||
if part.ClassName == "player_movement" then continue end
|
||||
|
||||
for key, val in RandomPairs(part.StorableVars) do
|
||||
|
||||
if key == "UniqueID" then continue end
|
||||
if key == "Name" then continue end
|
||||
if key == "OwnerName" then continue end
|
||||
if key == "Command" then continue end
|
||||
|
||||
log(part.ClassName .. ".Get" .. key)
|
||||
local val = part["Get"..key](part)
|
||||
|
||||
if key:EndsWith("UID") then
|
||||
if math.random() > 0.5 then
|
||||
val = table.Random(children)
|
||||
else
|
||||
val = part:CreatePart(table.Random(classes))
|
||||
end
|
||||
val = val:GetUniqueID()
|
||||
elseif isnumber(val) then
|
||||
val = math.Rand(-1000, 100)
|
||||
elseif isvector(val) then
|
||||
val = VectorRand()*1000
|
||||
elseif isangle(val) then
|
||||
val = Angle(math.Rand(0, 360), math.Rand(0, 360), math.Rand(0, 360))
|
||||
elseif isbool(val) then
|
||||
val = math.random() > 0.5
|
||||
elseif isstring(val) then
|
||||
|
||||
|
||||
|
||||
local udata = pac.GetPropertyUserdata(part, key)
|
||||
|
||||
if udata then
|
||||
local t = udata.editor_panel
|
||||
if t == "model" then
|
||||
val = RandomModel()
|
||||
elseif t == "material" then
|
||||
val = RandomMaterial()
|
||||
elseif key == "Bone" then
|
||||
for bone in RandomPairs(part:GetModelBones()) do
|
||||
val = bone
|
||||
break
|
||||
end
|
||||
else
|
||||
print(part.ClassName, key, t)
|
||||
val = pac.Hash()
|
||||
end
|
||||
else
|
||||
print(part, key)
|
||||
end
|
||||
end
|
||||
|
||||
log(part.ClassName .. ".Set" .. key .. " = " .. tostring(val))
|
||||
part["Set" .. key](part, val)
|
||||
end
|
||||
yield()
|
||||
test.SetTestTimeout(1)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
76
lua/pac3/core/client/tests/size_modifier.lua
Normal file
76
lua/pac3/core/client/tests/size_modifier.lua
Normal file
@@ -0,0 +1,76 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local function equal(a,b, msg, level)
|
||||
level = level or 0
|
||||
if a ~= b then
|
||||
error(tostring(a) .. " != " .. tostring(b) .. ": " .. msg, 2 + level)
|
||||
end
|
||||
end
|
||||
|
||||
local function check_shared(owner, what, expect)
|
||||
equal(test.RunLuaOnServer("return Entity(" .. owner:EntIndex() .. "):"..what.."()"), expect, " server mismatch with client", 1)
|
||||
end
|
||||
|
||||
function test.Run(done)
|
||||
local owner = pac.LocalPlayer
|
||||
|
||||
for _, class in ipairs({"entity", "entity2"}) do
|
||||
local root = pac.CreatePart("group")
|
||||
local entity = root:CreatePart(class)
|
||||
|
||||
entity:SetSize(0.5)
|
||||
|
||||
-- the owner is not valid right away, when the owner is valid, the changes are applied
|
||||
repeat yield() until entity:GetOwner():IsValid()
|
||||
|
||||
equal(owner:GetModelScale(), 0.5, "after :SetSize")
|
||||
root:Remove()
|
||||
equal(owner:GetModelScale(), 1, "should revert after root is removed")
|
||||
end
|
||||
|
||||
check_shared(owner, "GetCurrentViewOffset", Vector(0,0,64))
|
||||
|
||||
RunConsoleCommand("pac_modifier_size", "1")
|
||||
repeat yield() until GetConVar("pac_modifier_size"):GetBool()
|
||||
|
||||
pac.emut.MutateEntity(owner, "size", owner, 0.5)
|
||||
repeat yield() until owner:GetModelScale() == 0.5
|
||||
|
||||
check_shared(owner, "GetCurrentViewOffset", Vector(0,0,32))
|
||||
|
||||
equal(test.RunLuaOnServer("return Entity(" .. owner:EntIndex() .. "):GetModelScale()"), 0.5, " server mismatch with client")
|
||||
|
||||
pac.emut.MutateEntity(owner, "size", owner, 1)
|
||||
|
||||
repeat yield() until owner:GetModelScale() == 1
|
||||
check_shared(owner, "GetCurrentViewOffset", Vector(0,0,64))
|
||||
|
||||
RunConsoleCommand("pac_modifier_size", "0")
|
||||
repeat yield() until not GetConVar("pac_modifier_size"):GetBool()
|
||||
|
||||
pac.emut.MutateEntity(owner, "size", owner, 2)
|
||||
|
||||
repeat yield() until owner:GetModelScale() == 1
|
||||
check_shared(owner, "GetCurrentViewOffset", Vector(0,0,64))
|
||||
|
||||
pac.emut.RestoreMutations(owner, "size", owner)
|
||||
|
||||
RunConsoleCommand("pac_modifier_size", "1")
|
||||
repeat yield() until GetConVar("pac_modifier_size"):GetBool()
|
||||
|
||||
repeat yield() until owner:GetModelScale() == 1
|
||||
|
||||
check_shared(owner, "GetCurrentViewOffset", Vector(0,0,64))
|
||||
check_shared(owner, "GetViewOffsetDucked", Vector(0,0,28))
|
||||
check_shared(owner, "GetStepSize", 18)
|
||||
|
||||
done()
|
||||
end
|
||||
46
lua/pac3/core/client/tests/smoke.lua
Normal file
46
lua/pac3/core/client/tests/smoke.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
function test.Run(done)
|
||||
local function find_part_in_entities(part)
|
||||
for k,v in pairs(ents.GetAll()) do
|
||||
if v.PACPart == part then
|
||||
return v.PACPart
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, part in pairs(pac.GetLocalParts()) do
|
||||
part:Remove()
|
||||
end
|
||||
|
||||
assert(table.Count(pac.GetLocalParts()) == 0)
|
||||
|
||||
local part = pac.CreatePart("group")
|
||||
local model = part:CreatePart("model")
|
||||
assert(table.Count(pac.GetLocalParts()) == 2)
|
||||
|
||||
model:SetModel("models/props_combine/breenchair.mdl")
|
||||
|
||||
assert(find_part_in_entities(model) == model)
|
||||
|
||||
assert(model:GetOwner():GetModel() == model:GetOwner():GetModel())
|
||||
|
||||
model:Remove()
|
||||
|
||||
assert(table.Count(pac.GetLocalParts()) == 1)
|
||||
|
||||
part:Remove()
|
||||
|
||||
assert(table.Count(pac.GetLocalParts()) == 0)
|
||||
|
||||
done()
|
||||
end
|
||||
Reference in New Issue
Block a user