Files
flux/test/core/utils/image_utils_test.dart
T
brontomark 53496a2a9d
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 1m55s
Build and Release FLUX (Multi-Platform) / build-linux (push) Successful in 1m29s
Build and Release FLUX (Multi-Platform) / build-macos (push) Successful in 2m43s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 8m15s
aggiunto supporto al salvataggio rotazione immagini
2026-10-15 13:11:51 +02:00

50 lines
1.6 KiB
Dart

import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:flux/core/utils/image_utils.dart';
import 'package:image/image.dart' as img;
void main() {
group('ImageUtils Tests', () {
test('rotateBytes with quarterTurns 0 or 4 returns original bytes', () {
final dummy = Uint8List.fromList([1, 2, 3, 4]);
expect(ImageUtils.rotateBytes(dummy, quarterTurns: 0), equals(dummy));
expect(ImageUtils.rotateBytes(dummy, quarterTurns: 4), equals(dummy));
});
test('rotateBytes correctly rotates an image by 90 degrees', () {
// Creiamo un'immagine 10x20 (larghezza 10, altezza 20)
final testImg = img.Image(width: 10, height: 20);
final encodedPng = Uint8List.fromList(img.encodePng(testImg));
// Ruotiamo di 1 quarto (90°)
final rotatedBytes = ImageUtils.rotateBytes(
encodedPng,
quarterTurns: 1,
extension: 'png',
);
final decoded = img.decodeImage(rotatedBytes);
expect(decoded, isNotNull);
// Dopo 90 gradi di rotazione, larghezza e altezza devono invertirsi (20x10)
expect(decoded!.width, 20);
expect(decoded.height, 10);
});
test('rotateBytes correctly rotates an image by 180 degrees', () {
final testImg = img.Image(width: 15, height: 30);
final encodedPng = Uint8List.fromList(img.encodePng(testImg));
final rotatedBytes = ImageUtils.rotateBytes(
encodedPng,
quarterTurns: 2,
extension: 'png',
);
final decoded = img.decodeImage(rotatedBytes);
expect(decoded, isNotNull);
expect(decoded!.width, 15);
expect(decoded.height, 30);
});
});
}