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