Skip to content

Commit

Permalink
Haxe3 fixes for smoke.jeash.com, a few browser.* and samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
andyli committed Mar 16, 2013
1 parent decd4b3 commit 803704b
Show file tree
Hide file tree
Showing 37 changed files with 122 additions and 94 deletions.
4 changes: 4 additions & 0 deletions browser/media/Video.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import browser.media.VideoElement;
import browser.net.NetStream;
import browser.Html5Dom;
import browser.Lib;
#if !haxe3
import js.Dom;
#else
import js.html.*;
#end


class Video extends DisplayObject {
Expand Down
2 changes: 1 addition & 1 deletion browser/net/NetStream.hx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class NetStream extends EventDispatcher {

super();

nmeVideoElement = cast js.Lib.document.createElement("video");
nmeVideoElement = cast #if !haxe3 js.Lib.document #else js.Browser.document #end .createElement("video");
nmeConnection = connection;

play = Reflect.makeVarArgs(nmePlay);
Expand Down
2 changes: 1 addition & 1 deletion samples/01-Simple/compile-swf.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-main Sample
-swf9 Sample.swf
-swf Sample.swf
-swf-header 320:480:60:ccccff
2 changes: 1 addition & 1 deletion samples/03-Bitmaps/flash.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-main Sample
-swf9 Sample.swf
-swf Sample.swf
-swf-header 480:320:30:ffffff
-cp ../..
2 changes: 1 addition & 1 deletion samples/04-Text/compile_swf.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-swf9 Sample.swf
-swf Sample.swf
-main Sample
-swf-header 640:640:24:ffffff
-cp ..
2 changes: 1 addition & 1 deletion samples/05-CacheAsBitmap/flash.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-main Sample
-swf9 Sample.swf
-swf Sample.swf
-swf-header 320:480:60:ccccff
2 changes: 0 additions & 2 deletions samples/PiratePig/project.nmml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,4 @@
<certificate path="path/to/author.p12" if="blackberry" />
</section>

<haxeflag name="--dead-code-elimination" if="html5" />

</project>
2 changes: 1 addition & 1 deletion tools/command-line-simple/flash/hxml/debug.hxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-main ApplicationMain ::HAXE_FLAGS::
-swf-version ::SWF_VERSION::
-swf9 ::BUILD_DIR::/flash/bin/::APP_FILE::.swf
-swf ::BUILD_DIR::/flash/bin/::APP_FILE::.swf
-swf-header ::WIN_WIDTH:::::WIN_HEIGHT:::::WIN_FPS:::::WIN_FLASHBACKGROUND::
-cp ::BUILD_DIR::/flash/haxe
-D fdb
Expand Down
2 changes: 1 addition & 1 deletion tools/command-line-simple/flash/hxml/release.hxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-main ApplicationMain ::HAXE_FLAGS::
-swf-version ::SWF_VERSION::
-swf9 ::BUILD_DIR::/flash/bin/::APP_FILE::.swf
-swf ::BUILD_DIR::/flash/bin/::APP_FILE::.swf
-swf-header ::WIN_WIDTH:::::WIN_HEIGHT:::::WIN_FPS:::::WIN_FLASHBACKGROUND::
-cp ::BUILD_DIR::/flash/haxe
4 changes: 3 additions & 1 deletion tools/smoke.jeash.com/display/DisplayAddChildTransform.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class DisplayAddChildTransform extends Sprite {

private var _mcMess:Sprite;

static function main () flash.Lib.current.addChild(new DisplayAddChildTransform())
static function main () {
flash.Lib.current.addChild(new DisplayAddChildTransform());
}

public function new () {

Expand Down
5 changes: 3 additions & 2 deletions tools/smoke.jeash.com/display/DisplayObjectContainerZIndex.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class DisplayObjectContainerZIndex extends Sprite {
s1.addChild(s1a);
}

static function main ()
Lib.current.addChild(new DisplayObjectContainerZIndex())
static function main () {
Lib.current.addChild(new DisplayObjectContainerZIndex());
}
}
4 changes: 3 additions & 1 deletion tools/smoke.jeash.com/display/SimpleButtonTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class SimpleButtonTest extends Sprite {
var button:CustomSimpleButton = new CustomSimpleButton();
addChild(button);
}
static function main () Lib.current.addChild(new SimpleButtonTest())
static function main () {
Lib.current.addChild(new SimpleButtonTest());
}
}

class CustomSimpleButton extends SimpleButton {
Expand Down
4 changes: 3 additions & 1 deletion tools/smoke.jeash.com/display/VisibilityTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class VisibilityTest extends Sprite {

}

static function main () Lib.current.stage.addChild(new VisibilityTest())
static function main () {
Lib.current.stage.addChild(new VisibilityTest());
}

}
2 changes: 1 addition & 1 deletion tools/smoke.jeash.com/display/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all: $(JS) $(SWF) $(HTML)
haxe -debug -js $*.js -cp ../../../ --remap flash:browser -main $*

%.swf: %.hx
haxe -cp ~/projects/stax/src/main/haxe -swf-header 400:400:8:ffffff -swf9 $*.swf -main $*
haxe -cp ~/projects/stax/src/main/haxe -swf-header 400:400:8:ffffff -swf $*.swf -main $*

%.html: %.hx
xsltproc --stringparam jsfile "$*.js" -o $*.html template.xsl main.xml
Expand Down
5 changes: 4 additions & 1 deletion tools/smoke.jeash.com/events/KeyCodeTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import flash.events.KeyboardEvent;
import flash.Lib;

class KeyCodeTest {
static function main () new KeyCodeTest()
static function main () {
new KeyCodeTest();
}

public function new () {
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPress);
}
Expand Down
4 changes: 3 additions & 1 deletion tools/smoke.jeash.com/events/MouseEnabled.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ class MouseEnabled extends Sprite
#if js untyped window.phantomTestResult = true; #end
}

static function main () Lib.current.stage.addChild(new MouseEnabled())
static function main () {
Lib.current.stage.addChild(new MouseEnabled());
}
}
4 changes: 3 additions & 1 deletion tools/smoke.jeash.com/events/MouseRollOver.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import flash.events.MouseEvent;
import flash.Lib;

class MouseRollOver {
static function main () new MouseRollOver()
static function main () {
new MouseRollOver();
}

public function new () {
var s = new Sprite();
Expand Down
4 changes: 2 additions & 2 deletions tools/smoke.jeash.com/events/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ HTML := $(patsubst %.hx,%.html,$(wildcard *.hx))
all: $(JS) $(SWF) $(HTML)

%.js: %.hx
haxe -js $*.js -cp ../../../ --dead-code-elimination --remap flash:browser -main $*
haxe -js $*.js -cp ../../../ --remap flash:browser -main $*

%.swf: %.hx
haxe -swf-header 400:400:8:ffffff -swf9 $*.swf -main $*
haxe -swf-header 400:400:8:ffffff -swf $*.swf -main $*

%.html: %.hx
xsltproc --stringparam jsfile "$*.js" -o $*.html template.xsl main.xml
Expand Down
4 changes: 3 additions & 1 deletion tools/smoke.jeash.com/interop/OneWayBinding.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import flash.Lib;


class OneWayBinding {
static function main () new OneWayBinding()
static function main () {
new OneWayBinding();
}

public function new () {
var s = new Sprite();
Expand Down
2 changes: 1 addition & 1 deletion tools/smoke.jeash.com/media/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all: $(JS) $(SWF) $(HTML)
haxe -debug -js $*.js -cp ../../../ --remap flash:browser -main $*

%.swf: %.hx
haxe -cp ~/projects/stax/src/main/haxe -swf-header 400:400:8:ffffff -swf9 $*.swf -main $*
haxe -cp ~/projects/stax/src/main/haxe -swf-header 400:400:8:ffffff -swf $*.swf -main $*

%.html: %.hx
xsltproc --stringparam jsfile "$*.js" -o $*.html template.xsl main.xml
Expand Down
4 changes: 3 additions & 1 deletion tools/smoke.jeash.com/net/GetUrl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class GetUrl {
#if js untyped window.phantomTestResult = tgt.data; #end
}

static function main () new GetUrl()
static function main () {
new GetUrl();
}
}

4 changes: 3 additions & 1 deletion tools/smoke.jeash.com/net/GetUrlBinary.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ class GetUrlBinary {
#end
}

static function main () new GetUrlBinary()
static function main () {
new GetUrlBinary();
}
}
4 changes: 3 additions & 1 deletion tools/smoke.jeash.com/net/LoadFromBytesJpg.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class LoadFromBytesJpg {
#end
}

static function main () new LoadFromBytesJpg()
static function main () {
new LoadFromBytesJpg();
}
}

4 changes: 3 additions & 1 deletion tools/smoke.jeash.com/net/PostUrl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@ class PostUrl extends Sprite {
Lib.trace(event);
}

static function main () Lib.current.addChild(new PostUrl())
static function main () {
Lib.current.addChild(new PostUrl());
}
}
2 changes: 1 addition & 1 deletion tools/smoke.jeash.com/net/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all: $(JS) $(SWF) $(HTML)
haxe -debug -js $*.js -cp ../../../ --remap flash:browser -main $*

%.swf: %.hx
haxe -swf-header 400:400:8:ffffff -swf9 $*.swf -main $*
haxe -swf-header 400:400:8:ffffff -swf $*.swf -main $*

%.html: %.hx
xsltproc --stringparam jsfile "$*.js" -o $*.html template.xsl main.xml
Expand Down
2 changes: 1 addition & 1 deletion tools/smoke.jeash.com/phantomjs/PhantomJs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern class WebPage {
function release():Void;
function render(fileName:String):Void;
function renderBase64(format:String):String;
@:overload (function (type:String, key:Int):Void {})
@:overload(function (type:String, key:Int):Void {})
function sendEvent(type:String, x:Int, y:Int):Void;
function uploadFile(selector:String, fileName:String):Void;
dynamic function onAlert(msg:String):Void;
Expand Down
52 changes: 25 additions & 27 deletions tools/smoke.jeash.com/phantomjs/PhantomSuiteRunner.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import utest.ui.text.PrintReport;

using haxe.io.Path;

using tink.macro.tools.MacroTools;
using tink.core.types.Outcome;

using Lambda;
using Std;
using StringTools;
Expand Down Expand Up @@ -76,7 +73,7 @@ class PhantomSuiteRunner {
trace("-- done -- " + address);
}, ASYNC_WAIT );

trace("Loading ${address}".format());
trace('Loading ${address}');
page.open(address, executeAfterPageLoad(async));
}

Expand All @@ -88,25 +85,25 @@ class PhantomSuiteRunner {
cb();
}

public static function stringTest(expected: String) return function (page) stringTestPage(page, expected)
public static function stringTest(expected: String) {return function (page) stringTestPage(page, expected);}
public static function stringTestPage(page: WebPage, expected: String) {
Assert.equals(expected, page.evaluate(function () return untyped window.phantomTestResult));
}
public static function boolTest() return function (page) boolTestPage(page)
public static function boolTest() {return function (page) boolTestPage(page);}
public static function boolTestPage(page: WebPage) {
#if js
Assert.isTrue(page.evaluate(function () return untyped window.phantomTestResult));
#end
}
public static function intTest(expected: Int) return function (page) intTestPage(page, expected)
public static function intTest(expected: Int) {return function (page) intTestPage(page, expected);}
public static function intTestPage(page: WebPage, expected: Int) {
Assert.equals(expected, page.evaluate(function () return untyped window.phantomTestResult));
}
public static function arrayTest(expected: Array<Dynamic>) return function (page) arrayTestPage(page, expected)
public static function arrayTest(expected: Array<Dynamic>) {return function (page) arrayTestPage(page, expected);}
public static function arrayTestPage(page: WebPage, expected: Array<Dynamic>) {
Assert.same(expected, page.evaluate(function () return untyped window.phantomTestResult));
}
public static function imageTest(imageFileName: String) return function (page) imageTestPage(page, imageFileName)
public static function imageTest(imageFileName: String) {return function (page) imageTestPage(page, imageFileName);}
public static function imageTestPage(page: WebPage, imageFileName: String) {
#if js
var compareFileName = "/" + imageFileName.withoutDirectory().withoutExtension() + "_compare.png";
Expand All @@ -116,37 +113,37 @@ class PhantomSuiteRunner {
#end
}

public static function imageDump(imageFileName: String) return function (page) imageDumpPage(page, imageFileName)
public static function imageDump(imageFileName: String) {return function (page) imageDumpPage(page, imageFileName);}
public static function imageDumpPage(page: WebPage, imageFileName: String) {
#if js
page.render(ROOT_PATH + imageFileName);
#end
}

public static function sendMouseEvent(eventType: String, coords: Array<Int>) return function (page) sendMouseEventPage(page, eventType, coords)
public static function sendMouseEvent(eventType: String, coords: Array<Int>) {return function (page) sendMouseEventPage(page, eventType, coords);}
public static function sendMouseEventPage(page: WebPage, eventType: String, coords: Array<Int>) {
trace("sending event " + eventType + " to page at x,y = " + coords);
#if js
page.sendEvent(eventType, coords[0], coords[1]);
#end
}

public static function sendKeyboardEvent(eventType: String, keys: Array<Int>) return function (page) sendKeyboardEventPage(page, eventType, keys)
public static function sendKeyboardEvent(eventType: String, keys: Array<Int>) {return function (page) sendKeyboardEventPage(page, eventType, keys);}
public static function sendKeyboardEventPage(page: WebPage, eventType: String, keys: Array<Int>) {
trace("sending event " + eventType + " to page with keys = " + keys);
#if js
keys.map(function (key) page.sendEvent(eventType, key));
#end
}

@:macro public static function rootPath() {
macro public static function rootPath() {
#if neko
return sys.FileSystem.fullPath(Sys.getCwd() + "/../").toExpr();
return macro $v{sys.FileSystem.fullPath(Sys.getCwd() + "/../")};
#end
}

#if macro
@:macro public static function build () : Array<Field> {
macro public static function build () : Array<Field> {
var fields = [];
for (spec in findSpecs(ROOT_PATH, []))
for (test in PhantomSuiteRunner.loadSpec(spec))
Expand All @@ -169,52 +166,53 @@ class PhantomSuiteRunner {
var p = Context.makePosition({min: 0, max: 0, file: fileName });

var spec : TestSpec = try Json.parse(content) catch ( e : Dynamic ) Context.error(Std.string(e), p);
var url = BASE_URL + if (spec.target != null) basename.directory() + '/' + spec.target; else basename + ".html";
var url = BASE_URL + if (spec.target != null) basename.directory() + '/' + spec.target; else basename + ".html";

var fields = Context.getBuildFields();
var block = [];
if (spec.events != null) {
spec.events.map(function (s)
if (s.eventType != null && Std.is(s.coords, Array)) {
if (s.eventType.startsWith("key")) {
block.push("PhantomSuiteRunner.sendKeyboardEvent".resolve().call([s.eventType.toExpr(), s.coords.toExpr()]));
block.push(macro PhantomSuiteRunner.sendKeyboardEvent($v{s.eventType}, $v{s.coords}));
} else {
block.push("PhantomSuiteRunner.sendMouseEvent".resolve().call([s.eventType.toExpr(), s.coords.toExpr()]));
block.push(macro PhantomSuiteRunner.sendMouseEvent($v{s.eventType}, $v{s.coords}));
}
} else {
Context.error(s + " should have attribute 'eventType' and array 'coords'", p);
}
);
}

block.push(switch (spec.testType) {
case "STRING":
var expected = spec.assrt;
"PhantomSuiteRunner.stringTest".resolve().call([expected.toExpr()]);
macro PhantomSuiteRunner.stringTest($v{expected});

case "BOOL":
"PhantomSuiteRunner.boolTest".resolve().call([]);
macro PhantomSuiteRunner.boolTest();

case "INT":
var expected = spec.assrt;
"PhantomSuiteRunner.intTest".resolve().call([expected.toExpr()]);
macro PhantomSuiteRunner.intTest($v{expected});

case "ARRAY":
var expected = spec.assrt;
"PhantomSuiteRunner.arrayTest".resolve().call([expected.toExpr()]);
macro PhantomSuiteRunner.arrayTest($v{expected});

case "IMAGE":
var img = (basename + ".png");
if (sys.FileSystem.exists(ROOT_PATH + img)) {
"PhantomSuiteRunner.imageTest".resolve().call([img.toExpr()]);
macro PhantomSuiteRunner.imageTest($v{img});
} else {
"PhantomSuiteRunner.imageDump".resolve().call([img.toExpr()]);

macro PhantomSuiteRunner.imageDump($v{img});
}

default: Context.error(fileName + " should have a valid testType attribute", p);
});
var test = "PhantomSuiteRunner.loadPage".resolve().call([url.toExpr(), block.toArray()]);
fields.push({ name : "test" + basename.withoutDirectory(), doc: null, meta: [], access : [APublic], kind: FFun(test.func()), pos : p });
var test = macro function() PhantomSuiteRunner.loadPage($v{url}, $a{block});
var testFunc = switch(test.expr){ case EFunction(_, f): f; case _: throw "test is not a function"; }
fields.push({ name : "test" + basename.withoutDirectory(), doc: null, meta: [], access : [APublic], kind: FFun(testFunc), pos : Context.currentPos() });
return fields;

}
Expand Down
Loading

0 comments on commit 803704b

Please sign in to comment.