gpsfold: Remove $Id$ at EOF.
[gpstools.git] / branches / gpst.near / tests / run-tests.pl
blobe279f18af1ba82ccf30f27acddce1fb6c0c31443
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # $Id$
5 # Test suite for gpst.
7 # Character set: UTF-8
8 # ©opyleft 2006– Øyvind A. Holm <sunny@sunbase.org>
9 # License: GNU General Public License, see end of file for legal stuff.
10 #=======================================================================
12 BEGIN {
13 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
14 our @version_array;
17 use strict;
18 use Getopt::Long;
19 use Test::More qw{no_plan};
21 use GPST;
22 use GPSTdate;
23 use GPSTdebug;
24 use GPSTgeo;
25 use GPSTxml;
27 $| = 1;
29 our $Debug = 0;
31 our %Opt = (
32 'all' => 0,
33 'debug' => 0,
34 'help' => 0,
35 'todo' => 0,
36 'version' => 0,
39 our $progname = $0;
40 $progname =~ s#^.*/(.*?)$#$1#;
42 my $rcs_id = '$Id$';
43 my $id_date = $rcs_id;
44 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
46 Getopt::Long::Configure("bundling");
47 GetOptions(
48 "all|a" => \$Opt{'all'},
49 "debug" => \$Opt{'debug'},
50 "help|h" => \$Opt{'help'},
51 "todo|t" => \$Opt{'todo'},
52 "version" => \$Opt{'version'},
53 ) || die("$progname: Option error. Use -h for help.\n");
55 our %Cmd = (
56 'gpsbabel' => '/usr/local/bin/gpsbabel',
59 $Opt{'debug'} && ($Debug = 1);
60 $Opt{'help'} && usage(0);
61 $Opt{'version'} && print_version();
63 chomp(my $gpx_header = <<END);
64 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
65 <gpx
66 version="1.1"
67 creator="gpst - http://svn.sunbase.org/repos/utils/trunk/src/gpstools/"
68 xmlns="http://www.topografix.com/GPX/1/1"
69 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
70 xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
72 END
74 if ($Opt{'todo'} && !$Opt{'all'}) {
75 goto todo_section;
78 diag("Testing XML routines...");
80 # txt_to_xml() and xml_to_txt() {{{
82 is(txt_to_xml("abc"),
83 "abc",
84 "txt_to_xml(\"abc\")");
85 is(txt_to_xml("<&>"),
86 "&lt;&amp;&gt;",
87 "txt_to_xml(\"<&>\")");
88 is(txt_to_xml("first line\nsecond <\rthird\r\n<&>"),
89 "first line\nsecond &lt;\rthird\r\n&lt;&amp;&gt;",
90 "txt_to_xml() with multiline string");
92 is(xml_to_txt("abc"),
93 "abc",
94 "xml_to_txt(\"abc\")");
95 is(xml_to_txt("&lt;&amp;&gt;"),
96 "<&>",
97 "xml_to_txt(\"&lt;&amp;&gt;\")");
98 is(xml_to_txt("first line\nsecond &lt;\rthird\r\n&lt;&amp;&gt;"),
99 "first line\nsecond <\rthird\r\n<&>",
100 "xml_to_txt() with multiline string");
102 # }}}
104 diag("Testing date routines...");
106 # sec_to_string() {{{
108 is(sec_to_string(1148220825),
109 "2006-05-21 14:13:45",
110 "sec_to_string() without separator");
111 is(sec_to_string(1148220825, "T"),
112 "2006-05-21T14:13:45",
113 "sec_to_string() with separator");
114 is(sec_to_string(-5000),
115 undef,
116 "sec_to_string(-5000) — negative numbers unsupported atm");
117 is(sec_to_string(""),
118 undef,
119 "sec_to_string(\"\")");
120 is(sec_to_string("pH()rtY tW0"),
121 undef,
122 "sec_to_string() with invalid string");
123 is(sec_to_string("00000000000000000000001148220825"),
124 "2006-05-21 14:13:45",
125 "sec_to_string() with a bunch of leading zeros");
126 is(sec_to_string("1148220825.93"),
127 "2006-05-21 14:13:45.93",
128 "sec_to_string() with decimals");
129 is(sec_to_string("000000000000000000000000000001148220825.7312"),
130 "2006-05-21 14:13:45.7312",
131 "sec_to_string() with decimals and prefixing zeros");
132 is(sec_to_string("1148220825.93000"),
133 "2006-05-21 14:13:45.93",
134 "sec_to_string() with decimals and extra trailing zeros");
135 is(sec_to_string(".863"),
136 "1970-01-01 00:00:00.863",
137 "sec_to_string() with missing zero before decimal point");
139 # }}}
140 # sec_to_readable() {{{
142 is(sec_to_readable(0),
143 "0:00:00:00",
144 "sec_to_readable(0)");
145 is(sec_to_readable("pH()rtY tW0"),
146 undef,
147 "sec_to_readable() with invalid string");
148 is(sec_to_readable(86400),
149 "1:00:00:00",
150 "sec_to_readable(86400)");
151 is(sec_to_readable(86400*1000),
152 "1000:00:00:00",
153 "sec_to_readable(86400*1000)");
154 is(sec_to_readable(86400+7200+180+4),
155 "1:02:03:04",
156 "sec_to_readable(86400+7200+180+4)");
157 is(sec_to_readable("3.14"),
158 "0:00:00:03.14",
159 "sec_to_readable(\"3.14\")");
160 is(sec_to_readable("-124"),
161 undef,
162 "sec_to_readable() rejects negative numbers");
163 is(sec_to_readable("-2.34"),
164 undef,
165 "sec_to_readable() rejects negative decimal");
166 is(sec_to_readable(".87"),
167 "0:00:00:00.87",
168 "sec_to_readable(), missing zero before decimal point");
169 is(sec_to_readable(""),
170 "0:00:00:00",
171 "sec_to_readable() with empty string");
173 # }}}
175 diag("Testing geo routines...");
177 # ddd_to_dms() {{{
179 is(ddd_to_dms("12.34567"),
180 "12\xB020'44.4\"",
181 "ddd_to_dms(\"12.34567\")");
183 is(ddd_to_dms("0"),
184 "0\xB000'00.0\"",
185 "ddd_to_dms(\"0\")");
187 is(ddd_to_dms(""),
188 "0\xB000'00.0\"",
189 "ddd_to_dms(\"\")");
191 is(ddd_to_dms("pH()rtY tW0"),
192 undef,
193 "ddd_to_dms(\"pH()rtY tW0\")");
195 is(ddd_to_dms("-12.34567"),
196 "-12\xB020'44.4\"",
197 "ddd_to_dms(\"-12.34567\")");
199 is(ddd_to_dms("0.34567"),
200 "0\xB020'44.4\"",
201 "ddd_to_dms(\"0.34567\")");
203 is(ddd_to_dms(".34567"),
204 "0\xB020'44.4\"",
205 "ddd_to_dms(\".34567\")");
207 is(ddd_to_dms("-.34567"),
208 "-0\xB020'44.4\"",
209 "ddd_to_dms(\"-.34567\")");
211 is(ddd_to_dms("-0.34567"),
212 "-0\xB020'44.4\"",
213 "ddd_to_dms(\"-0.34567\")");
215 is(ddd_to_dms("180"),
216 "180\xB000'00.0\"",
217 "ddd_to_dms(\"180\")");
219 is(ddd_to_dms("-180"),
220 "-180\xB000'00.0\"",
221 "ddd_to_dms(\"-180\")");
223 is(ddd_to_dms("-1"),
224 "-1\xB000'00.0\"",
225 "ddd_to_dms(\"-1\")");
227 is(ddd_to_dms("2-3"),
228 undef,
229 "ddd_to_dms(\"2-3\")");
231 # }}}
232 # distance() {{{
233 like(distance(60.42541, 5.29959, 60.42424, 5.30177, "metre"),
234 qr/^\d\d\d\.\d+$/,
235 "distance() returns a decimal number"
238 # }}}
239 # list_nearest_waypoints() {{{
241 like(list_nearest_waypoints(60.42541, 5.29959, 3),
242 qr/^\(.*,.*,.*\)$/,
243 "list_nearest_waypoints()");
245 # }}}
247 diag("Testing trackpoint()...");
249 # trackpoint() {{{
251 my %Dat = ();
253 is(trackpoint(%Dat),
254 undef,
255 "trackpoint() receives empty hash");
257 my %Bck = (
258 # {{{
259 'format' => 'gpsml',
260 'year' => '2003',
261 'month' => '06',
262 'day' => '13',
263 'hour' => '14',
264 'min' => '36',
265 'sec' => '10',
266 'lat' => '59.5214',
267 'lon' => '7.392133',
268 'ele' => '762',
269 'error' => "",
270 'type' => 'tp',
271 # }}}
274 # trackpoint() (gpsml) {{{
275 %Dat = %Bck;
277 trackpoint(%Dat),
278 "<tp> <time>2003-06-13T14:36:10Z</time> <lat>59.5214</lat> <lon>7.392133</lon> <ele>762</ele> </tp>\n",
279 "trackpoint() (gpsml)"
282 # }}}
283 # trackpoint() (gpx) {{{
284 %Dat = %Bck;
285 $Dat{'format'} = "gpx";
287 trackpoint(%Dat),
288 qq{ <trkpt lat="59.5214" lon="7.392133"> <ele>762</ele> <time>2003-06-13T14:36:10Z</time> </trkpt>\n},
289 "trackpoint() (gpx)"
292 # }}}
294 # trackpoint(): Various loop tests {{{
296 for my $Elem (qw{format lat lon type}) {
297 my %Dat = %Bck;
299 $Dat{"$Elem"} = '2d';
300 is(trackpoint(%Dat),
301 undef,
302 "trackpoint(): {'$Elem'} with invalid value (\"$Dat{$Elem}\") returns undef"
307 for my $Elem (qw{year month day hour min sec}) {
308 # Date tests {{{
309 my %Dat;
311 %Dat = %Bck;
312 $Dat{"$Elem"} = '';
313 is(trackpoint(%Dat),
314 "<tp> <lat>59.5214</lat> <lon>7.392133</lon> <ele>762</ele> </tp>\n",
315 "trackpoint(): {'$Elem'} with empty value skips time"
318 %Dat = %Bck;
319 $Dat{"$Elem"} = '2d';
320 is(trackpoint(%Dat),
321 "<tp> <lat>59.5214</lat> <lon>7.392133</lon> <ele>762</ele> </tp>\n",
322 "trackpoint(): {'$Elem'} with invalid value (\"$Dat{$Elem}\") skips time"
325 %Dat = %Bck;
326 $Dat{$Elem} = "00000$Dat{$Elem}";
327 is(trackpoint(%Dat),
328 "<tp> <time>2003-06-13T14:36:10Z</time> <lat>59.5214</lat> <lon>7.392133</lon> <ele>762</ele> </tp>\n",
329 "trackpoint(): Strip prefixing zeros from {'$Elem'}"
332 %Dat = %Bck;
333 $Dat{"$Elem"} = 0-$Dat{$Elem};
334 is(trackpoint(%Dat),
335 "<tp> <lat>59.5214</lat> <lon>7.392133</lon> <ele>762</ele> </tp>\n",
336 "trackpoint(): {'$Elem'} is negative, skip time"
339 if ($Elem ne "sec") {
340 %Dat = %Bck;
341 $Dat{"$Elem"} = "$Dat{$Elem}.00";
342 is(trackpoint(%Dat),
343 "<tp> <lat>59.5214</lat> <lon>7.392133</lon> <ele>762</ele> </tp>\n",
344 "trackpoint(): Decimals in {'$Elem'}, skip time"
348 # }}}
351 %Dat = %Bck;
352 $Dat{'sec'} = "$Dat{'sec'}.00";
353 is(trackpoint(%Dat),
354 "<tp> <time>2003-06-13T14:36:10Z</time> <lat>59.5214</lat> <lon>7.392133</lon> <ele>762</ele> </tp>\n",
355 "trackpoint(): Remove trailing zeros in {'sec'} decimals"
358 for my $Elem (qw{format type error}) {
359 my %Dat = %Bck;
360 $Dat{$Elem} = undef;
361 is(trackpoint(%Dat),
362 undef,
363 "trackpoint(): Missing {'$Elem'}, return undef"
367 # Various loop tests }}}
369 # trackpoint() }}}
371 diag("Testing output from ../gpst");
373 like(`../gpst --version`, # {{{
374 qr/^(\$Id: .*? \$\n)+$/s,
375 "../gpst --version");
377 # }}}
378 testcmd("../gpst </dev/null", # {{{
379 <<END,
380 <?xml version="1.0" encoding="UTF-8"?>
381 <gpsml>
382 <track>
383 </track>
384 </gpsml>
388 # }}}
389 testcmd("../gpst -o gpx </dev/null", # {{{
390 <<END,
391 $gpx_header
392 <trk>
393 <trkseg>
394 </trkseg>
395 </trk>
396 </gpx>
400 # }}}
401 testcmd("../gpst --fix --chronology chronology-error.gpsml 2>chronofix.tmp", # {{{
402 <<END,
403 <?xml version="1.0" encoding="UTF-8"?>
404 <gpsml>
405 <track>
406 <title>\$Id: chronology-error.gpsml 1774 2006-05-20 02:48:39Z sunny \$</title>
407 <tp> <time>2006-05-02T09:46:37Z</time> <lat>60.45369</lat> <lon>5.31559</lon> <ele>95</ele> </tp>
408 <tp> <time>2006-05-02T09:46:42Z</time> <lat>60.45353</lat> <lon>5.31548</lon> <ele>94</ele> </tp>
409 <tp> <time>2006-05-02T09:46:46Z</time> <lat>60.45353</lat> <lon>5.31561</lon> <ele>94</ele> </tp>
410 <break/>
411 <etp err="chrono"> <time>2006-05-02T09:40:07Z</time> <lat>60.45369</lat> <lon>5.31597</lon> <desc>Out of chronology</desc> </etp>
412 <break/>
413 <pause>0:00:37:54</pause>
414 <tp> <time>2006-05-02T10:18:01Z</time> <lat>60.45418</lat> <lon>5.31517</lon> <ele>92</ele> </tp>
415 <tp> <time>2006-05-02T10:18:06Z</time> <lat>60.45407</lat> <lon>5.31542</lon> <ele>91</ele> </tp>
416 <tp> <time>2006-05-02T10:18:09Z</time> <lat>60.45401</lat> <lon>5.31543</lon> <ele>98</ele> </tp>
417 <tp> <time>2006-05-02T10:18:10Z</time> <lat>60.45395</lat> <lon>5.31544</lon> <ele>103</ele> </tp>
418 <tp> <time>2006-05-02T10:18:11Z</time> <lat>60.45391</lat> <lon>5.31545</lon> <ele>107</ele> </tp>
419 </track>
420 </gpsml>
422 "Remove bad timestamps",
425 # }}}
426 is(file_data("chronofix.tmp"), # {{{
427 "gpst: \"2006-05-02T09:46:46Z\": Next date is 0:00:06:39 in the past (2006-05-02T09:40:07Z)\n",
428 "Warning from --chronology --fix");
429 unlink("chronofix.tmp") || warn("chronofix.tmp: Cannot delete file: $!\n");
431 # }}}
432 testcmd("../gpst -t pause.gpx", # {{{
433 <<END,
434 <?xml version="1.0" encoding="UTF-8"?>
435 <gpsml>
436 <track>
437 <title>ACTIVE LOG164705</title>
438 <tp> <time>2006-05-21T16:49:11Z</time> <lat>60.425494</lat> <lon>5.299534</lon> <ele>25.26</ele> </tp>
439 <tp> <time>2006-05-21T16:49:46Z</time> <lat>60.425464</lat> <lon>5.29961</lon> <ele>24.931</ele> </tp>
440 <pause>0:00:02:18</pause>
441 <tp> <time>2006-05-21T16:52:04Z</time> <lat>60.425314</lat> <lon>5.299694</lon> <ele>27.975</ele> </tp>
442 <pause>0:00:04:32</pause>
443 <tp> <time>2006-05-21T16:56:36Z</time> <lat>60.425384</lat> <lon>5.299741</lon> <ele>31.017</ele> </tp>
444 <tp> <time>2006-05-21T16:56:47Z</time> <lat>60.425339</lat> <lon>5.299958</lon> <ele>30.98</ele> </tp>
445 <tp> <time>2006-05-21T16:56:56Z</time> <lat>60.425238</lat> <lon>5.29964</lon> <ele>30.538</ele> </tp>
446 <tp> <time>2006-05-21T16:57:03Z</time> <lat>60.425246</lat> <lon>5.299686</lon> <ele>30.515</ele> </tp>
447 <pause>0:00:02:05</pause>
448 <tp> <time>2006-05-21T16:59:08Z</time> <lat>60.425345</lat> <lon>5.299773</lon> <ele>31.936</ele> </tp>
449 <tp> <time>2006-05-21T17:00:54Z</time> <lat>60.425457</lat> <lon>5.299419</lon> <ele>31.794</ele> </tp>
450 </track>
451 </gpsml>
453 "Output gpsml with <pause> elements from GPX files",
456 # }}}
457 testcmd("../gpst -o gpx no_signal.mayko", # {{{
458 <<END,
459 $gpx_header
460 <trk>
461 <trkseg>
462 <trkpt lat="70.6800486" lon="23.6746151"> <time>2002-12-22T21:42:24Z</time> </trkpt>
463 <trkpt lat="70.6799322" lon="23.6740038"> <time>2002-12-22T21:42:32Z</time> </trkpt>
464 <trkpt lat="70.6796266" lon="23.6723991"> <time>2002-12-22T21:42:54Z</time> </trkpt>
465 <trkpt lat="70.6796266" lon="23.6723991"> <time>2002-12-22T21:43:51Z</time> </trkpt>
466 <trkpt lat="70.6796266" lon="23.6723991"> <time>2002-12-22T21:43:52Z</time> </trkpt>
467 <trkpt lat="70.6796266" lon="23.6723991"> <time>2002-12-22T21:43:54Z</time> </trkpt>
468 <trkpt lat="70.6800774" lon="23.6757566"> <time>2002-12-22T21:44:45Z</time> </trkpt>
469 <trkpt lat="70.6801502" lon="23.6753442"> <time>2002-12-22T21:44:52Z</time> </trkpt>
470 <trkpt lat="70.6801905" lon="23.6757542"> <time>2002-12-22T21:45:04Z</time> </trkpt>
471 </trkseg>
472 </trk>
473 </gpx>
475 "Output GPX from Mayko file with duplicates",
478 # }}}
479 testcmd("../gpst -d no_signal.mayko", # {{{
480 <<END,
481 <?xml version="1.0" encoding="UTF-8"?>
482 <gpsml>
483 <track>
484 <tp> <time>2002-12-22T21:42:24Z</time> <lat>70.6800486</lat> <lon>23.6746151</lon> </tp>
485 <tp> <time>2002-12-22T21:42:32Z</time> <lat>70.6799322</lat> <lon>23.6740038</lon> </tp>
486 <tp> <time>2002-12-22T21:42:54Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </tp>
487 <etp err="dup"> <time>2002-12-22T21:43:51Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </etp>
488 <etp err="dup"> <time>2002-12-22T21:43:52Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </etp>
489 <etp err="dup"> <time>2002-12-22T21:43:54Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </etp>
490 <tp> <time>2002-12-22T21:44:45Z</time> <lat>70.6800774</lat> <lon>23.6757566</lon> </tp>
491 <tp> <time>2002-12-22T21:44:52Z</time> <lat>70.6801502</lat> <lon>23.6753442</lon> </tp>
492 <tp> <time>2002-12-22T21:45:04Z</time> <lat>70.6801905</lat> <lon>23.6757542</lon> </tp>
493 </track>
494 </gpsml>
496 "Remove duplicated positions",
499 # }}}
500 testcmd("../gpst --round lat=4,lon=5,ele=1 pause.gpx", # {{{
501 <<END,
502 <?xml version="1.0" encoding="UTF-8"?>
503 <gpsml>
504 <track>
505 <title>ACTIVE LOG164705</title>
506 <tp> <time>2006-05-21T16:49:11Z</time> <lat>60.4255</lat> <lon>5.29953</lon> <ele>25.3</ele> </tp>
507 <tp> <time>2006-05-21T16:49:46Z</time> <lat>60.4255</lat> <lon>5.29961</lon> <ele>24.9</ele> </tp>
508 <tp> <time>2006-05-21T16:52:04Z</time> <lat>60.4253</lat> <lon>5.29969</lon> <ele>28</ele> </tp>
509 <tp> <time>2006-05-21T16:56:36Z</time> <lat>60.4254</lat> <lon>5.29974</lon> <ele>31</ele> </tp>
510 <tp> <time>2006-05-21T16:56:47Z</time> <lat>60.4253</lat> <lon>5.29996</lon> <ele>31</ele> </tp>
511 <tp> <time>2006-05-21T16:56:56Z</time> <lat>60.4252</lat> <lon>5.29964</lon> <ele>30.5</ele> </tp>
512 <tp> <time>2006-05-21T16:57:03Z</time> <lat>60.4252</lat> <lon>5.29969</lon> <ele>30.5</ele> </tp>
513 <tp> <time>2006-05-21T16:59:08Z</time> <lat>60.4253</lat> <lon>5.29977</lon> <ele>31.9</ele> </tp>
514 <tp> <time>2006-05-21T17:00:54Z</time> <lat>60.4255</lat> <lon>5.29942</lon> <ele>31.8</ele> </tp>
515 </track>
516 </gpsml>
520 # }}}
521 testcmd("../gpst -u no_signal.mayko >nosignal.tmp", # {{{
523 "Redirect stdout",
526 # }}}
527 testcmd("../gpst -u no_signal.mayko", # {{{
528 <<END,
529 xmaplog 1.0 Mon Dec 23 02:00:50 2002
530 1 70.6800486 23.6746151 57.4 0 12/22/2002 21:42:24
531 1 70.6799322 23.6740038 6.3 0 12/22/2002 21:42:32
532 1 70.6796266 23.6723991 6.0 0 12/22/2002 21:42:54
533 # 20021222T214351-20021222T214354: CO: No signal \x7B\x7B\x7B
534 # 1 70.6796266 23.6723991 0.0 0 12/22/2002 21:43:51
535 # 1 70.6796266 23.6723991 0.0 0 12/22/2002 21:43:52
536 # 1 70.6796266 23.6723991 0.0 0 12/22/2002 21:43:54
537 # 20021222T214351-20021222T214354: CO: No signal \x7D\x7D\x7D
538 # move
539 1 70.6800774 23.6757566 5.1 0 12/22/2002 21:44:45
540 1 70.6801502 23.6753442 4.8 0 12/22/2002 21:44:52
541 1 70.6801905 23.6757542 2.5 0 12/22/2002 21:45:04
543 "Read Mayko format with no signal, output old Mayko format",
546 # }}}
547 testcmd("../gpst nosignal.tmp", # {{{
548 <<END,
549 <?xml version="1.0" encoding="UTF-8"?>
550 <gpsml>
551 <track>
552 <tp> <time>2002-12-22T21:42:24Z</time> <lat>70.6800486</lat> <lon>23.6746151</lon> </tp>
553 <tp> <time>2002-12-22T21:42:32Z</time> <lat>70.6799322</lat> <lon>23.6740038</lon> </tp>
554 <tp> <time>2002-12-22T21:42:54Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </tp>
555 <desc>20021222T214351-20021222T214354: CO: No signal \x7B\x7B\x7B</desc>
556 <etp err="desc"> <time>2002-12-22T21:43:51Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </etp>
557 <etp err="desc"> <time>2002-12-22T21:43:52Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </etp>
558 <etp err="desc"> <time>2002-12-22T21:43:54Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </etp>
559 <desc>20021222T214351-20021222T214354: CO: No signal \x7D\x7D\x7D</desc>
560 <break/>
561 <tp> <time>2002-12-22T21:44:45Z</time> <lat>70.6800774</lat> <lon>23.6757566</lon> </tp>
562 <tp> <time>2002-12-22T21:44:52Z</time> <lat>70.6801502</lat> <lon>23.6753442</lon> </tp>
563 <tp> <time>2002-12-22T21:45:04Z</time> <lat>70.6801905</lat> <lon>23.6757542</lon> </tp>
564 </track>
565 </gpsml>
567 "Read output from 'gpst -u *.mayko'",
570 # }}}
571 unlink("nosignal.tmp") || warn("nosignal.tmp: Cannot delete file: $!\n");
572 testcmd("../gpst log.mcsv", # {{{
573 <<END,
574 <?xml version="1.0" encoding="UTF-8"?>
575 <gpsml>
576 <track>
577 <break/>
578 <title>ACTIVE LOG 125</title>
579 <tp> <time>2006-03-04T11:12:30Z</time> <lat>54.96883</lat> <lon>-1.62439</lon> <ele>77</ele> </tp>
580 <tp> <time>2006-03-04T11:12:47Z</time> <lat>54.96878</lat> <lon>-1.62413</lon> <ele>77</ele> </tp>
581 <tp> <time>2006-03-04T11:12:55Z</time> <lat>54.96913</lat> <lon>-1.62616</lon> <ele>77</ele> </tp>
582 <tp> <time>2006-03-04T11:13:04Z</time> <lat>54.96934</lat> <lon>-1.62624</lon> <ele>77.5</ele> </tp>
583 <tp> <time>2006-03-04T11:13:33Z</time> <lat>54.96934</lat> <lon>-1.62596</lon> <ele>78</ele> </tp>
584 <tp> <time>2006-03-04T11:13:48Z</time> <lat>54.96931</lat> <lon>-1.62645</lon> <ele>78</ele> </tp>
585 <tp> <time>2006-03-04T11:14:05Z</time> <lat>54.96918</lat> <lon>-1.62603</lon> <ele>79</ele> </tp>
586 <tp> <time>2006-03-04T11:14:33Z</time> <lat>54.96901</lat> <lon>-1.62364</lon> <ele>76.1</ele> </tp>
587 <tp> <time>2006-03-04T11:15:02Z</time> <lat>54.96922</lat> <lon>-1.6254</lon> <ele>76.1</ele> </tp>
588 <tp> <time>2006-03-04T11:15:27Z</time> <lat>54.96914</lat> <lon>-1.62526</lon> <ele>75.1</ele> </tp>
589 <tp> <time>2006-03-04T11:15:50Z</time> <lat>54.96911</lat> <lon>-1.62494</lon> <ele>75.1</ele> </tp>
590 <tp> <time>2006-03-04T11:16:03Z</time> <lat>54.9693</lat> <lon>-1.62489</lon> <ele>75.1</ele> </tp>
591 <tp> <time>2006-03-04T11:16:19Z</time> <lat>54.96901</lat> <lon>-1.62496</lon> <ele>75.1</ele> </tp>
592 <tp> <time>2006-03-04T11:16:52Z</time> <lat>54.96871</lat> <lon>-1.62466</lon> <ele>74.6</ele> </tp>
593 <tp> <time>2006-03-04T11:17:25Z</time> <lat>54.96908</lat> <lon>-1.62488</lon> <ele>72.7</ele> </tp>
594 <break/>
595 <title>ACTIVE LOG 126</title>
596 <tp> <time>2006-03-04T11:18:32Z</time> <lat>54.96904</lat> <lon>-1.62482</lon> <ele>72.7</ele> </tp>
597 <tp> <time>2006-03-04T11:18:35Z</time> <lat>54.96913</lat> <lon>-1.62499</lon> <ele>71.3</ele> </tp>
598 <tp> <time>2006-03-04T11:18:38Z</time> <lat>54.96904</lat> <lon>-1.62497</lon> <ele>70.8</ele> </tp>
599 <tp> <time>2006-03-04T11:18:48Z</time> <lat>54.96913</lat> <lon>-1.62496</lon> <ele>71.8</ele> </tp>
600 <tp> <time>2006-03-04T11:18:55Z</time> <lat>54.96924</lat> <lon>-1.62501</lon> <ele>72.2</ele> </tp>
601 <tp> <time>2006-03-04T11:19:11Z</time> <lat>54.9694</lat> <lon>-1.62521</lon> <ele>71.8</ele> </tp>
602 <tp> <time>2006-03-04T11:19:30Z</time> <lat>54.96916</lat> <lon>-1.62515</lon> <ele>71.3</ele> </tp>
603 <tp> <time>2006-03-04T11:19:53Z</time> <lat>54.96921</lat> <lon>-1.625</lon> <ele>71.3</ele> </tp>
604 <tp> <time>2006-03-04T11:20:21Z</time> <lat>54.96801</lat> <lon>-1.62417</lon> <ele>71.8</ele> </tp>
605 <break/>
606 <title>ACTIVE LOG 127</title>
607 <tp> <time>2006-03-04T11:21:16Z</time> <lat>54.96887</lat> <lon>-1.62504</lon> <ele>70.8</ele> </tp>
608 <tp> <time>2006-03-04T11:21:18Z</time> <lat>54.96898</lat> <lon>-1.62476</lon> <ele>69.8</ele> </tp>
609 <tp> <time>2006-03-04T11:21:29Z</time> <lat>54.9691</lat> <lon>-1.62475</lon> <ele>69.4</ele> </tp>
610 <tp> <time>2006-03-04T11:21:46Z</time> <lat>54.96918</lat> <lon>-1.62468</lon> <ele>70.3</ele> </tp>
611 <tp> <time>2006-03-04T11:22:39Z</time> <lat>54.9692</lat> <lon>-1.62465</lon> <ele>69.4</ele> </tp>
612 <tp> <time>2006-03-04T11:22:43Z</time> <lat>54.96924</lat> <lon>-1.62462</lon> <ele>71.8</ele> </tp>
613 <tp> <time>2006-03-04T11:22:45Z</time> <lat>54.96928</lat> <lon>-1.62463</lon> <ele>71.8</ele> </tp>
614 <tp> <time>2006-03-04T11:23:00Z</time> <lat>54.96945</lat> <lon>-1.62466</lon> <ele>69.4</ele> </tp>
615 </track>
616 </gpsml>
618 "Read Mapsource TAB-separated format",
621 # }}}
622 testcmd("../gpst two-digit_year.mcsv", # {{{
623 <<END,
624 <?xml version="1.0" encoding="UTF-8"?>
625 <gpsml>
626 <track>
627 <break/>
628 <title>ACTIVE LOG 032</title>
629 <tp> <time>2006-03-20T20:35:33Z</time> <lat>60.41324</lat> <lon>5.33352</lon> <ele>14</ele> </tp>
630 <tp> <time>2006-03-20T20:35:38Z</time> <lat>60.38802</lat> <lon>5.33845</lon> <ele>18</ele> </tp>
631 <tp> <time>2006-03-20T20:35:44Z</time> <lat>60.38709</lat> <lon>5.3379</lon> <ele>19</ele> </tp>
632 <tp> <time>2006-03-20T20:35:49Z</time> <lat>60.38641</lat> <lon>5.33732</lon> <ele>18</ele> </tp>
633 <tp> <time>2006-03-20T20:35:54Z</time> <lat>60.38581</lat> <lon>5.33647</lon> <ele>18</ele> </tp>
634 <tp> <time>2006-03-20T20:36:00Z</time> <lat>60.38516</lat> <lon>5.33528</lon> <ele>15</ele> </tp>
635 <tp> <time>2006-03-20T20:36:02Z</time> <lat>60.38495</lat> <lon>5.3349</lon> <ele>13</ele> </tp>
636 </track>
637 </gpsml>
639 "Read Mapsource TAB-separated format with two-digit year",
642 # }}}
643 testcmd("../gpst log.gpstxt", # {{{
644 <<END,
645 <?xml version="1.0" encoding="UTF-8"?>
646 <gpsml>
647 <track>
648 <tp> <time>2003-06-13T14:36:09Z</time> <lat>59.521517</lat> <lon>7.391867</lon> <ele>762</ele> </tp>
649 <tp> <time>2003-06-13T14:36:10Z</time> <lat>59.5214</lat> <lon>7.392133</lon> <ele>762</ele> </tp>
650 <tp> <time>2003-06-13T14:36:11Z</time> <lat>59.5213</lat> <lon>7.392417</lon> <ele>761</ele> </tp>
651 <tp> <time>2003-06-13T14:36:12Z</time> <lat>59.521183</lat> <lon>7.3927</lon> <ele>761</ele> </tp>
652 <etp err="nosignal"> <time>2003-06-13T14:36:13Z</time> </etp>
653 <tp> <time>2003-06-13T14:36:15Z</time> <lat>59.52085</lat> <lon>7.393517</lon> <ele>760</ele> </tp>
654 <tp> <time>2003-06-13T14:36:16Z</time> <lat>59.520733</lat> <lon>7.393783</lon> <ele>760</ele> </tp>
655 <tp> <time>2003-06-13T14:36:17Z</time> <lat>59.52065</lat> <lon>7.39405</lon> <ele>760</ele> </tp>
656 <tp> <time>2003-06-13T14:36:18Z</time> <lat>59.520583</lat> <lon>7.394333</lon> <ele>760</ele> </tp>
657 <tp> <time>2003-06-13T14:36:19Z</time> <lat>59.520533</lat> <lon>7.394633</lon> <ele>759</ele> </tp>
658 <tp> <time>2003-06-13T14:36:20Z</time> <lat>59.520483</lat> <lon>7.394917</lon> <ele>759</ele> </tp>
659 <tp> <time>2003-06-13T14:36:21Z</time> <lat>59.520433</lat> <lon>7.395233</lon> <ele>759</ele> </tp>
660 <etp err="nosignal"> <time>2003-06-13T14:36:22Z</time> </etp>
661 <tp> <time>2003-06-13T14:36:24Z</time> <lat>59.520283</lat> <lon>7.396233</lon> <ele>758</ele> </tp>
662 <tp> <time>2003-06-13T14:36:25Z</time> <lat>59.520233</lat> <lon>7.39655</lon> <ele>758</ele> </tp>
663 <tp> <time>2003-06-13T14:36:26Z</time> <lat>59.520183</lat> <lon>7.396883</lon> <ele>757</ele> </tp>
664 <tp> <time>2003-06-13T14:36:27Z</time> <lat>59.520133</lat> <lon>7.397217</lon> <ele>757</ele> </tp>
665 <tp> <time>2003-06-13T14:36:28Z</time> <lat>59.5201</lat> <lon>7.397567</lon> <ele>757</ele> </tp>
666 </track>
667 </gpsml>
669 "Read Garmin serial text format",
672 # }}}
673 testcmd("../gpst log.dos.mayko", # {{{
674 <<END,
675 <?xml version="1.0" encoding="UTF-8"?>
676 <gpsml>
677 <track>
678 <tp> <time>2003-06-15T10:27:45Z</time> <lat>58.1818158</lat> <lon>8.1225077</lon> </tp>
679 <tp> <time>2003-06-15T10:27:53Z</time> <lat>58.1818712</lat> <lon>8.12532</lon> </tp>
680 <tp> <time>2003-06-15T10:27:57Z</time> <lat>58.1816347</lat> <lon>8.1266031</lon> </tp>
681 <tp> <time>2003-06-15T10:28:03Z</time> <lat>58.1812099</lat> <lon>8.1284612</lon> </tp>
682 <tp> <time>2003-06-15T10:28:06Z</time> <lat>58.1810315</lat> <lon>8.129395</lon> </tp>
683 <tp> <time>2003-06-15T10:28:10Z</time> <lat>58.1809621</lat> <lon>8.13074</lon> </tp>
684 </track>
685 </gpsml>
687 "Read DOS-formatted Mayko format",
690 # }}}
691 testcmd("../gpst log.dos.gpstxt", # {{{
692 <<END,
693 <?xml version="1.0" encoding="UTF-8"?>
694 <gpsml>
695 <track>
696 <tp> <time>2003-01-05T16:47:11Z</time> <lat>66.908167</lat> <lon>15.022983</lon> <ele>11472</ele> </tp>
697 <tp> <time>2003-01-05T16:47:12Z</time> <lat>66.90625</lat> <lon>15.020667</lon> <ele>11472</ele> </tp>
698 <tp> <time>2003-01-05T16:47:13Z</time> <lat>66.904317</lat> <lon>15.01835</lon> <ele>11472</ele> </tp>
699 <tp> <time>2003-01-05T16:47:14Z</time> <lat>66.9024</lat> <lon>15.016017</lon> <ele>11473</ele> </tp>
700 <tp> <time>2003-01-05T16:47:15Z</time> <lat>66.900483</lat> <lon>15.0137</lon> <ele>11474</ele> </tp>
701 <tp> <time>2003-01-05T16:47:16Z</time> <lat>66.898567</lat> <lon>15.011383</lon> <ele>11474</ele> </tp>
702 <tp> <time>2003-01-05T16:47:17Z</time> <lat>66.896633</lat> <lon>15.009067</lon> <ele>11475</ele> </tp>
703 <tp> <time>2003-01-05T16:47:18Z</time> <lat>66.894717</lat> <lon>15.006733</lon> <ele>11475</ele> </tp>
704 <tp> <time>2003-01-05T16:47:19Z</time> <lat>66.8928</lat> <lon>15.004417</lon> <ele>11475</ele> </tp>
705 <tp> <time>2003-01-05T16:47:20Z</time> <lat>66.890867</lat> <lon>15.0021</lon> <ele>11475</ele> </tp>
706 <tp> <time>2003-01-05T16:47:21Z</time> <lat>66.88895</lat> <lon>14.999783</lon> <ele>11475</ele> </tp>
707 </track>
708 </gpsml>
710 "Read DOS-formatted Garmin serial text format",
713 # }}}
714 testcmd("../gpst log.unix.mcsv", # {{{
715 <<END,
716 <?xml version="1.0" encoding="UTF-8"?>
717 <gpsml>
718 <track>
719 <break/>
720 <title>ACTIVE LOG 058</title>
721 <tp> <time>2006-02-21T15:14:25Z</time> <lat>60.36662</lat> <lon>5.24885</lon> <ele>31.9</ele> </tp>
722 <tp> <time>2006-02-21T15:14:30Z</time> <lat>60.37057</lat> <lon>5.22956</lon> <ele>35.2</ele> </tp>
723 <tp> <time>2006-02-21T15:14:35Z</time> <lat>60.37019</lat> <lon>5.22817</lon> <ele>39.6</ele> </tp>
724 <tp> <time>2006-02-21T15:14:36Z</time> <lat>60.37012</lat> <lon>5.2279</lon> <ele>41</ele> </tp>
725 <tp> <time>2006-02-21T15:14:40Z</time> <lat>60.37009</lat> <lon>5.22682</lon> <ele>47.2</ele> </tp>
726 <tp> <time>2006-02-21T15:14:42Z</time> <lat>60.37011</lat> <lon>5.22641</lon> <ele>49.2</ele> </tp>
727 <tp> <time>2006-02-21T15:14:44Z</time> <lat>60.37011</lat> <lon>5.22607</lon> <ele>50.1</ele> </tp>
728 <tp> <time>2006-02-21T15:14:48Z</time> <lat>60.37002</lat> <lon>5.22568</lon> <ele>51.1</ele> </tp>
729 <tp> <time>2006-02-21T15:14:51Z</time> <lat>60.3701</lat> <lon>5.22548</lon> <ele>52.5</ele> </tp>
730 </track>
731 </gpsml>
733 "Read UNIX-formatted Garmin Mapsource TAB-separated format",
736 # }}}
737 testcmd("../gpst multitrack.gpx", # {{{
738 <<END,
739 <?xml version="1.0" encoding="UTF-8"?>
740 <gpsml>
741 <track>
742 <title>Track 1</title>
743 <tp> <time>2003-02-11T23:35:39Z</time> <lat>51.4968266</lat> <lon>-0.1448824</lon> </tp>
744 <tp> <time>2003-02-11T23:35:49Z</time> <lat>51.4968227</lat> <lon>-0.1449938</lon> </tp>
745 <tp> <time>2003-02-11T23:36:14Z</time> <lat>51.496904</lat> <lon>-0.1453202</lon> </tp>
746 <break/>
747 <title>Track 2</title>
748 <tp> <time>2003-02-11T23:36:16Z</time> <lat>51.4969214</lat> <lon>-0.1453398</lon> </tp>
749 <tp> <time>2003-02-11T23:36:31Z</time> <lat>51.4969816</lat> <lon>-0.1455514</lon> </tp>
750 <tp> <time>2003-02-11T23:36:43Z</time> <lat>51.4970224</lat> <lon>-0.1457489</lon> <ele>1000</ele> </tp>
751 <tp> <time>2003-02-11T23:36:50Z</time> <lat>51.4970452</lat> <lon>-0.1457804</lon> </tp>
752 <break/>
753 <title>Track 3</title>
754 <tp> <time>2003-02-11T23:37:05Z</time> <lat>51.497068</lat> <lon>-0.1458608</lon> </tp>
755 <tp> <time>2003-02-11T23:37:22Z</time> <lat>51.4971658</lat> <lon>-0.1460047</lon> </tp>
756 <tp> <time>2003-02-11T23:37:36Z</time> <lat>51.4972469</lat> <lon>-0.1461614</lon> </tp>
757 <break/>
758 <title>Track 4</title>
759 <tp> <time>2003-02-11T23:37:43Z</time> <lat>51.4972731</lat> <lon>-0.1462394</lon> </tp>
760 <tp> <time>2003-02-11T23:38:04Z</time> <lat>51.4973437</lat> <lon>-0.1463232</lon> </tp>
761 <tp> <time>2003-02-11T23:38:28Z</time> <lat>51.4973337</lat> <lon>-0.1462949</lon> </tp>
762 <tp> <time>2003-02-11T23:38:34Z</time> <lat>51.4973218</lat> <lon>-0.1462825</lon> </tp>
763 <tp> <time>2003-02-11T23:38:35Z</time> <lat>51.4973145</lat> <lon>-0.1462732</lon> </tp>
764 </track>
765 </gpsml>
767 "Read GPX file with multiple tracks",
770 # }}}
771 testcmd("../gpst compact.gpx", # {{{
772 <<END,
773 <?xml version="1.0" encoding="UTF-8"?>
774 <gpsml>
775 <track>
776 <title>All whitespace stripped</title>
777 <tp> <time>2002-12-30T15:22:04Z</time> <lat>70.660932</lat> <lon>23.7028354</lon> </tp>
778 <tp> <time>2002-12-30T15:22:06Z</time> <lat>70.6609392</lat> <lon>23.7028468</lon> </tp>
779 <tp> <time>2002-12-30T15:22:08Z</time> <lat>70.6609429</lat> <lon>23.7028499</lon> </tp>
780 <tp> <time>2002-12-30T15:22:11Z</time> <lat>70.6609381</lat> <lon>23.702862</lon> </tp>
781 <tp> <time>2002-12-30T15:22:12Z</time> <lat>70.6609368</lat> <lon>23.7028648</lon> </tp>
782 <tp> <time>2002-12-30T15:22:13Z</time> <lat>70.6609344</lat> <lon>23.7028652</lon> </tp>
783 <tp> <time>2002-12-30T15:22:15Z</time> <lat>70.6609349</lat> <lon>23.7028707</lon> </tp>
784 <tp> <time>2002-12-30T15:22:17Z</time> <lat>70.6609348</lat> <lon>23.7028654</lon> </tp>
785 <tp> <time>2002-12-30T15:22:19Z</time> <lat>70.6609347</lat> <lon>23.7028599</lon> </tp>
786 <tp> <time>2002-12-30T15:22:20Z</time> <lat>70.6609348</lat> <lon>23.7028609</lon> </tp>
787 <tp> <time>2002-12-30T15:22:23Z</time> <lat>70.6609388</lat> <lon>23.7028653</lon> </tp>
788 <tp> <time>2002-12-30T15:22:25Z</time> <lat>70.6609426</lat> <lon>23.7028732</lon> </tp>
789 </track>
790 </gpsml>
792 "Read GPX one-liner",
795 # }}}
796 testcmd("../gpst -re multitrack.gpx", # {{{
797 <<END,
798 <?xml version="1.0" encoding="UTF-8"?>
799 <gpsml>
800 <track>
801 <title>Track 1</title>
802 <break/>
803 <title>Track 2</title>
804 <tp> <time>2003-02-11T23:36:43Z</time> <lat>51.4970224</lat> <lon>-0.1457489</lon> <ele>1000</ele> </tp>
805 <break/>
806 <title>Track 3</title>
807 <break/>
808 <title>Track 4</title>
809 </track>
810 </gpsml>
812 "Require elevation from GPX data",
815 # }}}
816 testcmd("../gpst -re one_ele.dos.gpsml", # {{{
817 <<END,
818 <?xml version="1.0" encoding="UTF-8"?>
819 <gpsml>
820 <track>
821 <title>Only one point has elevation</title>
822 <tp> <time>2006-05-21T16:52:04Z</time> <lat>60.425314</lat> <lon>5.299694</lon> <ele>27.975</ele> </tp>
823 </track>
824 </gpsml>
826 "Require elevation from gpsml",
829 # }}}
830 testcmd("../gpst missing.gpsml", # {{{
831 <<END,
832 <?xml version="1.0" encoding="UTF-8"?>
833 <gpsml>
834 <track>
835 <title>Missing various elements</title>
836 <tp> <time>2006-04-30T17:16:59Z</time> </tp>
837 <tp> <time>2006-04-30T17:17:00Z</time> </tp>
838 <tp> <time>2006-04-30T17:17:09Z</time> <lat>60.42353</lat> <lon>5.34185</lon> </tp>
839 <tp> <time>2006-04-30T17:17:11Z</time> <ele>483</ele> </tp>
840 <tp> <time>2006-04-30T17:17:22Z</time> <ele>485</ele> </tp>
841 <tp> <lat>60.42347</lat> <lon>5.34212</lon> <ele>486</ele> </tp>
842 <tp> <ele>484</ele> </tp>
843 <tp> <ele>486</ele> </tp>
844 <tp> <desc>Missing everything</desc> </tp>
845 <tp> <time>2006-04-30T17:18:03Z</time> <ele>490</ele> </tp>
846 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
847 </track>
848 </gpsml>
850 "Read gpsml with various data missing",
853 # }}}
854 my $stripped_gpx_header = $gpx_header;
855 $stripped_gpx_header =~ s/^\s*(.*)$/$1/mg;
856 testcmd("../gpst -w -o gpx pause.gpx", # {{{
857 <<END,
858 $stripped_gpx_header
859 <trk>
860 <trkseg>
861 <trkpt lat="60.425494" lon="5.299534"><ele>25.260</ele><time>2006-05-21T16:49:11Z</time></trkpt>
862 <trkpt lat="60.425464" lon="5.299610"><ele>24.931</ele><time>2006-05-21T16:49:46Z</time></trkpt>
863 <trkpt lat="60.425314" lon="5.299694"><ele>27.975</ele><time>2006-05-21T16:52:04Z</time></trkpt>
864 <trkpt lat="60.425384" lon="5.299741"><ele>31.017</ele><time>2006-05-21T16:56:36Z</time></trkpt>
865 <trkpt lat="60.425339" lon="5.299958"><ele>30.980</ele><time>2006-05-21T16:56:47Z</time></trkpt>
866 <trkpt lat="60.425238" lon="5.299640"><ele>30.538</ele><time>2006-05-21T16:56:56Z</time></trkpt>
867 <trkpt lat="60.425246" lon="5.299686"><ele>30.515</ele><time>2006-05-21T16:57:03Z</time></trkpt>
868 <trkpt lat="60.425345" lon="5.299773"><ele>31.936</ele><time>2006-05-21T16:59:08Z</time></trkpt>
869 <trkpt lat="60.425457" lon="5.299419"><ele>31.794</ele><time>2006-05-21T17:00:54Z</time></trkpt>
870 </trkseg>
871 </trk>
872 </gpx>
874 "Strip whitespace from GPX output",
877 # }}}
879 TODO: {
880 local $TODO = "Shall lat/lon be cleared if one is missing?";
881 testcmd("../gpst -re missing.gpsml", # {{{
882 <<END,
883 <?xml version="1.0" encoding="UTF-8"?>
884 <gpsml>
885 <track>
886 <title>Missing various elements</title>
887 <tp> <time>2006-04-30T17:17:11Z</time> <ele>483</ele> </tp>
888 <tp> <time>2006-04-30T17:17:22Z</time> <ele>485</ele> </tp>
889 <tp> <lat>60.42347</lat> <lon>5.34212</lon> <ele>486</ele> </tp>
890 <tp> <ele>484</ele> </tp>
891 <tp> <ele>486</ele> </tp>
892 <tp> <time>2006-04-30T17:18:03Z</time> <ele>490</ele> </tp>
893 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
894 </track>
895 </gpsml>
897 "Require elevation",
900 # }}}
901 testcmd("../gpst -rt missing.gpsml", # {{{
902 <<END,
903 <?xml version="1.0" encoding="UTF-8"?>
904 <gpsml>
905 <track>
906 <title>Missing various elements</title>
907 <tp> <time>2006-04-30T17:16:59Z</time> </tp>
908 <tp> <time>2006-04-30T17:17:00Z</time> </tp>
909 <tp> <time>2006-04-30T17:17:09Z</time> <lat>60.42353</lat> <lon>5.34185</lon> </tp>
910 <tp> <time>2006-04-30T17:17:11Z</time> <ele>483</ele> </tp>
911 <tp> <time>2006-04-30T17:17:22Z</time> <ele>485</ele> </tp>
912 <tp> <time>2006-04-30T17:18:03Z</time> <ele>490</ele> </tp>
913 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
914 </track>
915 </gpsml>
917 "Require time",
920 # }}}
921 testcmd("../gpst -rp missing.gpsml", # {{{
922 <<END,
923 <?xml version="1.0" encoding="UTF-8"?>
924 <gpsml>
925 <track>
926 <title>Missing various elements</title>
927 <tp> <time>2006-04-30T17:17:09Z</time> <lat>60.42353</lat> <lon>5.34185</lon> </tp>
928 <tp> <lat>60.42347</lat> <lon>5.34212</lon> <ele>486</ele> </tp>
929 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
930 </track>
931 </gpsml>
933 "Require position",
936 # }}}
937 testcmd("../gpst -ret missing.gpsml", # {{{
938 <<END,
939 <?xml version="1.0" encoding="UTF-8"?>
940 <gpsml>
941 <track>
942 <title>Missing various elements</title>
943 <tp> <time>2006-04-30T17:17:11Z</time> <ele>483</ele> </tp>
944 <tp> <time>2006-04-30T17:17:22Z</time> <ele>485</ele> </tp>
945 <tp> <time>2006-04-30T17:18:03Z</time> <ele>490</ele> </tp>
946 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
947 </track>
948 </gpsml>
950 "Require elevation and time",
953 # }}}
954 testcmd("../gpst -retp missing.gpsml", # {{{
955 <<END,
956 <?xml version="1.0" encoding="UTF-8"?>
957 <gpsml>
958 <track>
959 <title>Missing various elements</title>
960 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
961 </track>
962 </gpsml>
964 "Require elevation, time and position",
967 # }}}
968 testcmd("../gpst -rep missing.gpsml", # {{{
969 <<END,
970 <?xml version="1.0" encoding="UTF-8"?>
971 <gpsml>
972 <track>
973 <title>Missing various elements</title>
974 <tp> <lat>60.42347</lat> <lon>5.34212</lon> <ele>486</ele> </tp>
975 <tp> <time>2006-04-30T17:18:05Z</time> <lat>60.42338</lat> <lon>5.34269</lon> <ele>487</ele> </tp>
976 </track>
977 </gpsml>
979 "Require elevation and position",
982 # }}}
985 testcmd("../gpst -o gpx missing.gpsml", # {{{
986 <<END,
987 $gpx_header
988 <trk>
989 <trkseg>
990 <trkpt lat="60.42353" lon="5.34185"> <time>2006-04-30T17:17:09Z</time> </trkpt>
991 <trkpt> <ele>483</ele> <time>2006-04-30T17:17:11Z</time> </trkpt>
992 <trkpt> <ele>485</ele> <time>2006-04-30T17:17:22Z</time> </trkpt>
993 <trkpt lat="60.42347" lon="5.34212"> <ele>486</ele> </trkpt>
994 <trkpt> <ele>484</ele> </trkpt>
995 <trkpt> <ele>486</ele> </trkpt>
996 <trkpt> <ele>490</ele> <time>2006-04-30T17:18:03Z</time> </trkpt>
997 <trkpt lat="60.42338" lon="5.34269"> <ele>487</ele> <time>2006-04-30T17:18:05Z</time> </trkpt>
998 </trkseg>
999 </trk>
1000 </gpx>
1002 "Output GPX from gpsml with missing data",
1005 # }}}
1006 testcmd("echo '<tp> </tp>' | ../gpst", # {{{
1007 <<END,
1008 <?xml version="1.0" encoding="UTF-8"?>
1009 <gpsml>
1010 <track>
1011 </track>
1012 </gpsml>
1014 "Don’t print empty trackpoints");
1016 # }}}
1017 testcmd("../gpst --epoch pause.gpx", # {{{
1018 <<END,
1019 <?xml version="1.0" encoding="UTF-8"?>
1020 <gpsml>
1021 <track>
1022 <title>ACTIVE LOG164705</title>
1023 <tp> <time>2006-05-21T16:49:11Z</time> <lat>60.425494</lat> <lon>5.299534</lon> <ele>25.26</ele> </tp>
1024 <tp> <time>2006-05-21T16:49:46Z</time> <lat>60.425464</lat> <lon>5.29961</lon> <ele>24.931</ele> </tp>
1025 <tp> <time>2006-05-21T16:52:04Z</time> <lat>60.425314</lat> <lon>5.299694</lon> <ele>27.975</ele> </tp>
1026 <tp> <time>2006-05-21T16:56:36Z</time> <lat>60.425384</lat> <lon>5.299741</lon> <ele>31.017</ele> </tp>
1027 <tp> <time>2006-05-21T16:56:47Z</time> <lat>60.425339</lat> <lon>5.299958</lon> <ele>30.98</ele> </tp>
1028 <tp> <time>2006-05-21T16:56:56Z</time> <lat>60.425238</lat> <lon>5.29964</lon> <ele>30.538</ele> </tp>
1029 <tp> <time>2006-05-21T16:57:03Z</time> <lat>60.425246</lat> <lon>5.299686</lon> <ele>30.515</ele> </tp>
1030 <tp> <time>2006-05-21T16:59:08Z</time> <lat>60.425345</lat> <lon>5.299773</lon> <ele>31.936</ele> </tp>
1031 <tp> <time>2006-05-21T17:00:54Z</time> <lat>60.425457</lat> <lon>5.299419</lon> <ele>31.794</ele> </tp>
1032 </track>
1033 </gpsml>
1035 "--epoch is ignored in gpsml output",
1038 # }}}
1039 testcmd("../gpst --epoch -o gpx pause.gpx", # {{{
1040 <<END,
1041 $gpx_header
1042 <trk>
1043 <trkseg>
1044 <trkpt lat="60.425494" lon="5.299534"> <ele>25.260</ele> <time>2006-05-21T16:49:11Z</time> </trkpt>
1045 <trkpt lat="60.425464" lon="5.299610"> <ele>24.931</ele> <time>2006-05-21T16:49:46Z</time> </trkpt>
1046 <trkpt lat="60.425314" lon="5.299694"> <ele>27.975</ele> <time>2006-05-21T16:52:04Z</time> </trkpt>
1047 <trkpt lat="60.425384" lon="5.299741"> <ele>31.017</ele> <time>2006-05-21T16:56:36Z</time> </trkpt>
1048 <trkpt lat="60.425339" lon="5.299958"> <ele>30.980</ele> <time>2006-05-21T16:56:47Z</time> </trkpt>
1049 <trkpt lat="60.425238" lon="5.299640"> <ele>30.538</ele> <time>2006-05-21T16:56:56Z</time> </trkpt>
1050 <trkpt lat="60.425246" lon="5.299686"> <ele>30.515</ele> <time>2006-05-21T16:57:03Z</time> </trkpt>
1051 <trkpt lat="60.425345" lon="5.299773"> <ele>31.936</ele> <time>2006-05-21T16:59:08Z</time> </trkpt>
1052 <trkpt lat="60.425457" lon="5.299419"> <ele>31.794</ele> <time>2006-05-21T17:00:54Z</time> </trkpt>
1053 </trkseg>
1054 </trk>
1055 </gpx>
1057 "--epoch is ignored in gpx output",
1060 # }}}
1062 testcmd("../gpst multitrack-pause.gpx", # {{{
1063 file_data("multitrack-pause.gpsml"),
1064 "Should be equal to multitrack-pause.gpsml"
1067 # }}}
1068 testcmd("../gpst -t multitrack-pause.gpx", # {{{
1069 <<END,
1070 <?xml version="1.0" encoding="UTF-8"?>
1071 <gpsml>
1072 <track>
1073 <title>track1</title>
1074 <tp> <time>2006-01-01T00:00:00Z</time> <lat>1</lat> <lon>1</lon> </tp>
1075 <tp> <time>2006-01-01T00:00:01Z</time> <lat>2</lat> <lon>2</lon> </tp>
1076 <tp> <time>2006-01-01T00:00:02Z</time> <lat>3</lat> <lon>3</lon> </tp>
1077 <break/>
1078 <title>track2</title>
1079 <pause>0:23:59:58</pause>
1080 <tp> <time>2006-01-02T00:00:00Z</time> <lat>1</lat> <lon>1</lon> </tp>
1081 <tp> <time>2006-01-02T00:00:04Z</time> <lat>2</lat> <lon>2</lon> </tp>
1082 <tp> <time>2006-01-02T00:00:16Z</time> <lat>3</lat> <lon>3</lon> </tp>
1083 <pause>0:01:00:00</pause>
1084 <tp> <time>2006-01-02T01:00:16Z</time> <lat>4</lat> <lon>4</lon> </tp>
1085 <break/>
1086 <title>track3</title>
1087 <pause>1:01:00:04</pause>
1088 <tp> <time>2006-01-03T02:00:20Z</time> <lat>5</lat> <lon>5</lon> </tp>
1089 </track>
1090 </gpsml>
1092 "Insert <pause> between gpx tracks"
1095 # }}}
1096 testcmd("../gpst -t multitrack-pause.gpsml", # {{{
1097 <<END,
1098 <?xml version="1.0" encoding="UTF-8"?>
1099 <gpsml>
1100 <track>
1101 <title>track1</title>
1102 <tp> <time>2006-01-01T00:00:00Z</time> <lat>1</lat> <lon>1</lon> </tp>
1103 <tp> <time>2006-01-01T00:00:01Z</time> <lat>2</lat> <lon>2</lon> </tp>
1104 <tp> <time>2006-01-01T00:00:02Z</time> <lat>3</lat> <lon>3</lon> </tp>
1105 <break/>
1106 <title>track2</title>
1107 <pause>0:23:59:58</pause>
1108 <tp> <time>2006-01-02T00:00:00Z</time> <lat>1</lat> <lon>1</lon> </tp>
1109 <tp> <time>2006-01-02T00:00:04Z</time> <lat>2</lat> <lon>2</lon> </tp>
1110 <tp> <time>2006-01-02T00:00:16Z</time> <lat>3</lat> <lon>3</lon> </tp>
1111 <pause>0:01:00:00</pause>
1112 <tp> <time>2006-01-02T01:00:16Z</time> <lat>4</lat> <lon>4</lon> </tp>
1113 <break/>
1114 <title>track3</title>
1115 <pause>1:01:00:04</pause>
1116 <tp> <time>2006-01-03T02:00:20Z</time> <lat>5</lat> <lon>5</lon> </tp>
1117 </track>
1118 </gpsml>
1120 "Insert <pause> between gpsml titles"
1123 # }}}
1125 todo_section:
1128 if ($Opt{'all'} || $Opt{'todo'}) {
1129 diag("Running TODO tests...");
1131 TODO: {
1132 local $TODO = "Remove extra \\n in the beginning";
1133 testcmd("../gpst -t -o clean pause.gpx", # {{{
1134 <<END,
1135 5.299534\t60.425494\t25.260
1136 5.299610\t60.425464\t24.931
1138 5.299694\t60.425314\t27.975
1140 5.299741\t60.425384\t31.017
1141 5.299958\t60.425339\t30.980
1142 5.299640\t60.425238\t30.538
1143 5.299686\t60.425246\t30.515
1145 5.299773\t60.425345\t31.936
1146 5.299419\t60.425457\t31.794
1148 "Output clean format with time breaks"
1150 # }}}
1151 testcmd("../gpst -o csv pause.gpx", # {{{
1152 <<END,
1153 2006-05-21 16:49:11\t5.299534\t60.425494\t25.260\t
1154 2006-05-21 16:49:46\t5.299610\t60.425464\t24.931\t
1155 2006-05-21 16:52:04\t5.299694\t60.425314\t27.975\t
1156 2006-05-21 16:56:36\t5.299741\t60.425384\t31.017\t
1157 2006-05-21 16:56:47\t5.299958\t60.425339\t30.980\t
1158 2006-05-21 16:56:56\t5.299640\t60.425238\t30.538\t
1159 2006-05-21 16:57:03\t5.299686\t60.425246\t30.515\t
1160 2006-05-21 16:59:08\t5.299773\t60.425345\t31.936\t
1161 2006-05-21 17:00:54\t5.299419\t60.425457\t31.794\t
1163 "csv format from gpx",
1166 # }}}
1167 testcmd("../gpst --epoch -o csv pause.gpx", # {{{
1168 <<END,
1169 1148230151\t5.299534\t60.425494\t25.260\t
1170 1148230186\t5.299610\t60.425464\t24.931\t
1171 1148230324\t5.299694\t60.425314\t27.975\t
1172 1148230596\t5.299741\t60.425384\t31.017\t
1173 1148230607\t5.299958\t60.425339\t30.980\t
1174 1148230616\t5.299640\t60.425238\t30.538\t
1175 1148230623\t5.299686\t60.425246\t30.515\t
1176 1148230748\t5.299773\t60.425345\t31.936\t
1177 1148230854\t5.299419\t60.425457\t31.794\t
1179 "csv format with epoch seconds from gpx",
1182 # }}}
1183 $TODO = "Use gpsml, this Mayko thing is obsolete.";
1184 testcmd("../gpst -u no_signal.mayko", # {{{
1185 <<END,
1186 <?xml version="1.0" encoding="UTF-8"?>
1187 <gpsml>
1188 <track>
1189 <tp> <time>2002-12-22T21:42:24Z</time> <lat>70.6800486</lat> <lon>23.6746151</lon> </tp>
1190 <tp> <time>2002-12-22T21:42:32Z</time> <lat>70.6799322</lat> <lon>23.6740038</lon> </tp>
1191 <tp> <time>2002-12-22T21:42:54Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </tp>
1192 <desc>20021222T214351-20021222T214354: CO: No signal \x7B\x7B\x7B</desc>
1193 <etp err="nosignal"> <time>2002-12-22T21:43:51Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </etp>
1194 <etp err="nosignal"> <time>2002-12-22T21:43:52Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </etp>
1195 <etp err="nosignal"> <time>2002-12-22T21:43:54Z</time> <lat>70.6796266</lat> <lon>23.6723991</lon> </etp>
1196 <desc>20021222T214351-20021222T214354: CO: No signal \x7D\x7D\x7D</desc>
1197 <break/>
1198 <tp> <time>2002-12-22T21:44:45Z</time> <lat>70.6800774</lat> <lon>23.6757566</lon> </tp>
1199 <tp> <time>2002-12-22T21:44:52Z</time> <lat>70.6801502</lat> <lon>23.6753442</lon> </tp>
1200 <tp> <time>2002-12-22T21:45:04Z</time> <lat>70.6801905</lat> <lon>23.6757542</lon> </tp>
1201 </track>
1202 </gpsml>
1204 "Output gpsml from the -u option",
1206 # }}}
1207 $TODO = "Tweak output";
1208 testcmd("../gpst -o gpx multitrack-pause.gpsml", # {{{
1209 file_data("multitrack-pause.gpx"),
1210 "Should be equal to multitrack-pause.gpx"
1213 # }}}
1217 diag("Testing finished.");
1219 sub testcmd {
1220 # {{{
1221 my ($Cmd, $Exp, $Desc) = @_;
1222 my $Txt = join("",
1223 "\"$Cmd\"",
1224 defined($Desc)
1225 ? " - $Desc"
1226 : ""
1229 is(`$Cmd`, $Exp, $Txt);
1230 # }}}
1233 sub file_data {
1234 # Return file content as a string {{{
1235 my $File = shift;
1236 my $Txt;
1237 if (open(FP, "<", $File)) {
1238 $Txt = join("", <FP>);
1239 close(FP);
1240 return($Txt);
1241 } else {
1242 return undef;
1244 # }}}
1247 sub print_version {
1248 # Print program version {{{
1249 print("$rcs_id\n");
1250 exit(0);
1251 # }}}
1252 } # print_version()
1254 sub usage {
1255 # Send the help message to stdout {{{
1256 my $Retval = shift;
1258 print(<<END);
1260 $rcs_id
1262 Usage: $progname [options] [file [files [...]]]
1264 Contains tests for the gpst(1) program.
1266 Options:
1268 -a, --all
1269 Run all tests, also TODOs.
1270 -h, --help
1271 Show this help.
1272 -t, --todo
1273 Run only the TODO tests.
1274 --version
1275 Print version information.
1276 --debug
1277 Print debugging messages.
1280 exit($Retval);
1281 # }}}
1282 } # usage()
1284 __END__
1286 # Plain Old Documentation (POD) {{{
1288 =pod
1290 =head1 NAME
1294 =head1 REVISION
1296 $Id$
1298 =head1 SYNOPSIS
1300 [options] [file [files [...]]]
1302 =head1 DESCRIPTION
1306 =head1 OPTIONS
1308 =over 4
1310 =item B<-a>, B<--all>
1312 Run all tests, also TODOs.
1314 =item B<-h>, B<--help>
1316 Print a brief help summary.
1318 =item B<-t>, B<--todo>
1320 Run only the TODO tests.
1322 =item B<--version>
1324 Print version information.
1326 =item B<--debug>
1328 Print debugging messages.
1330 =back
1332 =head1 BUGS
1336 =head1 AUTHOR
1338 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
1340 =head1 COPYRIGHT
1342 Copyleft © Øyvind A. Holm &lt;sunny@sunbase.org&gt;
1343 This is free software; see the file F<COPYING> for legalese stuff.
1345 =head1 LICENCE
1347 This program is free software; you can redistribute it and/or modify it
1348 under the terms of the GNU General Public License as published by the
1349 Free Software Foundation; either version 2 of the License, or (at your
1350 option) any later version.
1352 This program is distributed in the hope that it will be useful, but
1353 WITHOUT ANY WARRANTY; without even the implied warranty of
1354 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1355 See the GNU General Public License for more details.
1357 You should have received a copy of the GNU General Public License along
1358 with this program; if not, write to the Free Software Foundation, Inc.,
1359 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1361 =head1 SEE ALSO
1363 =cut
1365 # }}}
1367 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
1368 # End of file $Id$