This is an automated email from the ASF dual-hosted git repository.

gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new c3d2112  Fix for emulation Timer. Added start of unit tests for this 
to cover the fixed scenarios. Fixes #1165 Also Added missing Event metadata to 
the Core base class (JS version). Added mx.events.TimerEvent metadata to the 
emulation version.
c3d2112 is described below

commit c3d2112bc1515f050181a8af6f65c9dae3012798
Author: greg-dove <[email protected]>
AuthorDate: Sat Nov 13 15:14:05 2021 +1300

    Fix for emulation Timer. Added start of unit tests for this to cover the 
fixed scenarios. Fixes #1165
    Also Added missing Event metadata to the Core base class (JS version). 
Added mx.events.TimerEvent metadata to the emulation version.
---
 .../main/royale/org/apache/royale/utils/Timer.as   |  31 ++++-
 .../src/main/royale/mx/utils/ObjectUtil.as         |   2 +-
 .../MXRoyaleBase/src/main/royale/mx/utils/Timer.as |  89 +++++++++++--
 .../test/royale/flexUnitTests/MXRoyaleTester.as    |   1 +
 .../flexUnitTests/mxroyale/TimerEmulationTest.as   | 138 +++++++++++++++++++++
 5 files changed, 250 insertions(+), 11 deletions(-)

diff --git 
a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/Timer.as 
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/Timer.as
index ccbb730..a569295 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/Timer.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/Timer.as
@@ -38,7 +38,7 @@ COMPILE::JS
 /**
  *  Dispatched as requested via the delay and
  *  repeat count parameters in the constructor.
- *  
+ *
  *  @langversion 3.0
  *  @playerversion Flash 10.2
  *  @playerversion AIR 2.6
@@ -95,6 +95,21 @@ public class Timer extends flash.utils.Timer
        }
 }
 
+//--------------------------------------
+//  Events
+//--------------------------------------
+
+/**
+ *  Dispatched as requested via the delay and
+ *  repeat count parameters in the constructor.
+ *
+ *  @langversion 3.0
+ *  @playerversion Flash 10.2
+ *  @playerversion AIR 2.6
+ *  @productversion Royale 0.0
+ */
+[Event(name="timer", type="org.apache.royale.events.Event")]
+
 /**
  *  The Timer class dispatches events based on a delay
  *  and repeat count.  
@@ -183,11 +198,23 @@ public class Timer extends EventDispatcher
                    return;
                        
         _currentCount++;
+        var finished:Boolean;
         if (repeatCount > 0 && currentCount >= repeatCount) {
             stop();
+            finished = true;
         }
         
-        dispatchEvent(new Event('timer'));
+        dispatchEvent(timerEvent(TIMER));
+        if (finished) repeatsFinished();
+    }
+
+    protected function timerEvent(evtType:String):Event{
+        //for subclasses to override with an Event subclass, this class uses 
plain Event
+        return new Event(evtType);
+    }
+
+    protected function repeatsFinished():void{
+        //for subclass overrides only, this class does not dispatch any 
additional event here
     }
 }
 
diff --git 
a/frameworks/projects/MXRoyaleBase/src/main/royale/mx/utils/ObjectUtil.as 
b/frameworks/projects/MXRoyaleBase/src/main/royale/mx/utils/ObjectUtil.as
index a6a96d9..48d18c0 100644
--- a/frameworks/projects/MXRoyaleBase/src/main/royale/mx/utils/ObjectUtil.as
+++ b/frameworks/projects/MXRoyaleBase/src/main/royale/mx/utils/ObjectUtil.as
@@ -66,7 +66,7 @@ import org.apache.royale.reflection.getDynamicFields;
  *  @productversion Flex 3
  *
  *  @royalesuppressexport
- *  JS PAYG : non-reflectable utility class, unused methods will be subject to 
deadcode elimination
+ *  JS optimization : non-reflectable utility class, unused methods will be 
subject to dead-code elimination
  */
 public class ObjectUtil
 {
diff --git a/frameworks/projects/MXRoyaleBase/src/main/royale/mx/utils/Timer.as 
b/frameworks/projects/MXRoyaleBase/src/main/royale/mx/utils/Timer.as
index 439c5fc..383e4dd 100644
--- a/frameworks/projects/MXRoyaleBase/src/main/royale/mx/utils/Timer.as
+++ b/frameworks/projects/MXRoyaleBase/src/main/royale/mx/utils/Timer.as
@@ -21,7 +21,17 @@ package mx.utils
 
     import mx.events.TimerEvent;
 
-    import org.apache.royale.utils.Timer;
+    COMPILE::SWF{
+        import flash.utils.Timer;
+        import flash.events.TimerEvent;
+    }
+
+    COMPILE::JS{
+        import org.apache.royale.utils.Timer;
+        import org.apache.royale.events.Event;
+    }
+
+
 
     //--------------------------------------
     //  Events
@@ -35,7 +45,18 @@ package mx.utils
      *  @playerversion AIR 2.6
      *  @productversion Royale 0.9.8
      */
-    [Event(name="timerComplete", type="org.apache.royale.events.Event")]
+    [Event(name="timerComplete", type="mx.events.TimerEvent")]
+
+    /**
+     *  Dispatched as requested via the delay and
+     *  repeat count parameters in the constructor.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.0
+     */
+    [Event(name="timer", type="mx.events.TimerEvent")]
 
 
     /**
@@ -49,6 +70,7 @@ package mx.utils
      *
      *  @royalesuppresspublicvarwarning
      */
+    COMPILE::JS
     public class Timer extends org.apache.royale.utils.Timer
     {
         public function Timer(delay:Number, repeatCount:int = 0)
@@ -56,14 +78,65 @@ package mx.utils
             super(delay, repeatCount);
         }
 
-        override public function stop():void
+        override protected function timerEvent(evtType:String):Event{
+            return new TimerEvent(evtType);
+        }
+
+        override protected function repeatsFinished():void{
+            dispatchEvent(timerEvent(TimerEvent.TIMER_COMPLETE));
+        }
+    }
+
+    //--------------------------------------
+    //  Events
+    //--------------------------------------
+
+    /**
+     *  Dispatched when timer stops
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.9.8
+     */
+    [Event(name="timerComplete", type="mx.events.TimerEvent")]
+
+    /**
+     *  Dispatched as requested via the delay and
+     *  repeat count parameters in the constructor.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.0
+     */
+    [Event(name="timer", type="mx.events.TimerEvent")]
+    /**
+     *  The Timer class dispatches events based on a delay
+     *  and repeat count.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.9.8
+     *
+     */
+    COMPILE::SWF
+    public class Timer extends flash.utils.Timer
+    {
+        public function Timer(delay:Number, repeatCount:int = 0)
+        {
+            super(delay, repeatCount);
+            addEventListener("timer", interceptor, false, 9999);
+            addEventListener("timerComplete", interceptor, false, 9999);
+        }
+
+        private function interceptor(event:flash.events.Event):void
         {
-            super.stop();
-            COMPILE::JS
+            if (event is flash.events.TimerEvent)
             {
-                if (!running) {
-                    dispatchEvent(new TimerEvent('timerComplete'));
-                }
+                event.stopImmediatePropagation();
+                dispatchEvent(new mx.events.TimerEvent(event.type));
             }
         }
     }
diff --git 
a/frameworks/projects/MXRoyaleBase/src/test/royale/flexUnitTests/MXRoyaleTester.as
 
b/frameworks/projects/MXRoyaleBase/src/test/royale/flexUnitTests/MXRoyaleTester.as
index e7920c6..e267b20 100644
--- 
a/frameworks/projects/MXRoyaleBase/src/test/royale/flexUnitTests/MXRoyaleTester.as
+++ 
b/frameworks/projects/MXRoyaleBase/src/test/royale/flexUnitTests/MXRoyaleTester.as
@@ -36,6 +36,7 @@ package flexUnitTests
         public var flexSDK_ObjectUtilTests:FlexSDK_ObjectUtil_Tests;
         public var 
flexSDK_ObjectUtil_FLEX_34852_Tests:FlexSDK_ObjectUtil_FLEX_34852_Tests;
         public var 
flexSDK_ObjectUtil_Compare_Tests:FlexSDK_ObjectUtil_Compare_Tests;
+        public var timerEmulationTests:TimerEmulationTest;
         
     }
     
diff --git 
a/frameworks/projects/MXRoyaleBase/src/test/royale/flexUnitTests/mxroyale/TimerEmulationTest.as
 
b/frameworks/projects/MXRoyaleBase/src/test/royale/flexUnitTests/mxroyale/TimerEmulationTest.as
new file mode 100644
index 0000000..430dc5c
--- /dev/null
+++ 
b/frameworks/projects/MXRoyaleBase/src/test/royale/flexUnitTests/mxroyale/TimerEmulationTest.as
@@ -0,0 +1,138 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.mxroyale
+{
+    
+    
+
+    import org.apache.royale.test.asserts.*;
+    import org.apache.royale.test.async.Async;
+    import flexUnitTests.mxroyale.support.*;
+    
+    
+    COMPILE::SWF
+    {
+        import flash.utils.Timer;
+        import flash.events.TimerEvent;
+
+        //the 'emulation' swf versions should work the same also, to test swap 
the comment block between above and below
+        /*import mx.utils.Timer;
+        import mx.events.TimerEvent;*/
+
+    }
+    COMPILE::JS
+    {
+        import mx.utils.Timer;
+        import mx.events.TimerEvent;
+    }
+
+    
+    /**
+     * @royalesuppresspublicvarwarning
+     */
+    public class TimerEmulationTest
+    {
+    
+        
+        public static var isJS:Boolean = COMPILE::JS;
+    
+
+        [Before]
+        public function setUp():void
+        {
+        
+        }
+        
+        [After]
+        public function tearDown():void
+        {
+
+        }
+        
+        [BeforeClass]
+        public static function setUpBeforeClass():void
+        {
+        }
+        
+        [AfterClass]
+        public static function tearDownAfterClass():void
+        {
+        }
+    
+        private var timer:Timer;
+
+
+        private function recordTimerEventHandler(into:Array):Function{
+            return function(event:TimerEvent):void{
+                into.push(event.type);
+            }
+        }
+
+
+        [Test]
+        public function testNoRun():void{
+            var events:Array = [];
+            timer = new Timer(100,1);
+            var listener:Function  = recordTimerEventHandler(events);
+            timer.addEventListener(TimerEvent.TIMER,listener);
+            timer.addEventListener(TimerEvent.TIMER_COMPLETE,listener);
+            var expected:Array = []; //should be no events at all
+            timer.start();
+            timer.stop();
+            assertEquals(events.join(','), expected.join(','), 'Unexpected 
Timer Event sequence');
+        }
+
+    
+        [Test(async)]
+        public function testSingleRun():void{
+            var events:Array = [];
+
+            timer = new Timer(100,1);
+            var listener:Function  = recordTimerEventHandler(events);
+            timer.addEventListener(TimerEvent.TIMER,listener);
+            timer.addEventListener(TimerEvent.TIMER_COMPLETE,listener);
+            var expected:Array = [TimerEvent.TIMER, TimerEvent.TIMER_COMPLETE];
+            timer.start();
+            Async.delayCall(this, function():void
+            {
+                assertEquals(events.join(','), expected.join(','), 'Unexpected 
Timer Event sequence');
+            }, 150);
+        }
+
+
+        [Test(async)]
+        public function testDualRun():void{
+            var events:Array = [];
+
+            timer = new Timer(100,2);
+            var listener:Function  = recordTimerEventHandler(events);
+            timer.addEventListener(TimerEvent.TIMER,listener);
+            timer.addEventListener(TimerEvent.TIMER_COMPLETE,listener);
+            var expected:Array = [TimerEvent.TIMER, TimerEvent.TIMER, 
TimerEvent.TIMER_COMPLETE];
+            timer.start();
+            Async.delayCall(this, function():void
+            {
+                assertEquals(events.join(','), expected.join(','), 'Unexpected 
Timer Event sequence');
+            }, 250);
+        }
+    
+    
+        
+    }
+}

Reply via email to