mirror of
https://github.com/bryanthaboi/gen1recomp
synced 2026-09-26 13:33:27 -04:00
a9ce423bdc
CLOSES #1275, CLOSES #1295, CLOSES #1384, CLOSES #1628, CLOSES #1677, CLOSES #1682, CLOSES #1691, CLOSES #1813, CLOSES #1822, CLOSES #1861, CLOSES #1867, CLOSES #1868, CLOSES #1869, CLOSES #1870, CLOSES #1871, CLOSES #1872, CLOSES #1874, CLOSES #1876, CLOSES #1878, CLOSES #1880, CLOSES #1881, CLOSES #1882, CLOSES #1884, CLOSES #1885, CLOSES #1886, CLOSES #1887, CLOSES #1888, CLOSES #1889, CLOSES #1890, CLOSES #1891, CLOSES #1892, CLOSES #1893, CLOSES #1894, CLOSES #1895, CLOSES #1896, CLOSES #1899, CLOSES #1900, CLOSES #1901
94 lines
3.4 KiB
Lua
94 lines
3.4 KiB
Lua
package.path = "./?.lua;./?/init.lua;" .. package.path
|
|
|
|
local T = require("tests.harness")
|
|
local check, eq = T.check, T.eq
|
|
love = love or require("tests.love_stub")
|
|
|
|
love.graphics.setLineJoin = love.graphics.setLineJoin or function() end
|
|
love.graphics.newShader = love.graphics.newShader or function() return {} end
|
|
love.graphics.polygon = love.graphics.polygon or function() end
|
|
|
|
local Kit = require("src.ui.kit.Kit")
|
|
local Platform = require("src.core.Platform")
|
|
local HostShell = require("src.core.HostShell")
|
|
local FilePicker = require("src.core.FilePicker")
|
|
local RomImporter = require("src.import.RomImporter")
|
|
local LauncherView = require("src.import.LauncherView")
|
|
|
|
love.graphics.getDimensions = function() return 1280, 720 end
|
|
love.graphics.getPixelDimensions = function() return 1280, 720 end
|
|
|
|
local pumped = 0
|
|
local realPump = HostShell.pumpHostEvents
|
|
HostShell.pumpHostEvents = function() pumped = pumped + 1 end
|
|
|
|
local realPopen, realPclose = HostShell.popen, HostShell.pclose
|
|
HostShell.popen = function()
|
|
return { read = function() return "" end, close = function() end }
|
|
end
|
|
HostShell.pclose = function() end
|
|
|
|
local realCanSpawn = Platform.canSpawnProcess
|
|
Platform.canSpawnProcess = function() return true end
|
|
local realGetOS = love.system.getOS
|
|
love.system.getOS = function() return "OS X" end
|
|
|
|
local cancelled = FilePicker.open("Choose a cart", { label = "Cart",
|
|
exts = { "g1rcart" } })
|
|
eq(cancelled, nil, "empty chooser output reads as a cancel")
|
|
eq(pumped, 1, "the chooser's button-up is pumped once the read unblocks")
|
|
|
|
HostShell.popen, HostShell.pclose = realPopen, realPclose
|
|
HostShell.pumpHostEvents = realPump
|
|
love.system.getOS = realGetOS
|
|
|
|
local realOpen = FilePicker.open
|
|
FilePicker.open = function() return nil end
|
|
|
|
local imp = RomImporter.new(function() end, { launcher = true })
|
|
imp.tab = "red"
|
|
imp.ready = { red = true, blue = true }
|
|
imp._cartPopup = "red"
|
|
|
|
love.mouse.isDown = function() return false end
|
|
imp._prevMouseDown = true
|
|
imp._mouseAt = { x = 10, y = 10 }
|
|
imp._clickPt = { x = 10, y = 10 }
|
|
|
|
eq(imp:importCartFile("red"), false, "a cancelled cart import commits nothing")
|
|
eq(imp._cartPopup, "red", "Custom Carts stays open after a cancel")
|
|
eq(imp._cartNotice, nil, "a cancel is not an error worth a notice")
|
|
eq(imp._mouseAt, nil, "the armed drag is dropped when the dialog returns")
|
|
eq(imp._clickPt, nil, "no stale click survives the dialog")
|
|
eq(imp._prevMouseDown, false,
|
|
"the polled click machine resyncs to the real button state")
|
|
|
|
local ok, err = pcall(LauncherView.draw, imp)
|
|
check(ok, "Custom Carts draws after the cancel: " .. tostring(err))
|
|
|
|
local close = nil
|
|
for i = 1, (Kit._navPrevN or 0) do
|
|
local slot = Kit._nav[i]
|
|
if slot and slot.id == "cartpop-close" then close = slot end
|
|
end
|
|
check(close ~= nil, "the Close control is in the modal's nav graph")
|
|
|
|
if close then
|
|
LauncherView.clickAt(imp, close.x + close.w / 2, close.y + close.h / 2)
|
|
ok, err = pcall(LauncherView.draw, imp)
|
|
check(ok, "the click frame draws: " .. tostring(err))
|
|
LauncherView.update(imp, 1 / 60)
|
|
eq(imp._cartPopup, nil, "Close still closes Custom Carts after a cancel")
|
|
end
|
|
|
|
FilePicker.open = realOpen
|
|
Platform.canSpawnProcess = realCanSpawn
|
|
|
|
local src = io.open("src/core/FilePicker.lua", "r"):read("*a")
|
|
check(not src:match("io%.popen%("),
|
|
"FilePicker never reaches io.popen directly")
|
|
check(src:match("HostShell%.pumpHostEvents"),
|
|
"FilePicker's blocking read pumps host events afterwards")
|
|
|
|
print("ok cart import cancel keeps the modal live")
|