parsing_loc_from_exif_test.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import "package:photos/services/location_service.dart";
  2. import "package:test/test.dart";
  3. void main() {
  4. group('toLocationObj', () {
  5. test('returns null if lat or long are null', () {
  6. final gpsData = GPSData(null, null, null, null);
  7. expect(gpsData.toLocationObj(), isNull);
  8. final gpsDataWithLatOnly = GPSData(null, [1, 2, 3], null, null);
  9. expect(gpsDataWithLatOnly.toLocationObj(), isNull);
  10. final gpsDataWithLongOnly = GPSData(null, null, null, [1, 2, 3]);
  11. expect(gpsDataWithLongOnly.toLocationObj(), isNull);
  12. });
  13. test('returns null if lat or long have less than 3 elements', () {
  14. final gpsData1 = GPSData(null, [1, 2], null, [1, 2, 3]);
  15. expect(gpsData1.toLocationObj(), isNull);
  16. final gpsData2 = GPSData(null, [1, 2, 3], null, [1, 2]);
  17. expect(gpsData2.toLocationObj(), isNull);
  18. final gpsData3 = GPSData(null, [1, 2], null, [1, 2]);
  19. expect(gpsData3.toLocationObj(), isNull);
  20. });
  21. test('returns null if latRef or longRef is of invalid format', () {
  22. final gpsData1 = GPSData("A", [1, 2, 3], "xyz", [1, 2, 3]);
  23. expect(gpsData1.toLocationObj(), isNull);
  24. });
  25. void testParsingLocation(
  26. String? latRef,
  27. List<double> lat,
  28. String? longRef,
  29. List<double> long,
  30. double expectedLat,
  31. double expectedLong,
  32. ) {
  33. final gpsData = GPSData(latRef, lat, longRef, long);
  34. final location = gpsData.toLocationObj();
  35. expect(location, isNotNull);
  36. expect(location!.latitude, closeTo(expectedLat, 0.00001));
  37. expect(location.longitude, closeTo(expectedLong, 0.00001));
  38. }
  39. test('converts coordinates with different latRef and longRef combinations',
  40. () {
  41. testParsingLocation(
  42. "N",
  43. [40, 26, 46.84],
  44. "E",
  45. [79, 58, 56.33],
  46. 40.446344,
  47. 79.982313,
  48. );
  49. testParsingLocation(
  50. "N",
  51. [40, 26, 46.84],
  52. "W",
  53. [79, 58, 56.33],
  54. 40.446344,
  55. -79.982313,
  56. );
  57. testParsingLocation(
  58. "S",
  59. [40, 26, 46.84],
  60. "E",
  61. [79, 58, 56.33],
  62. -40.446344,
  63. 79.982313,
  64. );
  65. testParsingLocation(
  66. "S",
  67. [40, 26, 46.84],
  68. "W",
  69. [79, 58, 56.33],
  70. -40.446344,
  71. -79.982313,
  72. );
  73. });
  74. test(
  75. 'converts coordinates with missing latRef and longRef but with signed lat and long',
  76. () {
  77. testParsingLocation(
  78. null,
  79. [40, 26, 46.84],
  80. null,
  81. [79, 58, 56.33],
  82. 40.446344,
  83. 79.982313,
  84. );
  85. testParsingLocation(
  86. null,
  87. [-40, 26, 46.84],
  88. null,
  89. [79, 58, 56.33],
  90. -40.446344,
  91. 79.982313,
  92. );
  93. testParsingLocation(
  94. null,
  95. [40, 26, 46.84],
  96. null,
  97. [-79, 58, 56.33],
  98. 40.446344,
  99. -79.982313,
  100. );
  101. testParsingLocation(
  102. null,
  103. [40, -26, 46.84],
  104. null,
  105. [79, -58, 56.33],
  106. -40.446344,
  107. -79.982313,
  108. );
  109. });
  110. });
  111. }