Test fixes (except gl null reference error - test fails sometimes).

This commit is contained in:
Aiosa 2024-03-03 16:39:15 +01:00
parent 135fa76fde
commit a9b50a8fdb
5 changed files with 51 additions and 25 deletions

View File

@ -132,23 +132,33 @@
if (type === this._type) { if (type === this._type) {
return copy ? $.convertor.copy(this._tRef, this._data, type) : this._promise; return copy ? $.convertor.copy(this._tRef, this._data, type) : this._promise;
} }
return this._getDataAsUnsafe(this._tRef, this._data, type, copy); return this._transformDataIfNeeded(this._tRef, this._data, type, copy) || this._promise;
} }
return this._promise.then(data => this._getDataAsUnsafe(this._tRef, data, type, copy)); return this._promise.then(data => this._transformDataIfNeeded(this._tRef, data, type, copy) || data);
} }
_getDataAsUnsafe(referenceTile, data, type, copy) { _transformDataIfNeeded(referenceTile, data, type, copy) {
//might get destroyed in meanwhile //might get destroyed in meanwhile
if (this._destroyed) { if (this._destroyed) {
return $.Promise.resolve();
}
let result;
if (type !== this._type) {
result = $.convertor.convert(referenceTile, data, this._type, type);
} else if (copy) { //convert does not copy data if same type, do explicitly
result = $.convertor.copy(referenceTile, data, type);
}
if (result) {
return result.then(finalData => {
if (this._destroyed) {
$.convertor.destroy(finalData, type);
return undefined; return undefined;
} }
if (type !== this._type) { return finalData;
return $.convertor.convert(referenceTile, data, this._type, type); });
} }
if (copy) { //convert does not copy data if same type, do explicitly return false; // no conversion needed, parent function returns item as-is
return $.convertor.copy(referenceTile, data, type);
}
return data;
} }
/** /**

View File

@ -2145,13 +2145,13 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
); );
//make sure cache data is ready for drawing, if not, request the desired format //make sure cache data is ready for drawing, if not, request the desired format
const cache = tile.getCache(tile.cacheKey), const cache = tile.getCache(tile.cacheKey),
requiredTypes = _this.viewer.drawer.getSupportedDataFormats(); requiredTypes = _this._drawer.getSupportedDataFormats();
if (!cache) { if (!cache) {
$.console.warn("Tile %s not cached or not loaded at the end of tile-loaded event: tile will not be drawn - it has no data!", tile); $.console.warn("Tile %s not cached or not loaded at the end of tile-loaded event: tile will not be drawn - it has no data!", tile);
resolver(tile); resolver(tile);
} else if (!requiredTypes.includes(cache.type)) { } else if (!requiredTypes.includes(cache.type)) {
//initiate conversion as soon as possible if incompatible with the drawer //initiate conversion as soon as possible if incompatible with the drawer
cache.prepareForRendering(requiredTypes, _this.viewer.drawer.options.detachedCache).then(cacheRef => { cache.prepareForRendering(requiredTypes, _this._drawer.options.detachedCache).then(cacheRef => {
if (!cacheRef) { if (!cacheRef) {
return cache.transformTo(requiredTypes); return cache.transformTo(requiredTypes);
} }

View File

@ -543,6 +543,7 @@ $.Viewer = function( options ) {
// Open initial tilesources // Open initial tilesources
if (this.tileSources) { if (this.tileSources) {
console.log(this);
this.open( this.tileSources ); this.open( this.tileSources );
} }
@ -962,6 +963,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
redrawImmediately: true, redrawImmediately: true,
drawerOptions: null drawerOptions: null
}; };
console.debug("RESUEST DRAWER ", options.mainDrawer);
options = $.extend(true, defaultOpts, options); options = $.extend(true, defaultOpts, options);
const mainDrawer = options.mainDrawer; const mainDrawer = options.mainDrawer;
const redrawImmediately = options.redrawImmediately; const redrawImmediately = options.redrawImmediately;

View File

@ -133,11 +133,13 @@
}; };
const fakeTiledImage0 = { const fakeTiledImage0 = {
viewer: fakeViewer, viewer: fakeViewer,
source: OpenSeadragon.TileSource.prototype source: OpenSeadragon.TileSource.prototype,
redraw: function() {}
}; };
const fakeTiledImage1 = { const fakeTiledImage1 = {
viewer: fakeViewer, viewer: fakeViewer,
source: OpenSeadragon.TileSource.prototype source: OpenSeadragon.TileSource.prototype,
redraw: function() {}
}; };
const tile0 = createFakeTile('foo.jpg', fakeTiledImage0); const tile0 = createFakeTile('foo.jpg', fakeTiledImage0);
@ -186,7 +188,8 @@
}; };
const fakeTiledImage0 = { const fakeTiledImage0 = {
viewer: fakeViewer, viewer: fakeViewer,
source: OpenSeadragon.TileSource.prototype source: OpenSeadragon.TileSource.prototype,
draw: function() {}
}; };
const tile0 = createFakeTile('different.jpg', fakeTiledImage0); const tile0 = createFakeTile('different.jpg', fakeTiledImage0);
@ -242,12 +245,14 @@
const fakeTiledImage0 = { const fakeTiledImage0 = {
viewer: fakeViewer, viewer: fakeViewer,
source: OpenSeadragon.TileSource.prototype, source: OpenSeadragon.TileSource.prototype,
_tileCache: tileCache _tileCache: tileCache,
redraw: function() {}
}; };
const fakeTiledImage1 = { const fakeTiledImage1 = {
viewer: fakeViewer, viewer: fakeViewer,
source: OpenSeadragon.TileSource.prototype, source: OpenSeadragon.TileSource.prototype,
_tileCache: tileCache _tileCache: tileCache,
redraw: function() {}
}; };
//load data //load data
@ -436,12 +441,14 @@
const fakeTiledImage0 = { const fakeTiledImage0 = {
viewer: fakeViewer, viewer: fakeViewer,
source: OpenSeadragon.TileSource.prototype, source: OpenSeadragon.TileSource.prototype,
_tileCache: tileCache _tileCache: tileCache,
redraw: function() {}
}; };
const fakeTiledImage1 = { const fakeTiledImage1 = {
viewer: fakeViewer, viewer: fakeViewer,
source: OpenSeadragon.TileSource.prototype, source: OpenSeadragon.TileSource.prototype,
_tileCache: tileCache _tileCache: tileCache,
redraw: function() {}
}; };
//load data //load data

View File

@ -214,7 +214,9 @@
const dummyRect = new OpenSeadragon.Rect(0, 0, 0, 0, 0); const dummyRect = new OpenSeadragon.Rect(0, 0, 0, 0, 0);
const dummyTile = new OpenSeadragon.Tile(0, 0, 0, dummyRect, true, "", const dummyTile = new OpenSeadragon.Tile(0, 0, 0, dummyRect, true, "",
undefined, true, null, dummyRect, "", "key"); undefined, true, null, dummyRect, "", "key");
dummyTile.tiledImage = {}; dummyTile.tiledImage = {
redraw: function () {}
};
const cache = new OpenSeadragon.CacheRecord(); const cache = new OpenSeadragon.CacheRecord();
cache.addTile(dummyTile, "/test/data/A.png", "__TEST__url"); cache.addTile(dummyTile, "/test/data/A.png", "__TEST__url");
@ -263,7 +265,9 @@
const dummyRect = new OpenSeadragon.Rect(0, 0, 0, 0, 0); const dummyRect = new OpenSeadragon.Rect(0, 0, 0, 0, 0);
const dummyTile = new OpenSeadragon.Tile(0, 0, 0, dummyRect, true, "", const dummyTile = new OpenSeadragon.Tile(0, 0, 0, dummyRect, true, "",
undefined, true, null, dummyRect, "", "key"); undefined, true, null, dummyRect, "", "key");
dummyTile.tiledImage = {}; dummyTile.tiledImage = {
redraw: function () {}
};
const cache = new OpenSeadragon.CacheRecord(); const cache = new OpenSeadragon.CacheRecord();
cache.testGetSet = async function(type) { cache.testGetSet = async function(type) {
const value = await cache.getDataAs(type, false); const value = await cache.getDataAs(type, false);
@ -331,19 +335,20 @@
const dummyRect = new OpenSeadragon.Rect(0, 0, 0, 0, 0); const dummyRect = new OpenSeadragon.Rect(0, 0, 0, 0, 0);
const dummyTile = new OpenSeadragon.Tile(0, 0, 0, dummyRect, true, "", const dummyTile = new OpenSeadragon.Tile(0, 0, 0, dummyRect, true, "",
undefined, true, null, dummyRect, "", "key"); undefined, true, null, dummyRect, "", "key");
dummyTile.tiledImage = {}; dummyTile.tiledImage = {
redraw: function () {}
};
const cache = new OpenSeadragon.CacheRecord(); const cache = new OpenSeadragon.CacheRecord();
cache.addTile(dummyTile, "/test/data/A.png", "__TEST__url"); cache.addTile(dummyTile, "/test/data/A.png", "__TEST__url");
cache.getDataAs("__TEST__longConversionProcessForTesting").then(convertedData => { cache.getDataAs("__TEST__longConversionProcessForTesting").then(convertedData => {
test.equal(longConversionDestroy, 0, "Copy not destroyed."); test.equal(longConversionDestroy, 1, "Copy already destroyed.");
test.notOk(cache.loaded, "Cache was destroyed."); test.notOk(cache.loaded, "Cache was destroyed.");
test.equal(cache.data, undefined, "Already destroyed cache does not return data."); test.equal(cache.data, undefined, "Already destroyed cache does not return data.");
test.equal(urlDestroy, 1, "Url was destroyed."); test.equal(urlDestroy, 1, "Url was destroyed.");
test.notOk(conversionHappened, "Nothing happened since before us the cache was deleted."); test.ok(conversionHappened, "Conversion was fired.");
//destruction will likely happen after we finish current async callback //destruction will likely happen after we finish current async callback
setTimeout(async () => { setTimeout(async () => {
test.notOk(conversionHappened, "Still no conversion."); test.equal(longConversionDestroy, 1, "Copy destroyed.");
done(); done();
}, 25); }, 25);
}); });
@ -375,7 +380,9 @@
const dummyRect = new OpenSeadragon.Rect(0, 0, 0, 0, 0); const dummyRect = new OpenSeadragon.Rect(0, 0, 0, 0, 0);
const dummyTile = new OpenSeadragon.Tile(0, 0, 0, dummyRect, true, "", const dummyTile = new OpenSeadragon.Tile(0, 0, 0, dummyRect, true, "",
undefined, true, null, dummyRect, "", "key"); undefined, true, null, dummyRect, "", "key");
dummyTile.tiledImage = {}; dummyTile.tiledImage = {
redraw: function () {}
};
const cache = new OpenSeadragon.CacheRecord(); const cache = new OpenSeadragon.CacheRecord();
cache.addTile(dummyTile, "/test/data/A.png", "__TEST__url"); cache.addTile(dummyTile, "/test/data/A.png", "__TEST__url");
cache.transformTo("__TEST__longConversionProcessForTesting").then(_ => { cache.transformTo("__TEST__longConversionProcessForTesting").then(_ => {