/**
* GeoDress - A program for reverse geocoding
* Copyright (C) 2010 Stefan T.
*
* See COPYING for Details.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package geodress.tests;
import geodress.exceptions.NoMetaDataException;
import geodress.main.InfoConstants;
import geodress.model.reader.SanselanReader;
import java.io.File;
import java.io.IOException;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* Tests the {@link SanselanReader} class.
*
* @author Stefan T.
*/
public class SanselanReaderTest {
/** test picture with EXIF data */
private File testPictureWithExifBeach;
/** test picture with EXIF data */
private File testPictureWithExifParis;
/** test picture with EXIF data and user comment */
private File testPictureWithExifGate;
/** test picture with EXIF data and image description */
private File testPictureWithExifSky;
/** test picture without EXIF data */
private File testPictureWithoutExifField;
/** a test reader */
private SanselanReader reader;
/**
* Initializes the objects.
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
/* latitude: +39,50972222 longitude: +2,74916667 */
testPictureWithExifBeach = new File("testfiles" + File.separator
+ "beach.jpg");
/* latitude: +48.85828 longitude: +2.29503 */
testPictureWithExifParis = new File("testfiles" + File.separator
+ "paris.jpg");
/* latitude: +39.5667833333 longitude: +2.65058333333 */
testPictureWithExifGate = new File("testfiles" + File.separator
+ "gate.jpg");
/* latitude: +39.50976 longitude: +2.74928 */
testPictureWithExifSky = new File("testfiles" + File.separator
+ "sky.jpg");
testPictureWithoutExifField = new File("testfiles" + File.separator
+ "field.jpg");
reader = new SanselanReader();
}
/**
* Tests reading coordinates from a picture with EXIF.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testGpsRead1() throws Exception {
reader.setFile(testPictureWithExifBeach);
Assert.assertEquals(39.5097, Float.valueOf(reader
.getData(InfoConstants.GPS_LATITUDE)), 0.0001);
Assert.assertEquals(2.7492, Float.valueOf(reader
.getData(InfoConstants.GPS_LONGITUDE)), 0.0001);
}
/**
* Tests reading coordinates from a picture with EXIF.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testGpsRead2() throws Exception {
reader.setFile(testPictureWithExifParis);
Assert.assertEquals(48.85828, Float.valueOf(reader
.getData(InfoConstants.GPS_LATITUDE)), 0.0001);
Assert.assertEquals(2.29503, Float.valueOf(reader
.getData(InfoConstants.GPS_LONGITUDE)), 0.0001);
}
/**
* Tests reading coordinates from a picture with EXIF.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testGpsRead3() throws Exception {
reader.setFile(testPictureWithExifGate);
Assert.assertEquals(39.5668, Float.valueOf(reader
.getData(InfoConstants.GPS_LATITUDE)), 0.0001);
Assert.assertEquals(2.6506, Float.valueOf(reader
.getData(InfoConstants.GPS_LONGITUDE)), 0.0001);
}
/**
* Tests reading coordinates from a picture with EXIF.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testGpsRead4() throws Exception {
reader.setFile(testPictureWithExifSky);
Assert.assertEquals(39.50976, Float.valueOf(reader
.getData(InfoConstants.GPS_LATITUDE)), 0.0001);
Assert.assertEquals(2.74928, Float.valueOf(reader
.getData(InfoConstants.GPS_LONGITUDE)), 0.0001);
}
/**
* Tests reading coordinates from a picture without EXIF.
*
* @throws Exception
* may cause an exception
*/
@Test(expected = NoMetaDataException.class)
public void testGpsReadFail() throws Exception {
reader.setFile(testPictureWithoutExifField);
reader.getData(InfoConstants.GPS_LATITUDE);
reader.getData(InfoConstants.GPS_LONGITUDE);
}
/**
* Tests reading date/time from a picture with EXIF.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testDateRead() throws Exception {
reader.setFile(testPictureWithExifBeach);
Assert.assertEquals("2009:07:18 11:54:38", reader
.getData(InfoConstants.DATE_TIME));
reader.setFile(testPictureWithExifGate);
Assert.assertEquals("2009:07:16 13:39:10", reader
.getData(InfoConstants.DATE_TIME));
}
/**
* Tests reading date/time from a picture without EXIF.
*
* @throws Exception
* may cause an exception
*/
@Test(expected = NoMetaDataException.class)
public void testDateReadFail() throws Exception {
reader.setFile(testPictureWithoutExifField);
reader.getData(InfoConstants.DATE_TIME);
}
/**
* Tests reading user comment from a picture with EXIF.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testCommentRead() throws Exception {
reader.setFile(testPictureWithExifGate);
Assert.assertEquals("A gate on Mallorca.", reader
.getData(InfoConstants.USER_COMMENT));
}
/**
* Tests reading user comment from a picture without EXIF.
*
* @throws Exception
* may cause an exception
*/
@Test(expected = NoMetaDataException.class)
public void testCommentReadFail() throws Exception {
reader.setFile(testPictureWithoutExifField);
reader.getData(InfoConstants.USER_COMMENT);
}
/**
* Tests reading image description from a picture with EXIF.
*
* @throws Exception
* may cause an exception
*/
@Test
public void testDescriptionRead() throws Exception {
reader.setFile(testPictureWithExifSky);
Assert.assertEquals("Simply blue sky", reader
.getData(InfoConstants.IMAGE_DESCRIPTION));
}
/**
* Tests reading image description from a picture without EXIF.
*
* @throws Exception
* may cause an exception
*/
@Test(expected = NoMetaDataException.class)
public void testDescriptionReadFail() throws Exception {
reader.setFile(testPictureWithoutExifField);
reader.getData(InfoConstants.IMAGE_DESCRIPTION);
}
/**
* Tests handling of a non-existing picture.
*
* @throws Exception
* may cause an exception
*/
@Test(expected = IOException.class)
public void testPictureReadFail() throws Exception {
reader.setFile(new File("testfiles" + File.separator + "foo.jpg"));
}
}