diff --git a/src/main/java/osm/jp/gpx/ImportPicture.java b/src/main/java/osm/jp/gpx/ImportPicture.java index a507056..ac6e29c 100644 --- a/src/main/java/osm/jp/gpx/ImportPicture.java +++ b/src/main/java/osm/jp/gpx/ImportPicture.java @@ -105,6 +105,14 @@ // AppParameters.IMG_OUTPUT に置き換え if (params.isImgOutput()) { File outDir = new File(params.getProperty(AppParameters.IMG_OUTPUT_FOLDER)); + if (!outDir.exists()) { + // 出力ディレクトリが存在しないときは作成する + outDir.mkdir(); + } + else if (outDir.isFile()) { + // 出力ディレクトリがFILEのときはERROR + throw new FileNotFoundException(String.format("OUTPUT directory '%s' is a File!", outDir.getAbsolutePath())); + } outDir = new File(outDir, imgFolder.getImgDir().getName()); imgFolder.setOutDir(outDir); } diff --git a/src/test/java/osm/jp/gpx/Expecter.java b/src/test/java/osm/jp/gpx/Expecter.java index f7dfb1b..e08e01e 100644 --- a/src/test/java/osm/jp/gpx/Expecter.java +++ b/src/test/java/osm/jp/gpx/Expecter.java @@ -1,5 +1,27 @@ package osm.jp.gpx; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.io.File; +import java.util.List; + +import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.common.ImageMetadata; +import org.apache.commons.imaging.common.ImageMetadata.ImageMetadataItem; +import org.apache.commons.imaging.common.RationalNumber; +import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; +import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; +import org.apache.commons.imaging.formats.tiff.TiffImageMetadata.GPSInfo; +import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; +import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants; +import org.apache.commons.imaging.formats.tiff.taginfos.TagInfoRational; +import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; +import org.apache.commons.imaging.formats.tiff.write.TiffOutputField; +import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; + public class Expecter { String value; boolean expect; @@ -17,4 +39,84 @@ this.magvar = magvar; } + public static String comparePosition(double b) { + return String.format("%.4f", b); + } + + public static void check(Fixture dataset) { + Expecter[] es = dataset.expecters; + AppParameters params; + try { + params = new AppParameters(dataset.iniFilePath); + File outDir = new File(params.getProperty(AppParameters.IMG_OUTPUT_FOLDER)); + for (Expecter e : es) { + File file = new File(outDir, e.value); + System.out.println("[JUnit.debug] assert file='"+ file.getAbsolutePath() +"'"); + assertThat(file.exists(), is(e.expect)); + if (e.timeStr != null) { + + // JPEG メタデータが存在すること + ImageMetadata meta = Imaging.getMetadata(file); + + // メタデータは インスタンスJpegImageMetadata であること + assertThat((meta instanceof JpegImageMetadata), is(true)); + JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; + assertNotNull(jpegMetadata); + + // EXIFデータが存在すること + TiffImageMetadata exif = jpegMetadata.getExif(); + assertNotNull(exif); + + // EXIF-TIME が正しく設定されていること + String exifTime = ImportPicture.toEXIFString(ImportPicture.toEXIFDate(exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0])); + System.out.println("[debug] exifTime = '"+ exifTime +"' <--> '" + e.timeStr + "'"); + assertThat(exifTime, is(e.timeStr)); + + // LAT,LON + GPSInfo gpsInfo = exif.getGPS(); + if (e.latD != 90.0D) { + assertThat(Expecter.comparePosition(gpsInfo.getLatitudeAsDegreesNorth()), is(Expecter.comparePosition(e.latD))); + } + if (e.lonD != 180.0D) { + assertThat(Expecter.comparePosition(gpsInfo.getLongitudeAsDegreesEast()), is(Expecter.comparePosition(e.lonD))); + } + + // ELE + //RationalNumber[] ele = (RationalNumber[]) exif.getFieldValue(GpsTagConstants.GPS_TAG_GPS_ALTITUDE); + + // MAGVAR + if (e.magvar) { + boolean ismagvar = false; + List dirs = exif.getDirectories(); + for (ImageMetadataItem dir : dirs) { + if (dir instanceof TiffImageMetadata.Directory) { + List items = ((TiffImageMetadata.Directory)dir).getItems(); + for (ImageMetadataItem item : items) { + if (item instanceof TiffImageMetadata.TiffMetadataItem) { + String str = item.toString(); + assertNotNull(str); + TiffImageMetadata.TiffMetadataItem tiffitem = (TiffImageMetadata.TiffMetadataItem)item; + String name = GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION.name; + if (tiffitem.getKeyword() == name) { + str = tiffitem.getText(); + assertNotNull(str); + ismagvar = true; // MAGVARが設定されている + } + } + } + } + } + if (!ismagvar) { + fail("MAGVARが設定されていない"); + } + } + + // SPEED + + } + } + } catch (Exception e1) { + fail("予期しない例外: "+ e1.toString()); + } + } } diff --git a/src/test/java/osm/jp/gpx/Fixture.java b/src/test/java/osm/jp/gpx/Fixture.java index e26976a..8fdc8a3 100644 --- a/src/test/java/osm/jp/gpx/Fixture.java +++ b/src/test/java/osm/jp/gpx/Fixture.java @@ -40,6 +40,56 @@ /** + * ユニットテスト用データ + * [Canonカメラ] + */ + @DataPoints + public static Fixture[] stddatas = { + new Fixture( + "[std0].Canonカメラの場合.FILE_UPDATE時間を基準にして時間外のファイルはコピー対象外の時", + "target/test-classes/imgdata/Canon20200426.tar.gz", + "target/test-classes/cameradata/", + "target/test-classes/cameradata/", + "target/test-classes/cameradata/AdjustTime.ini", + new Expecter[] { + new Expecter("109_0426/IMG_0001.JPG", false, null, 90.0D, 180.0D, false), + new Expecter("109_0426/IMG_0004.JPG", true, "2020:04:26 10:58:18", 35.4393043555D, 139.4478441775D, false), + new Expecter("109_0426/IMG_0007.JPG", true, "2020:04:26 11:17:48", 35.4382312205D, 139.4584579300D, false), + new Expecter("109_0426/IMG_0010.JPG", true, "2020:04:26 11:20:42", 35.4374477640D, 139.4604294375D, false), + new Expecter("109_0426/IMG_0013.JPG", true, "2020:04:26 12:11:28", 35.4209551122D, 139.4677959569D, false), + new Expecter("109_0426/IMG_0016.JPG", true, "2020:04:26 12:19:42", 35.4202432372D, 139.4685635716D, false), + new Expecter("109_0426/IMG_0019.JPG", true, "2020:04:26 12:21:48", 35.4181452468D, 139.4684348255D, false), + new Expecter("109_0426/IMG_0022.JPG", false, null, 90.0D, 180.0D, false), + new Expecter("109_0426/IMG_0025.JPG", false, null, 90.0D, 180.0D, false), + new Expecter("109_0426/IMG_0028.JPG", false, null, 90.0D, 180.0D, false), + new Expecter("109_0426/IMG_0031.JPG", false, null, 90.0D, 180.0D, false), + new Expecter("109_0426/IMG_0034.JPG", false, null, 90.0D, 180.0D, false), + } + ), + new Fixture( + "[std1].Canonカメラの場合.FILE_UPDATE時間を基準,MAGVARをONの時", + "target/test-classes/imgdata/Canon20200426.tar.gz", + "target/test-classes/cameradata/", + "target/test-classes/cameradata/", + "target/test-classes/cameradata/AdjustTime.magvar.ini", + new Expecter[] { + new Expecter("109_0426/IMG_0001.JPG", false, null, 90.0D, 180.0D, false), + new Expecter("109_0426/IMG_0004.JPG", true, "2020:04:26 10:58:18", 35.4393043555D, 139.4478441775D, true), + new Expecter("109_0426/IMG_0007.JPG", true, "2020:04:26 11:17:48", 35.4382312205D, 139.4584579300D, true), + new Expecter("109_0426/IMG_0010.JPG", true, "2020:04:26 11:20:42", 35.4374477640D, 139.4604294375D, true), + new Expecter("109_0426/IMG_0013.JPG", true, "2020:04:26 12:11:28", 35.4209551122D, 139.4677959569D, true), + new Expecter("109_0426/IMG_0016.JPG", true, "2020:04:26 12:19:42", 35.4202432372D, 139.4685635716D, true), + new Expecter("109_0426/IMG_0019.JPG", true, "2020:04:26 12:21:48", 35.4181452468D, 139.4684348255D, true), + new Expecter("109_0426/IMG_0022.JPG", false, null, 90.0D, 180.0D, false), + new Expecter("109_0426/IMG_0025.JPG", false, null, 90.0D, 180.0D, false), + new Expecter("109_0426/IMG_0028.JPG", false, null, 90.0D, 180.0D, false), + new Expecter("109_0426/IMG_0031.JPG", false, null, 90.0D, 180.0D, false), + new Expecter("109_0426/IMG_0034.JPG", false, null, 90.0D, 180.0D, false), + } + ), + }; + + /** * 各種カメラGPXファイル */ @DataPoints @@ -53,9 +103,9 @@ "target/test-classes/ini/AdjustTime.20170518.A1.ini", new Expecter[] { new Expecter("10170518/DSC05183.JPG", false, null, 90.0D, 180.0D, false), - new Expecter("10170518/DSC05184.JPG", true, "2017:05:18 09:34:44", 35.4367520000D, 139.4082730000D, true), - new Expecter("10170518/DSC05196.JPG", true, "2017:05:18 09:37:32", 35.4376820000D, 139.4085150000D, true), - new Expecter("10170518/DSC05204.JPG", true, "2017:05:18 09:46:48", 35.4368560000D, 139.4082190000D, true), + new Expecter("10170518/DSC05184.JPG", true, "2017:05:18 09:34:44", 35.4367520000D, 139.4082730000D, false), + new Expecter("10170518/DSC05196.JPG", true, "2017:05:18 09:37:32", 35.4376820000D, 139.4085150000D, false), + new Expecter("10170518/DSC05204.JPG", true, "2017:05:18 09:46:48", 35.4368560000D, 139.4082190000D, false), new Expecter("10170518/DSC05205.JPG", false, null, 90.0D, 180.0D, false), } ), @@ -67,11 +117,11 @@ "target/test-classes/cameradata/20170518.gpx", "target/test-classes/ini/AdjustTime.20170518.A2.ini", new Expecter[] { - new Expecter("10170518/DSC05183.JPG", true, "2017:05:18 09:16:48", 90.0D, 180.0D, true), - new Expecter("10170518/DSC05184.JPG", true, "2017:05:18 09:34:44", 35.4367520000D, 139.4082730000D, true), - new Expecter("10170518/DSC05196.JPG", true, "2017:05:18 09:37:32", 35.4376820000D, 139.4085150000D, true), - new Expecter("10170518/DSC05204.JPG", true, "2017:05:18 09:46:48", 35.4368560000D, 139.4082190000D, true), - new Expecter("10170518/DSC05205.JPG", true, "2017:05:18 09:48:04", 90.0D, 180.0D, true), + new Expecter("10170518/DSC05183.JPG", true, "2017:05:18 09:16:48", 90.0D, 180.0D, false), + new Expecter("10170518/DSC05184.JPG", true, "2017:05:18 09:34:44", 35.4367520000D, 139.4082730000D, false), + new Expecter("10170518/DSC05196.JPG", true, "2017:05:18 09:37:32", 35.4376820000D, 139.4085150000D, false), + new Expecter("10170518/DSC05204.JPG", true, "2017:05:18 09:46:48", 35.4368560000D, 139.4082190000D, false), + new Expecter("10170518/DSC05205.JPG", true, "2017:05:18 09:48:04", 90.0D, 180.0D, false), } ), // 3. @@ -83,8 +133,8 @@ "target/test-classes/ini/AdjustTime.20170518.B1.ini", new Expecter[] { new Expecter("cameradata/20170518_092031A.jpg", false, null, 90.0D, 180.0D, false), - new Expecter("cameradata/20170518_094226A_snap.jpg", true, "2017:05:18 09:42:26", 35.4366860000D, 139.4082650000D, true), - new Expecter("cameradata/20170518_094737A.jpg", true, "2017:05:18 09:47:36", 35.4368200000D, 139.4082810000D, true), + new Expecter("cameradata/20170518_094226A_snap.jpg", true, "2017:05:18 09:42:26", 35.4366860000D, 139.4082650000D, false), + new Expecter("cameradata/20170518_094737A.jpg", true, "2017:05:18 09:47:36", 35.4368200000D, 139.4082810000D, false), new Expecter("cameradata/20170518_094827A.jpg", false, null, 90.0D, 180.0D, false), } ), @@ -96,10 +146,10 @@ "target/test-classes/cameradata/20170518.gpx", "target/test-classes/ini/AdjustTime.20170518.B2.ini", new Expecter[] { - new Expecter("cameradata/20170518_092031A.jpg", true, "2017:05:18 09:20:30", 90.0D, 180.0D, true), - new Expecter("cameradata/20170518_094226A_snap.jpg", true, "2017:05:18 09:42:26", 35.4366860000D, 139.4082650000D, true), - new Expecter("cameradata/20170518_094737A.jpg", true, "2017:05:18 09:47:36", 35.4368200000D, 139.4082810000D, true), - new Expecter("cameradata/20170518_094827A.jpg", true, "2017:05:18 09:48:26", 90.0D, 180.0D, true), + new Expecter("cameradata/20170518_092031A.jpg", true, "2017:05:18 09:20:30", 90.0D, 180.0D, false), + new Expecter("cameradata/20170518_094226A_snap.jpg", true, "2017:05:18 09:42:26", 35.4366860000D, 139.4082650000D, false), + new Expecter("cameradata/20170518_094737A.jpg", true, "2017:05:18 09:47:36", 35.4368200000D, 139.4082810000D, false), + new Expecter("cameradata/20170518_094827A.jpg", true, "2017:05:18 09:48:26", 90.0D, 180.0D, false), } ), // 5. @@ -115,7 +165,7 @@ new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true), @@ -145,25 +195,25 @@ "target/test-classes/ini/AdjustTime.M1b.separate.ini", new Expecter[] { // out of time ( - 2017-05-29T01:23:18) - new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:06", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:06", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true), // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37) - new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:10", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:10", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, false), // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03) new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true), new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true), // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53) - new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:14", 90.0D, 180.0D, true), - new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:44", 90.0D, 180.0D, true), + new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:14", 90.0D, 180.0D, false), + new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:44", 90.0D, 180.0D, false), // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35) new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true), @@ -183,7 +233,7 @@ new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true), @@ -213,25 +263,25 @@ "target/test-classes/ini/AdjustTime.M1d.separate.ini", new Expecter[] { // out of time ( - 2017-05-29T01:23:18) - new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:05", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:05", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true), // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37) - new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:09", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:09", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, false), // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03) new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true), new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true), // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53) - new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:15", 90.0D, 180.0D, true), - new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:45", 90.0D, 180.0D, true), + new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:15", 90.0D, 180.0D, false), + new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:45", 90.0D, 180.0D, false), // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35) new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true), @@ -252,7 +302,7 @@ new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true), @@ -282,25 +332,25 @@ "target/test-classes/ini/AdjustTime.M2b.separate.ini", new Expecter[] { // out of time ( - 2017-05-29T01:23:18) - new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:06", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:06", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true), // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37) - new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:10", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:10", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, false), // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03) new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true), new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true), // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53) - new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:14", 90.0D, 180.0D, true), - new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:44", 90.0D, 180.0D, true), + new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:14", 90.0D, 180.0D, false), + new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:44", 90.0D, 180.0D, false), // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35) new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true), @@ -320,7 +370,7 @@ new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true), @@ -350,25 +400,25 @@ "target/test-classes/ini/AdjustTime.M2d.separate.ini", new Expecter[] { // out of time ( - 2017-05-29T01:23:18) - new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:05", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:05", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true), // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37) - new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:09", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:09", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, false), // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03) new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true), new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true), // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53) - new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:15", 90.0D, 180.0D, true), - new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:45", 90.0D, 180.0D, true), + new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:15", 90.0D, 180.0D, false), + new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:45", 90.0D, 180.0D, false), // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35) new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true), @@ -388,7 +438,7 @@ new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true), @@ -418,25 +468,25 @@ "target/test-classes/ini/AdjustTime.M2b.separate.ini", new Expecter[] { // out of time ( - 2017-05-29T01:23:18) - new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:06", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:06", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true), // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37) - new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:10", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:10", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, false), // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03) new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true), new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true), // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53) - new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:14", 90.0D, 180.0D, true), - new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:44", 90.0D, 180.0D, true), + new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:14", 90.0D, 180.0D, false), + new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:44", 90.0D, 180.0D, false), // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35) new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true), @@ -456,7 +506,7 @@ new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true), @@ -486,25 +536,25 @@ "target/test-classes/ini/AdjustTime.M2d.separate.ini", new Expecter[] { // out of time ( - 2017-05-29T01:23:18) - new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:05", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:05", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, false), // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05) - new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true), + new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, false), new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true), new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true), // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37) - new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:09", 90.0D, 180.0D, true), - new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true), + new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:09", 90.0D, 180.0D, false), + new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, false), // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03) new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true), new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true), // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53) - new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:15", 90.0D, 180.0D, true), - new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:45", 90.0D, 180.0D, true), + new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:15", 90.0D, 180.0D, false), + new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:45", 90.0D, 180.0D, false), // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35) new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true), diff --git a/src/test/java/osm/jp/gpx/ImportPictureTest.java b/src/test/java/osm/jp/gpx/ImportPictureTest.java index fd51b0f..3d9b074 100644 --- a/src/test/java/osm/jp/gpx/ImportPictureTest.java +++ b/src/test/java/osm/jp/gpx/ImportPictureTest.java @@ -1,6 +1,5 @@ package osm.jp.gpx; -import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; import java.io.File; @@ -8,13 +7,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; - -import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.common.ImageMetadata; -import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; -import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; -import org.apache.commons.imaging.formats.tiff.TiffImageMetadata.GPSInfo; -import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; import org.junit.runner.*; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; @@ -30,42 +22,7 @@ public void パラメータテスト(Fixture dataset) throws Exception { ImportPictureTest.setup(dataset); ImportPictureTest.testdo(dataset.iniFilePath); - - Expecter[] es = dataset.expecters; - AppParameters params = new AppParameters(dataset.iniFilePath); - File outDir = new File(params.getProperty(AppParameters.IMG_OUTPUT_FOLDER)); - for (Expecter e : es) { - File file = new File(outDir, e.value); - System.out.println("[JUnit.debug] assert file='"+ file.getAbsolutePath() +"'"); - assertThat(file.exists(), is(e.expect)); - if (e.timeStr != null) { - // JPEG メタデータが存在すること - ImageMetadata meta = Imaging.getMetadata(file); - // メタデータは インスタンスJpegImageMetadata であること - assertThat((meta instanceof JpegImageMetadata), is(true)); - JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; - assertNotNull(jpegMetadata); - // EXIFデータが存在すること - TiffImageMetadata exif = jpegMetadata.getExif(); - assertNotNull(exif); - // EXIF-TIME が正しく設定されていること - String exifTime = ImportPicture.toEXIFString(ImportPicture.toEXIFDate(exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0])); - System.out.println("[debug] exifTime = '"+ exifTime +"' <--> '" + e.timeStr + "'"); - assertThat(exifTime, is(e.timeStr)); - // LAT,LON - GPSInfo gpsInfo = exif.getGPS(); - if (e.latD != 90.0D) { - assertThat(comparePosition(gpsInfo.getLatitudeAsDegreesNorth()), is(comparePosition(e.latD))); - } - if (e.lonD != 180.0D) { - assertThat(comparePosition(gpsInfo.getLongitudeAsDegreesEast()), is(comparePosition(e.lonD))); - } - } - } - } - - static String comparePosition(double b) { - return String.format("%.4f", b); + Expecter.check(dataset); } static void setup(Fixture dataset) throws IOException { diff --git a/src/test/java/osm/jp/gpx/ImportPictureUnitTest.java b/src/test/java/osm/jp/gpx/ImportPictureUnitTest.java new file mode 100644 index 0000000..d4cdd8c --- /dev/null +++ b/src/test/java/osm/jp/gpx/ImportPictureUnitTest.java @@ -0,0 +1,136 @@ +package osm.jp.gpx; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +import java.io.File; + +import org.junit.runner.*; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.runners.*; + +@RunWith(Enclosed.class) +public class ImportPictureUnitTest { + + public static class 出力ディレクトリが存在しないとき { + + @Before + public void setUp() throws Exception { + Fixture dataset = Fixture.stddatas[0]; + System.out.println(dataset.toString()); + + // カメラディレクトリを削除する + File dir = new File("target/test-classes/cameradata"); + if (dir.exists()) { + UnZip.delete(dir); + } + File outDir = new File("target/test-classes/output"); + if (outDir.exists()) { + UnZip.delete(outDir); + } + //outDir.mkdir(); + + // カメラディレクトリを作成する + UnZip.uncompress(new File(dataset.tarFilePath), new File("target/test-classes/cameradata")); + } + + + @Test + public void 実行() throws Exception { + Fixture dataset = Fixture.stddatas[0]; + try { + ImportPictureUnitTest.testdo(dataset.iniFilePath); + } + catch (Exception e) { + e.printStackTrace(); + fail("Exceptionが発生した。"); + } + + AppParameters params = new AppParameters(dataset.iniFilePath); + File outDir = new File(params.getProperty(AppParameters.IMG_OUTPUT_FOLDER)); + assertThat(outDir.exists(), is(true)); + + Expecter.check(dataset); + } + + @Test + public void MAGVARをON() throws Exception { + Fixture dataset = Fixture.stddatas[1]; + try { + ImportPictureUnitTest.testdo(dataset.iniFilePath); + } + catch (Exception e) { + e.printStackTrace(); + fail("Exceptionが発生した。"); + } + + AppParameters params = new AppParameters(dataset.iniFilePath); + File outDir = new File(params.getProperty(AppParameters.IMG_OUTPUT_FOLDER)); + assertThat(outDir.exists(), is(true)); + + Expecter.check(dataset); + } + + static String comparePosition(double b) { + return String.format("%.4f", b); + } + } + + public static class 出力ディレクトリがFILEのとき { + + @Before + public void setUp() throws Exception { + Fixture dataset = Fixture.stddatas[0]; + System.out.println(dataset.toString()); + + // カメラディレクトリを削除する + File dir = new File("target/test-classes/cameradata"); + if (dir.exists()) { + UnZip.delete(dir); + } + File outDir = new File("target/test-classes/output"); + if (outDir.exists()) { + UnZip.delete(outDir); + } + + // ファイルを生成 + outDir.createNewFile(); + + // カメラディレクトリを作成する + UnZip.uncompress(new File(dataset.tarFilePath), new File("target/test-classes/cameradata")); + } + + + @Test + public void 実行() throws Exception { + Fixture dataset = Fixture.stddatas[0]; + try { + ImportPictureUnitTest.testdo(dataset.iniFilePath); + fail("outDirがFILEなのに、例外が発生しなかった"); // 例外が発生しなかった + } + catch (Exception e) { + // 例外が発生する + assertThat(true, is(true)); + } + + AppParameters params = new AppParameters(dataset.iniFilePath); + File outDir = new File(params.getProperty(AppParameters.IMG_OUTPUT_FOLDER)); + assertThat(outDir.exists(), is(true)); + } + + static String comparePosition(double b) { + return String.format("%.4f", b); + } + } + + + /** + * 実行する + * @throws Exception + */ + static void testdo(String iniFilePath) throws Exception { + String[] argv = {iniFilePath}; + ImportPicture.main(argv); + } +} \ No newline at end of file