-
-
Notifications
You must be signed in to change notification settings - Fork 933
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into luan.benchmark
- Loading branch information
Showing
4 changed files
with
319 additions
and
2 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 |
---|---|---|
|
@@ -24,3 +24,4 @@ dev_dependencies: | |
flame_lint: ^1.2.1 | ||
flutter_test: | ||
sdk: flutter | ||
mocktail: ^1.0.4 |
69 changes: 69 additions & 0 deletions
69
packages/flame_texturepacker/test/flame_texturepacker_test.dart
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,69 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flame/cache.dart'; | ||
import 'package:flame/flame.dart'; | ||
import 'package:flame/game.dart'; | ||
import 'package:flame_texturepacker/flame_texturepacker.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
class _MockAssetBundle extends Mock implements AssetBundle {} | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
group('TexturepackerLoader', () { | ||
const atlasPath = | ||
'test/assets/newFormat/multiplePages/MultiplePageAtlasMap.atlas'; | ||
const atlasImage1 = | ||
'test/assets/newFormat/multiplePages/MultiplePageAtlasMap.png'; | ||
|
||
test('load atlas from storage', () async { | ||
final flameGame = FlameGame(); | ||
final atlas = await flameGame.atlasFromStorage(atlasPath); | ||
|
||
expect(atlas, isNotNull); | ||
expect(atlas.sprites.length, equals(12)); | ||
|
||
final firstSprite = atlas.findSpriteByName('robot_walk'); | ||
expect(firstSprite, isNotNull); | ||
expect(firstSprite!.srcSize, isNotNull); | ||
expect(firstSprite.srcPosition, isNotNull); | ||
}); | ||
|
||
test('load atlas from assets', () async { | ||
final bundle = _MockAssetBundle(); | ||
when(() => bundle.loadString(any())) | ||
.thenAnswer((_) async => File(atlasPath).readAsString()); | ||
when(() => bundle.load(any())).thenAnswer( | ||
(_) async => ByteData.sublistView( | ||
File(atlasImage1).readAsBytesSync(), | ||
), | ||
); | ||
|
||
final flameGame = FlameGame(); | ||
Flame.assets = AssetsCache(bundle: bundle, prefix: ''); | ||
Flame.images = Images(bundle: bundle, prefix: ''); | ||
|
||
final atlas = await flameGame.atlasFromAssets(atlasPath); | ||
|
||
expect(atlas, isNotNull); | ||
expect(atlas.sprites.length, equals(12)); | ||
|
||
final firstSprite = atlas.findSpriteByName('robot_walk'); | ||
expect(firstSprite, isNotNull); | ||
expect(firstSprite!.srcSize.x, greaterThan(0)); | ||
expect(firstSprite.srcSize.y, greaterThan(0)); | ||
expect(firstSprite.srcPosition, isNotNull); | ||
}); | ||
|
||
test('throws exception for invalid atlas path', () async { | ||
final flameGame = FlameGame(); | ||
expect( | ||
() => flameGame.atlasFromStorage('invalid_path.atlas'), | ||
throwsException, | ||
); | ||
}); | ||
}); | ||
} |
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
Oops, something went wrong.