Migrate AllCharAttributeTest to Flex Unit 4

Project: http://git-wip-us.apache.org/repos/asf/flex-tlf/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-tlf/commit/2b0067b7
Tree: http://git-wip-us.apache.org/repos/asf/flex-tlf/tree/2b0067b7
Diff: http://git-wip-us.apache.org/repos/asf/flex-tlf/diff/2b0067b7

Branch: refs/heads/develop
Commit: 2b0067b7de49ec926def1d65711c95917d2dc89e
Parents: 98bebb2
Author: piotrz <[email protected]>
Authored: Mon May 26 23:15:38 2014 +0200
Committer: piotrz <[email protected]>
Committed: Mon May 26 23:15:38 2014 +0200

----------------------------------------------------------------------
 automation_tests/src/AllTestsSuite.as           |   3 +
 automation_tests/src/AutomationTestClasses.as   |   2 +-
 .../src/UnitTest/Tests/AllAttributeTest.as      | 691 +++++++++++--------
 .../src/UnitTest/Tests/AllCharAttributeTest.as  | 136 ++--
 4 files changed, 435 insertions(+), 397 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/2b0067b7/automation_tests/src/AllTestsSuite.as
----------------------------------------------------------------------
diff --git a/automation_tests/src/AllTestsSuite.as 
b/automation_tests/src/AllTestsSuite.as
index ab31501..2134fcd 100644
--- a/automation_tests/src/AllTestsSuite.as
+++ b/automation_tests/src/AllTestsSuite.as
@@ -20,6 +20,7 @@ package
 {
 
     import UnitTest.Tests.AccessibilityMethodsTest;
+    import UnitTest.Tests.AllCharAttributeTest;
     import UnitTest.Tests.AllEventTest;
     import UnitTest.Tests.AttributeTest;
     import UnitTest.Tests.BoxTest;
@@ -40,6 +41,8 @@ package
         public var floatTest:FloatTest;
         public var operationTest:OperationTest;
         public var scrollingTest:ScrollingTest;
+        public var allAttributeTest:AllCharAttributeTest;
+      //  public var allParagraphTest:AllParaAttributeTest;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/2b0067b7/automation_tests/src/AutomationTestClasses.as
----------------------------------------------------------------------
diff --git a/automation_tests/src/AutomationTestClasses.as 
b/automation_tests/src/AutomationTestClasses.as
index db74742..3079ccf 100644
--- a/automation_tests/src/AutomationTestClasses.as
+++ b/automation_tests/src/AutomationTestClasses.as
@@ -35,7 +35,7 @@ package
                                                             */
                import AllTestsSuite; AllTestsSuite;
         import MinimalTestsSuite; MinimalTestsSuite;
-        import UnitTest.Tests.AccessibilityMethodsTest; 
AccessibilityMethodsTest;
+       // import UnitTest.Tests.AccessibilityMethodsTest; 
AccessibilityMethodsTest;
                /*import UnitTest.Tests.AllAttributeTest; AllAttributeTest;
                import UnitTest.Tests.AllCharAttributeTest; 
AllCharAttributeTest;
                import UnitTest.Tests.AllContAttributeTest; 
AllContAttributeTest;

http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/2b0067b7/automation_tests/src/UnitTest/Tests/AllAttributeTest.as
----------------------------------------------------------------------
diff --git a/automation_tests/src/UnitTest/Tests/AllAttributeTest.as 
b/automation_tests/src/UnitTest/Tests/AllAttributeTest.as
index 44bca88..4402025 100644
--- a/automation_tests/src/UnitTest/Tests/AllAttributeTest.as
+++ b/automation_tests/src/UnitTest/Tests/AllAttributeTest.as
@@ -18,310 +18,397 @@
 
////////////////////////////////////////////////////////////////////////////////
 package UnitTest.Tests
 {
-       import UnitTest.ExtendedClasses.TestDescriptor;
-       import UnitTest.ExtendedClasses.TestSuiteExtended;
-       import UnitTest.ExtendedClasses.VellumTestCase;
-       import UnitTest.Fixtures.TestConfig;
-       
-       import flash.display.Sprite;
-       
-       import flashx.textLayout.debug.assert;
-       import flashx.textLayout.formats.Category;
-       import flashx.textLayout.formats.FormatValue;
-       import flashx.textLayout.formats.TextLayoutFormat;
-       import flashx.textLayout.property.*;
+    import UnitTest.ExtendedClasses.VellumTestCase;
+    import UnitTest.Fixtures.TestConfig;
+
+    import flash.display.Sprite;
+
+    import flashx.textLayout.elements.FlowLeafElement;
+    import flashx.textLayout.elements.TextFlow;
+    import flashx.textLayout.formats.Category;
+    import flashx.textLayout.formats.FormatValue;
+    import flashx.textLayout.formats.TextLayoutFormat;
+    import flashx.textLayout.property.*;
 
     import org.flexunit.asserts.assertTrue;
 
     /** Base class for All*AttributeTest */
-       public class AllAttributeTest extends VellumTestCase
-       {
-               // test specific configuration
-               protected var testProp:Property;
-               protected var testValue:*;
-               protected var expectedValue:*;
-
-               public function AllAttributeTest(methodName:String, 
testID:String, testConfig:TestConfig, prop:Property, testValue:*, 
expectedValue:*)
-               {
-                       super (methodName, testID, testConfig);
-
-                       // assert(testValue != null,"null?");
-                       testProp = prop;
-                       this.testValue = testValue;
-                       this.expectedValue = expectedValue;
-
-                       // Note: These must correspond to a Watson product area 
(case-sensitive)
-                       metaData.productArea = "Text Attributes";
-               }
-
-               /* 
************************************************************** */
-               /* Use Format description and Property classes to generate 
testcases for Format in description
-               /* 
************************************************************** */
-
-               /** Build testcases for all properties in the description. 
Depending on the property type iterate over possible values and test. */
-               static internal function 
testAllProperties(ts:TestSuiteExtended, testConfig:TestConfig, 
description:Object, category:String, testClass:Class, methodName:String):void
-               {
-                       testAllNumberPropsFromMinToMax(ts, testConfig, 
description, category, testClass, methodName);
-                       testAllIntPropsFromMinToMax(ts, testConfig, 
description, category, testClass, methodName);
-                       testAllNumberOrPercentPropsFromMinToMax(ts, testConfig, 
description, category, testClass, methodName);
-                       testAllBooleanProps(ts, testConfig, description, 
category, testClass, methodName);
-                       testAllEnumProps(ts, testConfig, description, category, 
testClass, methodName);
-                       testAllSharedValues(ts, testConfig, description, 
category, testClass, methodName);
-               }
-
-               /**
-                * This builds testcases for properties in description that are 
Number types.  For each number property
-                * testcases are built to set the value to the below the 
minimum value, step from the minimum value to the maximum value
-                * and then above the maximum value.
-                */
-               static internal function 
testAllNumberPropsFromMinToMax(ts:TestSuiteExtended, testConfig:TestConfig, 
description:Object, category:String, testClass:Class, methodName:String):void
-               {
-                       for each (var prop:Property in description)
-                       {
-                               var handler:NumberPropertyHandler = 
prop.findHandler(NumberPropertyHandler) as NumberPropertyHandler;
-                               
-                               if (handler && prop.category == category)
-                               {
-                                       var minVal:Number = handler.minValue;
-                                       var maxVal:Number = handler.maxValue;
-                                       assertTrue(true, minVal < maxVal);
-                                       var delta:Number = (maxVal-minVal)/10;
-                                       var includeInMinimalTestSuite:Boolean;
-
-                                       for (var value:Number = minVal-delta;;)
-                                       {
-                                               var expectedValue:* = value < 
minVal ? undefined : (value > maxVal ? undefined : value);
-
-                                               // include in the minmalTest 
values below the range, min value, max value and values above the range
-                                               includeInMinimalTestSuite = 
(value <= minVal || value >= maxVal)
-
-                                               ts.addTestDescriptor( new 
TestDescriptor (testClass, methodName, testConfig, null, prop, value, 
expectedValue, includeInMinimalTestSuite) );
-
-                                               if (value > maxVal)
-                                                       break;
-                                               value += delta;
-                                       }
-                               }
-                       }
-               }
-               /**
-                * This builds testcases for properties in attributes in 
description that are Int types.  For each number property
-                * testcases are built to set the value to the below the 
minimum value, step from the minimum value to the maximum value
-                * and then above the maximum value.
-                */
-               static internal function 
testAllIntPropsFromMinToMax(ts:TestSuiteExtended, testConfig:TestConfig, 
description:Object, category:String, testClass:Class, methodName:String):void
-               {
-                       for each (var prop:Property in description)
-                       {
-                               if (prop.category == category)
-                               {
-                                       var handler:IntPropertyHandler = 
prop.findHandler(IntPropertyHandler) as IntPropertyHandler;
-                                       if (handler)
-                                       {
-                                               var minVal:int = 
handler.minValue;
-                                               var maxVal:int = 
handler.maxValue;
-                                               assertTrue(true, minVal < 
maxVal);
-                                               var delta:int = 
(maxVal-minVal)/10;
-                                               var 
includeInMinimalTestSuite:Boolean;
-       
-                                               for (var value:Number = 
minVal-delta;;)
-                                               {
-                                                       var expectedValue:* = 
value < minVal ? undefined : (value > maxVal ? undefined : value);
-       
-                                                       // include in the 
minmalTest values below the range, min value, max value and values above the 
range
-                                                       
includeInMinimalTestSuite = (value <= minVal || value >= maxVal)
-       
-                                                       ts.addTestDescriptor( 
new TestDescriptor (testClass, methodName, testConfig, null, prop, value, 
expectedValue, includeInMinimalTestSuite) );
-       
-                                                       if (value > maxVal)
-                                                               break;
-                                                       value += delta;
-                                               }
-                                       }
-                               }
-                       }
-               }
-               /**
-                * This builds testcases for properties in description that are 
NumberOrPercent types.  For each number property
-                * testcases are built to set the value to the below the 
minimum value, step from the minimum value to the maximum value
-                * and then above the maximum value.  This is done first using 
the min/max number values and then the min/max percent values.
-                */
-               static internal function 
testAllNumberOrPercentPropsFromMinToMax(ts:TestSuiteExtended, 
testConfig:TestConfig, description:Object, category:String, testClass:Class, 
methodName:String):void
-               {
-                       for each (var prop:Property in description)
-                       {
-                               if (prop.category == category)
-                               {
-                                       var numberHandler:NumberPropertyHandler 
= prop.findHandler(NumberPropertyHandler) as NumberPropertyHandler;
-                                       var 
percentHandler:PercentPropertyHandler = 
prop.findHandler(PercentPropertyHandler) as PercentPropertyHandler;
-                                       if (numberHandler && percentHandler)
-                                       {
-                                               var minVal:Number = 
numberHandler.minValue;
-                                               var maxVal:Number = 
numberHandler.maxValue;
-                                               assertTrue(true, minVal < 
maxVal);
-                                               var delta:Number = 
(maxVal-minVal)/10;
-                                               var 
includeInMinimalTestSuite:Boolean;
-       
-                                               for (var value:Number = 
minVal-delta;;)
-                                               {
-                                                       var expectedValue:* = 
value < minVal ? undefined : (value > maxVal ? undefined : value);
-       
-                                                       // include in the 
minmalTest values below the range, min value, max value and values above the 
range
-                                                       
includeInMinimalTestSuite = (value <= minVal || value >= maxVal)
-       
-                                                       ts.addTestDescriptor( 
new TestDescriptor (testClass, methodName, testConfig, null, prop, value, 
expectedValue, includeInMinimalTestSuite) );
-       
-                                                       if (value > maxVal)
-                                                               break;
-                                                       value += delta;
-                                               }
-
-                                               // repeat with percent values
-                                               minVal = 
percentHandler.minValue;
-                                               maxVal = 
percentHandler.maxValue;
-                                               assertTrue(true, minVal < 
maxVal);
-                                               delta = (maxVal-minVal)/10;
-       
-                                               for (value = minVal-delta;;)
-                                               {
-                                                       expectedValue = value < 
minVal ? undefined : (value > maxVal ? undefined : value.toString()+"%");
-                                                       ts.addTestDescriptor( 
new TestDescriptor (testClass, methodName, testConfig, null, prop, 
value.toString()+"%", expectedValue, true) );
-       
-                                                       if (value > maxVal)
-                                                               break;
-                                                       value += delta;
-                                               }
-                                       }
-                               }
-                       }
-               }
-               /**
-                * This builds testcases for properties in attributes in 
description that are Boolean types.  A testcase is generated
-                * for true and false for the value.
-                */
-               static internal function 
testAllBooleanProps(ts:TestSuiteExtended, testConfig:TestConfig, 
description:Object, category:String, testClass:Class, methodName:String):void
-               {
-                       for each (var prop:Property in description)
-                       {
-                               if (prop.category == category && 
prop.findHandler(BooleanPropertyHandler) != null)
-                               {
-                                       ts.addTestDescriptor( new 
TestDescriptor (testClass, methodName, testConfig, null, prop, true, true, 
true) );
-                                       ts.addTestDescriptor( new 
TestDescriptor (testClass, methodName, testConfig, null, prop, false, false, 
true) );
-                               }
-                       }
-               }
-
-               /**
-                * This builds testcases for properties in attributes in 
description that are Enumerated types types.  A testcase is generated
-                * for each possible enumerated value
-                */
-               static internal function testAllEnumProps(ts:TestSuiteExtended, 
testConfig:TestConfig, description:Object, category:String, testClass:Class, 
methodName:String):void
-               {
-                       var range:Object;
-                       var value:Object;
-                       
-                       for each (var prop:Property in description)
-                       {
-                               // new code
-                               if (prop.category == category)
-                               {
-                                       var handler:EnumPropertyHandler = 
prop.findHandler(EnumPropertyHandler) as EnumPropertyHandler;
-                                       if (handler)
-                                       {
-                                               range = handler.range;
-                                               for (value in range)
-                                               {
-                                                       if ( value != 
FormatValue.INHERIT )
-                                                               
ts.addTestDescriptor( new TestDescriptor (testClass, methodName, testConfig, 
null, prop, value, value, true) );
-                                               }
-                                               ts.addTestDescriptor( new 
TestDescriptor (testClass, methodName, testConfig, null, prop, "foo", 
undefined, true) );
-                                       }
-                                       
-                               }
-                       }
-               }
-               /**
-                * This builds testcases for setting all properties in 
description to inherit, null, undefined and an object.
-                */
-               static internal function 
testAllSharedValues(ts:TestSuiteExtended, testConfig:TestConfig, 
description:Object, category:String, testClass:Class, methodName:String):void
-               {
-                       for each (var prop:Property in description)
-                       {
-                               if (prop.category == category)
-                               {
-                                       ts.addTestDescriptor( new 
TestDescriptor (testClass, methodName, testConfig, null, prop, 
FormatValue.INHERIT, FormatValue.INHERIT, true) );
-                                       // try an object, null and undefined
-                                       ts.addTestDescriptor( new 
TestDescriptor (testClass, methodName, testConfig, null, prop, new Sprite(), 
undefined, false) );
-                                       ts.addTestDescriptor( new 
TestDescriptor (testClass, methodName, testConfig, null, prop, null, undefined, 
false) );
-                                       ts.addTestDescriptor( new 
TestDescriptor (testClass, methodName, testConfig, null, prop, undefined, 
undefined, false) );
-                                       ts.addTestDescriptor( new 
TestDescriptor (testClass,"clearFormatTest", testConfig, null, prop, undefined, 
undefined, false));
-                               }
-                       }
-               }
-
-               public function clearFormatTest():void
-               {
-                       SelManager.selectAll();
-
-                       var applyFormat:TextLayoutFormat  = new 
TextLayoutFormat();
-                       applyFormat[testProp.name] =  testProp.defaultValue;
-                       var clearFormat:TextLayoutFormat  = new 
TextLayoutFormat();
-                       clearFormat[testProp.name] =  FormatValue.INHERIT;
-
-                       switch(testProp.category)
-                       {
-                               case Category.CHARACTER:
-                                       
SelManager.applyFormat(applyFormat,null,null);
-                                       
AllCharAttributeTest.validateCharacterPropertyOnEntireFlow(SelManager.textFlow,testProp,testProp.defaultValue);
-                                       
SelManager.clearFormat(clearFormat,null,null);
-                                       
AllCharAttributeTest.validateCharacterPropertyOnEntireFlow(SelManager.textFlow,testProp,undefined);
-                                       break;
-                               case Category.PARAGRAPH:
-                                       
SelManager.applyFormat(null,applyFormat,null);
-                                       
AllParaAttributeTest.validateParagraphPropertyOnEntireFlow(SelManager.textFlow,testProp,testProp.defaultValue);
-                                       
SelManager.clearFormat(null,clearFormat,null);
-                                       
AllParaAttributeTest.validateParagraphPropertyOnEntireFlow(SelManager.textFlow,testProp,undefined);
-                                       break;
-                               case Category.CONTAINER:
-                                       
SelManager.applyFormat(null,null,applyFormat);
-                                       
AllContAttributeTest.validateContainerPropertyOnEntireFlow(SelManager.textFlow,testProp,testProp.defaultValue);
-                                       
SelManager.clearFormat(null,null,clearFormat);
-                                       
AllContAttributeTest.validateContainerPropertyOnEntireFlow(SelManager.textFlow,testProp,undefined);
-                                       break;
-                       }
-               }
-
-               private var errorHandlerCount:int = 0;
-               public function errorHandler(p:Property,value:Object):void
-               {
-                       errorHandlerCount++;
-               }
-
-               protected function assignmentHelper(target:Object):void
-               {
-                       Property.errorHandler = errorHandler;
-                       errorHandlerCount = 0;
-                       try {
-                               target[testProp.name] = testValue;
-                       }
-                       catch (e:Error)
-                       {
-                               Property.errorHandler = 
Property.defaultErrorHandler;
-                               assertTrue("Unexpected error in 
AllAttributeTest.assignmentHelper", false);
-                               throw(e);
-                       }
-                       Property.errorHandler = Property.defaultErrorHandler;
-
-                       if (expectedValue == undefined && testValue != 
undefined)
-                       {
-                               // expect an error
-                               assertTrue("Error expected but no error in 
AllAttributeTest.assignmentHelper",errorHandlerCount == 1);
-                       }
-                       else
-                       {
-                               // no error
-                               assertTrue("Error not expected but error found 
in AllAttributeTest.assignmentHelper",errorHandlerCount == 0);
-                       }
-               }
-       }
+    public class AllAttributeTest extends VellumTestCase
+    {
+        // test specific configuration
+        protected var testProp:Property;
+        protected var testValue:*;
+        protected var expectedValue:*;
+        protected var description:Object;
+        protected var category:String;
+
+        public function AllAttributeTest(methodName:String, testID:String, 
testConfig:TestConfig, prop:Property, testValue:*, expectedValue:*)
+        {
+            super(methodName, testID, testConfig);
+
+            // assert(testValue != null,"null?");
+            testProp = prop;
+            this.testValue = testValue;
+            this.expectedValue = expectedValue;
+            metaData = {};
+            // Note: These must correspond to a Watson product area 
(case-sensitive)
+            metaData.productArea = "Text Attributes";
+        }
+
+        /**
+         * This builds testcases for properties in description that are Number 
types.  For each number property
+         * testcases are built to set the value to the below the minimum 
value, step from the minimum value to the maximum value
+         * and then above the maximum value.
+         */
+        protected function 
testAllNumberPropsFromMinToMax(testConfig:TestConfig, description:Object, 
category:String):void
+        {
+            for each (testProp in description)
+            {
+                var handler:NumberPropertyHandler = 
testProp.findHandler(NumberPropertyHandler) as NumberPropertyHandler;
+
+                if (handler && testProp.category == category)
+                {
+                    var minVal:Number = handler.minValue;
+                    var maxVal:Number = handler.maxValue;
+                    assertTrue(true, minVal < maxVal);
+                    var delta:Number = (maxVal - minVal) / 10;
+                    var includeInMinimalTestSuite:Boolean;
+
+                    for (var value:Number = minVal - delta; ;)
+                    {
+                        expectedValue = value < minVal ? undefined : (value > 
maxVal ? undefined : value);
+                        testValue = value;
+                        // include in the minmalTest values below the range, 
min value, max value and values above the range
+                        includeInMinimalTestSuite = (value <= minVal || value 
>= maxVal)
+
+                        runOneCharacterAttributeTest();
+
+                        if (value > maxVal)
+                            break;
+                        value += delta;
+                    }
+                }
+            }
+        }
+
+        /**
+         * This builds testcases for properties in attributes in description 
that are Int types.  For each number property
+         * testcases are built to set the value to the below the minimum 
value, step from the minimum value to the maximum value
+         * and then above the maximum value.
+         */
+        protected function testAllIntPropsFromMinToMax(testConfig:TestConfig, 
description:Object, category:String):void
+        {
+            for each (testProp in description)
+            {
+                if (testProp.category == category)
+                {
+                    var handler:IntPropertyHandler = 
testProp.findHandler(IntPropertyHandler) as IntPropertyHandler;
+                    if (handler)
+                    {
+                        var minVal:int = handler.minValue;
+                        var maxVal:int = handler.maxValue;
+                        assertTrue(true, minVal < maxVal);
+                        var delta:int = (maxVal - minVal) / 10;
+                        var includeInMinimalTestSuite:Boolean;
+
+                        for (var value:Number = minVal - delta; ;)
+                        {
+                            expectedValue = value < minVal ? undefined : 
(value > maxVal ? undefined : value);
+                            testValue = value;
+                            // include in the minmalTest values below the 
range, min value, max value and values above the range
+                            includeInMinimalTestSuite = (value <= minVal || 
value >= maxVal)
+
+                            runOneCharacterAttributeTest();
+
+                            if (value > maxVal)
+                                break;
+                            value += delta;
+                        }
+                    }
+                }
+            }
+        }
+
+        /**
+         * This builds testcases for properties in description that are 
NumberOrPercent types.  For each number property
+         * testcases are built to set the value to the below the minimum 
value, step from the minimum value to the maximum value
+         * and then above the maximum value.  This is done first using the 
min/max number values and then the min/max percent values.
+         */
+        protected function 
testAllNumberOrPercentPropsFromMinToMax(testConfig:TestConfig, 
description:Object, category:String):void
+        {
+            for each (testProp in description)
+            {
+                if (testProp.category == category)
+                {
+                    var numberHandler:NumberPropertyHandler = 
testProp.findHandler(NumberPropertyHandler) as NumberPropertyHandler;
+                    var percentHandler:PercentPropertyHandler = 
testProp.findHandler(PercentPropertyHandler) as PercentPropertyHandler;
+                    if (numberHandler && percentHandler)
+                    {
+                        var minVal:Number = numberHandler.minValue;
+                        var maxVal:Number = numberHandler.maxValue;
+                        assertTrue(true, minVal < maxVal);
+                        var delta:Number = (maxVal - minVal) / 10;
+                        var includeInMinimalTestSuite:Boolean;
+
+                        for (var value:Number = minVal - delta; ;)
+                        {
+                            expectedValue = value < minVal ? undefined : 
(value > maxVal ? undefined : value);
+                            testValue = value;
+
+                            // include in the minmalTest values below the 
range, min value, max value and values above the range
+                            includeInMinimalTestSuite = (value <= minVal || 
value >= maxVal)
+
+                            runOneCharacterAttributeTest();
+                            //ts.addTestDescriptor( new TestDescriptor 
(testClass, methodName, testConfig, null, prop, value, expectedValue, 
includeInMinimalTestSuite) );
+
+                            if (value > maxVal)
+                                break;
+                            value += delta;
+                        }
+
+                        // repeat with percent values
+                        minVal = percentHandler.minValue;
+                        maxVal = percentHandler.maxValue;
+                        assertTrue(true, minVal < maxVal);
+                        delta = (maxVal - minVal) / 10;
+
+                        for (value = minVal - delta; ;)
+                        {
+                            expectedValue = value < minVal ? undefined : 
(value > maxVal ? undefined : value.toString() + "%");
+                            //ts.addTestDescriptor( new TestDescriptor 
(testClass, methodName, testConfig, null, prop, value.toString()+"%", 
expectedValue, true) );
+
+                            testValue = value.toString() + "%";
+
+                            runOneCharacterAttributeTest();
+
+                            if (value > maxVal)
+                                break;
+                            value += delta;
+                        }
+                    }
+                }
+            }
+        }
+
+        /**
+         * This builds testcases for properties in attributes in description 
that are Boolean types.  A testcase is generated
+         * for true and false for the value.
+         */
+        protected function testAllBooleanProps(testConfig:TestConfig, 
description:Object, category:String):void
+        {
+            for each (testProp in description)
+            {
+                if (testProp.category == category && 
testProp.findHandler(BooleanPropertyHandler) != null)
+                {
+                    expectedValue = testValue = true;
+                    runOneCharacterAttributeTest();
+
+                    expectedValue = testValue = false;
+                    runOneCharacterAttributeTest();
+                }
+            }
+        }
+
+        /**
+         * This builds testcases for properties in attributes in description 
that are Enumerated types types.  A testcase is generated
+         * for each possible enumerated value
+         */
+        protected function testAllEnumProps(testConfig:TestConfig, 
description:Object, category:String):void
+        {
+            var range:Object = null;
+            var value:Object = null;
+
+            for each (testProp in description)
+            {
+                // new code
+                if (testProp.category == category)
+                {
+                    var handler:EnumPropertyHandler = 
testProp.findHandler(EnumPropertyHandler) as EnumPropertyHandler;
+                    if (handler)
+                    {
+                        range = handler.range;
+                        for (value in range)
+                        {
+                            if (value != FormatValue.INHERIT)
+                            {
+                                expectedValue = testValue = value;
+                                runOneCharacterAttributeTest();
+                            }
+                        }
+                        expectedValue = undefined;
+                        testValue = "foo";
+                        runOneCharacterAttributeTest();
+                    }
+
+                }
+            }
+        }
+
+        /**
+         * This builds testcases for setting all properties in description to 
inherit, null, undefined and an object.
+         */
+        protected function testAllSharedValues(testConfig:TestConfig, 
description:Object, category:String):void
+        {
+            for each (testProp in description)
+            {
+                if (testProp.category == category)
+                {
+
+                    testValue = expectedValue = FormatValue.INHERIT;
+                    runOneCharacterAttributeTest();
+
+                    testValue = new Sprite();
+                    expectedValue = undefined;
+                    runOneCharacterAttributeTest();
+
+                    testValue = null;
+                    expectedValue = undefined;
+                    runOneCharacterAttributeTest();
+
+                    testValue = expectedValue = undefined;
+                    runOneCharacterAttributeTest();
+
+                    testValue = expectedValue = undefined;
+                    clearFormatTest();
+                }
+            }
+        }
+
+        public function clearFormatTest():void
+        {
+            SelManager.selectAll();
+
+            var applyFormat:TextLayoutFormat = new TextLayoutFormat();
+            applyFormat[testProp.name] = testProp.defaultValue;
+            var clearFormat:TextLayoutFormat = new TextLayoutFormat();
+            clearFormat[testProp.name] = FormatValue.INHERIT;
+
+            switch (testProp.category)
+            {
+                case Category.CHARACTER:
+                    SelManager.applyFormat(applyFormat, null, null);
+                    validateCharacterPropertyOnEntireFlow(SelManager.textFlow, 
testProp, testProp.defaultValue);
+                    SelManager.clearFormat(clearFormat, null, null);
+                    validateCharacterPropertyOnEntireFlow(SelManager.textFlow, 
testProp, undefined);
+                    break;
+                case Category.PARAGRAPH:
+                    SelManager.applyFormat(null, applyFormat, null);
+                  //  
AllParaAttributeTest.validateParagraphPropertyOnEntireFlow(SelManager.textFlow, 
testProp, testProp.defaultValue);
+                    SelManager.clearFormat(null, clearFormat, null);
+                   // 
AllParaAttributeTest.validateParagraphPropertyOnEntireFlow(SelManager.textFlow, 
testProp, undefined);
+                    break;
+                case Category.CONTAINER:
+                    SelManager.applyFormat(null, null, applyFormat);
+                    
AllContAttributeTest.validateContainerPropertyOnEntireFlow(SelManager.textFlow, 
testProp, testProp.defaultValue);
+                    SelManager.clearFormat(null, null, clearFormat);
+                    
AllContAttributeTest.validateContainerPropertyOnEntireFlow(SelManager.textFlow, 
testProp, undefined);
+                    break;
+            }
+        }
+
+        private var errorHandlerCount:int = 0;
+
+        public function errorHandler(p:Property, value:Object):void
+        {
+            errorHandlerCount++;
+        }
+
+        protected function assignmentHelper(target:Object):void
+        {
+            Property.errorHandler = errorHandler;
+            errorHandlerCount = 0;
+            try
+            {
+                target[testProp.name] = testValue;
+            }
+            catch (e:Error)
+            {
+                Property.errorHandler = Property.defaultErrorHandler;
+                assertTrue("Unexpected error in 
AllAttributeTest.assignmentHelper", false);
+                throw(e);
+            }
+            Property.errorHandler = Property.defaultErrorHandler;
+
+            if (expectedValue == undefined && testValue != undefined)
+            {
+                // expect an error
+                assertTrue("Error expected but no error in 
AllAttributeTest.assignmentHelper", errorHandlerCount == 1);
+            }
+            else
+            {
+                // no error
+                assertTrue("Error not expected but error found in 
AllAttributeTest.assignmentHelper", errorHandlerCount == 0);
+            }
+        }
+
+
+        /**
+         * Generic function to run one character attribute test.  Uses the 
selection manager to set the attributes on the entire flow at the span level
+         * to value and then validates that the value is expectedValue.
+         */
+        private function runOneCharacterAttributeTest():void
+        {
+            if (testProp == null)
+                return;        // must be set
+
+            SelManager.selectAll();
+
+            // Test direct change on single leaf
+            var leaf:FlowLeafElement = 
SelManager.textFlow.findLeaf(SelManager.absoluteStart);
+            var originalValue:* = leaf[testProp.name];
+
+            assignmentHelper(leaf);
+
+            var expectedResult:*;
+            if (expectedValue === undefined)
+                expectedResult = testValue === undefined || testValue === null 
? undefined : originalValue;
+            else
+                expectedResult = expectedValue;
+
+            assertTrue("FlowLeafElement does not have the expected value after 
direct change", leaf[testProp.name] == expectedResult);
+            leaf[testProp.name] = originalValue;
+
+            var ca:TextLayoutFormat = new TextLayoutFormat();
+            assignmentHelper(ca);
+            SelManager.applyLeafFormat(ca);
+
+            // expect that all FlowLeafElements have expectedValue as the 
properties value
+            if (expectedValue !== undefined)
+                assertTrue("not all FlowLeafElements have the expected value", 
validateCharacterPropertyOnEntireFlow(SelManager.textFlow, testProp, 
expectedValue));
+        }
+
+
+        // support function to walk all FlowLeafElements and verify that prop 
is val
+        private function 
validateCharacterPropertyOnEntireFlow(textFlow:TextFlow, prop:Property, 
val:*):Boolean
+        {
+            var idx:int = 0;
+            var elem:FlowLeafElement = textFlow.getFirstLeaf();
+            assertTrue("either the first FlowLeafElement is null or the 
textFlow length is zero", elem != null || textFlow.textLength == 0);
+            while (elem)
+            {
+                // error if elements have zero length
+                assertTrue("The FlowLeafElement has zero length", 
elem.textLength != 0);
+
+                // expect all values of prop to be supplied val
+                if (elem.format[prop.name] !== val || elem[prop.name] !== val)
+                    return false;
+
+                // inherit is never computed
+                if ((val == FormatValue.INHERIT && 
elem.computedFormat[prop.name] == val) || elem.computedFormat[prop.name] === 
undefined)
+                    return false;
+
+                // skip to the next element
+                var nextElem:FlowLeafElement = elem.getNextLeaf();
+                var absoluteEnd:int = elem.getAbsoluteStart() + 
elem.textLength;
+                if (nextElem == null)
+                    assertTrue("absoluteEnd of the last FlowLeafElement is not 
the end of the textFlow", absoluteEnd == textFlow.textLength);
+                else
+                    assertTrue("the end of this FlowLeafElement does not equal 
the start of the next", absoluteEnd == nextElem.getAbsoluteStart());
+
+                elem = nextElem;
+            }
+            return true;
+        }
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/2b0067b7/automation_tests/src/UnitTest/Tests/AllCharAttributeTest.as
----------------------------------------------------------------------
diff --git a/automation_tests/src/UnitTest/Tests/AllCharAttributeTest.as 
b/automation_tests/src/UnitTest/Tests/AllCharAttributeTest.as
index ff0596e..a9e1561 100644
--- a/automation_tests/src/UnitTest/Tests/AllCharAttributeTest.as
+++ b/automation_tests/src/UnitTest/Tests/AllCharAttributeTest.as
@@ -18,103 +18,51 @@
 
////////////////////////////////////////////////////////////////////////////////
 package UnitTest.Tests
 {
-       import UnitTest.ExtendedClasses.TestSuiteExtended;
-       import UnitTest.Fixtures.TestConfig;
+    import UnitTest.Fixtures.TestConfig;
 
-       import flashx.textLayout.elements.FlowLeafElement;
-       import flashx.textLayout.elements.TextFlow;
-       import flashx.textLayout.formats.Category;
-       import flashx.textLayout.formats.FormatValue;
-       import flashx.textLayout.formats.TextLayoutFormat;
-       import flashx.textLayout.property.Property;
-       import flashx.textLayout.tlf_internal;
+    import flashx.textLayout.formats.Category;
+    import flashx.textLayout.formats.TextLayoutFormat;
 
-    import org.flexunit.asserts.assertTrue;
+    import flashx.textLayout.tlf_internal;
 
     use namespace tlf_internal;
 
-       public class AllCharAttributeTest extends AllAttributeTest
-       {
-               public function AllCharAttributeTest(methodName:String, 
testID:String, testConfig:TestConfig, prop:Property, testValue:Object, 
expectedValue:*)
-               {
-                       super (methodName, testID, testConfig, prop, testValue, 
expectedValue);
-
-                       // Note: These must correspond to a Watson product area 
(case-sensitive)
-                       metaData.productArea = "Text Attributes";
-                       metaData.productSubArea = "Character Attributes";
-               }
-
-               public static function suite(testConfig:TestConfig, 
ts:TestSuiteExtended):void
-               {
-                       // generate test cases
-                       testAllProperties(ts, testConfig, 
TextLayoutFormat.description, Category.CHARACTER, AllCharAttributeTest, 
"runOneCharacterAttributeTest");
-               }
-
-               /**
-                * Generic function to run one character attribute test.  Uses 
the selection manager to set the attributes on the entire flow at the span level
-                * to value and then validates that the value is expectedValue.
-                */
-               public function runOneCharacterAttributeTest():void
-               {
-                       if (testProp == null)
-                               return; // must be set
-
-                       SelManager.selectAll();
-
-                       // Test direct change on single leaf
-                       var leaf:FlowLeafElement = 
SelManager.textFlow.findLeaf(SelManager.absoluteStart);
-                       var originalValue:* = leaf[testProp.name];
-
-                       assignmentHelper(leaf);
-
-                       var expectedResult:*;
-                       if (expectedValue === undefined)
-                               expectedResult = testValue === undefined || 
testValue === null ? undefined : originalValue;
-                       else
-                               expectedResult = expectedValue;
-
-                       assertTrue("FlowLeafElement does not have the expected 
value after direct change", leaf[testProp.name] == expectedResult);
-                       leaf[testProp.name] = originalValue;
-
-                       var ca:TextLayoutFormat = new TextLayoutFormat();
-                       assignmentHelper(ca);
-                       SelManager.applyLeafFormat(ca);
-
-                       // expect that all FlowLeafElements have expectedValue 
as the properties value
-                       if (expectedValue !== undefined)
-                               assertTrue("not all FlowLeafElements have the 
expected value", 
validateCharacterPropertyOnEntireFlow(SelManager.textFlow,testProp,expectedValue));
-               }
-
-               // support function to walk all FlowLeafElements and verify 
that prop is val
-               static public function 
validateCharacterPropertyOnEntireFlow(textFlow:TextFlow, 
prop:Property,val:*):Boolean
-               {
-                       var idx:int = 0;
-                       var elem:FlowLeafElement = textFlow.getFirstLeaf();
-                       assertTrue("either the first FlowLeafElement is null or 
the textFlow length is zero", elem != null || textFlow.textLength == 0);
-                       while (elem)
-                       {
-                               // error if elements have zero length
-                               assertTrue("The FlowLeafElement has zero 
length", elem.textLength != 0);
-
-                               // expect all values of prop to be supplied val
-                               if (elem.format[prop.name] !== val || 
elem[prop.name] !== val)
-                                       return false;
-
-                               // inherit is never computed
-                               if ((val == FormatValue.INHERIT && 
elem.computedFormat[prop.name] == val) || elem.computedFormat[prop.name] === 
undefined)
-                                       return false;
-
-                               // skip to the next element
-                               var nextElem:FlowLeafElement = 
elem.getNextLeaf();
-                               var absoluteEnd:int = elem.getAbsoluteStart() + 
elem.textLength;
-                               if (nextElem == null)
-                                       assertTrue("absoluteEnd of the last 
FlowLeafElement is not the end of the textFlow", absoluteEnd == 
textFlow.textLength);
-                               else
-                                       assertTrue("the end of this 
FlowLeafElement does not equal the start of the next", absoluteEnd == 
nextElem.getAbsoluteStart());
-
-                               elem = nextElem;
-                       }
-                       return true;
-               }
-       }
+    public class AllCharAttributeTest extends AllAttributeTest
+    {
+        public function AllCharAttributeTest()
+        {
+            super("", "AllCharAttributeTest", TestConfig.getInstance(), null, 
null, null);
+            // Note: These must correspond to a Watson product area 
(case-sensitive)
+            metaData.productArea = "Text Attributes";
+            metaData.productSubArea = "Character Attributes";
+        }
+
+
+        [Before]
+        override public function setUpTest():void
+        {
+            super.setUpTest();
+
+            testProp = null;
+            expectedValue = null;
+            testValue = null;
+        }
+
+        [After]
+        override public function tearDownTest():void
+        {
+            super.tearDownTest();
+        }
+
+        [Test]
+        public function propertiesCharacterTests():void
+        {
+            testAllNumberPropsFromMinToMax(TestConfig.getInstance(), 
TextLayoutFormat.description, Category.CHARACTER);
+            testAllIntPropsFromMinToMax(TestConfig.getInstance(), 
TextLayoutFormat.description, Category.CHARACTER);
+            testAllNumberOrPercentPropsFromMinToMax(TestConfig.getInstance(), 
TextLayoutFormat.description, Category.CHARACTER);
+            testAllBooleanProps(TestConfig.getInstance(), 
TextLayoutFormat.description, Category.CHARACTER);
+            testAllEnumProps(TestConfig.getInstance(), 
TextLayoutFormat.description, Category.CHARACTER);
+            testAllSharedValues(TestConfig.getInstance(), 
TextLayoutFormat.description, Category.CHARACTER);
+        }
+    }
 }

Reply via email to