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.util.Calendar;
|
---|
11 | import java.util.Date;
|
---|
12 | import java.util.GregorianCalendar;
|
---|
13 | import java.util.TimeZone;
|
---|
14 |
|
---|
15 | import org.junit.Before;
|
---|
16 | import org.junit.Test;
|
---|
17 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
18 | import org.openstreetmap.josm.tools.date.DateUtilsTest;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * EXIF metadata extraction test
|
---|
22 | * @since 6209
|
---|
23 | */
|
---|
24 | public class ExifReaderTest {
|
---|
25 |
|
---|
26 | private File orientationSampleFile, directionSampleFile;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Setup test
|
---|
30 | */
|
---|
31 | @Before
|
---|
32 | public void setUp() {
|
---|
33 | directionSampleFile = new File("data_nodist/exif-example_direction.jpg");
|
---|
34 | orientationSampleFile = new File("data_nodist/exif-example_orientation=6.jpg");
|
---|
35 | DateUtilsTest.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Test time extraction
|
---|
40 | * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
|
---|
41 | */
|
---|
42 | @Test
|
---|
43 | public void testReadTime() throws ParseException {
|
---|
44 | Date date = ExifReader.readTime(directionSampleFile);
|
---|
45 | assertEquals(new GregorianCalendar(2010, Calendar.MAY, 15, 17, 12, 05).getTime(), date);
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Test orientation extraction
|
---|
50 | */
|
---|
51 | @Test
|
---|
52 | public void testReadOrientation() {
|
---|
53 | Integer orientation = ExifReader.readOrientation(orientationSampleFile);
|
---|
54 | assertEquals(Integer.valueOf(6), orientation);
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Test coordinates extraction
|
---|
59 | */
|
---|
60 | @Test
|
---|
61 | public void testReadLatLon() {
|
---|
62 | LatLon latlon = ExifReader.readLatLon(directionSampleFile);
|
---|
63 | assertNotNull(latlon);
|
---|
64 | DecimalFormat f = new DecimalFormat("00.0");
|
---|
65 | assertEquals("51°46'"+f.format(43.0)+"\"", LatLon.dms(latlon.lat()));
|
---|
66 | assertEquals("8°21'"+f.format(56.3)+"\"", LatLon.dms(latlon.lon()));
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Test coordinates extraction
|
---|
71 | */
|
---|
72 | @Test
|
---|
73 | public void testReadDirection() {
|
---|
74 | Double direction = ExifReader.readDirection(directionSampleFile);
|
---|
75 | assertEquals(new Double(46.5), direction);
|
---|
76 | }
|
---|
77 | }
|
---|