Skip to content

Commit

Permalink
画像読込のテストコード実装
Browse files Browse the repository at this point in the history
  • Loading branch information
4ster1sk committed Nov 13, 2024
1 parent 82e95dc commit b5c6086
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
Binary file added test/assets/images/exif_ifd_only.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/assets/images/exif_no_data.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/assets/images/exif_test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/assets/images/test.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/assets/images/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions test/state_notifier/note_create_page/image_exif_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import "dart:io";
import "package:flutter_test/flutter_test.dart";
import "package:image/image.dart";
import "package:miria/state_notifier/note_create_page/note_create_state_notifier.dart";

void main() {
group("画像読込", () {
test("PNG画像が読み込めること", () async {
final file = File("test/assets/images/test.png");
final d = await NoteCreateNotifier().loadImage(file);
expect(decodePng(d), isNotNull);
});

test("GIF画像が読み込めること", () async {
final file = File("test/assets/images/test.gif");
final d = await NoteCreateNotifier().loadImage(file);

expect(decodeGif(d), isNotNull);
});

test("JPEG画像が読み込めること", () async {
final file = File("test/assets/images/exif_test.jpg");
final d = await NoteCreateNotifier().loadImage(file);
expect(decodeJpg(d), isNotNull);
});

test("入力JPEG画像にgpsIfdのキーがあること", () async {
final file = File("test/assets/images/exif_test.jpg");
final exif = decodeJpgExif(await file.readAsBytes());
expect(exif?.gpsIfd.values.length, 5);
});

test("出力JPEG画像にgpsIfdのキーが存在しないこと", () async {
final file = File("test/assets/images/exif_test.jpg");
final d = await NoteCreateNotifier().loadImage(file);
final exif = decodeJpgExif(d);
expect(exif, isNotNull);
expect(exif?.gpsIfd.keys.length, 0);
});

test("出力JPEG画像のEXIFに向き以外存在しないこと", () async {
final file = File("test/assets/images/exif_test.jpg");
final d = await NoteCreateNotifier().loadImage(file);
final exif = decodeJpgExif(d);
expect(exif, isNotNull);
expect(exif?.imageIfd.keys.length, 1);
expect(exif?.imageIfd.keys.first, 274);
});

test("出力JPEG画像のEXIFのOrientation値が6であること", () async {
final file = File("test/assets/images/exif_test.jpg");
final d = await NoteCreateNotifier().loadImage(file);
final exif = decodeJpgExif(d);
expect(exif, isNotNull);
expect(exif?.imageIfd.keys.length, 1);
expect(exif?.imageIfd.orientation, 6);
});

test("EXIFがIFDだけのJPEG画像が読み込めること", () async {
final file = File("test/assets/images/exif_ifd_only.jpg");
final d = await NoteCreateNotifier().loadImage(file);
final img = decodeJpg(d);
expect(img, isNotNull);
});

test("EXIFがIFDだけのJPEG画像はOrientation値が1になること", () async {
final file = File("test/assets/images/exif_ifd_only.jpg");
final d = await NoteCreateNotifier().loadImage(file);
final exif = decodeJpgExif(d);
expect(exif, isNotNull);
expect(exif?.imageIfd.keys.length, 1);
expect(exif?.imageIfd.orientation, 1);
});

test("EXIFがないJPEG画像の場合はEXIFをつけないこと", () async {
final file = File("test/assets/images/exif_no_data.jpg");
final d = await NoteCreateNotifier().loadImage(file);
expect(decodeJpg(d), isNotNull);
final exif = decodeJpgExif(d);
expect(exif, isNull);
});
});
}

0 comments on commit b5c6086

Please sign in to comment.