1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertNotNull;
|
---|
6 |
|
---|
7 | import java.io.File;
|
---|
8 | import java.text.DecimalFormat;
|
---|
9 | import java.text.ParseException;
|
---|
10 | import java.text.SimpleDateFormat;
|
---|
11 | import java.util.Calendar;
|
---|
12 | import java.util.Date;
|
---|
13 | import java.util.GregorianCalendar;
|
---|
14 | import java.util.TimeZone;
|
---|
15 |
|
---|
16 | import org.junit.Before;
|
---|
17 | import org.junit.Test;
|
---|
18 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
19 | import org.openstreetmap.josm.tools.date.DateUtilsTest;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * EXIF metadata extraction test
|
---|
23 | * @since 6209
|
---|
24 | */
|
---|
25 | public 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 | }
|
---|