Skip to content

Commit

Permalink
BitmapDataTest: A little more lenience (Canvas reads are somewhat ran…
Browse files Browse the repository at this point in the history
…domized in certain browsers)
  • Loading branch information
joshtynjala committed Sep 10, 2024
1 parent 3f3a47b commit 93b19fc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
24 changes: 12 additions & 12 deletions test/es6/openfl/display/BitmapDataTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,10 @@ describe ("ES6 | BitmapData", function () {

for (i = 0; i < TEST_WIDTH * TEST_HEIGHT; i++) {
pixel = pixels.readInt();
assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 2);
}

// Now run the same test again to make sure the source
Expand All @@ -768,10 +768,10 @@ describe ("ES6 | BitmapData", function () {
pixels.position = 0;
for (i = 0; i < TEST_WIDTH * TEST_HEIGHT; i++) {
pixel = pixels.readInt();
assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 2);
}

bitmapData = new BitmapData (TEST_WIDTH, TEST_HEIGHT, destAlpha);
Expand All @@ -785,10 +785,10 @@ describe ("ES6 | BitmapData", function () {
expectedColor |= 0xFF000000;
}

assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 2);
}

// There are 6 combinations with an ARGB source that all must be tested:
Expand Down
34 changes: 22 additions & 12 deletions test/haxe/openfl/display/BitmapDataTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,20 @@ class BitmapDataTest
for (i in 0...Std.int(TEST_WIDTH * TEST_HEIGHT))
{
pixel = pixels.readInt();
Assert.assert(Math.abs(((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 1);
Assert.assert(Math.abs(((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 1);
Assert.assert(Math.abs(((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 1);
Assert.assert(Math.abs(((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 1);
if (Math.abs(((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) > 1
|| Math.abs(((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) > 1
|| Math.abs(((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) > 1
|| Math.abs(((expectedColor) & 0xFF) - ((pixel) & 0xFF)) > 1) {
trace(StringTools.hex(expectedColor), StringTools.hex(pixel));
trace(StringTools.hex((expectedColor >> 24) & 0xFF), StringTools.hex((pixel >> 24) & 0xFF));
trace(StringTools.hex((expectedColor >> 16) & 0xFF), StringTools.hex((pixel >> 16) & 0xFF));
trace(StringTools.hex((expectedColor >> 8) & 0xFF), StringTools.hex((pixel >> 8) & 0xFF));
trace(StringTools.hex((expectedColor) & 0xFF),StringTools.hex ((pixel) & 0xFF));
}
Assert.assert(Math.abs(((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 2);
Assert.assert(Math.abs(((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 2);
Assert.assert(Math.abs(((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 2);
Assert.assert(Math.abs(((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 2);
}

// Now run the same test again to make sure the source
Expand All @@ -683,10 +693,10 @@ class BitmapDataTest
for (i in 0...Std.int(TEST_WIDTH * TEST_HEIGHT))
{
pixel = pixels.readInt();
Assert.assert(Math.abs(((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 1);
Assert.assert(Math.abs(((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 1);
Assert.assert(Math.abs(((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 1);
Assert.assert(Math.abs(((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 1);
Assert.assert(Math.abs(((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 2);
Assert.assert(Math.abs(((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 2);
Assert.assert(Math.abs(((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 2);
Assert.assert(Math.abs(((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 2);
}

bitmapData = new BitmapData(TEST_WIDTH, TEST_HEIGHT, destAlpha);
Expand All @@ -701,10 +711,10 @@ class BitmapDataTest
expectedColor |= 0xFF000000;
}

Assert.assert(Math.abs(((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 1);
Assert.assert(Math.abs(((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 1);
Assert.assert(Math.abs(((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 1);
Assert.assert(Math.abs(((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 1);
Assert.assert(Math.abs(((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 2);
Assert.assert(Math.abs(((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 2);
Assert.assert(Math.abs(((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 2);
Assert.assert(Math.abs(((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 2);
}

// There are 6 combinations with an ARGB source that all must be tested:
Expand Down
24 changes: 12 additions & 12 deletions test/typescript/openfl/display/BitmapDataTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,10 @@ describe ("TypeScript | BitmapData", function () {

for (i = 0; i < TEST_WIDTH * TEST_HEIGHT; i++) {
pixel = pixels.readInt();
assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 2);
}

// Now run the same test again to make sure the source
Expand All @@ -768,10 +768,10 @@ describe ("TypeScript | BitmapData", function () {
pixels.position = 0;
for (i = 0; i < TEST_WIDTH * TEST_HEIGHT; i++) {
pixel = pixels.readInt();
assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 2);
}

bitmapData = new BitmapData (TEST_WIDTH, TEST_HEIGHT, destAlpha);
Expand All @@ -785,10 +785,10 @@ describe ("TypeScript | BitmapData", function () {
expectedColor |= 0xFF000000;
}

assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 1);
assert (Math.abs (((expectedColor >> 24) & 0xFF) - ((pixel >> 24) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 16) & 0xFF) - ((pixel >> 16) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor >> 8) & 0xFF) - ((pixel >> 8) & 0xFF)) <= 2);
assert (Math.abs (((expectedColor) & 0xFF) - ((pixel) & 0xFF)) <= 2);
}

// There are 6 combinations with an ARGB source that all must be tested:
Expand Down

0 comments on commit 93b19fc

Please sign in to comment.