source: josm/trunk/test/unit/org/openstreetmap/josm/tools/ExifReaderTest.java@ 9669

Last change on this file since 9669 was 9499, checked in by simon04, 8 years ago

fix #11685 - Use sub-second exif/xmp data

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNotNull;
6
7import java.io.File;
8import java.text.DecimalFormat;
9import java.text.ParseException;
10import java.text.SimpleDateFormat;
11import java.util.Calendar;
12import java.util.Date;
13import java.util.GregorianCalendar;
14import java.util.TimeZone;
15
16import org.junit.Before;
17import org.junit.Test;
18import org.openstreetmap.josm.data.coor.LatLon;
19import org.openstreetmap.josm.tools.date.DateUtilsTest;
20
21/**
22 * EXIF metadata extraction test
23 * @since 6209
24 */
25public class ExifReaderTest {
26
27 private File orientationSampleFile, directionSampleFile;
28
29 /**
30 * Setup test
31 */
32 @Before
33 public void setUp() {
34 directionSampleFile = new File("data_nodist/exif-example_direction.jpg");
35 orientationSampleFile = new File("data_nodist/exif-example_orientation=6.jpg");
36 DateUtilsTest.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
37 }
38
39 /**
40 * Test time extraction
41 * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
42 */
43 @Test
44 public void testReadTime() throws ParseException {
45 Date date = ExifReader.readTime(directionSampleFile);
46 assertEquals(new GregorianCalendar(2010, Calendar.MAY, 15, 17, 12, 05).getTime(), date);
47 }
48
49 /**
50 * Tests reading sub-seconds from the EXIF header
51 * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
52 */
53 @Test
54 public void testReadTimeSubSecond1() throws ParseException {
55 Date date = ExifReader.readTime(new File("data_nodist/IMG_20150711_193419.jpg"));
56 String dateStr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").format(date);
57 assertEquals("2015-07-11T19:34:19.100", dateStr);
58 }
59
60 /**
61 * Test orientation extraction
62 */
63 @Test
64 public void testReadOrientation() {
65 Integer orientation = ExifReader.readOrientation(orientationSampleFile);
66 assertEquals(Integer.valueOf(6), orientation);
67 }
68
69 /**
70 * Test coordinates extraction
71 */
72 @Test
73 public void testReadLatLon() {
74 LatLon latlon = ExifReader.readLatLon(directionSampleFile);
75 assertNotNull(latlon);
76 DecimalFormat f = new DecimalFormat("00.0");
77 assertEquals("51°46'"+f.format(43.0)+"\"", LatLon.dms(latlon.lat()));
78 assertEquals("8°21'"+f.format(56.3)+"\"", LatLon.dms(latlon.lon()));
79 }
80
81 /**
82 * Test coordinates extraction
83 */
84 @Test
85 public void testReadDirection() {
86 Double direction = ExifReader.readDirection(directionSampleFile);
87 assertEquals(new Double(46.5), direction);
88 }
89}
Note: See TracBrowser for help on using the repository browser.