From 6f874c47c28e0683edb3aa9215a8152297d6e4b9 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Fri, 4 Dec 2020 22:56:33 +0800 Subject: [PATCH] No good TestRunner framework anymore --- tests/RunAll.hx | 2 +- tests/haxe/TestMain.hx | 21 ++++--- .../nme/display/TestBitmapDataCopyChannel.hx | 63 +++++++++++++------ tests/haxe/nme/display/TestTilesheet.hx | 37 +++++++---- 4 files changed, 85 insertions(+), 38 deletions(-) diff --git a/tests/RunAll.hx b/tests/RunAll.hx index 0a1aeecad..8b2a8fbbc 100644 --- a/tests/RunAll.hx +++ b/tests/RunAll.hx @@ -25,7 +25,7 @@ class RunAll static function filter(inName:String):Bool { - return inName!="android" && inName!="native" && inName!="html5" && inName!="watchos" && inName!="SwfAssetLib.hx" && inName!="ios" && inName!="compat" && inName!="preloader" && inName!="store" && inName!="firebase"; + return inName!="android" && inName!="native" && inName!="html5" && inName!="watchos" && inName!="SwfAssetLib.hx" && inName!="ios" && inName!="compat" && inName!="preloader" && inName!="store" && inName!="firebase" && inName!="cppia" && inName!="script"; } public static function main() diff --git a/tests/haxe/TestMain.hx b/tests/haxe/TestMain.hx index c4d211a83..8f1df0507 100644 --- a/tests/haxe/TestMain.hx +++ b/tests/haxe/TestMain.hx @@ -7,15 +7,22 @@ import nme.StaticNme; class TestMain { - static function main(){ + static function main() + { //nme.display.BitmapData.defaultPremultiplied = false; - var r = new haxe.unit.TestRunner(); - r.add(new TestBitmapDataCopyChannel()); - r.add(new TestTilesheet()); - - var t0 = Timer.stamp(); - var success = r.run(); + var success = false; + var t0 = Timer.stamp(); + try + { + new TestTilesheet(); + new TestBitmapDataCopyChannel(); + success = true; + } + catch(e:Dynamic) + { + trace("Error:" + e); + } trace(" Time : " + (Timer.stamp()-t0)*1000 ); Sys.exit(success ? 0 : 1); } diff --git a/tests/haxe/nme/display/TestBitmapDataCopyChannel.hx b/tests/haxe/nme/display/TestBitmapDataCopyChannel.hx index 294f19a18..c6853def8 100644 --- a/tests/haxe/nme/display/TestBitmapDataCopyChannel.hx +++ b/tests/haxe/nme/display/TestBitmapDataCopyChannel.hx @@ -1,17 +1,42 @@ package nme.display; import nme.geom.Rectangle; import nme.geom.Point; -class TestBitmapDataCopyChannel extends haxe.unit.TestCase +class TestBitmapDataCopyChannel { var source:BitmapData; var destination:BitmapData; - override public function setup() + public function new() + { + setup(); + testX(); + testY(); + testTopLeftDestination(); + testTopLeftSource(); + testCopyToFarToRight(); + testDestinationOnRight_doesNotOverlapOnLeft(); + testSpamPastingOverlappingBottom_shouldNotExplode(); + testGreen(); + testBlue(); + testAlpha(); + + tearDown(); + } + + + function assertEquals(a:Dynamic,b:Dynamic,message:String) + { + if (a!=b) + throw(message); + Sys.println('$message .. ok'); + } + + public function setup() { nme.display.BitmapData.defaultPremultiplied = false; } - override public function tearDown() + public function tearDown() { nme.display.BitmapData.defaultPremultiplied = true; } @@ -21,7 +46,7 @@ class TestBitmapDataCopyChannel extends haxe.unit.TestCase destination = new BitmapData(2,2,true,0x00000000); var bounds:Rectangle = new Rectangle(0,1,1,1); destination.copyChannel(source, bounds, new Point(1,1), BitmapDataChannel.RED, BitmapDataChannel.RED); - assertEquals(0x00FF0000, destination.getPixel32(1,1)); + assertEquals(0x00FF0000, destination.getPixel32(1,1),"copy channel red"); } public function testY() { @@ -29,10 +54,10 @@ class TestBitmapDataCopyChannel extends haxe.unit.TestCase destination = new BitmapData(2,2,true,0x00000000); var bounds:Rectangle = new Rectangle(0,1,1,1); destination.copyChannel(source, bounds, new Point(), BitmapDataChannel.RED, BitmapDataChannel.RED); - assertEquals(0x00FF0000, destination.getPixel32(0,0)); - assertEquals(0x00000000, destination.getPixel32(0,1)); - assertEquals(0x00000000, destination.getPixel32(1,0)); - assertEquals(0x00000000, destination.getPixel32(1,1)); + assertEquals(0x00FF0000, destination.getPixel32(0,0),"copy channel 00"); + assertEquals(0x00000000, destination.getPixel32(0,1),"copy channel 01"); + assertEquals(0x00000000, destination.getPixel32(1,0),"copy channel 10"); + assertEquals(0x00000000, destination.getPixel32(1,1),"copy channel 11"); } public function testTopLeftDestination() { @@ -40,7 +65,7 @@ class TestBitmapDataCopyChannel extends haxe.unit.TestCase destination = new BitmapData(2,2,true,0x00000000); var bounds:Rectangle = new Rectangle(0,0,2,2); destination.copyChannel(source, bounds, new Point(-1,-1), BitmapDataChannel.RED, BitmapDataChannel.RED); - assertEquals(0x00FF0000, destination.getPixel32(0,0)); + assertEquals(0x00FF0000, destination.getPixel32(0,0),"top-left dest"); } public function testTopLeftSource() { @@ -48,7 +73,7 @@ class TestBitmapDataCopyChannel extends haxe.unit.TestCase destination = new BitmapData(2,2,true,0x00000000); var bounds:Rectangle = new Rectangle(-1,-1,2,2); destination.copyChannel(source, bounds, new Point(), BitmapDataChannel.RED, BitmapDataChannel.RED); - assertEquals(0x00FF0000, destination.getPixel32(0,0)); + assertEquals(0x00FF0000, destination.getPixel32(0,0),"top-left source"); } public function testCopyToFarToRight():Void { @@ -56,8 +81,8 @@ class TestBitmapDataCopyChannel extends haxe.unit.TestCase destination = new BitmapData(2,1,true,0x00000000); var bounds:Rectangle = new Rectangle(1,0,2,1); destination.copyChannel(source, bounds, new Point(), BitmapDataChannel.RED, BitmapDataChannel.RED); - assertEquals(0x00FF0000, destination.getPixel32(0,0)); - assertEquals(0x00000000, destination.getPixel32(1,0)); + assertEquals(0x00FF0000, destination.getPixel32(0,0),"copy right"); + assertEquals(0x00000000, destination.getPixel32(1,0),"copy right"); } public function testDestinationOnRight_doesNotOverlapOnLeft():Void { @@ -65,8 +90,8 @@ class TestBitmapDataCopyChannel extends haxe.unit.TestCase destination = new BitmapData(2,2,true,0x00000000); var bounds:Rectangle = new Rectangle(0,0,10,10); destination.copyChannel(source, bounds, new Point(1,0), BitmapDataChannel.RED, BitmapDataChannel.RED); - assertEquals(0x00000000, destination.getPixel32(0,0)); - assertEquals(0x00000000, destination.getPixel32(0,1)); + assertEquals(0x00000000, destination.getPixel32(0,0),"not overlap"); + assertEquals(0x00000000, destination.getPixel32(0,1),"not overlap"); } public function testSpamPastingOverlappingBottom_shouldNotExplode():Void { @@ -76,24 +101,24 @@ class TestBitmapDataCopyChannel extends haxe.unit.TestCase destination = new BitmapData(2,2,true,0x00000000); var bounds:Rectangle = new Rectangle(0,0, size, size); destination.copyChannel(source, bounds, new Point(0,1), BitmapDataChannel.RED, BitmapDataChannel.RED); - assertEquals(0x00000000, destination.getPixel32(0,0)); - assertEquals(0x00000000, destination.getPixel32(1,0)); } + assertEquals(0x00000000, destination.getPixel32(0,0),"paste ok"); + assertEquals(0x00000000, destination.getPixel32(1,0),"paste ok"); } public function testGreen():Void { copyChannel(BitmapDataChannel.GREEN); - assertEquals(0x0000CC00, destination.getPixel32(0,0)); + assertEquals(0x0000CC00, destination.getPixel32(0,0),"green pixel"); } public function testBlue():Void { copyChannel(BitmapDataChannel.BLUE); - assertEquals(0x000000DD, destination.getPixel32(0,0)); + assertEquals(0x000000DD, destination.getPixel32(0,0),"blue pixel"); } public function testAlpha():Void { copyChannel(BitmapDataChannel.ALPHA); - assertEquals(0xAA000000, destination.getPixel32(0,0)); + assertEquals(0xAA000000, destination.getPixel32(0,0),"alpha pixel"); } function copyChannel(channel:Int):Void { diff --git a/tests/haxe/nme/display/TestTilesheet.hx b/tests/haxe/nme/display/TestTilesheet.hx index 5329f279a..8c96c4b40 100644 --- a/tests/haxe/nme/display/TestTilesheet.hx +++ b/tests/haxe/nme/display/TestTilesheet.hx @@ -1,12 +1,12 @@ package nme.display; import nme.geom.Rectangle; -class TestTilesheet extends haxe.unit.TestCase +class TestTilesheet { var tilesheet:Tilesheet; - override public function setup() + public function setup() { var bd = new BitmapData(32,32,true,0xFFFFFFFF); tilesheet = new Tilesheet( bd ); @@ -15,10 +15,10 @@ class TestTilesheet extends haxe.unit.TestCase public function testGetTileRect() { var tileId:Int = tilesheet.addTileRect(new Rectangle (2, 4, 6, 8)); var rect:Rectangle = tilesheet.getTileRect( tileId ); - assertEquals(rect.x, 2); - assertEquals(rect.y, 4); - assertEquals(rect.width, 6); - assertEquals(rect.height, 8); + assertEquals(rect.x, 2, "rect x"); + assertEquals(rect.y, 4, "rect y"); + assertEquals(rect.width, 6, "rect w"); + assertEquals(rect.height, 8, "rect h"); } public function testGetTileRectNoNewAlloc() @@ -26,14 +26,29 @@ class TestTilesheet extends haxe.unit.TestCase var tileId:Int = tilesheet.addTileRect(new Rectangle (2, 4, 6, 8)); var rect:Rectangle = new Rectangle(0,0,10,10); var result = tilesheet.getTileRect( tileId, rect ); - assertEquals(rect, result); + assertEquals(rect, result,"NoNewAlloc"); } public function testGetTileRectOutOfBounds() { var rect1:Rectangle = tilesheet.getTileRect( -1 ); - assertEquals(rect1, null); - - var rect2:Rectangle = tilesheet.getTileRect( tilesheet.tileCount ); - assertEquals(rect2, null); + assertEquals(rect1, null,"Null rect"); + + var rect2:Rectangle = tilesheet.getTileRect( tilesheet.tileCount ); + assertEquals(rect2, null,"Null end-of-list"); + } + + function assertEquals(a:Dynamic,b:Dynamic,message:String) + { + if (a!=b) + throw(message); + Sys.println('$message .. ok'); + } + + public function new() + { + setup(); + testGetTileRect(); + testGetTileRectNoNewAlloc(); + testGetTileRectOutOfBounds(); } }