summaryrefslogtreecommitdiff
path: root/test/utils
diff options
context:
space:
mode:
authormirror <mirror@localhost>2026-11-22 08:41:00 +0900
committermirror <mirror@localhost>2026-11-22 08:41:00 +0900
commit449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch)
treec131c3528c4d517f56e19b854a7453fedb097d40 /test/utils
downloadaves-src-master.tar.gz
aves-src-master.zip
snapshot of aves v1.13.12 (secrets removed: android/app/google-services.json)HEADv1.13.12master
Diffstat (limited to 'test/utils')
-rw-r--r--test/utils/android_file_utils.dart27
-rw-r--r--test/utils/file_utils_test.dart14
-rw-r--r--test/utils/geo_utils_test.dart37
-rw-r--r--test/utils/math_utils_test.dart38
-rw-r--r--test/utils/string_utils_test.dart19
-rw-r--r--test/utils/time_utils_test.dart44
-rw-r--r--test/utils/xmp_utils_test.dart472
7 files changed, 651 insertions, 0 deletions
diff --git a/test/utils/android_file_utils.dart b/test/utils/android_file_utils.dart
new file mode 100644
index 0000000..581acb9
--- /dev/null
+++ b/test/utils/android_file_utils.dart
@@ -0,0 +1,27 @@
+import 'package:aves/services/common/services.dart';
+import 'package:aves/services/storage_service.dart';
+import 'package:aves/utils/android_file_utils.dart';
+import 'package:path/path.dart' as p;
+import 'package:test/test.dart';
+
+import '../fake/storage_service.dart';
+
+void main() {
+ setUp(() async {
+ // specify Posix style path context for consistent behaviour when running tests on Windows
+ getIt.registerLazySingleton<p.Context>(() => p.Context(style: p.Style.posix));
+
+ getIt.registerLazySingleton<StorageService>(FakeStorageService.new);
+
+ await androidFileUtils.init();
+ });
+
+ tearDown(() async {
+ await getIt.reset();
+ });
+
+ test('camera album identification', () {
+ expect(androidFileUtils.isCameraPath('${FakeStorageService.primaryPath}DCIM/Camera'), true);
+ expect(androidFileUtils.isCameraPath('${FakeStorageService.primaryPath}DCIM/YoloCamera'), false);
+ });
+}
diff --git a/test/utils/file_utils_test.dart b/test/utils/file_utils_test.dart
new file mode 100644
index 0000000..6dea8bd
--- /dev/null
+++ b/test/utils/file_utils_test.dart
@@ -0,0 +1,14 @@
+import 'package:aves/l10n/l10n.dart';
+import 'package:aves/utils/file_utils.dart';
+import 'package:aves/widgets/aves_app.dart';
+import 'package:test/test.dart';
+
+void main() {
+ test('format file size', () {
+ final l10n = lookupAppLocalizations(AvesApp.supportedLocales.first);
+ final locale = l10n.localeName;
+ expect(formatFileSize(locale, 1024), '1.00 KB');
+ expect(formatFileSize(locale, 1536), '1.50 KB');
+ expect(formatFileSize(locale, 1073741824), '1.00 GB');
+ });
+}
diff --git a/test/utils/geo_utils_test.dart b/test/utils/geo_utils_test.dart
new file mode 100644
index 0000000..c343813
--- /dev/null
+++ b/test/utils/geo_utils_test.dart
@@ -0,0 +1,37 @@
+import 'package:aves/l10n/l10n.dart';
+import 'package:aves/model/settings/enums/coordinate_format.dart';
+import 'package:aves/widgets/aves_app.dart';
+import 'package:aves_map/aves_map.dart';
+import 'package:latlong2/latlong.dart';
+import 'package:test/test.dart';
+
+void main() {
+ test('Decimal degrees to DMS (sexagesimal)', () {
+ final l10n = lookupAppLocalizations(AvesApp.supportedLocales.first);
+ expect(ExtraCoordinateFormat.toDMS(l10n, const LatLng(37.496667, 127.0275)), ['37° 29′ 48.00″ N', '127° 1′ 39.00″ E']); // Gangnam
+ expect(ExtraCoordinateFormat.toDMS(l10n, const LatLng(78.9243503, 11.9230465)), ['78° 55′ 27.66″ N', '11° 55′ 22.97″ E']); // Ny-Ålesund
+ expect(ExtraCoordinateFormat.toDMS(l10n, const LatLng(-38.6965891, 175.9830047)), ['38° 41′ 47.72″ S', '175° 58′ 58.82″ E']); // Taupo
+ expect(ExtraCoordinateFormat.toDMS(l10n, const LatLng(-64.249391, -56.6556145)), ['64° 14′ 57.81″ S', '56° 39′ 20.21″ W']); // Marambio
+ expect(ExtraCoordinateFormat.toDMS(l10n, const LatLng(0, 0)), ['0° 0′ 0.00″ N', '0° 0′ 0.00″ E']);
+ expect(ExtraCoordinateFormat.toDMS(l10n, const LatLng(0, 0), minuteSecondPadding: true), ['0° 00′ 00.00″ N', '0° 00′ 00.00″ E']);
+ expect(ExtraCoordinateFormat.toDMS(l10n, const LatLng(0, 0), secondDecimals: 0), ['0° 0′ 0″ N', '0° 0′ 0″ E']);
+ expect(ExtraCoordinateFormat.toDMS(l10n, const LatLng(0, 0), secondDecimals: 4), ['0° 0′ 0.0000″ N', '0° 0′ 0.0000″ E']);
+ });
+
+ test('Decimal degrees to DDM', () {
+ final l10n = lookupAppLocalizations(AvesApp.supportedLocales.first);
+ expect(ExtraCoordinateFormat.toDDM(l10n, const LatLng(37.496667, 127.0275)), ['37° 29.8000′ N', '127° 1.6500′ E']); // Gangnam
+ expect(ExtraCoordinateFormat.toDDM(l10n, const LatLng(78.9243503, 11.9230465)), ['78° 55.4610′ N', '11° 55.3828′ E']); // Ny-Ålesund
+ expect(ExtraCoordinateFormat.toDDM(l10n, const LatLng(-38.6965891, 175.9830047)), ['38° 41.7953′ S', '175° 58.9803′ E']); // Taupo
+ expect(ExtraCoordinateFormat.toDDM(l10n, const LatLng(-64.249391, -56.6556145)), ['64° 14.9635′ S', '56° 39.3369′ W']); // Marambio
+ expect(ExtraCoordinateFormat.toDDM(l10n, const LatLng(0, 0)), ['0° 0.0000′ N', '0° 0.0000′ E']);
+ expect(ExtraCoordinateFormat.toDDM(l10n, const LatLng(0, 0), minutePadding: true), ['0° 00.0000′ N', '0° 00.0000′ E']);
+ expect(ExtraCoordinateFormat.toDDM(l10n, const LatLng(0, 0), minuteDecimals: 0), ['0° 0′ N', '0° 0′ E']);
+ expect(ExtraCoordinateFormat.toDDM(l10n, const LatLng(0, 0), minuteDecimals: 6), ['0° 0.000000′ N', '0° 0.000000′ E']);
+ });
+
+ test('bounds center', () {
+ expect(GeoUtils.getLatLngCenter(const [LatLng(10, 30), LatLng(30, 50)]), const LatLng(20.28236664671092, 39.351653000319956));
+ expect(GeoUtils.getLatLngCenter(const [LatLng(10, -179), LatLng(30, 179)]), const LatLng(20.00279344048298, -179.9358157370226));
+ });
+}
diff --git a/test/utils/math_utils_test.dart b/test/utils/math_utils_test.dart
new file mode 100644
index 0000000..d698711
--- /dev/null
+++ b/test/utils/math_utils_test.dart
@@ -0,0 +1,38 @@
+import 'dart:ui';
+
+import 'package:aves/utils/math_utils.dart';
+import 'package:test/test.dart';
+
+void main() {
+ test('highest power of 2 that is smaller than or equal to the number', () {
+ expect(highestPowerOf2(1024), 1024);
+ expect(highestPowerOf2(42), 32);
+ expect(highestPowerOf2(0), 0);
+ expect(highestPowerOf2(-42), 0);
+ expect(highestPowerOf2(.5), 0);
+ expect(highestPowerOf2(1.5), 1);
+ });
+
+ test('smallest power of 2 that is larger than or equal to the number', () {
+ expect(smallestPowerOf2(1024), 1024);
+ expect(smallestPowerOf2(42), 64);
+ expect(smallestPowerOf2(0), 1);
+ expect(smallestPowerOf2(-42), 1);
+ expect(smallestPowerOf2(.5), 1);
+ expect(smallestPowerOf2(1.5), 2);
+ expect(smallestPowerOf2(0.5, allowNegativePower: true), 0.5);
+ expect(smallestPowerOf2(0.1, allowNegativePower: true), 0.125);
+ expect(smallestPowerOf2(0, allowNegativePower: true), 1);
+ });
+
+ test('rounding to a given precision after the decimal', () {
+ expect(roundToPrecision(1.2345678, decimals: 3), 1.235);
+ expect(roundToPrecision(0, decimals: 3), 0);
+ });
+
+ test('segment intersection', () {
+ const s1 = (Offset(1, 1), Offset(3, 2));
+ const s2 = (Offset(1, 4), Offset(2, -1));
+ expect(segmentIntersection(s1, s2), const Offset(17 / 11, 14 / 11));
+ });
+}
diff --git a/test/utils/string_utils_test.dart b/test/utils/string_utils_test.dart
new file mode 100644
index 0000000..a7792fb
--- /dev/null
+++ b/test/utils/string_utils_test.dart
@@ -0,0 +1,19 @@
+import 'package:aves/utils/string_utils.dart';
+import 'package:test/test.dart';
+
+void main() {
+ test('Sentence case', () {
+ expect('XResolution'.toSentenceCase(), 'X Resolution');
+ expect('PixelXDimension'.toSentenceCase(), 'Pixel X Dimension');
+ expect('FocalPointX'.toSentenceCase(), 'Focal Point X');
+
+ expect('ISOSpeedRatings[1]'.toSentenceCase(), 'ISO Speed Ratings [1]');
+ expect('LegacyIPTCDigest'.toSentenceCase(), 'Legacy IPTC Digest');
+ expect('DocumentID'.toSentenceCase(), 'Document ID');
+
+ expect('H'.toSentenceCase(), 'H');
+ expect('LW[1]'.toSentenceCase(), 'LW [1]');
+
+ expect('bits_per_raw_sample'.toSentenceCase(), 'Bits Per Raw Sample');
+ });
+}
diff --git a/test/utils/time_utils_test.dart b/test/utils/time_utils_test.dart
new file mode 100644
index 0000000..233594f
--- /dev/null
+++ b/test/utils/time_utils_test.dart
@@ -0,0 +1,44 @@
+import 'package:aves/utils/time_utils.dart';
+import 'package:test/test.dart';
+
+void main() {
+ test('Comparison extension functions', () {
+ expect(DateTime(1593, 7, 8).isAtSameYearAs(null), false);
+ expect(DateTime(1903, 9, 25).isAtSameYearAs(DateTime(1970, 2, 25)), false);
+ expect(DateTime(1929, 3, 22).isAtSameYearAs(DateTime(1929, 3, 22)), true);
+
+ expect(DateTime(1593, 7, 8).isAtSameMonthAs(null), false);
+ expect(DateTime(1903, 9, 25).isAtSameMonthAs(DateTime(1970, 2, 25)), false);
+ expect(DateTime(1929, 3, 22).isAtSameMonthAs(DateTime(1929, 3, 22)), true);
+
+ expect(DateTime(1593, 7, 8).isAtSameDayAs(null), false);
+ expect(DateTime(1903, 9, 25).isAtSameDayAs(DateTime(1970, 2, 25)), false);
+ expect(DateTime(1929, 3, 22).isAtSameDayAs(DateTime(1929, 3, 22)), true);
+ });
+
+ test('Parse dates', () {
+ DateTime shiftTimeZoneOffset(DateTime date) {
+ // local time zone offset may not be the same across time (because of DST),
+ // so we cannot reliably use `DateTime.now().timeZoneOffset`
+ return date.add(date.timeZoneOffset);
+ }
+
+ expect(parseUnknownDateFormat('1600995564713'), shiftTimeZoneOffset(DateTime(2020, 9, 25, 0, 59, 24, 713)));
+ expect(parseUnknownDateFormat('pre1600995564713suf'), shiftTimeZoneOffset(DateTime(2020, 9, 25, 0, 59, 24, 713)));
+
+ expect(parseUnknownDateFormat('1600995564'), shiftTimeZoneOffset(DateTime(2020, 9, 25, 0, 59, 24, 0)));
+ expect(parseUnknownDateFormat('pre1600995564suf'), shiftTimeZoneOffset(DateTime(2020, 9, 25, 0, 59, 24, 0)));
+
+ expect(parseUnknownDateFormat('IMG_20210901_142523_783'), DateTime(2021, 9, 1, 14, 25, 23, 783));
+ expect(parseUnknownDateFormat('Screenshot_20211028-115056_Aves'), DateTime(2021, 10, 28, 11, 50, 56, 0));
+
+ expect(parseUnknownDateFormat('Screenshot_2022-05-14-15-40-29-164_uri'), DateTime(2022, 5, 14, 15, 40, 29, 164));
+ expect(parseUnknownDateFormat('2019-02-18 16.00.12-DCM'), DateTime(2019, 2, 18, 16, 0, 12, 0));
+ expect(parseUnknownDateFormat('2020-11-01 00.31.02'), DateTime(2020, 11, 1, 0, 31, 2, 0));
+ expect(parseUnknownDateFormat('2019-10-31 135703'), DateTime(2019, 10, 31, 13, 57, 3, 0));
+ expect(parseUnknownDateFormat('Foo_2023-03-12_01-59-23.614_1920x1080'), DateTime(2023, 3, 12, 1, 59, 23, 614));
+
+ expect(parseUnknownDateFormat('signal-2025-08-26-12-03-16-348'), DateTime(2025, 8, 26, 12, 3, 16, 348));
+ expect(parseUnknownDateFormat('signal-2025-04-18-094154'), DateTime(2025, 4, 18, 9, 41, 54));
+ });
+}
diff --git a/test/utils/xmp_utils_test.dart b/test/utils/xmp_utils_test.dart
new file mode 100644
index 0000000..d45e13e
--- /dev/null
+++ b/test/utils/xmp_utils_test.dart
@@ -0,0 +1,472 @@
+import 'package:aves/model/entry/extensions/metadata_edition.dart';
+import 'package:aves/ref/metadata/xmp.dart';
+import 'package:aves/utils/xmp_utils.dart';
+import 'package:test/test.dart';
+import 'package:xml/xml.dart';
+
+void main() {
+ const toolkit = 'test-toolkit';
+
+ String? _toExpect(String? xmpString) => xmpString != null
+ ? XmlDocument.parse(xmpString).toXmlString(
+ pretty: true,
+ sortAttributes: (a, b) => a.name.qualified.compareTo(b.name.qualified),
+ )
+ : null;
+
+ List<XmlNode> _getDescriptions(String xmpString) {
+ final xmpDoc = XmlDocument.parse(xmpString);
+ final root = xmpDoc.rootElement;
+ final rdf = root.getElement(XmpElements.rdfRoot, namespace: XmpNamespaces.rdf);
+ return rdf!.children.where((node) {
+ return node is XmlElement && node.name.local == XmpElements.rdfDescription && node.name.namespaceUri == XmpNamespaces.rdf;
+ }).toList();
+ }
+
+ const inMultiDescriptionRatings = '''
+<x:xmpmeta xmlns:x="adobe:ns:meta/">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description xmlns:xmp="http://ns.adobe.com/xap/1.0/" rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b">
+ <xmp:Rating>5</xmp:Rating>
+ </rdf:Description>
+ <rdf:Description xmlns:MicrosoftPhoto="http://ns.microsoft.com/photo/1.0/" rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b">
+ <MicrosoftPhoto:Rating>99</MicrosoftPhoto:Rating>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
+''';
+ const inRatingAttribute = '''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core Test.SNAPSHOT">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description xmlns:xmp="http://ns.adobe.com/xap/1.0/" rdf:about="" xmp:Rating="5" />
+ </rdf:RDF>
+</x:xmpmeta>
+''';
+ const inRatingElement = '''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core Test.SNAPSHOT">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description xmlns:xmp="http://ns.adobe.com/xap/1.0/" rdf:about="">
+ <xmp:Rating>5</xmp:Rating>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
+''';
+ const inSubjects = '''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core Test.SNAPSHOT">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about=""
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <dc:subject>
+ <rdf:Bag>
+ <rdf:li>the king</rdf:li>
+ </rdf:Bag>
+ </dc:subject>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
+''';
+ const inSubjectsCreator = '''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core Test.SNAPSHOT">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about=""
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmp:ModifyDate="2021-12-24T21:41:46+09:00"
+ xmp:MetadataDate="2021-12-24T21:41:46+09:00">
+ <dc:creator>
+ <rdf:Seq>
+ <rdf:li>c</rdf:li>
+ </rdf:Seq>
+ </dc:creator>
+ <dc:subject>
+ <rdf:Bag>
+ <rdf:li>a</rdf:li>
+ <rdf:li>b</rdf:li>
+ </rdf:Bag>
+ </dc:subject>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
+''';
+ const inMotionPhotoMicroVideo = '''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.1.0-jc003">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about=""
+ xmlns:GCamera="http://ns.google.com/photos/1.0/camera/"
+ GCamera:MicroVideo="1"
+ GCamera:MicroVideoVersion="1"
+ GCamera:MicroVideoOffset="1228513"
+ GCamera:MicroVideoPresentationTimestampUs="233246"/>
+ </rdf:RDF>
+</x:xmpmeta>
+''';
+ const inMotionPhotoContainer = '''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.1.0-jc003">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about=""
+ xmlns:GCamera="http://ns.google.com/photos/1.0/camera/"
+ xmlns:Container="http://ns.google.com/photos/1.0/container/"
+ xmlns:Item="http://ns.google.com/photos/1.0/container/item/"
+ GCamera:MotionPhoto="1"
+ GCamera:MotionPhotoVersion="1"
+ GCamera:MotionPhotoPresentationTimestampUs="2306056">
+ <Container:Directory>
+ <rdf:Seq>
+ <rdf:li rdf:parseType="Resource">
+ <Container:Item
+ Item:Mime="image/jpeg"
+ Item:Semantic="Primary"
+ Item:Length="0"
+ Item:Padding="59"/>
+ </rdf:li>
+ <rdf:li rdf:parseType="Resource">
+ <Container:Item
+ Item:Mime="video/mp4"
+ Item:Semantic="MotionPhoto"
+ Item:Length="3491777"
+ Item:Padding="0"/>
+ </rdf:li>
+ </rdf:Seq>
+ </Container:Directory>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
+''';
+
+ test('Get string', () async {
+ expect(XMP.getString(_getDescriptions(inRatingAttribute), XmpElements.xmpRating, namespace: XmpNamespaces.xmp), '5');
+ expect(XMP.getString(_getDescriptions(inRatingElement), XmpElements.xmpRating, namespace: XmpNamespaces.xmp), '5');
+ expect(XMP.getString(_getDescriptions(inSubjects), XmpElements.xmpRating, namespace: XmpNamespaces.xmp), null);
+ });
+
+ test('Set tags without existing XMP', () async {
+ final modifyDate = DateTime.now();
+ final xmpDate = XMP.toXmpDate(modifyDate);
+
+ expect(
+ _toExpect(await XMP.edit(
+ null,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editTagsXmp(descriptions, {'one', 'two'}),
+ modifyDate: modifyDate,
+ )),
+ _toExpect('''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="$toolkit">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about=""
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/"
+ xmp:MetadataDate="$xmpDate"
+ xmp:ModifyDate="$xmpDate">
+ <dc:subject>
+ <rdf:Bag>
+ <rdf:li>one</rdf:li>
+ <rdf:li>two</rdf:li>
+ </rdf:Bag>
+ </dc:subject>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
+'''));
+ });
+
+ test('Set tags to XMP with ratings (multiple descriptions)', () async {
+ final modifyDate = DateTime.now();
+ final xmpDate = XMP.toXmpDate(modifyDate);
+
+ expect(
+ _toExpect(await XMP.edit(
+ inMultiDescriptionRatings,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editTagsXmp(descriptions, {'one', 'two'}),
+ modifyDate: modifyDate,
+ )),
+ _toExpect('''
+<x:xmpmeta xmlns:x="adobe:ns:meta/">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/"
+ xmp:MetadataDate="$xmpDate"
+ xmp:ModifyDate="$xmpDate">
+ <xmp:Rating>5</xmp:Rating>
+ <dc:subject>
+ <rdf:Bag>
+ <rdf:li>one</rdf:li>
+ <rdf:li>two</rdf:li>
+ </rdf:Bag>
+ </dc:subject>
+ </rdf:Description>
+ <rdf:Description xmlns:MicrosoftPhoto="http://ns.microsoft.com/photo/1.0/" rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b">
+ <MicrosoftPhoto:Rating>99</MicrosoftPhoto:Rating>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
+'''));
+ });
+
+ test('Set tags to XMP with subjects only', () async {
+ final modifyDate = DateTime.now();
+ final xmpDate = XMP.toXmpDate(modifyDate);
+
+ expect(
+ _toExpect(await XMP.edit(
+ inSubjects,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editTagsXmp(descriptions, {'one', 'two'}),
+ modifyDate: modifyDate,
+ )),
+ _toExpect('''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core Test.SNAPSHOT">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about=""
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/"
+ xmp:MetadataDate="$xmpDate"
+ xmp:ModifyDate="$xmpDate">
+ <dc:subject>
+ <rdf:Bag>
+ <rdf:li>one</rdf:li>
+ <rdf:li>two</rdf:li>
+ </rdf:Bag>
+ </dc:subject>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
+'''));
+ });
+
+ test('Remove tags from XMP with subjects only', () async {
+ expect(
+ _toExpect(await XMP.edit(
+ inSubjects,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editTagsXmp(descriptions, {}),
+ )),
+ _toExpect(null));
+ });
+
+ test('Remove tags from XMP with subjects and creator', () async {
+ final modifyDate = DateTime.now();
+ final xmpDate = XMP.toXmpDate(modifyDate);
+
+ expect(
+ _toExpect(await XMP.edit(
+ inSubjectsCreator,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editTagsXmp(descriptions, {}),
+ modifyDate: modifyDate,
+ )),
+ _toExpect('''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core Test.SNAPSHOT">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about=""
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/"
+ xmp:MetadataDate="$xmpDate"
+ xmp:ModifyDate="$xmpDate">
+ <dc:creator>
+ <rdf:Seq>
+ <rdf:li>c</rdf:li>
+ </rdf:Seq>
+ </dc:creator>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
+'''));
+ });
+
+ test('Set rating without existing XMP', () async {
+ final modifyDate = DateTime.now();
+ final xmpDate = XMP.toXmpDate(modifyDate);
+
+ expect(
+ _toExpect(await XMP.edit(
+ null,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, 3),
+ modifyDate: modifyDate,
+ )),
+ _toExpect('''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="$toolkit">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about=""
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/"
+ xmp:Rating="3"
+ xmp:MetadataDate="$xmpDate"
+ xmp:ModifyDate="$xmpDate" />
+ </rdf:RDF>
+</x:xmpmeta>
+'''));
+ });
+
+ test('Set rating to XMP with ratings (multiple descriptions)', () async {
+ final modifyDate = DateTime.now();
+ final xmpDate = XMP.toXmpDate(modifyDate);
+
+ expect(
+ _toExpect(await XMP.edit(
+ inMultiDescriptionRatings,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, 3),
+ modifyDate: modifyDate,
+ )),
+ _toExpect('''
+<x:xmpmeta xmlns:x="adobe:ns:meta/">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b"
+ xmlns:MicrosoftPhoto="http://ns.microsoft.com/photo/1.0/"
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/"
+ MicrosoftPhoto:Rating="50"
+ xmp:Rating="3"
+ xmp:MetadataDate="$xmpDate"
+ xmp:ModifyDate="$xmpDate" />
+ </rdf:RDF>
+</x:xmpmeta>
+'''));
+ });
+
+ test('Set rating to XMP with rating attribute', () async {
+ final modifyDate = DateTime.now();
+ final xmpDate = XMP.toXmpDate(modifyDate);
+
+ expect(
+ _toExpect(await XMP.edit(
+ inRatingAttribute,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, 3),
+ modifyDate: modifyDate,
+ )),
+ _toExpect('''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core Test.SNAPSHOT">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about=""
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/"
+ xmp:Rating="3"
+ xmp:MetadataDate="$xmpDate"
+ xmp:ModifyDate="$xmpDate" />
+ </rdf:RDF>
+</x:xmpmeta>
+'''));
+ });
+
+ test('Set rating to XMP with rating element', () async {
+ final modifyDate = DateTime.now();
+ final xmpDate = XMP.toXmpDate(modifyDate);
+
+ expect(
+ _toExpect(await XMP.edit(
+ inRatingElement,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, 3),
+ modifyDate: modifyDate,
+ )),
+ _toExpect('''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core Test.SNAPSHOT">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about=""
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/"
+ xmp:Rating="3"
+ xmp:MetadataDate="$xmpDate"
+ xmp:ModifyDate="$xmpDate" />
+ </rdf:RDF>
+</x:xmpmeta>
+'''));
+ });
+
+ test('Set rating to XMP with subjects only', () async {
+ final modifyDate = DateTime.now();
+ final xmpDate = XMP.toXmpDate(modifyDate);
+
+ expect(
+ _toExpect(await XMP.edit(
+ inSubjects,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, 3),
+ modifyDate: modifyDate,
+ )),
+ _toExpect('''
+<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core Test.SNAPSHOT">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about=""
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:xmp="http://ns.adobe.com/xap/1.0/"
+ xmp:Rating="3"
+ xmp:MetadataDate="$xmpDate"
+ xmp:ModifyDate="$xmpDate">
+ <dc:subject>
+ <rdf:Bag>
+ <rdf:li>the king</rdf:li>
+ </rdf:Bag>
+ </dc:subject>
+ </rdf:Description>
+ </rdf:RDF>
+</x:xmpmeta>
+'''));
+ });
+
+ test('Remove rating from XMP with subjects only', () async {
+ final modifyDate = DateTime.now();
+
+ expect(
+ _toExpect(await XMP.edit(
+ inSubjects,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, null),
+ modifyDate: modifyDate,
+ )),
+ _toExpect(inSubjects));
+ });
+
+ test('Remove trailer media info from XMP with micro video', () async {
+ final modifyDate = DateTime.now();
+
+ expect(
+ _toExpect(await XMP.edit(
+ inMotionPhotoMicroVideo,
+ toolkit,
+ ExtraAvesEntryMetadataEdition.removeContainerXmp,
+ modifyDate: modifyDate,
+ )),
+ _toExpect(null));
+ });
+
+ test('Remove trailer media info from XMP with container', () async {
+ final modifyDate = DateTime.now();
+
+ expect(
+ _toExpect(await XMP.edit(
+ inMotionPhotoContainer,
+ toolkit,
+ ExtraAvesEntryMetadataEdition.removeContainerXmp,
+ modifyDate: modifyDate,
+ )),
+ _toExpect(null));
+ });
+
+ test('Remove trailer media info from XMP with no related metadata', () async {
+ final modifyDate = DateTime.now();
+
+ expect(
+ _toExpect(await XMP.edit(
+ inSubjects,
+ toolkit,
+ ExtraAvesEntryMetadataEdition.removeContainerXmp,
+ modifyDate: modifyDate,
+ )),
+ _toExpect(inSubjects));
+ });
+
+ test('Remove rating from XMP with ratings (multiple descriptions)', () async {
+ final modifyDate = DateTime.now();
+
+ expect(
+ _toExpect(await XMP.edit(
+ inMultiDescriptionRatings,
+ toolkit,
+ (descriptions) => ExtraAvesEntryMetadataEdition.editRatingXmp(descriptions, null),
+ modifyDate: modifyDate,
+ )),
+ _toExpect(null));
+ });
+}