import 'dart:typed_data'; import 'package:flutter_test/flutter_test.dart'; import 'package:image/image.dart' as img; import 'package:bully/services/ai_export_service.dart'; /// Construit un JPEG porteur de métadonnées EXIF comme le ferait un téléphone : /// position GPS, modèle d'appareil et orientation. Uint8List _photoWithExif({int orientation = 1}) { final image = img.Image(width: 40, height: 20); img.fill(image, color: img.ColorRgb8(120, 120, 120)); image.exif.imageIfd['Model'] = 'Pixel 8'; image.exif.imageIfd.orientation = orientation; image.exif.gpsIfd['GPSLatitude'] = 48.8584; image.exif.gpsIfd['GPSLongitude'] = 2.2945; return img.encodeJpg(image); } void main() { final service = AiExportService(); group('stripMetadata', () { test('supprime le GPS et les autres métadonnées EXIF', () { final original = _photoWithExif(); // Garde-fou : sans EXIF au départ, le test ne prouverait rien. expect(img.decodeImage(original)!.exif.isEmpty, isFalse); final stripped = service.stripMetadata(original); final result = img.decodeImage(stripped!)!; expect(result.exif.isEmpty, isTrue); expect(result.exif.gpsIfd.isEmpty, isTrue); }); test('applique l\'orientation aux pixels avant de retirer le tag', () { // Orientation 6 = rotation de 90°, donc les dimensions s'inversent. final original = _photoWithExif(orientation: 6); final result = img.decodeImage(service.stripMetadata(original)!)!; expect(result.width, 20); expect(result.height, 40); expect(result.exif.isEmpty, isTrue); }); test('conserve les dimensions quand il n\'y a pas d\'orientation', () { final result = img.decodeImage(service.stripMetadata(_photoWithExif())!)!; expect(result.width, 40); expect(result.height, 20); }); test('retourne null sur une image illisible', () { expect(service.stripMetadata(Uint8List.fromList([1, 2, 3, 4])), isNull); }); }); }