nc-photos/test/entity/exif_test.dart
Ming Ming bb71dcc22b Remove MakerNote from Exif
It's too large for nothing
2021-04-24 00:46:32 +08:00

150 lines
3.9 KiB
Dart

import 'dart:typed_data';
import 'package:equatable/equatable.dart';
import 'package:exifdart/exifdart.dart';
import 'package:nc_photos/entity/exif.dart';
import 'package:test/test.dart';
void main() {
group("Exif", () {
group("toJson", () {
test("int", () {
final exif = Exif(<String, dynamic>{
"ImageWidth": 1024,
});
expect(exif.toJson(), <String, dynamic>{
"ImageWidth": 1024,
});
});
test("String", () {
final exif = Exif(<String, dynamic>{
"Make": "dummy",
});
expect(exif.toJson(), <String, dynamic>{
"Make": "dummy",
});
});
test("Rational", () {
final exif = Exif(<String, dynamic>{
"XResolution": Rational(72, 1),
});
expect(exif.toJson(), <String, dynamic>{
"XResolution": {"numerator": 72, "denominator": 1},
});
});
test("List<int>", () {
final exif = Exif(<String, dynamic>{
"YCbCrSubSampling": [2, 2],
});
expect(exif.toJson(), <String, dynamic>{
"YCbCrSubSampling": [2, 2],
});
});
test("List<Rational>", () {
final exif = Exif(<String, dynamic>{
"GPSLatitude": [Rational(2, 1), Rational(3, 1), Rational(4, 100)],
});
expect(exif.toJson(), <String, dynamic>{
"GPSLatitude": [
{"numerator": 2, "denominator": 1},
{"numerator": 3, "denominator": 1},
{"numerator": 4, "denominator": 100},
],
});
});
test("MakerNote", () {
final exif = Exif(<String, dynamic>{
"MakerNote": Uint8List.fromList([0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF]),
});
expect(exif.toJson(), <String, dynamic>{});
});
});
group("fromJson", () {
test("int", () {
final json = <String, dynamic>{
"ImageWidth": 1024,
};
expect(
Exif.fromJson(json),
Exif(<String, dynamic>{
"ImageWidth": 1024,
}));
});
test("String", () {
final json = <String, dynamic>{
"Make": "dummy",
};
expect(
Exif.fromJson(json),
Exif(<String, dynamic>{
"Make": "dummy",
}));
});
test("Rational", () {
final json = <String, dynamic>{
"XResolution": {"numerator": 72, "denominator": 1},
};
final Rational exif = Exif.fromJson(json)["XResolution"];
expect(exif.makeComparable(), _Rational(72, 1));
});
test("List<int>", () {
final json = <String, dynamic>{
"YCbCrSubSampling": [2, 2],
};
expect(
Exif.fromJson(json),
Exif(<String, dynamic>{
"YCbCrSubSampling": [2, 2],
}));
});
test("List<Rational>", () {
final json = <String, dynamic>{
"GPSLatitude": [
{"numerator": 2, "denominator": 1},
{"numerator": 3, "denominator": 1},
{"numerator": 4, "denominator": 100},
],
};
final List<Rational> exif =
Exif.fromJson(json)["GPSLatitude"].cast<Rational>();
expect(exif.map((e) => e.makeComparable()).toList(),
[_Rational(2, 1), _Rational(3, 1), _Rational(4, 100)]);
});
test("MakerNote", () {
final json = <String, dynamic>{
"MakerNote": "ADNmmcz_",
};
expect(Exif.fromJson(json), Exif(<String, dynamic>{}));
});
});
});
}
extension on Rational {
_Rational makeComparable() => _Rational.of(this);
}
class _Rational extends Rational with EquatableMixin {
_Rational(int numerator, int denominator) : super(numerator, denominator);
factory _Rational.of(Rational r) {
return _Rational(r.numerator, r.denominator);
}
@override
get props => [
numerator,
denominator,
];
}