Skip to content

Commit 0166535

Browse files
Tests: Add helpers for qualifying type of repaint
Assuming the screen has been splatted via "DHRDarkness", computing the amount restored by a subsequent repaint is possible, and this can remove the burden of manually assessing the change.
1 parent 448bff5 commit 0166535

File tree

7 files changed

+105
-43
lines changed

7 files changed

+105
-43
lines changed

tests/date_and_time.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ test.Step(
1515
a2d.OAShortcut("2") -- 24-hour
1616
apple2.DHRDarkness()
1717
a2d.DialogOK()
18-
test.Snap("verify full repaint and 24-hour format")
18+
test.ExpectEquals(a2d.RepaintType(), "full", "repaint", {snap=true})
19+
test.Snap("verify 24-hour format shown")
1920
a2d.CloseAllWindows()
2021
a2d.InvokeMenuItem(a2d.STARTUP_MENU, 1) -- slot 7
2122
a2d.WaitForRestart()
@@ -88,11 +89,12 @@ test.Step(
8889
test.Snap("verify dialog date matches packaged file dates")
8990
apple2.DHRDarkness()
9091
a2d.DialogOK()
91-
test.Snap("verify full repaint and dates now Today")
92+
test.ExpectEquals(a2d.RepaintType(), "full", "repaint", {snap=true})
93+
test.Snap("verify dates now Today")
9294
a2d.SelectAndOpen("DATE.AND.TIME")
9395
apple2.DHRDarkness()
9496
a2d.DialogOK()
95-
test.Snap("verify no full repaint")
97+
test.ExpectEquals(a2d.RepaintType(), "minimal", "repaint", {snap=true})
9698
a2d.InvokeMenuItem(a2d.STARTUP_MENU, 1) -- slot 7
9799
a2d.WaitForRestart()
98100
end)
@@ -337,5 +339,6 @@ test.Step(
337339
apple2.UpArrowKey()
338340
apple2.DHRDarkness()
339341
a2d.DialogOK()
340-
test.Snap("verify full repaint and Today date")
342+
test.ExpectEquals(a2d.RepaintType(), "full", "repaint", {snap=true})
343+
test.Snap("verify bottom date shows Today")
341344
end)

tests/desk_accessories.lua

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test.Step(
88
a2d.CloseWindow()
99
end)
1010

11-
function MoveDoesntRepaintTest(name, path, x, y)
11+
function MoveDoesntRepaintTest(name, path, x, y, opt_threshold)
1212
test.Step(
1313
name .. " doesn't repaint on non-move",
1414
function()
@@ -21,10 +21,16 @@ function MoveDoesntRepaintTest(name, path, x, y)
2121
emu.wait(2/60)
2222
m.ButtonDown()
2323
emu.wait(10/60)
24-
test.Snap("verify drag highlight")
2524
m.ButtonUp()
2625
end)
27-
test.Snap("verify no repaint")
26+
27+
if opt_threshold then
28+
-- Needed for Joystick, as MouseKeys tickles the buttons
29+
-- Needed for Bounce as the animation continues
30+
test.ExpectLessThan(a2d.RepaintFraction(), opt_threshold, "repaint")
31+
else
32+
test.ExpectEquals(a2d.RepaintType(), "none", "repaint", {snap=true})
33+
end
2834
a2d.CloseWindow()
2935
a2d.CloseAllWindows()
3036
a2d.InvokeMenuItem(a2d.STARTUP_MENU, 1) -- restart
@@ -36,11 +42,11 @@ MoveDoesntRepaintTest("Calculator", "/A2.DESKTOP/APPLE.MENU/CALCULATOR", 280, 55
3642
MoveDoesntRepaintTest("Calendar", "/A2.DESKTOP/APPLE.MENU/CALENDAR", 280, 40)
3743
MoveDoesntRepaintTest("Key Caps", "/A2.DESKTOP/APPLE.MENU/KEY.CAPS", 280, 50)
3844
MoveDoesntRepaintTest("Control Panel", "/A2.DESKTOP/APPLE.MENU/CONTROL.PANELS/CONTROL.PANEL", 280, 30)
39-
MoveDoesntRepaintTest("Joystick", "/A2.DESKTOP/APPLE.MENU/CONTROL.PANELS/JOYSTICK", 280, 50)
45+
MoveDoesntRepaintTest("Joystick", "/A2.DESKTOP/APPLE.MENU/CONTROL.PANELS/JOYSTICK", 280, 50, 0.02)
4046
MoveDoesntRepaintTest("Map", "/A2.DESKTOP/APPLE.MENU/CONTROL.PANELS/MAP", 280, 40)
4147
MoveDoesntRepaintTest("Options", "/A2.DESKTOP/APPLE.MENU/CONTROL.PANELS/OPTIONS", 280, 45)
4248
MoveDoesntRepaintTest("Views", "/A2.DESKTOP/APPLE.MENU/CONTROL.PANELS/VIEWS", 280, 50)
43-
MoveDoesntRepaintTest("Bounce", "/A2.DESKTOP/APPLE.MENU/TOYS/BOUNCE", 280, 45)
49+
MoveDoesntRepaintTest("Bounce", "/A2.DESKTOP/APPLE.MENU/TOYS/BOUNCE", 280, 45, 0.05)
4450
MoveDoesntRepaintTest("Eyes", "/A2.DESKTOP/APPLE.MENU/TOYS/EYES", 280, 60)
4551
MoveDoesntRepaintTest("Lights Out", "/A2.DESKTOP/APPLE.MENU/TOYS/LIGHTS.OUT", 280, 60)
4652
MoveDoesntRepaintTest("Neko", "/A2.DESKTOP/APPLE.MENU/TOYS/NEKO", 280, 50)

tests/international.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ test.Step(
1717
a2d.OAShortcut("2") -- D/M/Y
1818
apple2.DHRDarkness()
1919
a2d.DialogOK()
20-
21-
test.Snap("Verify full repaint and D/M/Y format")
20+
test.ExpectEquals(a2d.RepaintType(), "full", "repaint", {snap=true})
21+
test.Snap("verify D/M/Y format")
2222
end)
2323

2424
test.Step(
@@ -30,6 +30,5 @@ test.Step(
3030
-- don't change anything
3131
apple2.DHRDarkness()
3232
a2d.DialogOK()
33-
34-
test.Snap("Verify minimal repaint")
33+
test.ExpectEquals(a2d.RepaintType(), "minimal", "repaint", {snap=true})
3534
end)

tests/lib/a2d.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,5 +549,31 @@ end
549549

550550
--------------------------------------------------
551551

552+
function a2d.RepaintFraction()
553+
local count = 0
554+
for row = 0,191 do
555+
for col = 0,79 do
556+
if not apple2.ValidateDHRDarkness(row, col) then
557+
count = count + 1
558+
end
559+
end
560+
end
561+
return count / (192*80)
562+
end
563+
564+
-- Heuristic-based
565+
function a2d.RepaintType()
566+
local fraction = a2d.RepaintFraction()
567+
if fraction > 0.90 then
568+
return "full"
569+
elseif fraction < 0.01 then
570+
return "none"
571+
else
572+
return "minimal"
573+
end
574+
end
575+
576+
--------------------------------------------------
577+
552578

553579
return a2d

tests/lib/apple2.lua

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -759,16 +759,25 @@ end
759759
-- Misc Utilities
760760
--------------------------------------------------
761761

762-
function apple2.GetDoubleHiresByte(row, col)
762+
function GetDHRByteAddress(row, col)
763763
local bank = col % 2
764764
col = col >> 1
765765
local aa = (row & 0xC0) >> 6
766766
local bbb = (row & 0x38) >> 3
767767
local ccc = (row & 0x07)
768-
local addr = 0x2000 + (aa * 0x28) + (bbb * 0x80) + (ccc * 0x400) + col
768+
return bank, 0x2000 + (aa * 0x28) + (bbb * 0x80) + (ccc * 0x400) + col
769+
end
770+
771+
function apple2.GetDoubleHiresByte(row, col)
772+
local bank, addr = GetDHRByteAddress(row, col)
769773
return apple2.ReadRAMDevice(addr + 0x10000 * (1-bank))
770774
end
771775

776+
function apple2.SetDoubleHiresByte(row, col, value)
777+
local bank, addr = GetDHRByteAddress(row, col)
778+
apple2.WriteRAMDevice(addr + 0x10000 * (1-bank), value)
779+
end
780+
772781
function apple2.GrabTextScreen()
773782
local is80 = apple2.ReadSSW("RD80VID") > 127
774783
local screen = ""
@@ -791,30 +800,28 @@ end
791800

792801
--------------------------------------------------
793802

794-
function apple2.DHRDarkness()
795-
function SetDHRByte(col, row, value)
796-
local bank = col % 2
797-
col = col >> 1
798-
local aa = (row & 0xC0) >> 6
799-
local bbb = (row & 0x38) >> 3
800-
local ccc = (row & 0x07)
801-
local addr = 0x2000 + (aa * 0x28) + (bbb * 0x80) + (ccc * 0x400) + col
802-
apple2.WriteRAMDevice(addr + 0x10000 * (1-bank), value)
803-
end
804-
805-
local bytes = {
806-
{0x00, 0x00, 0x00, 0x00},
807-
{0x08, 0x11, 0x22, 0x44},
808-
{0x00, 0x00, 0x00, 0x00},
809-
{0x22, 0x44, 0x08, 0x11},
810-
}
803+
local darkness_bytes = {
804+
{0x00, 0x00, 0x00, 0x00},
805+
{0x08, 0x11, 0x22, 0x44},
806+
{0x00, 0x00, 0x00, 0x00},
807+
{0x22, 0x44, 0x08, 0x11},
808+
}
811809

810+
function apple2.DHRDarkness()
812811
for row = 0,191 do
813812
for col = 0,79 do
814-
SetDHRByte(col, row, bytes[row % 4 + 1][col % 4 + 1])
813+
local byte = darkness_bytes[row % 4 + 1][col % 4 + 1]
814+
apple2.SetDoubleHiresByte(row, col, byte)
815815
end
816816
end
817817
end
818+
819+
-- Expect apple2.DHRDarkness() was previously called
820+
function apple2.ValidateDHRDarkness(row, col)
821+
local expected = darkness_bytes[row % 4 + 1][col % 4 + 1]
822+
return apple2.GetDoubleHiresByte(row, col) == expected
823+
end
824+
818825
--------------------------------------------------
819826

820827
return apple2

tests/lib/test.lua

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ function test.Failure(message)
6161
os.exit(1)
6262
end
6363

64+
--------------------------------------------------
65+
-- Snapshots
66+
--------------------------------------------------
67+
6468
function test.Snap(opt_title)
6569
snap(opt_title)
6670
end
@@ -72,26 +76,43 @@ function test.MultiSnap(frames, opt_title)
7276
end
7377
end
7478

75-
function test.Expect(expr, message)
79+
--------------------------------------------------
80+
-- Expectations
81+
--------------------------------------------------
82+
83+
function test.Expect(expr, message, options)
7684
if not expr then
85+
if options and options.snap then
86+
test.Snap("FAILURE - " .. message)
87+
end
7788
error("Expectation failure: " .. message)
7889
end
7990
end
8091

81-
function test.ExpectEquals(actual, expected, message)
82-
test.Expect(actual == expected, message .. " - " .. actual .. " should equal " .. expected)
92+
function format(value)
93+
if type(value) == "string" then
94+
return string.format("%q", value)
95+
elseif type(value) == "boolean" then
96+
return value and "true" or "false"
97+
else
98+
return value
99+
end
100+
end
101+
102+
function test.ExpectEquals(actual, expected, message, options)
103+
test.Expect(actual == expected, message .. " - actual " .. format(actual) .. " should equal " .. format(expected), options)
83104
end
84105

85-
function test.ExpectNotEquals(actual, expected, message)
86-
test.Expect(actual ~= expected, message .. " - " .. actual .. " should not equal " .. expected)
106+
function test.ExpectNotEquals(actual, expected, message, options)
107+
test.Expect(actual ~= expected, message .. " - actual " .. format(actual) .. " should not equal " .. format(expected), options)
87108
end
88109

89-
function test.ExpectLessThan(a, b, message)
90-
test.Expect(a < b, message .. " - " .. a .. " should be < " .. b)
110+
function test.ExpectLessThan(a, b, message, options)
111+
test.Expect(a < b, message .. " - actual " .. format(a) .. " should be < " .. format(b), options)
91112
end
92113

93-
function test.ExpectLessThanOrEqual(a, b, message)
94-
test.Expect(a <= b, message .. " - " .. a .. " should be <= " .. b)
114+
function test.ExpectLessThanOrEqual(a, b, message, options)
115+
test.Expect(a <= b, message .. " - actual " .. format(a) .. " should be <= " .. format(b), options)
95116
end
96117

97118
--------------------------------------------------

tests/text_preview.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ test.Step(
153153
test.Snap("verify thumb highlighted")
154154
m.ButtonUp()
155155
a2d.WaitForRepaint()
156-
test.Snap("verify no repaint")
156+
test.Expect(a2d.RepaintType(), "none", {snap=true})
157157
end)
158158
a2d.CloseWindow()
159159
a2d.InvokeMenuItem(a2d.STARTUP_MENU, 1) -- reboot

0 commit comments

Comments
 (0)