-
-
Notifications
You must be signed in to change notification settings - Fork 860
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first tests for TileRemovalState
- Loading branch information
1 parent
fc884d1
commit 028ed3b
Showing
4 changed files
with
157 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import 'package:flutter/src/scheduler/ticker.dart'; | ||
import 'package:flutter_map/flutter_map.dart'; | ||
import 'package:flutter_map/src/layer/tile_layer/tile_range.dart'; | ||
import 'package:flutter_map/src/layer/tile_layer/tile_removal_state.dart'; | ||
import 'package:flutter_map/src/misc/private/bounds.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../../test_utils/test_tile_image.dart'; | ||
|
||
void main() { | ||
group('tilesToPrune', () { | ||
test('prunes tiles outside of the visible range', () { | ||
final tileImages = [ | ||
MockTileImage( | ||
coordinates: const TileCoordinates(1, 1, 1), | ||
loadFinished: true, | ||
readyToDisplay: true, | ||
), | ||
MockTileImage( | ||
coordinates: const TileCoordinates(2, 1, 1), | ||
loadFinished: true, | ||
readyToDisplay: true, | ||
), | ||
]; | ||
final removalState = TileRemovalState( | ||
tileImages: tileImages, | ||
visibleRange: DiscreteTileRange( | ||
1, | ||
Bounds(const CustomPoint(2, 1), const CustomPoint(3, 3)), | ||
), | ||
keepRange: DiscreteTileRange( | ||
1, | ||
Bounds(const CustomPoint(2, 1), const CustomPoint(3, 3)), | ||
), | ||
evictStrategy: EvictErrorTileStrategy.none, | ||
); | ||
expect(removalState.tilesToPrune(), [tileImages.first]); | ||
}); | ||
|
||
test('keeps ancestor tile if a tile has not loaded yet', () { | ||
final tileImages = [ | ||
MockTileImage( | ||
coordinates: const TileCoordinates(0, 0, 0), | ||
loadFinished: true, | ||
readyToDisplay: true, | ||
), | ||
MockTileImage( | ||
coordinates: const TileCoordinates(0, 0, 1), | ||
loadFinished: false, | ||
readyToDisplay: false, | ||
), | ||
]; | ||
final removalState = TileRemovalState( | ||
tileImages: tileImages, | ||
visibleRange: DiscreteTileRange( | ||
1, | ||
Bounds(const CustomPoint(0, 0), const CustomPoint(0, 0)), | ||
), | ||
keepRange: DiscreteTileRange( | ||
1, | ||
Bounds(const CustomPoint(0, 0), const CustomPoint(0, 0)), | ||
), | ||
evictStrategy: EvictErrorTileStrategy.none, | ||
); | ||
expect(removalState.tilesToPrune(), isNot(contains(tileImages.first))); | ||
}); | ||
|
||
test('keeps descendant tile if there is no loaded tile obscuring it', () { | ||
final tileImages = [ | ||
MockTileImage( | ||
coordinates: const TileCoordinates(0, 0, 0), | ||
loadFinished: false, | ||
readyToDisplay: false, | ||
), | ||
MockTileImage( | ||
coordinates: const TileCoordinates(0, 0, 1), | ||
loadFinished: false, | ||
readyToDisplay: false, | ||
), | ||
MockTileImage( | ||
coordinates: const TileCoordinates(0, 0, 2), | ||
loadFinished: true, | ||
readyToDisplay: true, | ||
), | ||
]; | ||
final removalState = TileRemovalState( | ||
tileImages: tileImages, | ||
visibleRange: DiscreteTileRange( | ||
1, | ||
Bounds(const CustomPoint(0, 0), const CustomPoint(0, 0)), | ||
), | ||
keepRange: DiscreteTileRange( | ||
1, | ||
Bounds(const CustomPoint(0, 0), const CustomPoint(0, 0)), | ||
), | ||
evictStrategy: EvictErrorTileStrategy.none, | ||
); | ||
expect(removalState.tilesToPrune(), isNot(contains(tileImages.last))); | ||
}); | ||
}); | ||
} | ||
|
||
class MockTileImage extends TileImage { | ||
@override | ||
final bool readyToDisplay; | ||
|
||
MockTileImage({ | ||
required super.coordinates, | ||
required this.readyToDisplay, | ||
required bool loadFinished, | ||
void Function(TileCoordinates coordinates)? onLoadComplete, | ||
void Function(TileImage tile, Object error, StackTrace? stackTrace)? | ||
onLoadError, | ||
TileDisplay? tileDisplay, | ||
super.errorImage, | ||
}) : super( | ||
vsync: const MockTickerProvider(), | ||
imageProvider: testWhiteTileImage, | ||
onLoadComplete: onLoadComplete ?? (_) {}, | ||
onLoadError: onLoadError ?? (_, __, ___) {}, | ||
tileDisplay: const TileDisplay.instantaneous(), | ||
) { | ||
loadFinishedAt = loadFinished ? DateTime.now() : null; | ||
} | ||
} | ||
|
||
class MockTickerProvider extends TickerProvider { | ||
const MockTickerProvider(); | ||
|
||
@override | ||
Ticker createTicker(TickerCallback onTick) { | ||
return Ticker((elapsed) {}); | ||
} | ||
} |
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
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,8 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/painting.dart'; | ||
|
||
// Base 64 encoded 256x256 white tile. | ||
const _whiteTile = | ||
'iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAANQTFRF////p8QbyAAAAB9JREFUeJztwQENAAAAwqD3T20ON6AAAAAAAAAAAL4NIQAAAfFnIe4AAAAASUVORK5CYII='; | ||
final testWhiteTileImage = MemoryImage(base64Decode(_whiteTile)); |
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,13 @@ | ||
import 'package:flutter/rendering.dart'; | ||
import 'package:flutter_map/src/layer/tile_layer/tile_coordinates.dart'; | ||
import 'package:flutter_map/src/layer/tile_layer/tile_layer.dart'; | ||
import 'package:flutter_map/src/layer/tile_layer/tile_provider/base_tile_provider.dart'; | ||
|
||
import 'test_tile_image.dart'; | ||
|
||
class TestTileProvider extends TileProvider { | ||
@override | ||
ImageProvider<Object> getImage( | ||
TileCoordinates coordinates, TileLayer options) => | ||
testWhiteTileImage; | ||
} |