OSDN Git Service

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