OSDN Git Service

92a3f0132ea2a604f13c2d63ce448552d44b63ef
[importpicture/importpicture.git] / src / test / java / osm / jp / gpx / ElementMapTRKPTTest.java
1 package osm.jp.gpx;
2
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.hamcrest.CoreMatchers.notNullValue;
5 import static org.hamcrest.CoreMatchers.nullValue;
6 import static org.junit.Assert.*;
7 import java.text.DateFormat;
8 import java.text.ParseException;
9 import java.text.SimpleDateFormat;
10 import java.util.Date;
11
12 import org.junit.After;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.experimental.runners.Enclosed;
16 import org.junit.runner.RunWith;
17
18 @RunWith(Enclosed.class)
19 public class ElementMapTRKPTTest {
20
21     public static class Keyのみ {
22         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
23         ElementMapTRKPT map = null;
24         long timeL;
25         static String[] values = {
26             "1970-01-01 08:59:59.999",
27             "1970-01-01 09:00:00.000",
28             "1970-01-01 09:00:00.001",
29             "2018-10-25 07:59:59.999",
30             "2018-10-25 08:00:00.000",
31             "2018-10-25 08:00:00.001"
32         };
33
34         @Before
35         public void setUp() throws Exception {
36             timeL = (sdf.parse("2018-10-25 08:00:00.000")).getTime();
37             map = new ElementMapTRKPT(new AppParameters(AppParameters.FILE_PATH));
38             map.put(new Date(timeL), null);                     // 5-6: 2018-10-25 08:00:00.000
39             map.put(new Date(timeL + 1L), null);        // 7: 2018-10-25 08:00:00.001
40             map.put(new Date(timeL - 1L), null);        // 4: 2018-10-25 07:59:59.999
41             map.put(new Date(1L), null);                        // 3: 1970-01-01 09:00:00.001
42             map.put(new Date(0L), null);                        // 2: 1970-01-01 09:00:00.000
43             map.put(new Date(-1L), null);                       // 1: 1970-01-01 08:59:59.999
44             map.put(new Date(timeL), null);                     // 5-6: 2018-10-25 08:00:00.000
45         }
46
47         @After
48         public void tearDown() throws Exception {
49                 AppParametersTest.delTestData("AdjustTime.ini");
50         }
51
52         @Test
53         public void 同一キーをPUTした場合() {
54             assertThat(map.size(), is(6));
55         }
56
57         @Test
58         public void イテレータを使って読みだす() {
59             assertThat(map.size(), is(6));
60
61             int i = 0;
62             for (Date key : map.keySet()) {
63                 assertThat(sdf.format(key), is(values[i++]));
64             }
65         }
66
67         @Test
68         public void 拡張FOR文を使って読みだす() {
69             assertThat(map.size(), is(6));
70
71             int i = 0;
72             for (Date key : map.keySet()) {
73                 assertThat(sdf.format(key), is(values[i++]));
74             }
75         }
76     }
77
78     public static class Keyとvalueのセット {
79         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
80         ElementMapTRKPT map = null;
81         long timeL;
82
83         /*
84          * <trkpt lat="35.8812697884" lon="137.9952202085"><time>2017-05-29T01:23:18Z</time></trkpt>
85          * <trkpt lat="35.8811769169" lon="137.9951928835"><time>2017-05-29T01:23:21Z</time><ele>614.90</ele></trkpt>
86          * <trkpt lat="35.881112963" lon="137.9951796401"><time>2017-05-29T01:23:24Z</time><ele>615.00</ele></trkpt>
87          * <trkpt lat="35.881072646" lon="137.9951728508"><time>2017-05-29T01:23:27Z</time><ele>615.03</ele></trkpt>
88          */
89         static String[][] values = {
90             {"2017-05-29T01:23:18Z", "35.8812697884", "137.9952202085", null},
91             {"2017-05-29T01:23:21Z", "35.8811769169", "137.9951928835", "614.90"},
92             {"2017-05-29T01:23:24Z", "35.881112963", "137.9951796401", "615.00"},
93             {"2017-05-29T01:23:27Z", "35.881072646", "137.9951728508", "615.03"}
94         };
95
96         TagTrkpt createElement(String[] values) throws ParseException {
97                 TagTrkpt trkpt = new TagTrkpt(Double.valueOf(values[1]), Double.valueOf(values[2]));
98             trkpt.setTime(ImportPicture.toUTCDate(values[0]));
99             if (values[3] != null) {
100                 trkpt.setEle(values[3]);
101             }
102             return trkpt;
103         }
104
105         @Before
106         public void setUp() throws Exception {
107             AppParameters params = new AppParameters(AppParameters.FILE_PATH);
108             params.setGpxOverwriteMagvar(true);
109
110             map = new ElementMapTRKPT(params);
111             for (int cnt = values.length; cnt > 0; cnt--) {
112                 map.put(createElement(values[cnt - 1]));
113             }
114         }
115
116         @After
117         public void tearDown() throws Exception {
118                 AppParametersTest.delTestData("AdjustTime.ini");
119         }
120
121         @Test
122         public void コンテンツの数をチェック() {
123             assertThat(map.size(), is(4));
124         }
125
126         @Test
127         public void KEYが時間順に取り出せるか() {
128             int i = 0;
129             for (Date key : map.keySet()) {
130                 try {
131                     String s = sdf.format(ImportPicture.toUTCDate(values[i++][0]));
132                     assertThat(sdf.format(key), is(s));
133                 } catch (ParseException e) {
134                     e.printStackTrace();
135                 }
136             }
137         }
138
139         @Test
140         public void get_17() throws ParseException {
141             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:17Z"));
142             assertThat(tag, is(nullValue()));
143         }
144
145         @Test
146         public void get_18() throws ParseException {
147             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:18Z"));
148             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z"));
149             assertThat(tag.eleStr, is(nullValue()));
150             assertThat(tag.lat, is(Double.valueOf(values[0][1])));
151             assertThat(tag.lon, is(Double.valueOf(values[0][2])));
152             assertNull(tag.magvarStr);
153         }
154
155         @Test
156         public void get_19() throws ParseException {
157             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:19Z"));
158             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z"));
159             assertNull(tag.eleStr);
160             assertThat(tag.lat, is(Double.valueOf(values[0][1])));
161             assertThat(tag.lon, is(Double.valueOf(values[0][2])));
162             assertNull(tag.magvarStr);
163         }
164
165         @Test
166         public void get_20() throws ParseException {
167             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:20Z"));
168             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z"));
169             assertNull(tag.eleStr);
170             assertThat(tag.lat, is(Double.valueOf(values[0][1])));
171             assertThat(tag.lon, is(Double.valueOf(values[0][2])));
172             assertNull(tag.magvarStr);
173         }
174
175         @Test
176         public void get_21() throws ParseException {
177             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:21Z"));
178             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z"));
179             assertThat(tag.eleStr, is("614.90"));
180             assertThat(tag.lat, is(Double.valueOf(values[1][1])));
181             assertThat(tag.lon, is(Double.valueOf(values[1][2])));
182             assertNotNull(tag.magvarStr);
183         }
184
185         @Test
186         public void get_22() throws ParseException {
187             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:22Z"));
188             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z"));
189             assertThat(tag.eleStr, is("614.90"));
190             assertThat(tag.lat, is(Double.valueOf(values[1][1])));
191             assertThat(tag.lon, is(Double.valueOf(values[1][2])));
192             assertNotNull(tag.magvarStr);
193         }
194
195         @Test
196         public void get_23() throws ParseException {
197             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:23Z"));
198             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z"));
199             assertThat(tag.eleStr, is("614.90"));
200             assertThat(tag.lat, is(Double.valueOf(values[1][1])));
201             assertThat(tag.lon, is(Double.valueOf(values[1][2])));
202             assertNotNull(tag.magvarStr);
203         }
204
205         @Test
206         public void get_24() throws ParseException {
207             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:24Z"));
208             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z"));
209             assertThat(tag.eleStr, is("615.00"));
210             assertThat(tag.lat, is(Double.valueOf(values[2][1])));
211             assertThat(tag.lon, is(Double.valueOf(values[2][2])));
212             assertThat(tag.magvarStr, is(notNullValue()));
213         }
214
215         @Test
216         public void get_25() throws ParseException {
217             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:25Z"));
218             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z"));
219             assertThat(tag.eleStr, is("615.00"));
220             assertThat(tag.lat, is(Double.valueOf(values[2][1])));
221             assertThat(tag.lon, is(Double.valueOf(values[2][2])));
222             assertThat(tag.magvarStr, is(notNullValue()));
223         }
224
225         @Test
226         public void get_26() throws ParseException {
227             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:26Z"));
228             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z"));
229             assertThat(tag.eleStr, is("615.00"));
230             assertThat(tag.lat, is(Double.valueOf(values[2][1])));
231             assertThat(tag.lon, is(Double.valueOf(values[2][2])));
232             assertThat(tag.magvarStr, is(notNullValue()));
233         }
234
235         @Test
236         public void get_27() throws ParseException {
237             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:27Z"));
238             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z"));
239             assertThat(tag.eleStr, is("615.03"));
240             assertThat(tag.lat, is(Double.valueOf(values[3][1])));
241             assertThat(tag.lon, is(Double.valueOf(values[3][2])));
242             assertNotNull(tag.magvarStr);
243         }
244
245         @Test
246         public void get_28() throws ParseException {
247             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:28Z"));
248             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z"));
249             assertThat(tag.eleStr, is("615.03"));
250             assertThat(tag.lat, is(Double.valueOf(values[3][1])));
251             assertThat(tag.lon, is(Double.valueOf(values[3][2])));
252             assertThat(tag.magvarStr, is(notNullValue()));
253         }
254
255         @Test
256         public void get_30() throws ParseException {
257             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:30Z"));
258             assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z"));
259             assertThat(tag.eleStr, is("615.03"));
260             assertThat(tag.lat, is(Double.valueOf(values[3][1])));
261             assertThat(tag.lon, is(Double.valueOf(values[3][2])));
262             assertThat(tag.magvarStr, is(notNullValue()));
263         }
264
265         @Test
266         public void get_31() throws ParseException {
267             TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:31Z"));
268             assertThat(tag, is(nullValue()));
269         }
270     }
271
272     public static class タイムスタンプの書式 {
273         @Test
274         public void EXIF時刻書式テスト() throws Exception {
275             String dateTimeOriginal = "2017:06:30 09:59:59";
276             Date time = ImportPicture.toEXIFDate(dateTimeOriginal);
277             assertThat(ImportPicture.toEXIFString(time), is("2017:06:30 09:59:59"));
278             assertThat(ImportPicture.toUTCString(time), is("2017-06-30T00:59:59Z"));
279             DateFormat dfUTC = new SimpleDateFormat(ImportPicture.TIME_FORMAT_STRING);
280             assertThat(dfUTC.format(time), is("2017-06-30T09:59:59Z"));
281         }
282     }
283 }