TileCache tests

This commit is contained in:
Ian Gilman 2014-11-20 11:51:24 -08:00
parent cf0059daa5
commit 78e44d487b
6 changed files with 114 additions and 1 deletions

View File

@ -155,7 +155,7 @@ $.TileCache.prototype = /** @lends OpenSeadragon.TileCache.prototype */{
// Note that just because we're unloading a tile doesn't necessarily mean // Note that just because we're unloading a tile doesn't necessarily mean
// we're unloading an image. With repeated calls it should sort itself out, though. // we're unloading an image. With repeated calls it should sort itself out, though.
if ( this._imagesLoadedCount >= this._maxImageCacheCount ) { if ( this._imagesLoadedCount > this._maxImageCacheCount ) {
var worstTile = null; var worstTile = null;
var worstTileIndex = -1; var worstTileIndex = -1;
var prevTile, worstTime, worstLevel, prevTime, prevLevel, prevTileRecord; var prevTile, worstTime, worstLevel, prevTime, prevLevel, prevTileRecord;

View File

@ -69,6 +69,7 @@
<script src="/test/modules/world.js"></script> <script src="/test/modules/world.js"></script>
<script src="/test/modules/drawer.js"></script> <script src="/test/modules/drawer.js"></script>
<script src="/test/modules/tiledimage.js"></script> <script src="/test/modules/tiledimage.js"></script>
<script src="/test/modules/tilecache.js"></script>
<!-- The navigator tests are the slowest (for now; hopefully they can be sped up) <!-- The navigator tests are the slowest (for now; hopefully they can be sped up)
so we put them last. --> so we put them last. -->
<script src="/test/modules/navigator.js"></script> <script src="/test/modules/navigator.js"></script>

111
test/modules/tilecache.js Normal file
View File

@ -0,0 +1,111 @@
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */
(function() {
// ----------
module('TileCache', {
setup: function () {
testLog.reset();
},
teardown: function () {
}
});
// ----------
asyncTest('basics', function() {
var fakeTiledImage0 = {};
var fakeTiledImage1 = {};
var fakeTile0 = {
url: 'foo.jpg',
image: {},
unload: function() {}
};
var fakeTile1 = {
url: 'foo.jpg',
image: {},
unload: function() {}
};
var cache = new OpenSeadragon.TileCache();
equal(cache.numTilesLoaded(), 0, 'no tiles to begin with');
cache.cacheTile({
tile: fakeTile0,
tiledImage: fakeTiledImage0
});
equal(cache.numTilesLoaded(), 1, 'tile count after cache');
cache.cacheTile({
tile: fakeTile1,
tiledImage: fakeTiledImage1
});
equal(cache.numTilesLoaded(), 2, 'tile count after second cache');
cache.clearTilesFor(fakeTiledImage0);
equal(cache.numTilesLoaded(), 1, 'tile count after first clear');
cache.clearTilesFor(fakeTiledImage1);
equal(cache.numTilesLoaded(), 0, 'tile count after second clear');
start();
});
// ----------
asyncTest('maxImageCacheCount', function() {
var fakeTiledImage0 = {};
var fakeTile0 = {
url: 'different.jpg',
image: {},
unload: function() {}
};
var fakeTile1 = {
url: 'same.jpg',
image: {},
unload: function() {}
};
var fakeTile2 = {
url: 'same.jpg',
image: {},
unload: function() {}
};
var cache = new OpenSeadragon.TileCache({
maxImageCacheCount: 1
});
equal(cache.numTilesLoaded(), 0, 'no tiles to begin with');
cache.cacheTile({
tile: fakeTile0,
tiledImage: fakeTiledImage0
});
equal(cache.numTilesLoaded(), 1, 'tile count after add');
cache.cacheTile({
tile: fakeTile1,
tiledImage: fakeTiledImage0
});
equal(cache.numTilesLoaded(), 1, 'tile count after add of second image');
cache.cacheTile({
tile: fakeTile2,
tiledImage: fakeTiledImage0
});
equal(cache.numTilesLoaded(), 2, 'tile count after additional same image');
start();
});
})();

View File

@ -34,6 +34,7 @@
<script src="/test/modules/world.js"></script> <script src="/test/modules/world.js"></script>
<script src="/test/modules/drawer.js"></script> <script src="/test/modules/drawer.js"></script>
<script src="/test/modules/tiledimage.js"></script> <script src="/test/modules/tiledimage.js"></script>
<script src="/test/modules/tilecache.js"></script>
<!-- The navigator tests are the slowest (for now; hopefully they can be sped up) <!-- The navigator tests are the slowest (for now; hopefully they can be sped up)
so we put them last. --> so we put them last. -->
<script src="/test/modules/navigator.js"></script> <script src="/test/modules/navigator.js"></script>