-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #92 - I carefully checked the output and it looks good, so this is more of a regression test than anything else
- Loading branch information
1 parent
7ebaff7
commit 6d3299a
Showing
9 changed files
with
603 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { describe, it } from "vitest"; | ||
import { TestMachine } from "../test-machine.js"; | ||
import assert from "assert"; | ||
import { Video } from "../../video.js"; | ||
import sharp from "sharp"; | ||
import pixelmatch from "pixelmatch"; | ||
|
||
class CapturingVideo extends Video { | ||
constructor() { | ||
super(false, new Uint32Array(1024 * 1024), () => {}); | ||
this.paint_ext = (left, top, right, bottom) => this._onPaint(left, top, right, bottom); | ||
this._capturing = false; | ||
this._captureSharp = null; | ||
} | ||
|
||
_onPaint(left, top, right, bottom) { | ||
if (this._capturing) { | ||
const width = right - left; | ||
const height = bottom - top; | ||
const bufferCopy = new Uint8Array(this.fb32.buffer.slice(0)); | ||
this._captureSharp = sharp(bufferCopy, { | ||
raw: { width: 1024, height: 1024, channels: 4 }, | ||
}).extract({ left: left, top: top, width, height }); | ||
this._capturing = false; | ||
} | ||
} | ||
|
||
async capture(testMachine) { | ||
this._capturing = true; | ||
await testMachine.runUntilVblank(); | ||
if (this._capturing) throw new Error("Should have captured by now"); | ||
return this._captureSharp; | ||
} | ||
} | ||
|
||
async function setupTestMachine(video) { | ||
const testMachine = new TestMachine(null, { video: video }); | ||
await testMachine.initialise(); | ||
await testMachine.runUntilInput(); | ||
await testMachine.loadDisc("discs/eng_test.ssd"); | ||
await testMachine.type("*EXEC !BOOT"); | ||
await testMachine.runFor(3 * 1000 * 1000); | ||
return testMachine; | ||
} | ||
|
||
const rootDir = "tests/integration/ceefax"; | ||
const outputDir = `tests/integration/output`; | ||
|
||
async function compare(video, testMachine, expectedName) { | ||
const outputName = `${expectedName.replace("expected", "actual")}`; | ||
const captureSharp = await video.capture(testMachine); | ||
const outputFile = `${outputDir}/${outputName}`; | ||
await captureSharp.removeAlpha().toFile(outputFile); | ||
const expectedFile = `${rootDir}/${expectedName}`; | ||
const diffFile = `${outputDir}/${outputName.replace(".png", ".diff.png")}`; | ||
|
||
const { data: expectedData, info } = await sharp(expectedFile) | ||
.ensureAlpha() | ||
.raw() | ||
.toBuffer({ resolveWithObject: true }); | ||
const actualData = await sharp(outputFile).ensureAlpha().raw().toBuffer(); | ||
const diffData = new Uint8Array(info.width * info.height * info.channels); | ||
|
||
const numDiffPixels = pixelmatch(expectedData, actualData, diffData, info.width, info.height, { | ||
threshold: 0.1, | ||
}); | ||
await sharp(diffData, { raw: info }).removeAlpha().toFile(diffFile); | ||
assert.equal( | ||
numDiffPixels, | ||
0, | ||
`Images do not match - expected ${expectedFile}, got ${outputFile}, diffs: ${diffFile}}`, | ||
); | ||
} | ||
|
||
describe("Test Ceefax test page", () => { | ||
it("should match the Ceefax test page (no flash)", async () => { | ||
const video = new CapturingVideo(); | ||
const testMachine = await setupTestMachine(video); | ||
await compare(video, testMachine, `expected_flash_0.png`); | ||
}); | ||
it("should match the Ceefax test page (flash)", async () => { | ||
const video = new CapturingVideo(); | ||
const testMachine = await setupTestMachine(video); | ||
await testMachine.runFor(1500000); | ||
await compare(video, testMachine, `expected_flash_1.png`); | ||
}); | ||
it("should match the Ceefax test page after reveal (no flash)", async () => { | ||
const video = new CapturingVideo(); | ||
const testMachine = await setupTestMachine(video); | ||
await testMachine.type(" "); | ||
await compare(video, testMachine, `expected_reveal_flash_0.png`); | ||
}); | ||
it("should match the Ceefax test page after reveal (flash)", async () => { | ||
const video = new CapturingVideo(); | ||
const testMachine = await setupTestMachine(video); | ||
await testMachine.type(" "); | ||
await testMachine.runFor(1500000); | ||
await compare(video, testMachine, `expected_reveal_flash_1.png`); | ||
}); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters