http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/GenericTests/src/testshim/FlexJSUnitTestRunner.as ---------------------------------------------------------------------- diff --git a/manualtests/GenericTests/src/testshim/FlexJSUnitTestRunner.as b/manualtests/GenericTests/src/testshim/FlexJSUnitTestRunner.as deleted file mode 100644 index 7494963..0000000 --- a/manualtests/GenericTests/src/testshim/FlexJSUnitTestRunner.as +++ /dev/null @@ -1,186 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package testshim { - -import org.apache.flex.reflection.MetaDataArgDefinition; -import org.apache.flex.reflection.MetaDataDefinition; -import org.apache.flex.reflection.MethodDefinition; -import org.apache.flex.reflection.TypeDefinition; -import org.apache.flex.reflection.describeType; - -import flexunit.framework.Assert; -public class FlexJSUnitTestRunner { - - - public function FlexJSUnitTestRunner(testerClass:Class, notificationReceiver:Function) { - this.testerClass = testerClass; - this.callback = notificationReceiver; - prepare(); - } - - private var testerClass:Class; - private var callback:Function; - - private var _testingName:String; - public function get testingName():String{ - return _testingName; - } - private var _successCount:uint=0; - public function get successCount():uint { - return _successCount; - } - - private var _failCount:uint=0; - public function get failCount():uint { - return _failCount; - } - - private var _successfulAssertions:uint=0; - public function get successfulAssertions():uint { - return _successfulAssertions; - } - - private var beforeClassFunc:Function; - private var afterClassFunc:Function; - private var setupFunc:MethodDefinition; - private var tearDownFunc:MethodDefinition; - - private var testMethods:Array=[]; - - private function prepare():void{ - var typeDef:TypeDefinition = describeType(testerClass); - _testingName = typeDef.name; - var staticMethods:Array = typeDef.staticMethods; - for each (var methodDef:MethodDefinition in staticMethods) { - var beforeClass:Array = methodDef.retrieveMetaDataByName("BeforeClass"); - var afterClass:Array = methodDef.retrieveMetaDataByName("AfterClass"); - if ( beforeClass.length ) { - if (beforeClassFunc!=null) throw new Error("BeforeClass used more than once in "+typeDef.qualifiedName); - beforeClassFunc = testerClass[methodDef.name]; - } - if ( afterClass.length ) { - if (afterClassFunc!=null) throw new Error("AfterClass used more than once in "+typeDef.qualifiedName); - afterClassFunc = testerClass[methodDef.name]; - } - } - var methods:Array = typeDef.methods; - for each (methodDef in methods) { - var beforeTests:Array = methodDef.retrieveMetaDataByName("Before"); - var afterTests:Array = methodDef.retrieveMetaDataByName("After"); - if ( beforeTests.length ) { - if (setupFunc!=null) throw new Error("Before used more than once in "+typeDef.qualifiedName); - setupFunc = methodDef; - } - if ( afterTests.length ) { - if (tearDownFunc!=null) throw new Error("After used more than once in "+typeDef.qualifiedName); - tearDownFunc = methodDef; - } - var test:Array = methodDef.retrieveMetaDataByName("Test"); - if (test.length) { - testMethods.push(methodDef); - } - testMethods.sortOn("name"); - } - - if (testMethods.length == 0) { - throw new Error("Zero test methods detected in "+typeDef.qualifiedName+", check to make sure -keep-as3-metadata is configured"); - } - } - - private function begin():void { - if (beforeClassFunc!=null) beforeClassFunc(); - } - - public function runTests():void{ - begin(); - var testInstance:Object = new testerClass(); - if (setupFunc!=null) { - testInstance[setupFunc.name](); - } - var i:uint=0, l:uint=testMethods.length; - - for(;i<l;i++) { - runFlexJSTest(_testingName,testInstance,testMethods[i],callback); - } - - if (tearDownFunc!=null) { - testInstance[tearDownFunc.name](); - } - end(); - } - - private function end():void{ - if (afterClassFunc!=null) afterClassFunc(); - } - - - private function runFlexJSTest(testClass:String,instance:Object,methodDef:MethodDefinition,callback:Function=null):void{ - var methodName:String = methodDef.name; - trace('running test in '+testClass+":"+methodName); - var varianceMetas:Array = methodDef.retrieveMetaDataByName("TestVariance"); - - var method:Function = instance[methodName]; - var preAssertCount:uint = Assert.assertionsMade; - var result:TestResult = new TestResult(); - result.assertions = 0; - result.pass = true; - result.error = null; - result.testClass = testClass; - result.testMethod = methodName; - - while (varianceMetas.length) { - var varianceMeta:MetaDataDefinition = varianceMetas.shift(); - var varianceArgs:Array = varianceMeta.getArgsByKey("variance"); - var i:uint=0, l:uint= varianceArgs.length; - if (l) { - result.hasVariance=true; - for(;i<l;i++) varianceArgs[i] = varianceArgs[i].value; - result.varianceTarget = varianceArgs.join(","); - } - if (result.hasVariance) { - var descriptionArgs:Array= varianceMeta.getArgsByKey("description"); - if (descriptionArgs.length) result.varianceDescription = ""; - while(descriptionArgs.length) { - var description:MetaDataArgDefinition = descriptionArgs.shift(); - result.varianceDescription +=description.value; - if (descriptionArgs.length) result.varianceDescription += ", "; - } - } - } - //run the test method - try { - method(); - } catch (e:Error) { - result.pass=false; - result.error = e.name+":" + e.message; - } - result.assertions = Assert.assertionsMade - preAssertCount; - if (preAssertCount == Assert.assertionsMade) { - result.warning = "WARNING: This test method appears to have zero Assertions"; - } - if (result.pass) _successCount++; - else _failCount++; - _successfulAssertions += result.assertions; - if (callback!=null) { - callback(result); - } - } - -} -}
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/GenericTests/src/testshim/TestResult.as ---------------------------------------------------------------------- diff --git a/manualtests/GenericTests/src/testshim/TestResult.as b/manualtests/GenericTests/src/testshim/TestResult.as deleted file mode 100644 index d9bc514..0000000 --- a/manualtests/GenericTests/src/testshim/TestResult.as +++ /dev/null @@ -1,56 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// -package testshim { -public class TestResult { - public function TestResult() { - } - - public var testClass:String; - - public var testMethod:String; - - public var pass:Boolean; - - public var assertions:uint; - - public var error:String; - - public var hasVariance:Boolean; - - public var varianceTarget:String; - - public var varianceDescription:String; - - public var warning:String; - - public function toString(newline:String=null):String { - if (newline==null) newline="\n"; - var s:String=""; - var postFix:String = testMethod+" in "+testClass; - if (pass) { - s += "PASSED ("+assertions+" assertions made) ["+postFix+"]"; - } else { - s += "FAILED ( at assertion "+assertions+" in test method) ["+postFix+"]"+newline; - s += "["+error+"]"; - } - return s; - } - -} -} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/GenericTests/testsview/image/Flex.png ---------------------------------------------------------------------- diff --git a/manualtests/GenericTests/testsview/image/Flex.png b/manualtests/GenericTests/testsview/image/Flex.png deleted file mode 100644 index cb68fec..0000000 Binary files a/manualtests/GenericTests/testsview/image/Flex.png and /dev/null differ http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/GenericTests/testsview/index.html ---------------------------------------------------------------------- diff --git a/manualtests/GenericTests/testsview/index.html b/manualtests/GenericTests/testsview/index.html deleted file mode 100644 index 270b933..0000000 --- a/manualtests/GenericTests/testsview/index.html +++ /dev/null @@ -1,128 +0,0 @@ -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<!DOCTYPE html> -<html> -<head> - <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <style> - .boxLeft { - display:inline-block; - width:50% ; - position:absolute; - top:100px; - bottom:15px; - left:0px - } - .boxRight { - display:inline-block; - width:50% ; - position:absolute; - top:100px; - bottom:15px; - right:0px - } - .pageStyles { - font-family: Arial,sans-serif; - color: #333; - background: #f5f5f5; - font-size: 14px; - line-height: 1.5; - } - h1 { - font-size: 28px; - line-height: 1.25; - font-weight: normal; - } - em { - font-weight: bold; - } - .logo { - margin-right: 10px; - float: left; - width: 48px; - height: 48px; - border-radius: 50%; - border: 0; - margin: 0; - padding: 0; - } - .titleContent { - white-space:nowrap; - } - </style> - <script type="text/javascript"> - - console.API; - - if (typeof console._commandLineAPI !== 'undefined') { - console.API = console._commandLineAPI; //chrome - } else if (typeof console._inspectorCommandLineAPI !== 'undefined') { - console.API = console._inspectorCommandLineAPI; //Safari - } else if (typeof console.clear !== 'undefined') { - console.API = console; - } - - function swapJSBuild() { - var button = document.getElementById("swapJsButton"); - var JS_RELEASE = "JS-Release"; - var JS_DEBUG = "JS-Debug"; - var SWAP_TO_RELEASE = "Swap To "+JS_RELEASE; - var SWAP_TO_DEBUG = "Swap To "+JS_DEBUG; - var debug = "../bin/js-debug/index.html"; - var release = "../bin/js-release/index.html"; - var jsIframe = document.getElementById("jsIframe"); - var status = document.getElementById("jsStatus"); - if (button && jsIframe) { - var current = button.innerHTML; - switch (current) { - case SWAP_TO_RELEASE: - console.API.clear(); - button.innerHTML = SWAP_TO_DEBUG; - jsIframe.src = release; - status.innerHTML = "Currently showing <em>"+JS_RELEASE+"</em>";; - break; - case SWAP_TO_DEBUG: - console.API.clear(); - button.innerHTML = SWAP_TO_RELEASE; - jsIframe.src = debug; - status.innerHTML = "Currently showing <em>"+JS_DEBUG+"</em>"; - break; - } - } - } - </script> -</head> -<body class="pageStyles"> - <div> - <div > - <img class="logo" src="image/Flex.png" alt="Apache Flex logo"> - <div class="titleContent"> - <h1>FlexJS Framework Development Unit Tests</h1> - </div> - <div id="jsStatus" style="position: relative; display: inline-block;">Currently showing <em>JS-Debug</em></div> - <button id="swapJsButton" onclick="swapJSBuild()" type="button" class="quoteButton TextButton" style="position: relative; display: inline-block;">Swap To JS-Release</button> - </div> - <div class="boxLeft"> - <iframe id="jsIframe" src="../bin/js-debug/index.html" frameborder="1" scrolling="no" height="100%" width="100%" align="left" ></iframe> - </div> - <div class="boxRight"> - <iframe id="swfIframe" src="../bin-debug/GenericTests.html" frameborder="1" scrolling="no" height="100%" width="100%" align="left" ></iframe> - </div> - </div> -</body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/ImageTest/build.xml ---------------------------------------------------------------------- diff --git a/manualtests/ImageTest/build.xml b/manualtests/ImageTest/build.xml index 5b5fbfa..16bad87 100644 --- a/manualtests/ImageTest/build.xml +++ b/manualtests/ImageTest/build.xml @@ -23,48 +23,21 @@ <property name="FLEXJS_HOME" location="../.."/> <property name="example" value="ImageTest" /> + <property file="${FLEXJS_HOME}/env.properties"/> <property environment="env"/> - <property file="${FLEXJS_HOME}/build.properties"/> + <property file="${FLEXJS_HOME}/build.properties"/> <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> - <available file="${env.FALCON_HOME}/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${env.FALCON_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk"/> - - <available file="${env.FALCONJX_HOME}/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${env.FALCONJX_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler.jx/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler.jx"/> - - <available file="${env.GOOG_HOME}/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${env.GOOG_HOME}"/> - - <available file="${FLEXJS_HOME}/js/lib/google/closure-library/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${FLEXJS_HOME}/js/lib/google/closure-library"/> + <include file="${basedir}/../build_example.xml" /> - <target name="main" depends="clean,build_example.compile,build_example.compilejs" description="Clean build of FlexJSUI.swc"> + <target name="main" depends="clean,build_example.compile" description="Clean build of ${example}"> </target> <target name="clean"> <delete dir="${basedir}/bin" failonerror="false" /> <delete dir="${basedir}/bin-debug" failonerror="false" /> <delete dir="${basedir}/bin-release" failonerror="false" /> + <delete dir="${basedir}/target" failonerror="false" /> </target> - </project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/LanguageTests/build.xml ---------------------------------------------------------------------- diff --git a/manualtests/LanguageTests/build.xml b/manualtests/LanguageTests/build.xml index 6de5e8a..0e986cb 100644 --- a/manualtests/LanguageTests/build.xml +++ b/manualtests/LanguageTests/build.xml @@ -22,50 +22,25 @@ <project name="languagetests" default="main" basedir="."> <property name="FLEXJS_HOME" location="../.."/> <property name="example" value="LanguageTests" /> + + <property name="file_suffix" value="as" /> <property file="${FLEXJS_HOME}/env.properties"/> <property environment="env"/> - <property file="${FLEXJS_HOME}/build.properties"/> + <property file="${FLEXJS_HOME}/build.properties"/> <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> - <available file="${env.FALCON_HOME}/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${env.FALCON_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk"/> - - <available file="${env.FALCONJX_HOME}/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${env.FALCONJX_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler.jx/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler.jx"/> - - <available file="${env.GOOG_HOME}/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${env.GOOG_HOME}"/> - - <available file="${FLEXJS_HOME}/js/lib/google/closure-library/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${FLEXJS_HOME}/js/lib/google/closure-library"/> + <include file="${basedir}/../build_example.xml" /> - <target name="main" depends="clean,build_example.compileas,build_example.compileasjs" description="Clean build of ${example}"> + <target name="main" depends="clean,build_example.compile" description="Clean build of ${example}"> </target> <target name="clean"> <delete dir="${basedir}/bin" failonerror="false" /> <delete dir="${basedir}/bin-debug" failonerror="false" /> <delete dir="${basedir}/bin-release" failonerror="false" /> + <delete dir="${basedir}/target" failonerror="false" /> </target> </project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/ListsTest/build.xml ---------------------------------------------------------------------- diff --git a/manualtests/ListsTest/build.xml b/manualtests/ListsTest/build.xml index e6d7c8b..4acc6da 100644 --- a/manualtests/ListsTest/build.xml +++ b/manualtests/ListsTest/build.xml @@ -25,47 +25,20 @@ <property file="${FLEXJS_HOME}/env.properties"/> <property environment="env"/> - <property file="${FLEXJS_HOME}/build.properties"/> + <property file="${FLEXJS_HOME}/build.properties"/> <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> - <available file="${env.FALCON_HOME}/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${env.FALCON_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk"/> - - <available file="${env.FALCONJX_HOME}/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${env.FALCONJX_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler.jx/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler.jx"/> - - <available file="${env.GOOG_HOME}/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${env.GOOG_HOME}"/> - - <available file="${FLEXJS_HOME}/js/lib/google/closure-library/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${FLEXJS_HOME}/js/lib/google/closure-library"/> + <include file="${basedir}/../build_example.xml" /> - <target name="main" depends="clean,build_example.compile,build_example.compilejs" description="Clean build of ${example}"> + <target name="main" depends="clean,build_example.compile" description="Clean build of ${example}"> </target> <target name="clean"> <delete dir="${basedir}/bin" failonerror="false" /> <delete dir="${basedir}/bin-debug" failonerror="false" /> <delete dir="${basedir}/bin-release" failonerror="false" /> + <delete dir="${basedir}/target" failonerror="false" /> </target> </project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/ProxyTest/build.xml ---------------------------------------------------------------------- diff --git a/manualtests/ProxyTest/build.xml b/manualtests/ProxyTest/build.xml index 2e1bcb7..83084b6 100644 --- a/manualtests/ProxyTest/build.xml +++ b/manualtests/ProxyTest/build.xml @@ -23,50 +23,22 @@ <property name="FLEXJS_HOME" location="../.."/> <property name="example" value="ProxyTest" /> + <property file="${FLEXJS_HOME}/env.properties"/> <property environment="env"/> - <property file="${FLEXJS_HOME}/build.properties"/> + <property file="${FLEXJS_HOME}/build.properties"/> <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> - <!-- use this to add keep metadata option --> - <property name="theme_arg" value="-keep-as3-metadata+=Event" /> - <available file="${env.FALCON_HOME}/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${env.FALCON_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk"/> - - <available file="${env.FALCONJX_HOME}/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${env.FALCONJX_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler.jx/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler.jx"/> - - <available file="${env.GOOG_HOME}/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${env.GOOG_HOME}"/> - - <available file="${FLEXJS_HOME}/js/lib/google/closure-library/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${FLEXJS_HOME}/js/lib/google/closure-library"/> + <include file="${basedir}/../build_example.xml" /> - <target name="main" depends="clean,build_example.compile,build_example.compilejs" description="Clean build of FlexJSUI.swc"> + <target name="main" depends="clean,build_example.compile" description="Clean build of ${example}"> </target> <target name="clean"> <delete dir="${basedir}/bin" failonerror="false" /> <delete dir="${basedir}/bin-debug" failonerror="false" /> <delete dir="${basedir}/bin-release" failonerror="false" /> + <delete dir="${basedir}/target" failonerror="false" /> </target> </project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/ReflectionTest/build.xml ---------------------------------------------------------------------- diff --git a/manualtests/ReflectionTest/build.xml b/manualtests/ReflectionTest/build.xml index d65e7a8..b9bfd2c 100644 --- a/manualtests/ReflectionTest/build.xml +++ b/manualtests/ReflectionTest/build.xml @@ -23,50 +23,22 @@ <property name="FLEXJS_HOME" location="../.."/> <property name="example" value="ReflectionTest" /> + <property file="${FLEXJS_HOME}/env.properties"/> <property environment="env"/> - <property file="${FLEXJS_HOME}/build.properties"/> + <property file="${FLEXJS_HOME}/build.properties"/> <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> - <!-- use this to add keep metadata option --> - <property name="theme_arg" value="-keep-as3-metadata+=Event" /> - <available file="${env.FALCON_HOME}/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${env.FALCON_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk"/> - - <available file="${env.FALCONJX_HOME}/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${env.FALCONJX_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler.jx/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler.jx"/> - - <available file="${env.GOOG_HOME}/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${env.GOOG_HOME}"/> - - <available file="${FLEXJS_HOME}/js/lib/google/closure-library/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${FLEXJS_HOME}/js/lib/google/closure-library"/> + <include file="${basedir}/../build_example.xml" /> - <target name="main" depends="clean,build_example.compile,build_example.compilejs" description="Clean build of FlexJSUI.swc"> + <target name="main" depends="clean,build_example.compile" description="Clean build of ${example}"> </target> <target name="clean"> <delete dir="${basedir}/bin" failonerror="false" /> <delete dir="${basedir}/bin-debug" failonerror="false" /> <delete dir="${basedir}/bin-release" failonerror="false" /> + <delete dir="${basedir}/target" failonerror="false" /> </target> </project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/RollEventsTest/build.xml ---------------------------------------------------------------------- diff --git a/manualtests/RollEventsTest/build.xml b/manualtests/RollEventsTest/build.xml index 767c856..3dedfed 100644 --- a/manualtests/RollEventsTest/build.xml +++ b/manualtests/RollEventsTest/build.xml @@ -23,48 +23,23 @@ <property name="FLEXJS_HOME" location="../.."/> <property name="example" value="RollEventsTest" /> + <property file="${FLEXJS_HOME}/env.properties"/> <property environment="env"/> - <property file="${FLEXJS_HOME}/build.properties"/> + <property file="${FLEXJS_HOME}/build.properties"/> <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> - <available file="${env.FALCON_HOME}/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${env.FALCON_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk"/> - - <available file="${env.FALCONJX_HOME}/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${env.FALCONJX_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler.jx/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler.jx"/> - - <available file="${env.GOOG_HOME}/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${env.GOOG_HOME}"/> - - <available file="${FLEXJS_HOME}/js/lib/google/closure-library/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${FLEXJS_HOME}/js/lib/google/closure-library"/> + <include file="${basedir}/../build_example.xml" /> - <target name="main" depends="clean,build_example.compile,build_example.compilejs" description="Clean build of FlexJSUI.swc"> + <target name="main" depends="clean,build_example.compile" description="Clean build of ${example}"> </target> <target name="clean"> <delete dir="${basedir}/bin" failonerror="false" /> <delete dir="${basedir}/bin-debug" failonerror="false" /> <delete dir="${basedir}/bin-release" failonerror="false" /> + <delete dir="${basedir}/target" failonerror="false" /> </target> + </project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/TLFEditTestFlexJS/build.xml ---------------------------------------------------------------------- diff --git a/manualtests/TLFEditTestFlexJS/build.xml b/manualtests/TLFEditTestFlexJS/build.xml index fc35c60..24985be 100644 --- a/manualtests/TLFEditTestFlexJS/build.xml +++ b/manualtests/TLFEditTestFlexJS/build.xml @@ -22,51 +22,25 @@ <project name="TLFEditTestFlexJS" default="main" basedir="."> <property name="FLEXJS_HOME" location="../.."/> <property name="example" value="TLFEditTestFlexJS" /> + <property name="swf.version" value="20" /> <property file="${FLEXJS_HOME}/env.properties"/> <property environment="env"/> - <property file="${FLEXJS_HOME}/build.properties"/> + <property file="${FLEXJS_HOME}/build.properties"/> <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> - <available file="${env.FALCON_HOME}/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${env.FALCON_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk/lib/falcon-mxmlc.jar" - type="file" - property="FALCON_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk"/> - - <available file="${env.FALCONJX_HOME}/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${env.FALCONJX_HOME}"/> - - <available file="${FLEXJS_HOME}/../flex-falcon/compiler.jx/lib/jsc.jar" - type="file" - property="FALCONJX_HOME" - value="${FLEXJS_HOME}/../flex-falcon/compiler.jx"/> - - <available file="${env.GOOG_HOME}/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${env.GOOG_HOME}"/> - - <available file="${FLEXJS_HOME}/js/lib/google/closure-library/closure/goog/base.js" - type="file" - property="GOOG_HOME" - value="${FLEXJS_HOME}/js/lib/google/closure-library"/> + <include file="${basedir}/../build_example.xml" /> - <target name="main" depends="clean,build_example.compile,build_example.compilejs" description="Clean build of ${example}"> + <target name="main" depends="clean,build_example.compile" description="Clean build of ${example}"> </target> <target name="clean"> <delete dir="${basedir}/bin" failonerror="false" /> <delete dir="${basedir}/bin-debug" failonerror="false" /> <delete dir="${basedir}/bin-release" failonerror="false" /> + <delete dir="${basedir}/target" failonerror="false" /> </target> </project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/README.txt ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/README.txt b/manualtests/UnitTests/README.txt new file mode 100644 index 0000000..98c2bae --- /dev/null +++ b/manualtests/UnitTests/README.txt @@ -0,0 +1,61 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +DESCRIPTION + +The UnitTests application is a very basic form of unit testing primarily +intended for FlexJS framework developers. It is a 'lite' version of a small portion of +Flexunit code to support basic assertion tests. + +This Flex application may be run as a Flash SWF or cross-compiled (using Falcon JX) +into JavaScript and HTML and run without Flash. + +There is a convenience html page inside the top level testsview directory for hosting the tests side-by-side +that permits developers to refresh the test builds simultaneously and compare results in the browser, including the +ability to toggle between JS-Debug and JS-Release builds. +While this is primarily intended for framework developers, it may be useful as a starting point +for cross-compiled unit testing (during development only) in regular FlexJS projects. + +FRAMEWORK DEVELOPER NOTES +To add new tests, follow the examples inside the flexUnitTests package, and add any new Test +group or category level class (the classes directly inside flexUnitTests package) into the top +level TestClasses.as file. This should be all that is necessary to add new tests. + +MetaData +[BeforeClass] -same as flexunit (typical: 'setupBeforClass')- runs a static method before the test class is instantiated +[AfterClass] -same as flexunit (typical: 'tearDownAfterClass')- runs a static method after the test class has been processed +[Before] -same as flexunit (typical: 'setup') - runs an instance method before the test class' test methods are processed +[After] -same as flexunit (typical: 'tearDown') - runs an instance method after the test class' test methods are processed +[Test] -same as flexunit (typical: 'testXXXX') - denotes a test method. No assumption about order of test methods being called should be made + +[TestVariance(variance="JS",description="Reason for variation in JS expected results")] +The above is specific to this test app, and permits annotation of test methods where the expected results are different between compiler targets. +The variance key in the meta data should be either "SWF" or "JS". This is the compiler target with the result that is considered to be different +to what it ideally 'should be', but correct as per the current implementation of the framework. Usually this will be "JS". It indicates a known +but currently acceptable difference between compiler targets. + + +GENERAL NOTES + +In its first working version this app only supports synchronous simple assertions and +is intended to use test classes that are compatible with the flexunit tests that are +used in the full framework build. Future versions may include more advanced features. + +The cross-compilation to JavaScript often results in non-fatal warnings. Some of these warnings +should be addressed in future releases of the Falcon JX compiler. http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/build.xml ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/build.xml b/manualtests/UnitTests/build.xml new file mode 100644 index 0000000..68d82b3 --- /dev/null +++ b/manualtests/UnitTests/build.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> + + +<project name="GenericTests" default="main" basedir="."> + <property name="FLEXJS_HOME" location="../.."/> + <property name="example" value="UnitTests" /> + + <!-- adding flexuint style meta collection, and additional testing meta tags (Event,Bindable,TestMeta)--> + <property name="theme_arg" value="-keep-as3-metadata+=Test,BeforeClass,AfterClass,Before,After,TestVariance,Event,Bindable,TestMeta" /> + <!-- adding flexuint style meta collection, and additional testing meta tags (Event,Bindable,TestMeta)--> + <property name="extlib_arg" value="-keep-code-with-metadata=Test,BeforeClass,AfterClass,Before,After,TestVariance,TestMeta" /> + + <property file="${FLEXJS_HOME}/env.properties"/> + <property environment="env"/> + <property file="${FLEXJS_HOME}/build.properties"/> + <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> + + <!-- make ant src and output consistent with maven --> + <property name="maven_compat" value="true"/> + + <include file="${basedir}/../build_example.xml" /> + + <target name="main" depends="clean,build_example.compile" description="Clean build of ${example}"> + </target> + + <target name="clean"> + <delete dir="${basedir}/bin" failonerror="false" /> + <delete dir="${basedir}/bin-debug" failonerror="false" /> + <delete dir="${basedir}/bin-release" failonerror="false" /> + <delete dir="${basedir}/target" failonerror="false" /> + </target> + + <target name="examine" depends="build_example.get.browser"> + <echo message="View the swf and js unit tests side-by-side"/> + <exec executable="${browser}" dir="${basedir}" failonerror="true"> + <arg value="file:///${basedir}/testsview/index.html"/> + </exec> + </target> + +</project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/src/README.txt ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/src/README.txt b/manualtests/UnitTests/src/README.txt new file mode 100644 index 0000000..4ef6e3f --- /dev/null +++ b/manualtests/UnitTests/src/README.txt @@ -0,0 +1,61 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +DESCRIPTION + +The GenericTests application is a very basic form of unit testing primarily +intended for FlexJS framework developers. It is a 'lite' version of a small portion of +Flexunit code to support basic assertion tests. + +This Flex application may be run as a Flash SWF or cross-compiled (using Falcon JX) +into JavaScript and HTML and run without Flash. + +There is a convenience html page for hosting the tests side-by-side that permits developers +to refresh the test builds simultaneously and compare results in the browser, including the +ability to toggle between JS-Debug and JS-Release builds. +While this is primarily intended for framework developers, it may be useful as a starting point +for cross-compiled unit testing (during development only) in regular FlexJS projects. + +FRAMEWORK DEVELOPER NOTES +To add new tests, follow the examples inside the flexUnitTests package, and add any new Test +group or category level class (the classes directly inside flexUnitTests package) into the top +level TestClasses.as file. This should be all that is necessary to add new tests. + +MetaData +[BeforeClass] -same as flexunit (typical: 'setupBeforClass')- runs a static method before the test class is instantiated +[AfterClass] -same as flexunit (typical: 'tearDownAfterClass')- runs a static method after the test class has been processed +[Before] -same as flexunit (typical: 'setup') - runs an instance method before the test class' test methods are processed +[After] -same as flexunit (typical: 'tearDown') - runs an instance method after the test class' test methods are processed +[Test] -same as flexunit (typical: 'testXXXX') - denotes a test method. No assumption about order of test methods being called should be made + +[TestVariance(variance="JS",description="Reason for variation in JS expected results")] +The above is specific to this test app, and permits annotation of test methods where the expected results are different between compiler targets. +The variance key in the meta data should be either "SWF" or "JS". This is the compiler target with the result that is considered to be different +to what it ideally 'should be', but correct as per the current implementation of the framework. Usually this will be "JS". It indicates a known +but currently acceptable difference between compiler targets. + + +GENERAL NOTES + +In its first working version this app only supports synchronous simple assertions and +is intended to use test classes that are compatible with the flexunit tests that are +used in the full framework build. Future versions may include more advanced features. + +The cross-compilation to JavaScript often results in non-fatal warnings. Some of these warnings +should be addressed in future releases of the Falcon JX compiler. http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/src/main/config/compile-app-config.xml ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/src/main/config/compile-app-config.xml b/manualtests/UnitTests/src/main/config/compile-app-config.xml new file mode 100644 index 0000000..00454bd --- /dev/null +++ b/manualtests/UnitTests/src/main/config/compile-app-config.xml @@ -0,0 +1,25 @@ +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<flex-config> + <js-output-optimization> + <optimization>skipFunctionCoercions</optimization> + </js-output-optimization> + <compiler> + </compiler> +</flex-config> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/src/main/flex/MyInitialView.mxml ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/src/main/flex/MyInitialView.mxml b/manualtests/UnitTests/src/main/flex/MyInitialView.mxml new file mode 100644 index 0000000..83497e1 --- /dev/null +++ b/manualtests/UnitTests/src/main/flex/MyInitialView.mxml @@ -0,0 +1,190 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +--> +<js:View xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:js="library://ns.apache.org/flexjs/basic" + xmlns:local="*" + xmlns:acc="org.apache.flex.html.accessories.*" + initComplete="runTests()" +> + + <fx:Style> + .title { + font-size: 16px; + font-weight: bold; + } + .body { + left:10px; + right:10px; + } + </fx:Style> + + <fx:Script> + <![CDATA[ + import org.apache.flex.html.Label; + import org.apache.flex.reflection.VariableDefinition; + import org.apache.flex.reflection.getDefinitionByName; + import org.apache.flex.reflection.describeType; + import org.apache.flex.reflection.TypeDefinition; + + import testshim.FlexJSUnitTestRunner; + import testshim.TestResult; + + + + private var _tests:Array; + + public function runTests():void { + var label:Label; + var groups:Array = TestClasses.testClasses; + var spaces:String = PLATFORM == "JS" ? " " : " "; + while (groups.length) { + var testGroupClass:Class = groups.shift() as Class; + var td:TypeDefinition = describeType(testGroupClass); + label = new Label(); + label.text = "Running " + td.name + " Tests"; + output.addElement(label); + var testClasses:Array = td.variables; + testClasses.sortOn("name"); + var i:uint = 0, l:uint = testClasses.length; + if (l == 0) { + label = new Label(); + label.text = spaces+ "[Zero tests detected]"; + output.addElement(label); + continue; + } + for (; i < l; i++) { + var varDef:VariableDefinition = testClasses[i]; + + var testClass:Class = getDefinitionByName(varDef.type.qualifiedName) as Class; + fails = []; + passes = []; + variances = []; + warnings = []; + var runner:FlexJSUnitTestRunner = new FlexJSUnitTestRunner(testClass, onTestResult); + runner.runTests(); + label = new Label(); + + label.text = "TEST: " + runner.testingName + spaces + "Passed:" + runner.successCount + ", Failed:" + runner.failCount + ", assertions made:" + runner.successfulAssertions; + label.style = {color: runner.failCount == 0 ? "green" : "red"}; + output.addElement(label); + if (runner.failCount > 0 || fails.length) { + //show any failing test details + appendTestResults(fails); + } + if (variances.length) { + appendTestResults(variances); + } + if (warnings.length) { + appendTestResults(warnings); + } + } + } + + } + + + private var fails:Array; + private var passes:Array; + private var variances:Array; + private var warnings:Array; + public function onTestResult(result:TestResult):void { + if (result.pass) passes.push(result); + else fails.push(result); + + if (result.hasVariance && result.pass) { + if (result.varianceTarget.indexOf(PLATFORM) != -1) { + //variance applies to this target + variances.push(result); + } + } + + if (result.warning!=null && result.pass && !result.hasVariance) { + // a test result that would otherwise indicate a pass, but has a warning + warnings.push(result); + } + } + + public function appendTestResults(array:Array):void { + array = array.slice(); + var spaces:String = " "; + var newline:String = "\n" ; + while (array.length) { + var result:TestResult = array.shift(); + var label:Label = new Label(); + //label.x=10; <- fails in js, using 'spaces' below instead + var message:String = spaces + result.toString(newline +spaces); + + if (result.hasVariance) + message = spaces + "VARIANCE:" + result.varianceDescription + newline + message ; + if (result.warning != null) { + message = spaces + result.warning +newline +message; + } + if (PLATFORM == "JS") { + message = escapeForHtml(message); + var jsSpaces:String = spaces.split(" ").join(" "); + message = message.split(spaces).join(jsSpaces); + } + + label.text = message; + + if (result.pass) { + var showOrange:Boolean = false; + if (result.hasVariance || result.warning!=null) showOrange = true; + label.style = {color: showOrange ? 0xFFA500 : "green"}; + } else label.style = {color: "red"}; + output.addElement(label); + } + } + + private static function escapeForHtml( string : String ) : String { + return string.split("<").join("<").split(">").join(">").split("\n").join("<br/>"); + } + + + private static function getPlatform():String { + try { + var check:* = getDefinitionByName("flash.system.Capabilities"); + } catch (e:Error) { + return "JS"; + } + //if this next reference to 'check' is not included, then the above try/catch code + // appears to be optimized away in js-release mode + //[this issue was added to ObservedBugs Tests] + if (check == null) { + return "JS"; + } + return "SWF"; + } + + public static const PLATFORM:String = getPlatform(); + ]]> + </fx:Script> + <js:beads> + <js:ViewDataBinding/> + </js:beads> + <js:Group id="cont" height="50" className="body"> + <js:Label text="{PLATFORM} Cross-compiled Unit Tests" className="title" /> + </js:Group> + <js:Group id="output" height="700" y="50" className="body"> + <js:beads> + <js:VerticalFlexLayout /> + </js:beads> + </js:Group> +</js:View> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/src/main/flex/README.txt ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/src/main/flex/README.txt b/manualtests/UnitTests/src/main/flex/README.txt new file mode 100644 index 0000000..4ef6e3f --- /dev/null +++ b/manualtests/UnitTests/src/main/flex/README.txt @@ -0,0 +1,61 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +DESCRIPTION + +The GenericTests application is a very basic form of unit testing primarily +intended for FlexJS framework developers. It is a 'lite' version of a small portion of +Flexunit code to support basic assertion tests. + +This Flex application may be run as a Flash SWF or cross-compiled (using Falcon JX) +into JavaScript and HTML and run without Flash. + +There is a convenience html page for hosting the tests side-by-side that permits developers +to refresh the test builds simultaneously and compare results in the browser, including the +ability to toggle between JS-Debug and JS-Release builds. +While this is primarily intended for framework developers, it may be useful as a starting point +for cross-compiled unit testing (during development only) in regular FlexJS projects. + +FRAMEWORK DEVELOPER NOTES +To add new tests, follow the examples inside the flexUnitTests package, and add any new Test +group or category level class (the classes directly inside flexUnitTests package) into the top +level TestClasses.as file. This should be all that is necessary to add new tests. + +MetaData +[BeforeClass] -same as flexunit (typical: 'setupBeforClass')- runs a static method before the test class is instantiated +[AfterClass] -same as flexunit (typical: 'tearDownAfterClass')- runs a static method after the test class has been processed +[Before] -same as flexunit (typical: 'setup') - runs an instance method before the test class' test methods are processed +[After] -same as flexunit (typical: 'tearDown') - runs an instance method after the test class' test methods are processed +[Test] -same as flexunit (typical: 'testXXXX') - denotes a test method. No assumption about order of test methods being called should be made + +[TestVariance(variance="JS",description="Reason for variation in JS expected results")] +The above is specific to this test app, and permits annotation of test methods where the expected results are different between compiler targets. +The variance key in the meta data should be either "SWF" or "JS". This is the compiler target with the result that is considered to be different +to what it ideally 'should be', but correct as per the current implementation of the framework. Usually this will be "JS". It indicates a known +but currently acceptable difference between compiler targets. + + +GENERAL NOTES + +In its first working version this app only supports synchronous simple assertions and +is intended to use test classes that are compatible with the flexunit tests that are +used in the full framework build. Future versions may include more advanced features. + +The cross-compilation to JavaScript often results in non-fatal warnings. Some of these warnings +should be addressed in future releases of the Falcon JX compiler. http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/src/main/flex/TestClasses.as ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/src/main/flex/TestClasses.as b/manualtests/UnitTests/src/main/flex/TestClasses.as new file mode 100644 index 0000000..f7273c0 --- /dev/null +++ b/manualtests/UnitTests/src/main/flex/TestClasses.as @@ -0,0 +1,37 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package +{ + //test groups + import flexUnitTests.*; + + + public class TestClasses + { + + public static function get testClasses():Array { + return [ + CoreTester, + ReflectionTester, + ObservedBugsTester, + JiraIssuesTester + ]; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/src/main/flex/UnitTests.mxml ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/src/main/flex/UnitTests.mxml b/manualtests/UnitTests/src/main/flex/UnitTests.mxml new file mode 100644 index 0000000..0db0af9 --- /dev/null +++ b/manualtests/UnitTests/src/main/flex/UnitTests.mxml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<!--- +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +--> +<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:local="*" + xmlns:models="models.*" + xmlns:controllers="controllers.*" + xmlns:js="library://ns.apache.org/flexjs/basic" + > + <fx:Style> + @namespace js "library://ns.apache.org/flexjs/basic"; + js|Application { + background-color:#ffffff ; + } + </fx:Style> + <js:valuesImpl> + <js:SimpleCSSValuesImpl /> + </js:valuesImpl> + <js:initialView> + <local:MyInitialView /> + </js:initialView> +</js:Application> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/src/main/flex/flexUnitTests/CoreTester.as ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/src/main/flex/flexUnitTests/CoreTester.as b/manualtests/UnitTests/src/main/flex/flexUnitTests/CoreTester.as new file mode 100644 index 0000000..9af36e3 --- /dev/null +++ b/manualtests/UnitTests/src/main/flex/flexUnitTests/CoreTester.as @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package flexUnitTests +{ + import flexUnitTests.core.* + + [Suite] + [RunWith("org.flexunit.runners.Suite")] + public class CoreTester + { + public function CoreTester() + { + // for JS, force-link these classes in the output + var arr:Array = [StrandTesterTest, BinaryDataTesterTest]; + } + + // in JS, using a class as a type won't include the class in + // the output since types are not chcked in JS. It is when + // the actual class is referenced that it will be included + // in the output. + // Is there a reason to use reflection to gather the set + // of tests? I would think an array of tests would wokr + // better and allow you to define order. + public var strandTesterTest:StrandTesterTest; + public var binaryDataTesterTest:BinaryDataTesterTest; + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/src/main/flex/flexUnitTests/JiraIssuesTester.as ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/src/main/flex/flexUnitTests/JiraIssuesTester.as b/manualtests/UnitTests/src/main/flex/flexUnitTests/JiraIssuesTester.as new file mode 100644 index 0000000..fc37533 --- /dev/null +++ b/manualtests/UnitTests/src/main/flex/flexUnitTests/JiraIssuesTester.as @@ -0,0 +1,29 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package flexUnitTests +{ + import flexUnitTests.jira.* + + [Suite] + [RunWith("org.flexunit.runners.Suite")] + public class JiraIssuesTester + { + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/src/main/flex/flexUnitTests/ObservedBugsTester.as ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/src/main/flex/flexUnitTests/ObservedBugsTester.as b/manualtests/UnitTests/src/main/flex/flexUnitTests/ObservedBugsTester.as new file mode 100644 index 0000000..11f62e3 --- /dev/null +++ b/manualtests/UnitTests/src/main/flex/flexUnitTests/ObservedBugsTester.as @@ -0,0 +1,33 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package flexUnitTests +{ + import flexUnitTests.observedbugs.* + + [Suite] + [RunWith("org.flexunit.runners.Suite")] + public class ObservedBugsTester + { + public function ObservedBugsTester() + { + var arr:Array = [ObservedBugTests]; + } + public var observedBugsTest1:ObservedBugTests; + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/src/main/flex/flexUnitTests/ReflectionTester.as ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/src/main/flex/flexUnitTests/ReflectionTester.as b/manualtests/UnitTests/src/main/flex/flexUnitTests/ReflectionTester.as new file mode 100644 index 0000000..74c5b4d --- /dev/null +++ b/manualtests/UnitTests/src/main/flex/flexUnitTests/ReflectionTester.as @@ -0,0 +1,38 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package flexUnitTests +{ + import flexUnitTests.reflection.*; + + [Suite] + [RunWith("org.flexunit.runners.Suite")] + public class ReflectionTester + { + public function ReflectionTester() + { + // see notes in CoreTester + var arr:Array = [ReflectionTesterTest, ReflectionTesterTestUseCache, ReflectionTesterTestAlias]; + } + + public var reflectionTesterCacheTest:ReflectionTesterTestUseCache; + public var reflectionTesterTest:ReflectionTesterTest; + + public var reflectionTesterAliasTest:ReflectionTesterTestAlias; + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/523eac21/manualtests/UnitTests/src/main/flex/flexUnitTests/core/BinaryDataTesterTest.as ---------------------------------------------------------------------- diff --git a/manualtests/UnitTests/src/main/flex/flexUnitTests/core/BinaryDataTesterTest.as b/manualtests/UnitTests/src/main/flex/flexUnitTests/core/BinaryDataTesterTest.as new file mode 100644 index 0000000..b10d18c --- /dev/null +++ b/manualtests/UnitTests/src/main/flex/flexUnitTests/core/BinaryDataTesterTest.as @@ -0,0 +1,567 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package flexUnitTests.core +{ + + + import org.apache.flex.utils.Endian; + import flexunit.framework.Assert; + import org.apache.flex.utils.BinaryData + + + public class BinaryDataTesterTest + { + + [Before] + public function setUp():void { + } + + [After] + public function tearDown():void { + } + + [BeforeClass] + public static function setUpBeforeClass():void { + } + + [AfterClass] + public static function tearDownAfterClass():void { + } + + + //util check functions + private static function bytesMatchExpectedData(bd:BinaryData,expected:Array,offset:int=0):Boolean{ + var len:uint = expected.length; + var end:uint=offset+len; + for (var i:int=offset;i<end;i++) { + var check:uint = bd.readByteAt(i); + if (expected[i-offset]!=check) { + // trace('failed at ',i,expected[i-offset],check); + return false; + } + } + return true; + } + + private static function reversedBytesMatch(bd1:BinaryData,bd2:BinaryData,len:uint,offset:int=0):Boolean{ + var end:uint=offset+len; + for (var i:int=offset;i<end;i++) { + if (bd1.readByteAt(i) != bd2.readByteAt(end-1-i)) return false; + } + return true; + + } + + + [Test] + public function testBasicPositionAndLength():void + { + var ba:BinaryData = new BinaryData(); + + Assert.assertEquals("new Instance, position", 0, ba.position); + Assert.assertEquals("new Instance, length", 0, ba.length); + + ba.position=100; + Assert.assertEquals("position change, position", 100, ba.position); + Assert.assertEquals("position change, length", 0, ba.length); + Assert.assertEquals("position change, length", 0, ba.bytesAvailable); + + ba.length=100; + Assert.assertEquals("length change, position", 100, ba.position); + Assert.assertEquals("length change, length", 100, ba.length); + + ba.length=50; + Assert.assertEquals("length change, position", 50, ba.position); + Assert.assertEquals("length change, length", 50, ba.length); + + + } + + [Test] + public function testAdvancedPositionAndLength():void + { + var ba:BinaryData = new BinaryData(); + + ba.position=100; + ba.length=100; + + ba.writeByteAt(49,255); + Assert.assertEquals("writeByteAt does not affect position",100, ba.position); + Assert.assertEquals("writeByteAt (internal) does not affect length",100, ba.length); + + ba.readByteAt(48); + Assert.assertEquals("readByteAt does not affect position",100, ba.position); + Assert.assertEquals("readByteAt does not affect length",100, ba.length); + + ba.writeByteAt(199,255); + Assert.assertEquals("writeByteAt (beyond length) does affect length",200, ba.length); + Assert.assertEquals("writeByteAt (beyond length) does not affect position",100, ba.position); + + Assert.assertStrictlyEquals("out of range byte read request",0 ,ba.readByteAt(205)); + + } + + + [Test] + public function testUTFWritePosition():void + { + var ba:BinaryData = new BinaryData(); + ba.writeUTF('This is a test'); + //writeUTF + Assert.assertEquals("basic post-writeUTF position", 16, ba.position); + ba=new BinaryData(); + ba.writeUTFBytes('This is a test'); + //writeUTFBytes + Assert.assertEquals("basic post-writeUTFBytes position", 14, ba.position); + + //overlapping + ba.position=5; + ba.writeUTFBytes('This is a test'); + Assert.assertEquals("Advanced post-writeUTFBytes position (overlap)", 19, ba.position); + + } + + [Test] + public function testBooleanRoundTripping():void + { + var ba:BinaryData = new BinaryData(); + ba.writeBoolean(true); + ba.writeBoolean(false); + ba.position = 0; + Assert.assertTrue(ba.readBoolean()); + Assert.assertFalse(ba.readBoolean()); + } + + [Test] + public function testByteRoundTripping():void + { + var ba:BinaryData = new BinaryData(); + ba.writeByte(255); + ba.writeByte(256); + ba.writeByte(-256); + ba.writeByte(-257); + ba.writeByte(-128); + ba.writeByte(128); + ba.writeByte(127); + ba.writeByte(-50); + ba.writeByte(50); + ba.position = 0; + + + Assert.assertEquals("Error testing post writeByte/readByte round-tripping", -1, ba.readByte()); + Assert.assertEquals("Error testing post writeByte/readByte round-tripping", 0, ba.readByte()); + Assert.assertEquals("Error testing post writeByte/readByte round-tripping", 0, ba.readByte()); + Assert.assertEquals("Error testing post writeByte/readByte round-tripping", -1, ba.readByte()); + Assert.assertEquals("Error testing post writeByte/readByte round-tripping", -128, ba.readByte()); + Assert.assertEquals("Error testing post writeByte/readByte round-tripping", -128, ba.readByte()); + Assert.assertEquals("Error testing post writeByte/readByte round-tripping", 127, ba.readByte()); + Assert.assertEquals("Error testing post writeByte/readByte round-tripping", -50, ba.readByte()); + Assert.assertEquals("Error testing post writeByte/readByte round-tripping", 50, ba.readByte()); + } + + + [Test] + public function testUnsignedByteRoundTripping():void + { + var ba:BinaryData = new BinaryData(); + ba.writeByte(255); + ba.writeByte(256); + ba.writeByte(-256); + ba.writeByte(-257); + ba.writeByte(-128); + ba.writeByte(128); + ba.writeByte(127); + ba.writeByte(-50); + ba.writeByte(50); + ba.position = 0; + //check read values + + Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", 255, ba.readUnsignedByte()); + Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", 0, ba.readUnsignedByte()); + Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", 0, ba.readUnsignedByte()); + Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", 255, ba.readUnsignedByte()); + Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", 128, ba.readUnsignedByte()); + Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", 128, ba.readUnsignedByte()); + Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", 127, ba.readUnsignedByte()); + Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", 206, ba.readUnsignedByte()); + Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", 50, ba.readUnsignedByte()); + } + + + [Test] + public function testBasicEndian():void + { + + var systemEndian:String = Endian.systemEndian; + //check we have a decisive systemEndian detection + Assert.assertNotNull(systemEndian ); + + + var ba:BinaryData = new BinaryData(); + var defaultEndian:String = ba.endian; + + var alternateEndian:String = (defaultEndian == Endian.BIG_ENDIAN) ? Endian.LITTLE_ENDIAN : Endian.BIG_ENDIAN; + var expected:Object ={}; + expected[Endian.BIG_ENDIAN] = 218038271; + expected[Endian.LITTLE_ENDIAN] = 4294966796; + var bytes:Array = [12, 254, 255, 255]; + for each(var byte:uint in bytes) ba.writeByte(byte); + ba.position = 0; + + Assert.assertEquals("testing endian:"+defaultEndian, expected[defaultEndian] , ba.readUnsignedInt()); + + ba.position = 0; + ba.endian = alternateEndian; + var result:uint = ba.readUnsignedInt(); + + Assert.assertEquals("testing endian:"+alternateEndian, expected[alternateEndian], result); + + ba.position = 0; + ba.endian = defaultEndian; + Assert.assertEquals("testing endian:"+defaultEndian, int(expected[defaultEndian]), ba.readInt()); + + ba.position = 0; + ba.endian = alternateEndian; + Assert.assertEquals("testing endian:"+alternateEndian, int(expected[alternateEndian]), ba.readInt()); + + var leBA:BinaryData = new BinaryData(); + leBA.endian = Endian.LITTLE_ENDIAN; + var beBA:BinaryData = new BinaryData(); + beBA.endian = Endian.BIG_ENDIAN; + //int writing + beBA.writeInt(-500); + leBA.writeInt(-500); + //check they represent reversed byte sequence + Assert.assertTrue(reversedBytesMatch(beBA,leBA,4)); + beBA.position=0; + leBA.position=0; + //check they each read back to the same uint value + Assert.assertEquals('big endian',4294966796,beBA.readUnsignedInt()); + Assert.assertEquals('little endian',4294966796,leBA.readUnsignedInt()); + + beBA.position=0; + leBA.position=0; + //uint writing + beBA.writeUnsignedInt(4294966796); + leBA.writeUnsignedInt(4294966796); + //check they represent reversed byte sequence + Assert.assertTrue(reversedBytesMatch(beBA,leBA,4)); + beBA.position=0; + leBA.position=0; + //check they each read back to the same uint value + Assert.assertEquals('big endian',4294966796,beBA.readUnsignedInt()); + Assert.assertEquals('little endian',4294966796,leBA.readUnsignedInt()); + + + beBA.position=0; + leBA.position=0; + + //check they each read back to the same int value + Assert.assertEquals('big endian',-500,beBA.readInt()); + Assert.assertEquals('little endian',-500,leBA.readInt()); + + + beBA.position=0; + leBA.position=0; + + //short writing + beBA.writeShort(-500); + leBA.writeShort(-500); + //check they represent reversed byte sequence + Assert.assertTrue(reversedBytesMatch(beBA,leBA,2)); + beBA.position=0; + leBA.position=0; + //check they each read back to the same uint value + Assert.assertEquals('big endian',65036,beBA.readUnsignedShort()); + Assert.assertEquals('little endian',65036,leBA.readUnsignedShort()); + + + beBA.position=0; + leBA.position=0; + + //check they each read back to the same int value + Assert.assertEquals('big endian',-500,beBA.readShort()); + Assert.assertEquals('little endian',-500,leBA.readShort()); + + } + + + [Test] + public function testUTFRoundtripping():void + { + + //test big-endian round-tripping + var ba:BinaryData = new BinaryData(); + ba.endian = Endian.BIG_ENDIAN; + ba.writeUTF('This is a test'); + //writeUTF + Assert.assertEquals("basic post-writeUTF position", 16, ba.position); + ba.position = 0; + Assert.assertEquals("utf big endian round-tripping", 'This is a test', ba.readUTF()); + + ba = new BinaryData(); + //test little-endian round-tripping + ba.endian = Endian.LITTLE_ENDIAN; + ba.writeUTF('This is a test'); + //writeUTF + Assert.assertEquals("basic post-writeUTF position", 16, ba.position); + ba.position = 0; + Assert.assertEquals("utf big endian round-tripping", 'This is a test', ba.readUTF()); + + } + + + [Test] + public function testShortRoundTripping():void + { + var ba:BinaryData = new BinaryData(); + //test LITTLE_ENDIAN round-tripping + ba.endian = Endian.LITTLE_ENDIAN; + ba.writeShort(255); + ba.writeShort(-50); + ba.writeShort(50); + ba.position = 0; + + Assert.assertEquals("Error testing post writeShort/readShort round-tripping", 6, ba.length); + Assert.assertEquals("Error testing post writeShort/readShort round-tripping", 255, ba.readShort()); + Assert.assertEquals("Error testing post writeShort/readShort round-tripping", -50, ba.readShort()); + Assert.assertEquals("Error testing post writeShort/readShort round-tripping", 50, ba.readShort()); + + //test BIG_ENDIAN round-tripping + + ba.position = 0; + ba.endian = Endian.BIG_ENDIAN ; + ba.writeShort(255); + ba.writeShort(-50); + ba.writeShort(50); + ba.position = 0; + + Assert.assertEquals("Error testing post writeShort/readShort round-tripping", 6, ba.length); + Assert.assertEquals("Error testing post writeShort/readShort round-tripping", 255, ba.readShort()); + Assert.assertEquals("Error testing post writeShort/readShort round-tripping", -50, ba.readShort()); + Assert.assertEquals("Error testing post writeShort/readShort round-tripping", 50, ba.readShort()); + } + + + [Test] + public function testUnsignedShortRoundTripping():void + { + var ba:BinaryData = new BinaryData(); + //test LITTLE_ENDIAN round-tripping + ba.endian = Endian.LITTLE_ENDIAN; + ba.writeShort(255); + ba.writeShort(-50); + ba.writeShort(50); + ba.position = 0; + + Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", 6, ba.length); + Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", 255, ba.readUnsignedShort()); + Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", 65486, ba.readUnsignedShort()); + Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", 50, ba.readUnsignedShort()); + + //test BIG_ENDIAN round-tripping + + ba.position = 0; + ba.endian = Endian.BIG_ENDIAN ; + ba.writeShort(255); + ba.writeShort(-50); + ba.writeShort(50); + ba.position = 0; + + Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", 6, ba.length); + Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", 255, ba.readUnsignedShort()); + Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", 65486, ba.readUnsignedShort()); + Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", 50, ba.readUnsignedShort()); + } + + [Test] + public function testIntRoundTripping():void + { + var ba:BinaryData = new BinaryData(); + //test LITTLE_ENDIAN round-tripping + ba.endian = Endian.LITTLE_ENDIAN; + ba.writeInt(65536); + ba.writeInt(-50); + ba.writeInt(50); + ba.position = 0; + + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 12, ba.length); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 65536, ba.readInt()); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", -50, ba.readInt()); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 50, ba.readInt()); + + //test BIG_ENDIAN round-tripping + + ba.position = 0; + ba.endian = Endian.BIG_ENDIAN ; + ba.writeInt(65536); + ba.writeInt(-50); + ba.writeInt(50); + ba.position = 0; + + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 12, ba.length); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 65536, ba.readInt()); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", -50, ba.readInt()); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 50, ba.readInt()); + } + + + [Test] + public function testUnsignedIntRoundTripping():void + { + var ba:BinaryData = new BinaryData(); + //test LITTLE_ENDIAN round-tripping + ba.endian = Endian.LITTLE_ENDIAN; + ba.writeUnsignedInt(65536); + ba.writeUnsignedInt(-50); + ba.writeUnsignedInt(50); + ba.position = 0; + + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 12, ba.length); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping",65536, ba.readUnsignedInt()); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 4294967246, ba.readUnsignedInt()); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 50, ba.readUnsignedInt()); + + //test BIG_ENDIAN round-tripping + + ba.position = 0; + ba.endian = Endian.BIG_ENDIAN ; + ba.writeUnsignedInt(65536); + ba.writeUnsignedInt(-50); + ba.writeUnsignedInt(50); + ba.position = 0; + + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 12, ba.length); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping",65536, ba.readUnsignedInt()); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 4294967246, ba.readUnsignedInt()); + Assert.assertEquals("Error testing post writeInt/readInt round-tripping", 50, ba.readUnsignedInt()); + } + + [Test] + public function testFloatRoundTripping():void + { + var ble:BinaryData = new BinaryData(); + //test LITTLE_ENDIAN round-tripping + ble.endian = Endian.LITTLE_ENDIAN; + ble.writeFloat(86.54); + + + Assert.assertEquals("Error testing post writeFloat/readFloat round-tripping", 4, ble.length); + Assert.assertEquals("Error testing post writeFloat/readFloat round-tripping", 4, ble.position); + //check bytes to account for precision loss between double and float comparisons + Assert.assertTrue("Error testing post writeFloat/readFloat round-tripping", bytesMatchExpectedData(ble,[123,20,173,66])); + + var bbe:BinaryData = new BinaryData(); + //test BIG_ENDIAN round-tripping + bbe.endian = Endian.BIG_ENDIAN; + bbe.writeFloat(86.54); + + + Assert.assertEquals("Error testing post writeFloat/readFloat round-tripping", 4, bbe.length); + Assert.assertEquals("Error testing post writeFloat/readFloat round-tripping", 4, bbe.position); + //check bytes to account for precision loss between double and float comparisons + Assert.assertTrue("Error testing post writeFloat/readFloat round-tripping", bytesMatchExpectedData(bbe,[66,173,20,123])); + + + } + + + [Test] + public function testDoubleRoundTripping():void + { + + var ble:BinaryData = new BinaryData(); + //test LITTLE_ENDIAN round-tripping + ble.endian = Endian.LITTLE_ENDIAN; + ble.writeDouble(86.54); + + + Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", 8, ble.length); + Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", 8, ble.position); + + //check bytes + Assert.assertTrue("Error testing post writeDouble/readDouble round-tripping", bytesMatchExpectedData(ble,[195,245,40,92,143,162,85,64])); + + var bbe:BinaryData = new BinaryData(); + //test BIG_ENDIAN round-tripping + bbe.endian = Endian.BIG_ENDIAN; + bbe.writeDouble(86.54); + + + Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", 8, bbe.length); + Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", 8, bbe.position); + //check bytes + + Assert.assertTrue("Error testing post writeDouble/readDouble round-tripping", bytesMatchExpectedData(bbe,[64,85,162,143,92,40,245,195])); + + + ble.position = 0; + bbe.position = 0; + Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", 86.54, bbe.readDouble()); + Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", 86.54, ble.readDouble()); + + Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", 8, bbe.position); + Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", 8, ble.position); + + } + + + + [Test] + public function testWriteBytes():void + { + var ba:BinaryData = new BinaryData(); + for (var i:int=0;i<50;i++) ba.writeByte(i); + + + var newBa:BinaryData = new BinaryData(); + newBa.writeBytes(ba); + + Assert.assertEquals("BinaryData writeBytes: length", 50, newBa.length); + Assert.assertEquals("BinaryData writeBytes: position", 50, newBa.position); + + for (i=0;i<50;i++) { + Assert.assertEquals("BinaryData writeBytes: content check", i, newBa.array[i]); + } + + + + } + + [Test] + public function testReadBytes():void + { + var ba:BinaryData = new BinaryData(); + for (var i:int=0;i<50;i++) ba.writeByte(i); + ba.position=0; + var newBa:BinaryData = new BinaryData(); + + ba.readBytes(newBa,5,10); + Assert.assertEquals("BinaryData readBytes: position", 10, ba.position); + Assert.assertEquals("BinaryData readBytes: length", 15, newBa.length); + Assert.assertEquals("BinaryData readBytes: position", 0, newBa.position); + var expected:Array = [0,0,0,0,0,0,1,2,3,4,5,6,7,8,9]; + for (i=5;i<15;i++) { + Assert.assertEquals("BinaryData readBytes: content check", expected[i], newBa.array[i]); + } + } + + + } +}
