Skip to content

Commit

Permalink
No good TestRunner framework anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugh Sanderson committed Dec 4, 2020
1 parent e16306c commit 6f874c4
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 38 deletions.
2 changes: 1 addition & 1 deletion tests/RunAll.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 14 additions & 7 deletions tests/haxe/TestMain.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
63 changes: 44 additions & 19 deletions tests/haxe/nme/display/TestBitmapDataCopyChannel.hx
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -21,52 +46,52 @@ 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() {
source = new BitmapData(2,2,true,0xFFFFFFFF);
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() {
source = new BitmapData(2,2,true,0xFFFFFFFF);
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() {
source = new BitmapData(2,2,true,0xFFFFFFFF);
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 {
source = new BitmapData(2,2,true,0xFFFFFFFF);
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 {
source = new BitmapData(10,10,true,0xFFFFFFFF);
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 {
Expand All @@ -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 {
Expand Down
37 changes: 26 additions & 11 deletions tests/haxe/nme/display/TestTilesheet.hx
Original file line number Diff line number Diff line change
@@ -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 );
Expand All @@ -15,25 +15,40 @@ 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()
{
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();
}
}

0 comments on commit 6f874c4

Please sign in to comment.