Permalink
Browse files

added unit tests for event. adding clone methods to events.

  • Loading branch information...
mikechambers committed Mar 11, 2009
1 parent 396e273 commit b9613c3440bf2a1eb687240700bc3a2d306c86a3
Showing with 1,507 additions and 18 deletions.
  1. +51 −13 src/com/adobe/air/filesystem/FileMonitor.as
  2. +5 −3 src/com/adobe/air/filesystem/VolumeMonitor.as
  3. +7 −0 src/com/adobe/air/filesystem/events/FileMonitorEvent.as
  4. +32 −0 src/com/adobe/protocols/dict/Database.as
  5. +32 −0 src/com/adobe/protocols/dict/Definition.as
  6. +32 −0 src/com/adobe/protocols/dict/Dict.as
  7. +32 −0 src/com/adobe/protocols/dict/DictionaryServer.as
  8. +32 −0 src/com/adobe/protocols/dict/MatchStrategy.as
  9. +32 −0 src/com/adobe/protocols/dict/Response.as
  10. +32 −0 src/com/adobe/protocols/dict/events/ConnectedEvent.as
  11. +32 −0 src/com/adobe/protocols/dict/events/DatabaseEvent.as
  12. +32 −0 src/com/adobe/protocols/dict/events/DefinitionEvent.as
  13. +32 −0 src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as
  14. +32 −0 src/com/adobe/protocols/dict/events/DictionaryServerEvent.as
  15. +32 −0 src/com/adobe/protocols/dict/events/DisconnectedEvent.as
  16. +32 −0 src/com/adobe/protocols/dict/events/ErrorEvent.as
  17. +32 −0 src/com/adobe/protocols/dict/events/MatchEvent.as
  18. +32 −0 src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as
  19. +32 −0 src/com/adobe/protocols/dict/events/NoMatchEvent.as
  20. +32 −0 src/com/adobe/protocols/dict/util/CompleteResponseEvent.as
  21. +32 −0 src/com/adobe/protocols/dict/util/SocketHelper.as
  22. +42 −2 tests/src/CoreLibTestRunner.as
  23. +63 −0 tests/src/com/adobe/air/filesystem/FileMonitorTest.as
  24. +57 −0 tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as
  25. +58 −0 tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as
  26. +49 −0 tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as
  27. +50 −0 tests/src/com/adobe/protocols/events/ConnectedEventTest.as
  28. +50 −0 tests/src/com/adobe/protocols/events/DatabaseEventTest.as
  29. +50 −0 tests/src/com/adobe/protocols/events/DefinitionEventTest.as
  30. +50 −0 tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as
  31. +50 −0 tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as
  32. +50 −0 tests/src/com/adobe/protocols/events/DisconnectedEventTest.as
  33. +50 −0 tests/src/com/adobe/protocols/events/ErrorEventTest.as
  34. +50 −0 tests/src/com/adobe/protocols/events/MatchEventTest.as
  35. +50 −0 tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as
  36. +49 −0 tests/src/com/adobe/protocols/events/NoMatchEventTest.as
  37. +50 −0 tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as
  38. +50 −0 tests/src/com/adobe/webapis/events/ServiceEventTest.as
@@ -75,7 +75,8 @@ package com.adobe.air.filesystem
{
private var _file:File;
private var timer:Timer;
- private static const MONITOR_INTERVAL:Number = 1000;
+ public static const DEFAULT_MONITOR_INTERVAL:Number = 1000;
+ private var _interval:Number;
private var fileExists:Boolean = false;
private var lastModifiedTime:Number;
@@ -84,48 +85,86 @@ package com.adobe.air.filesystem
* Constructor
*
* @parameter file The File that will be monitored for changes.
+ *
+ * @param interval How often in milliseconds the file is polled for
+ * change events. Default value is 1000, minimum value is 1000
*/
- public function FileMonitor(file:File = null)
+ public function FileMonitor(file:File = null, interval:Number = -1)
{
this.file = file;
+
+ if(interval != -1)
+ {
+ if(interval < 1000)
+ {
+ _interval = 1000;
+ }
+ else
+ {
+ _interval = interval;
+ }
+ }
+ else
+ {
+ _interval = DEFAULT_MONITOR_INTERVAL;
+ }
}
/**
- * File being monitored for changes.
+ * File being monitored for changes.
+ *
+ * Setting the property will result in unwatch() being called.
*/
public function get file():File
{
return _file;
}
public function set file(file:File):void
- {
- if(file == null)
- {
- return;
- }
-
+ {
if(timer && timer.running)
{
unwatch();
}
_file = file;
+ if(!_file)
+ {
+ fileExists = false;
+ return;
+ }
+
+ //note : this will throw an error if new File() is passed in.
fileExists = _file.exists;
if(fileExists)
{
lastModifiedTime = _file.modificationDate.getTime();
- }
+ }
+
}
+ /**
+ * How often the system is polled for Volume change events.
+ */
+ public function get interval():Number
+ {
+ return _interval;
+ }
+
/**
* Begins monitoring the specified file for changes.
*
* Broadcasts Event.CHANGE event when the file's modification date has changed.
*/
public function watch():void
{
+ if(!file)
+ {
+ //should we throw an error?
+ return;
+ }
+
if(timer && timer.running)
{
return;
@@ -134,8 +173,8 @@ package com.adobe.air.filesystem
//check and see if timer is active. if it is, return
if(!timer)
{
- timer = new Timer(MONITOR_INTERVAL);
- timer.addEventListener(TimerEvent.TIMER, onTimerEvent);
+ timer = new Timer(_interval);
+ timer.addEventListener(TimerEvent.TIMER, onTimerEvent, false, 0, true);
}
timer.start();
@@ -153,7 +192,6 @@ package com.adobe.air.filesystem
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, onTimerEvent);
- timer = null;
}
private function onTimerEvent(e:TimerEvent):void
@@ -57,8 +57,6 @@ package com.adobe.air.filesystem
/**
* Class that monitors changes to the File volumes attached to the operating
* system.
- *
- *
*/
public class VolumeMonitor extends EventDispatcher
{
@@ -82,6 +80,10 @@ package com.adobe.air.filesystem
{
_interval = 1000;
}
+ else
+ {
+ _interval = interval;
+ }
}
else
{
@@ -105,7 +107,7 @@ package com.adobe.air.filesystem
if(!timer)
{
timer = new Timer(_interval);
- timer.addEventListener(TimerEvent.TIMER, onTimerEvent);
+ timer.addEventListener(TimerEvent.TIMER, onTimerEvent,false,0, true);
}
//we reinitialize the hash everytime we start watching
@@ -18,5 +18,12 @@ package com.adobe.air.filesystem.events
super(type, bubbles, cancelable);
}
+ public override function clone():Event
+ {
+ var out:FileMonitorEvent = new FileMonitorEvent(type, bubbles, cancelable);
+ out.file = file;
+
+ return out;
+ }
}
}
@@ -1,3 +1,35 @@
+/*
+ Copyright (c) 2009, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
package com.adobe.protocols.dict
{
public class Database
@@ -1,3 +1,35 @@
+/*
+ Copyright (c) 2009, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
package com.adobe.protocols.dict
{
public class Definition
@@ -1,3 +1,35 @@
+/*
+ Copyright (c) 2009, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
package com.adobe.protocols.dict
{
import com.adobe.protocols.dict.events.*;
@@ -1,3 +1,35 @@
+/*
+ Copyright (c) 2009, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
package com.adobe.protocols.dict
{
public class DictionaryServer
@@ -1,3 +1,35 @@
+/*
+ Copyright (c) 2009, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
package com.adobe.protocols.dict
{
public class MatchStrategy
@@ -1,3 +1,35 @@
+/*
+ Copyright (c) 2009, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
package com.adobe.protocols.dict
{
public class Response
Oops, something went wrong.

0 comments on commit b9613c3

Please sign in to comment.