OSDN Git Service

fixed: GUIを一新した
[importpicture/importpicture.git] / test / osm / jp / gpx / ImportPictureTest.java
1 package osm.jp.gpx;
2
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.junit.Assert.*;
5
6 import java.io.BufferedInputStream;
7 import java.io.BufferedOutputStream;
8 import java.io.File;
9 import java.io.FileInputStream;
10 import java.io.FileOutputStream;
11 import java.io.IOException;
12 import java.nio.channels.FileChannel;
13
14 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
15 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
16 import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
17 import org.apache.commons.imaging.Imaging;
18 import org.apache.commons.imaging.common.ImageMetadata;
19 import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
20 import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
21 import org.apache.commons.imaging.formats.tiff.TiffImageMetadata.GPSInfo;
22 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
23 import org.junit.runner.*;
24 import org.junit.experimental.theories.DataPoints;
25 import org.junit.experimental.theories.Theories;
26 import org.junit.experimental.theories.Theory;
27
28 public class ImportPictureTest {
29     static class Expecter {
30         String value;
31         boolean expect;
32         String timeStr;
33         double latD;
34         double lonD;
35         boolean magvar;
36
37         public Expecter(String value, boolean expect, String timeStr, double latD, double lonD, boolean magvar) {
38             this.value = value;
39             this.expect = expect;
40             this.timeStr = timeStr;
41             this.latD = latD;
42             this.lonD = lonD;
43             this.magvar = magvar;
44         }
45     }
46
47     static class Fixture {
48         String comment;                         // テスト概要(コメント)
49         String tarFilePath;                     // TARデータ
50         String gpxSourcePath;           // GPXファイル(オリジナル)
51         String gpxDestinationPath;      // GPXファイル(配置先)
52         String iniFilePath;                     // iniファイル
53         Expecter[] expecters;
54
55         public Fixture(
56             String comment,
57             String tarFilePath,
58             String gpxSourcePath,
59             String gpxDestinationPath,
60             String iniFilePath,
61             Expecter[] expecters
62         ) {
63             this.comment = comment;
64             this.tarFilePath = tarFilePath;
65             this.gpxSourcePath = gpxSourcePath;
66             this.gpxDestinationPath = gpxDestinationPath;
67             this.iniFilePath = iniFilePath;
68             this.expecters = expecters;
69         }
70
71         @Override
72         public String toString() {
73             String msg = "テストパターン : "+ comment + "\n";
74             msg += "\ttarFilePath = "+ tarFilePath +"\n";
75             msg += "\tgpxSourcePath = "+ gpxSourcePath +"\n";
76             msg += "\tgpxDestinationPath = "+ gpxDestinationPath +"\n";
77             msg += "\tiniFilePath = "+ iniFilePath;
78             return msg;
79         }
80     }
81
82
83     @RunWith(Theories.class)
84     public static class 各種カメラGPXファイル {
85
86         @DataPoints
87         public static Fixture[] datas = {
88             // 1
89             new Fixture(
90                 "[A1].SONYカメラの場合.FILE_UPDATE時間を基準にして時間外のファイルはコピー対象外の時",
91                 "testdata/Sony20170518.tar.gz", 
92                 "testdata/20170518.gpx",
93                 "testdata/cameradata/20170518.gpx",
94                 "testdata/AdjustTime.20170518.A1.ini",
95                 new Expecter[] {
96                     new Expecter("10170518/20170518_.gpx", true, null, 90.0D, 180.0D, false),
97                     new Expecter("10170518/DSC05183.JPG", false, null, 90.0D, 180.0D, false),
98                     new Expecter("10170518/DSC05184.JPG", true, "2017:05:18 09:34:44", 35.4367520000D, 139.4082730000D, true),
99                     new Expecter("10170518/DSC05196.JPG", true, "2017:05:18 09:37:32", 35.4376820000D, 139.4085150000D, true),
100                     new Expecter("10170518/DSC05204.JPG", true, "2017:05:18 09:46:48", 35.4368560000D, 139.4082190000D, true),
101                     new Expecter("10170518/DSC05205.JPG", false, null, 90.0D, 180.0D, false),
102                 }
103             ),
104             // 2
105             new Fixture(
106                 "[A2].SONYカメラの場合.FILE_UPDATE時間を基準にして時間外のファイルもコピーする時",
107                 "testdata/Sony20170518.tar.gz", 
108                 "testdata/20170518.gpx",
109                 "testdata/cameradata/20170518.gpx",
110                 "testdata/AdjustTime.20170518.A2.ini",
111                 new Expecter[] {
112                     new Expecter("10170518/20170518_.gpx", true, null, 90.0D, 180.0D, false),
113                     new Expecter("10170518/DSC05183.JPG", true, "2017:05:18 09:16:48", 90.0D, 180.0D, true),
114                     new Expecter("10170518/DSC05184.JPG", true, "2017:05:18 09:34:44", 35.4367520000D, 139.4082730000D, true),
115                     new Expecter("10170518/DSC05196.JPG", true, "2017:05:18 09:37:32", 35.4376820000D, 139.4085150000D, true),
116                     new Expecter("10170518/DSC05204.JPG", true, "2017:05:18 09:46:48", 35.4368560000D, 139.4082190000D, true),
117                     new Expecter("10170518/DSC05205.JPG", true, "2017:05:18 09:48:04", 90.0D, 180.0D, true),
118                 }
119             ),
120             // 3.
121             new Fixture(
122                 "[B1].WiMiUSカメラの場合.FILE_UPDATE時間を基準にして時間外のファイルはコピー対象外の時",
123                 "testdata/WiMiUS20170518.tar.gz", 
124                 "testdata/20170518.gpx",
125                 "testdata/cameradata/20170518.gpx",
126                 "testdata/AdjustTime.20170518.B1.ini",
127                 new Expecter[] {
128                     new Expecter("cameradata/20170518_.gpx", true, null, 90.0D, 180.0D, false),
129                     new Expecter("cameradata/20170518_092031A.jpg", false, null, 90.0D, 180.0D, false),
130                     new Expecter("cameradata/20170518_094226A_snap.jpg", true, "2017:05:18 09:42:26", 35.4366860000D, 139.4082650000D, true),
131                     new Expecter("cameradata/20170518_094737A.jpg", true, "2017:05:18 09:47:36", 35.4368200000D, 139.4082810000D, true),
132                     new Expecter("cameradata/20170518_094827A.jpg", false, null, 90.0D, 180.0D, false),
133                 }
134             ),
135             // 4.
136             new Fixture(
137                 "[B2].WiMiUSカメラの場合.FILE_UPDATE時間を基準にして時間外のファイルもコピーする時",
138                 "testdata/WiMiUS20170518.tar.gz", 
139                 "testdata/20170518.gpx",
140                 "testdata/cameradata/20170518.gpx",
141                 "testdata/AdjustTime.20170518.B2.ini",
142                 new Expecter[] {
143                     new Expecter("cameradata/20170518_.gpx", true, null, 90.0D, 180.0D, false),
144                     new Expecter("cameradata/20170518_092031A.jpg", true, "2017:05:18 09:20:30", 90.0D, 180.0D, true),
145                     new Expecter("cameradata/20170518_094226A_snap.jpg", true, "2017:05:18 09:42:26", 35.4366860000D, 139.4082650000D, true),
146                     new Expecter("cameradata/20170518_094737A.jpg", true, "2017:05:18 09:47:36", 35.4368200000D, 139.4082810000D, true),
147                     new Expecter("cameradata/20170518_094827A.jpg", true, "2017:05:18 09:48:26", 90.0D, 180.0D, true),
148                 }
149             ),
150             // 5.
151             new Fixture(
152                 "[M1a].GPXが複数のTRKSEGに分割している場合.FILE_UPDATE時間を基準.GarminColorado",
153                 "testdata/separate.tar.gz",
154                 "testdata/muiltiTRK.GarminColorado.gpx.xml",
155                 "testdata/cameradata/separate.gpx",
156                 "testdata/AdjustTime.M1a.separate.ini",
157                 new Expecter[] {
158                     // GPX file
159                     new Expecter("separate/separate_.gpx", true, null, 90.0D, 180.0D, false),
160
161                     // out of time ( - 2017-05-29T01:23:18)
162                     new Expecter("separate/20170529_102305A.jpg", false, null, 90.0D, 180.0D, false),
163                     new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false),
164
165                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
166                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
167                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
168                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true),
169
170                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
171                     new Expecter("separate/20170529_102409A.jpg", false, null, 90.0D, 180.0D, false),
172                     new Expecter("separate/20170529_102418A.jpg", false, null, 90.0D, 180.0D, false),
173
174                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
175                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
176                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
177
178                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
179                     new Expecter("separate/20170529_103315A.jpg", false, null, 90.0D, 180.0D, false),
180                     new Expecter("separate/20170529_103545A.jpg", false, null, 90.0D, 180.0D, false),
181
182                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
183                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
184                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:18", 35.8339846227D, 138.0625408050D, true),
185                 }
186             ),
187
188             new Fixture(
189                 "[M1b].GPXが複数のTRKSEGに分割している場合.FILE_UPDATE時間を基準.GarminColorado",
190                 "testdata/separate.tar.gz", 
191                 "testdata/muiltiTRK.GarminColorado.gpx.xml",
192                 "testdata/cameradata/separate.gpx",
193                 "testdata/AdjustTime.M1b.separate.ini",
194                 new Expecter[] {
195                     // GPX file
196                     new Expecter("separate/separate_.gpx", true, null, 90.D, 180.0D, false),
197
198                     // out of time ( - 2017-05-29T01:23:18)
199                     new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:06", 90.0D, 180.0D, true),
200                     new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true),
201
202                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
203                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
204                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
205                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true),
206
207                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
208                     new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:10", 90.0D, 180.0D, true),
209                     new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true),
210
211                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
212                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
213                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
214
215                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
216                     new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:14", 90.0D, 180.0D, true),
217                     new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:44", 90.0D, 180.0D, true),
218
219                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
220                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
221                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:18", 35.8339846227D, 138.0625408050D, true),
222                 }
223             ),
224
225             new Fixture(
226                 "[M1c].GPXが複数のTRKSEGに分割している場合.EXIF時間を基準.GarminColorado",
227                 "testdata/separate.tar.gz", 
228                 "testdata/muiltiTRK.GarminColorado.gpx.xml",
229                 "testdata/cameradata/separate.gpx",
230                 "testdata/AdjustTime.M1c.separate.ini",
231                 new Expecter[] {
232                     // GPX file
233                     new Expecter("separate/separate_.gpx", true, null, 90.0D, 180.0D, false),
234
235                     // out of time ( - 2017-05-29T01:23:18)
236                     new Expecter("separate/20170529_102305A.jpg", false, null, 90.0D, 180.0D, false),
237                     new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false),
238
239                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
240                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
241                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
242                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true),
243
244                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
245                     new Expecter("separate/20170529_102409A.jpg", false, null, 90.0D, 180.0D, false),
246                     new Expecter("separate/20170529_102418A.jpg", false, null, 90.0D, 180.0D, false),
247
248                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
249                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
250                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
251
252                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
253                     new Expecter("separate/20170529_103315A.jpg", false, null, 90.0D, 180.0D, false),
254                     new Expecter("separate/20170529_103545A.jpg", false, null, 90.0D, 180.0D, false),
255
256                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
257                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
258                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:19", 35.8339846227D, 138.0625408050D, true),
259                 }
260             ),
261
262             new Fixture(
263                 "[M1d].GPXが複数のTRKSEGに分割している場合.EXIF時間を基準.GarminColorado",
264                 "testdata/separate.tar.gz", 
265                 "testdata/muiltiTRK.GarminColorado.gpx.xml",
266                 "testdata/cameradata/separate.gpx",
267                 "testdata/AdjustTime.M1d.separate.ini",
268                 new Expecter[] {
269                     // GPX file
270                     new Expecter("separate/separate_.gpx", true, null, 90.0D, 180.0D, false),
271
272                     // out of time ( - 2017-05-29T01:23:18)
273                     new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:05", 90.0D, 180.0D, true),
274                     new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true),
275
276                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
277                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
278                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
279                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true),
280
281                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
282                     new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:09", 90.0D, 180.0D, true),
283                     new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true),
284
285                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
286                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
287                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
288
289                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
290                     new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:15", 90.0D, 180.0D, true),
291                     new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:45", 90.0D, 180.0D, true),
292
293                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
294                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
295                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:19", 35.8339846227D, 138.0625408050D, true),
296                 }
297             ),
298
299
300             new Fixture(
301                 "[M2a].GPXが複数のTRKSEGに分割している場合.FILE_UPDATE時間を基準.eTrex_20J",
302                 "testdata/separate.tar.gz", 
303                 "testdata/multiTRKSEG.eTrex_20J.gpx.xml",
304                 "testdata/cameradata/separate.gpx",
305                 "testdata/AdjustTime.M2a.separate.ini",
306                 new Expecter[] {
307                     // GPX file
308                     new Expecter("separate/separate_.gpx", true, null, 90.0D, 180.0D, false),
309
310                     // out of time ( - 2017-05-29T01:23:18)
311                     new Expecter("separate/20170529_102305A.jpg", false, null, 90.0D, 180.0D, false),
312                     new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false),
313
314                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
315                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
316                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
317                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true),
318
319                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
320                     new Expecter("separate/20170529_102409A.jpg", false, null, 90.0D, 180.0D, false),
321                     new Expecter("separate/20170529_102418A.jpg", false, null, 90.0D, 180.0D, false),
322
323                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
324                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
325                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
326
327                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
328                     new Expecter("separate/20170529_103315A.jpg", false, null, 90.0D, 180.0D, false),
329                     new Expecter("separate/20170529_103545A.jpg", false, null, 90.0D, 180.0D, false),
330
331                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
332                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
333                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:18", 35.8339846227D, 138.0625408050D, true),
334                 }
335             ),
336
337             new Fixture(
338                 "[M2b].GPXが複数のTRKSEGに分割している場合.FILE_UPDATE時間を基準.eTrex_20J",
339                 "testdata/separate.tar.gz", 
340                 "testdata/multiTRKSEG.eTrex_20J.gpx.xml",
341                 "testdata/cameradata/separate.gpx",
342                 "testdata/AdjustTime.M2b.separate.ini",
343                 new Expecter[] {
344                     // GPX file
345                     new Expecter("separate/separate_.gpx", true, null, 90.0D, 180.0D, false),
346
347                     // out of time ( - 2017-05-29T01:23:18)
348                     new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:06", 90.0D, 180.0D, true),
349                     new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true),
350
351                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
352                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
353                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
354                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true),
355
356                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
357                     new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:10", 90.0D, 180.0D, true),
358                     new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true),
359
360                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
361                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
362                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
363
364                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
365                     new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:14", 90.0D, 180.0D, true),
366                     new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:44", 90.0D, 180.0D, true),
367
368                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
369                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
370                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:18", 35.8339846227D, 138.0625408050D, true),
371                 }
372             ),
373
374             new Fixture(
375                 "[M2c].GPXが複数のTRKSEGに分割している場合.EXIF時間を基準.eTrex_20J",
376                 "testdata/separate.tar.gz", 
377                 "testdata/multiTRKSEG.eTrex_20J.gpx.xml",
378                 "testdata/cameradata/separate.gpx",
379                 "testdata/AdjustTime.M2c.separate.ini",
380                 new Expecter[] {
381                     // GPX file
382                     new Expecter("separate/separate_.gpx", true, null, 90.0D, 180.0D, false),
383
384                     // out of time ( - 2017-05-29T01:23:18)
385                     new Expecter("separate/20170529_102305A.jpg", false, null, 90.0D, 180.0D, false),
386                     new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false),
387
388                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
389                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
390                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
391                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true),
392
393                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
394                     new Expecter("separate/20170529_102409A.jpg", false, null, 90.0D, 180.0D, false),
395                     new Expecter("separate/20170529_102418A.jpg", false, null, 90.0D, 180.0D, false),
396
397                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
398                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
399                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
400
401                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
402                     new Expecter("separate/20170529_103315A.jpg", false, null, 90.0D, 180.0D, false),
403                     new Expecter("separate/20170529_103545A.jpg", false, null, 90.0D, 180.0D, false),
404
405                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
406                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
407                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:19", 35.8339889813D, 138.0625394639D, true),
408                 }
409             ),
410
411             new Fixture(
412                 "[M2d].GPXが複数のTRKSEGに分割している場合.EXIF時間を基準.eTrex_20J",
413                 "testdata/separate.tar.gz", 
414                 "testdata/multiTRKSEG.eTrex_20J.gpx.xml",
415                 "testdata/cameradata/separate.gpx",
416                 "testdata/AdjustTime.M2d.separate.ini",
417                 new Expecter[] {
418                     // GPX file
419                     new Expecter("separate/separate_.gpx", true, null, 90.0D, 180.0D, false),
420
421                     // out of time ( - 2017-05-29T01:23:18)
422                     new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:05", 90.0D, 180.0D, true),
423                     new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true),
424
425                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
426                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
427                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
428                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true),
429
430                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
431                     new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:09", 90.0D, 180.0D, true),
432                     new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true),
433
434                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
435                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
436                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
437
438                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
439                     new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:15", 90.0D, 180.0D, true),
440                     new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:45", 90.0D, 180.0D, true),
441
442                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
443                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
444                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:19", 35.8339889813D, 138.0625394639D, true),
445                 }
446             ),
447
448             new Fixture(
449                 "[M3a].GPXが複数のTRKSEGに分割している場合.FILE_UPDATE時間を基準.eTrex_20Jreverse",
450                 "testdata/separate.tar.gz", 
451                 "testdata/multiTRKSEGreverse.eTrex_20J.gpx.xml",
452                 "testdata/cameradata/separate.gpx",
453                 "testdata/AdjustTime.M2a.separate.ini",
454                 new Expecter[] {
455                     // GPX file
456                     new Expecter("separate/separate_.gpx", true, null, 90.0D, 180.0D, false),
457
458                     // out of time ( - 2017-05-29T01:23:18)
459                     new Expecter("separate/20170529_102305A.jpg", false, null, 90.0D, 180.0D, false),
460                     new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false),
461
462                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
463                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
464                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
465                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true),
466
467                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
468                     new Expecter("separate/20170529_102409A.jpg", false, null, 90.0D, 180.0D, false),
469                     new Expecter("separate/20170529_102418A.jpg", false, null, 90.0D, 180.0D, false),
470
471                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
472                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
473                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
474
475                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
476                     new Expecter("separate/20170529_103315A.jpg", false, null, 90.0D, 180.0D, false),
477                     new Expecter("separate/20170529_103545A.jpg", false, null, 90.0D, 180.0D, false),
478
479                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
480                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
481                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:18", 35.8339846227D, 138.0625408050D, true),
482                 }
483             ),
484
485             new Fixture(
486                 "[M3b].GPXが複数のTRKSEGに分割している場合.FILE_UPDATE時間を基準.eTrex_20Jreverse",
487                 "testdata/separate.tar.gz", 
488                 "testdata/multiTRKSEGreverse.eTrex_20J.gpx.xml",
489                 "testdata/cameradata/separate.gpx",
490                 "testdata/AdjustTime.M2b.separate.ini",
491                 new Expecter[] {
492                     // GPX file
493                     new Expecter("separate/separate_.gpx", true, null, 90.0D, 180.0D, false),
494
495                     // out of time ( - 2017-05-29T01:23:18)
496                     new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:06", 90.0D, 180.0D, true),
497                     new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true),
498
499                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
500                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
501                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
502                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:04", 35.8808881603D, 137.9979396332D, true),
503
504                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
505                     new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:10", 90.0D, 180.0D, true),
506                     new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true),
507
508                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
509                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
510                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
511
512                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
513                     new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:14", 90.0D, 180.0D, true),
514                     new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:44", 90.0D, 180.0D, true),
515
516                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
517                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
518                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:18", 35.8339846227D, 138.0625408050D, true),
519                 }
520             ),
521
522             new Fixture(
523                 "[M3c].GPXが複数のTRKSEGに分割している場合.EXIF時間を基準.eTrex_20Jreverse",
524                 "testdata/separate.tar.gz", 
525                 "testdata/multiTRKSEGreverse.eTrex_20J.gpx.xml",
526                 "testdata/cameradata/separate.gpx",
527                 "testdata/AdjustTime.M2c.separate.ini",
528                 new Expecter[] {
529                     // GPX file
530                     new Expecter("separate/separate_.gpx", true, null, 90.0D, 180.0D, false),
531
532                     // out of time ( - 2017-05-29T01:23:18)
533                     new Expecter("separate/20170529_102305A.jpg", false, null, 90.0D, 180.0D, false),
534                     new Expecter("separate/20170529_102314A.jpg", false, null, 90.0D, 180.0D, false),
535
536                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
537                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
538                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
539                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true),
540
541                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
542                     new Expecter("separate/20170529_102409A.jpg", false, null, 90.0D, 180.0D, false),
543                     new Expecter("separate/20170529_102418A.jpg", false, null, 90.0D, 180.0D, false),
544
545                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
546                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
547                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
548
549                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
550                     new Expecter("separate/20170529_103315A.jpg", false, null, 90.0D, 180.0D, false),
551                     new Expecter("separate/20170529_103545A.jpg", false, null, 90.0D, 180.0D, false),
552
553                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
554                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
555                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:19", 35.8339889813D, 138.0625394639D, true),
556                 }
557             ),
558
559             new Fixture(
560                 "[M3d].GPXが複数のTRKSEGに分割している場合.EXIF時間を基準.eTrex_20Jreverse",
561                 "testdata/separate.tar.gz", 
562                 "testdata/multiTRKSEGreverse.eTrex_20J.gpx.xml",
563                 "testdata/cameradata/separate.gpx",
564                 "testdata/AdjustTime.M2d.separate.ini",
565                 new Expecter[] {
566                     // GPX file
567                     new Expecter("separate/separate_.gpx", true, null, 90.0D, 180.0D, false),
568
569                     // out of time ( - 2017-05-29T01:23:18)
570                     new Expecter("separate/20170529_102305A.jpg", true, "2017:05:29 10:23:05", 90.0D, 180.0D, true),
571                     new Expecter("separate/20170529_102314A.jpg", true, "2017:05:29 10:23:14", 90.0D, 180.0D, true),
572
573                     // in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
574                     new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
575                     new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
576                     new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true),
577
578                     // out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
579                     new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:09", 90.0D, 180.0D, true),
580                     new Expecter("separate/20170529_102418A.jpg", true, "2017:05:29 10:24:18", 90.0D, 180.0D, true),
581
582                     // in TRKSEG(2) (2017-05-29T01:24:37 - 2017-05-29T01:33:03)
583                     new Expecter("separate/20170529_102448A.jpg", true, "2017:05:29 10:24:48", 35.8788877353D, 138.0039562471D, true),
584                     new Expecter("separate/20170529_103246A.jpg", true, "2017:05:29 10:32:46", 35.8405660931D, 138.0353022180D, true),
585
586                     // out of time (2017-05-29T01:33:03 - 2017-05-29T01:35:53)
587                     new Expecter("separate/20170529_103315A.jpg", true, "2017:05:29 10:33:15", 90.0D, 180.0D, true),
588                     new Expecter("separate/20170529_103545A.jpg", true, "2017:05:29 10:35:45", 90.0D, 180.0D, true),
589
590                     // in TRKSEG(3) (2017-05-29T01:35:53 - 2017-05-29T01:47:35)
591                     new Expecter("separate/20170529_103615A.jpg", true, "2017:05:29 10:36:14", 35.8359798510D, 138.0600296706D, true),
592                     new Expecter("separate/20170529_104119A.jpg", true, "2017:05:29 10:41:19", 35.8339889813D, 138.0625394639D, true),
593                 }
594             ),
595         };
596
597         @Theory
598         public void パラメータテスト(Fixture dataset) throws Exception {
599             ImportPictureTest.setup(dataset);
600             ImportPictureTest.testdo(dataset.iniFilePath);
601             //SimpleDateFormat format = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", Locale.UK);
602
603             Expecter[] es = dataset.expecters;
604             AppParameters params = new AppParameters(dataset.iniFilePath);
605             File outDir = new File(params.getProperty(AppParameters.IMG_OUTPUT_FOLDER));
606             for (Expecter e : es) {
607                 File file = new File(outDir, e.value);
608                 System.out.println("[JUnit.debug] assert file='"+ file.getAbsolutePath() +"'");
609                 assertThat(file.exists(), is(e.expect));
610                 if (e.timeStr != null) {
611                     // JPEG メタデータが存在すること
612                     ImageMetadata meta = Imaging.getMetadata(file);
613                     // メタデータは インスタンスJpegImageMetadata であること
614                     assertThat((meta instanceof JpegImageMetadata), is(true));
615                     JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta;
616                     assertNotNull(jpegMetadata);
617                     // EXIFデータが存在すること
618                     TiffImageMetadata exif = jpegMetadata.getExif();
619                     assertNotNull(exif);
620                     // EXIF-TIME が正しく設定されていること
621                     String exifTime = ImportPicture.toEXIFString(ImportPicture.toEXIFDate(exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0]));
622                     System.out.println("[debug] exifTime = '"+ exifTime +"' <--> '" + e.timeStr + "'");
623                     assertThat(exifTime, is(e.timeStr));
624                     // LAT,LON
625                     GPSInfo gpsInfo = exif.getGPS();
626                     if (e.latD != 90.0D) {
627                         assertThat(comparePosition(gpsInfo.getLatitudeAsDegreesNorth()), is(comparePosition(e.latD)));
628                     }
629                     if (e.lonD != 180.0D) {
630                         assertThat(comparePosition(gpsInfo.getLongitudeAsDegreesEast()), is(comparePosition(e.lonD)));
631                     }
632                 }
633             }
634         }
635
636         static String comparePosition(double b) {
637             return String.format("%.4f", b);
638         }
639     }
640
641     static void setup(Fixture dataset) throws IOException {
642         System.out.println(dataset.toString());
643
644         // カメラディレクトリを削除する
645         File dir = new File("testdata/cameradata");
646         if (dir.exists()) {
647             ImportPictureTest.delete(dir);
648         }
649         File outDir = new File("testdata/output");
650         if (outDir.exists()) {
651             ImportPictureTest.delete(outDir);
652         }
653         outDir.mkdir();
654
655         // カメラディレクトリを作成する
656         ImportPictureTest.uncompress(new File(dataset.tarFilePath), new File("testdata/cameradata"));
657
658         // GPXファイルをセット
659         try (FileInputStream inStream = new FileInputStream(new File(dataset.gpxSourcePath));
660             FileOutputStream outStream = new FileOutputStream(new File(dataset.gpxDestinationPath));
661             FileChannel inChannel = inStream.getChannel();
662             FileChannel outChannel = outStream.getChannel())
663         {
664             inChannel.transferTo(0, inChannel.size(), outChannel);
665         }
666     }
667
668     /**
669      * 実行する
670      * @throws Exception
671      */
672     static void testdo(String iniFilePath) {
673         try {
674             String[] argv = {iniFilePath};
675             ImportPicture.main(argv);
676         }
677         catch (Exception e) {
678             e.printStackTrace();
679             fail("Exceptionが発生した。");
680         }
681     }
682
683     /**
684      * *.tar.gz解凍
685      * ファイル更新日時をオリジナルと同じにします。
686      * @param tazFile 解凍する*.tar.gzファイル
687      * @param dest 解凍先フォルダ
688      * @throws IOException 
689      */
690     public static void uncompress(File tazFile, File dest) throws IOException {
691         dest.mkdir();
692         
693         try (TarArchiveInputStream tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tazFile))))) {
694             TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
695             while (tarEntry != null) {
696                 File destPath = new File(dest, tarEntry.getName());
697                 //System.out.println("uncompress: " + destPath.getCanonicalPath());
698                 if (tarEntry.isDirectory()) {
699                     destPath.mkdirs();
700                 }
701                 else {
702                     File dir = new File(destPath.getParent());
703                     if (!dir.exists()) {
704                         dir.mkdirs();
705                     }
706                     destPath.createNewFile();
707                     byte[] btoRead = new byte[1024];
708                     try (BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath))) {
709                         int len = 0;
710                         while ((len = tarIn.read(btoRead)) != -1) {
711                             bout.write(btoRead, 0, len);
712                         }
713                     }
714                     destPath.setLastModified(tarEntry.getLastModifiedDate().getTime());
715                     btoRead = null;
716                 }
717                 tarEntry = tarIn.getNextTarEntry();
718             }
719         }
720     }
721
722     public static void delete(File file) throws IOException {
723         if (!file.exists()) {
724             System.out.println("ERROR: ファイルまたはディレクトリが見つかりませんでした。");
725             throw new IOException("File not found.");
726         }
727         
728         if (file.isDirectory()) {
729             File files[] = file.listFiles();
730             if (files != null) {
731                 for (File file1 : files) {
732                     delete(file1); // 再帰呼び出し
733                 }
734             }
735         }
736         if (!file.delete()) {
737             System.out.println("ERROR: ファイルは削除できませんでした。 '" + file.getAbsolutePath() +"'");
738         }
739     }
740 }