Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug where hasItem would return true even for items not yet loaded.
This is a regression bug, also added tests. Thanks benny (http://groups.google.com/group/bulkloader-users/browse_thread/thread/29f4bdbe1fe03759?hl=en)
- Loading branch information
Arthur Debert
committed
Sep 18, 2009
1 parent
c7457ea
commit 7790888
Showing
4 changed files
with
177 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
149 changes: 75 additions & 74 deletions
149
tests/src/br/com/stimuli/loading/tests/BulkLoaderTestSuite.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,83 @@ | ||
package br.com.stimuli.loading.tests { | ||
import br.com.stimuli.kisstest.TestSuite; | ||
import flash.events.*; | ||
import br.com.stimuli.loading.tests.*; | ||
import flash.utils.*; | ||
import flash.media.SoundMixer; | ||
|
||
/**@private*/ | ||
public class BulkLoaderTestSuite extends TestSuite { | ||
public var testClasses : Array = [ | ||
HostPriorityTest, | ||
LoaderImageItemTest, | ||
GuessTypeTest, | ||
LoaderItemMovieTest, | ||
LoadNowTest, | ||
CollectionTestCase, | ||
RemoveAllTest, | ||
RemoveAllSimpleTest, | ||
GetClassDefinitionTest, | ||
RegisterNewTypeTest, | ||
TwoItemsWithTheSameURLTest, | ||
OnErrorTest, | ||
ErrorResumeTest, | ||
SmartURLTest, | ||
VideoContentTest, | ||
RemoveFailedItemTest, | ||
OnCompleteTest, | ||
AutoIdTest, | ||
StringSubstituionTest, | ||
LazyJSONLoaderTest, | ||
LazyXMLLoaderTest, | ||
LazyXMLInternalsTest, | ||
LoaderItemAVM1MovieTest, | ||
VideoContentPausedAtStartTestCase, | ||
PauseAllResumeTest, | ||
ClearNowTest, | ||
StartPausedTest, | ||
ProgressEventsTest, | ||
ReloadTest, | ||
import br.com.stimuli.kisstest.TestSuite; | ||
import flash.events.*; | ||
import br.com.stimuli.loading.tests.*; | ||
import flash.utils.*; | ||
import flash.media.SoundMixer; | ||
|
||
ClearMemoryTest, | ||
ResumeAllTest, | ||
ResumeTest, | ||
BulkStartTest, | ||
XMLItemTest, | ||
InstanceRetrivalTestCase, | ||
URLItemTest, | ||
AudioContentTest | ||
]; | ||
|
||
public var testsRun : Object = {} ; | ||
/**@private*/ | ||
public class BulkLoaderTestSuite extends TestSuite { | ||
public var testClasses : Array = [ | ||
HasItemTest, | ||
HostPriorityTest, | ||
LoaderImageItemTest, | ||
GuessTypeTest, | ||
LoaderItemMovieTest, | ||
LoadNowTest, | ||
CollectionTestCase, | ||
RemoveAllTest, | ||
RemoveAllSimpleTest, | ||
GetClassDefinitionTest, | ||
RegisterNewTypeTest, | ||
TwoItemsWithTheSameURLTest, | ||
OnErrorTest, | ||
ErrorResumeTest, | ||
SmartURLTest, | ||
VideoContentTest, | ||
RemoveFailedItemTest, | ||
OnCompleteTest, | ||
AutoIdTest, | ||
StringSubstituionTest, | ||
LazyJSONLoaderTest, | ||
LazyXMLLoaderTest, | ||
LazyXMLInternalsTest, | ||
LoaderItemAVM1MovieTest, | ||
VideoContentPausedAtStartTestCase, | ||
PauseAllResumeTest, | ||
ClearNowTest, | ||
StartPausedTest, | ||
ProgressEventsTest, | ||
ReloadTest, | ||
|
||
ClearMemoryTest, | ||
ResumeAllTest, | ||
ResumeTest, | ||
BulkStartTest, | ||
XMLItemTest, | ||
InstanceRetrivalTestCase, | ||
URLItemTest, | ||
AudioContentTest | ||
]; | ||
|
||
public var testsRun : Object = {} ; | ||
public static var LOADING_VERBOSE : Boolean = false; | ||
|
||
|
||
public function BulkLoaderTestSuite() { | ||
super(); | ||
SoundMixer.soundTransform.volume = 0; | ||
super(); | ||
SoundMixer.soundTransform.volume = 0; | ||
testClasses.forEach(function(cl : Class, ...rest):void{addTestCase(cl)}) | ||
for (var prop : String in testsRun){ | ||
//trace(prop.substring(6, prop.length -1) + " (" + testsRun[prop].length + ")", ":"); | ||
for each (var testName : String in testsRun[prop]){ | ||
//trace("\t",testName ); | ||
} | ||
} | ||
} | ||
|
||
public function addTestsFromClass(klass : Class) : void{ | ||
for each (var name : String in describeType(klass).factory.method.@name){ | ||
if (name.substr(0, 4) == "test"){ | ||
addTest(new klass(name)); | ||
if(!testsRun[String(klass)]){ | ||
testsRun[String(klass)] = []; | ||
} | ||
testsRun[String(klass)].push(name); | ||
} | ||
} | ||
} | ||
for (var prop : String in testsRun){ | ||
//trace(prop.substring(6, prop.length -1) + " (" + testsRun[prop].length + ")", ":"); | ||
for each (var testName : String in testsRun[prop]){ | ||
//trace("\t",testName ); | ||
} | ||
} | ||
} | ||
|
||
public function addTestsFromClass(klass : Class) : void{ | ||
for each (var name : String in describeType(klass).factory.method.@name){ | ||
if (name.substr(0, 4) == "test"){ | ||
addTest(new klass(name)); | ||
if(!testsRun[String(klass)]){ | ||
testsRun[String(klass)] = []; | ||
} | ||
testsRun[String(klass)].push(name); | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package br.com.stimuli.loading.tests { | ||
import flash.net.URLRequest; | ||
import flash.net.*; | ||
import flash.events.*; | ||
import flash.utils.*; | ||
import flash.display.*; | ||
import br.com.stimuli.kisstest.TestCase; | ||
import br.com.stimuli.loading.BulkLoader; | ||
import br.com.stimuli.loading.loadingtypes.*; | ||
/**@private*/ | ||
public class HasItemTest extends TestCase { | ||
|
||
public var _bulkLoader : BulkLoader; | ||
public var lastProgress : Number = 0; | ||
|
||
|
||
public var ioError : Event; | ||
|
||
public var dispatchedProgressAfterComplete : Boolean = false; | ||
public var numHasItems : int = 0; | ||
public var timer : Timer; | ||
public function HasItemTest(name : String) : void { | ||
super(name); | ||
this.name = name; | ||
} | ||
public var items :Array = [ | ||
"http://www.emptywhite.com/bulkloader-assets/some-text.txt", | ||
"http://www.emptywhite.com/bulkloader-assets/movie.flv" , | ||
"http://www.emptywhite.com/bulkloader-assets/samplexml.xml", | ||
"http://www.emptywhite.com/bulkloader-assets/shoes.jpg", | ||
"http://www.emptywhite.com/bulkloader-assets/chopin.mp3" | ||
] | ||
// Override the run method and begin the request for remote data | ||
public override function setUp():void { | ||
_bulkLoader = new BulkLoader(BulkLoader.getUniqueName()) | ||
for each(var url : String in items){_bulkLoader.add(url, {"preventCache":true});} | ||
_bulkLoader.start(); | ||
_bulkLoader.addEventListener(BulkLoader.COMPLETE, completeHandler); | ||
_bulkLoader.addEventListener(BulkLoader.PROGRESS, progressHandler); | ||
for each(url in items){ | ||
if (_bulkLoader.hasItem(url)) numHasItems ++; | ||
} | ||
} | ||
|
||
public function onIOError(evt : Event) : void{ | ||
ioError = evt; | ||
// call the on complete manually | ||
completeHandler(evt); | ||
tearDown(); | ||
} | ||
|
||
public function completeHandler(event:Event):void { | ||
timer = new Timer(2000, 1); | ||
timer.addEventListener( TimerEvent.TIMER_COMPLETE, runWrapper) | ||
timer.start(); | ||
} | ||
|
||
public function runWrapper(evt : Event) : void{ | ||
dispatchEvent(new Event(Event.INIT)); | ||
} | ||
|
||
/** This also works as an assertion that event progress will never be NaN | ||
*/ | ||
public function progressHandler(event:ProgressEvent):void { | ||
//var evt : * = event as Object; | ||
var current :Number = Math.floor((event as Object).percentLoaded * 100) /100; | ||
var delta : Number = current - lastProgress; | ||
if (current > lastProgress && delta > 0.099){ | ||
lastProgress = current; | ||
if (BulkLoaderTestSuite.LOADING_VERBOSE) trace(current * 100 , "% loaded") ; | ||
} | ||
for each(var propName : String in ["percentLoaded", "weightPercent", "ratioLoaded"] ){ | ||
if (isNaN(event[propName]) ){ | ||
trace(propName, "is not a number" ); | ||
assertFalse(isNaN(event[propName])); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
override public function tearDown():void { | ||
_bulkLoader.clear(); | ||
BulkLoader.removeAllLoaders(); | ||
_bulkLoader = null; | ||
} | ||
|
||
public function testHasItemsIsFalseAtStart():void { | ||
assertEquals(numHasItems, 0); | ||
} | ||
|
||
|
||
public function testHasItemsIsTrueOnLoad() : void{ | ||
numHasItems = 0; | ||
for each(var url :String in items){ | ||
if (_bulkLoader.hasItem(url)) numHasItems ++; | ||
} | ||
assertEquals(numHasItems, items.length); | ||
} | ||
} | ||
} |