[7937] | 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;
|
---|
[9394] | 13 | import java.util.TimeZone;
|
---|
[7937] | 14 |
|
---|
| 15 | import org.junit.Before;
|
---|
| 16 | import org.junit.Test;
|
---|
| 17 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
[9394] | 18 | import org.openstreetmap.josm.tools.date.DateUtilsTest;
|
---|
[7937] | 19 |
|
---|
| 20 | /**
|
---|
| 21 | * EXIF metadata extraction test
|
---|
| 22 | * @since 6209
|
---|
| 23 | */
|
---|
| 24 | public class ExifReaderTest {
|
---|
| 25 |
|
---|
[7959] | 26 | private File orientationSampleFile, directionSampleFile;
|
---|
[8509] | 27 |
|
---|
[7937] | 28 | /**
|
---|
| 29 | * Setup test
|
---|
| 30 | */
|
---|
| 31 | @Before
|
---|
[8509] | 32 | public void setUp() {
|
---|
[7959] | 33 | directionSampleFile = new File("data_nodist/exif-example_direction.jpg");
|
---|
| 34 | orientationSampleFile = new File("data_nodist/exif-example_orientation=6.jpg");
|
---|
[9394] | 35 | DateUtilsTest.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
|
---|
[7937] | 36 | }
|
---|
| 37 |
|
---|
[8509] | 38 | /**
|
---|
[7937] | 39 | * Test time extraction
|
---|
[8509] | 40 | * @throws ParseException if {@link ExifReader#readTime} fails to parse date/time of sample file
|
---|
[7937] | 41 | */
|
---|
| 42 | @Test
|
---|
| 43 | public void testReadTime() throws ParseException {
|
---|
[7959] | 44 | Date date = ExifReader.readTime(directionSampleFile);
|
---|
[7937] | 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() {
|
---|
[7959] | 53 | Integer orientation = ExifReader.readOrientation(orientationSampleFile);
|
---|
| 54 | assertEquals(Integer.valueOf(6), orientation);
|
---|
[7937] | 55 | }
|
---|
[8509] | 56 |
|
---|
[7937] | 57 | /**
|
---|
| 58 | * Test coordinates extraction
|
---|
| 59 | */
|
---|
| 60 | @Test
|
---|
| 61 | public void testReadLatLon() {
|
---|
[7959] | 62 | LatLon latlon = ExifReader.readLatLon(directionSampleFile);
|
---|
[7937] | 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() {
|
---|
[7959] | 74 | Double direction = ExifReader.readDirection(directionSampleFile);
|
---|
[7937] | 75 | assertEquals(new Double(46.5), direction);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|