hate-no-d/tests/cases/02_explicit.lua
pedro-bento 449be4c4b7
Some checks failed
release / linux/x86_64 (pull_request) Failing after 1m54s
release / freebsd/x86_64 (pull_request) Successful in 5m1s
release / linux/aarch64 (pull_request) Failing after 1m54s
release / linux/armv7 (pull_request) Failing after 2m12s
release / linux/i686 (pull_request) Failing after 1m59s
release / android (pull_request) Successful in 2m54s
release / windows/i686 (pull_request) Successful in 2m3s
release / windows/x86_64 (pull_request) Successful in 2m15s
probe
2026-10-24 22:20:01 +01:00

35 lines
1.1 KiB
Lua

-- 02: explicit UnloadImage is immediate, idempotent, and does not double-free
-- when the object is later collected.
local M = dofile("tests/helpers.lua")
local R = M.load()
M.reset()
local b = M.snapshot()
local img = R.GenImageColor(4, 4, R.RED)
M.ok(img.data ~= nil, "image data allocated")
M.eq(M.delta(b, "armed"), 1, "image armed")
R.UnloadImage(img)
M.eq(M.delta(b, "released"), 1, "explicit unload released exactly once")
M.eq(img.data, nil, "img.data nil after unload")
M.eq(img.width, 0, "img.width zero after unload")
M.eq(img.height, 0, "img.height zero after unload")
-- Calling it again is a no-op.
R.UnloadImage(img)
M.eq(M.delta(b, "released"), 1, "second explicit unload is a no-op")
-- Dropping the disarmed object must not release it a second time.
img = nil
M.gc(3)
M.eq(M.delta(b, "released"), 1, "GC after explicit unload is a no-op")
-- A plain GC-collected image releases exactly once.
local img2 = R.GenImageColor(4, 4, R.RED)
img2 = nil
M.gc(3)
M.eq(M.delta(b, "released"), 2, "GC released the second image exactly once")
M.eq(M.delta(b, "errors"), 0, "no finalizer errors")
print("ok 02_explicit")