source: src/webapp/webservice/tests/NmeaTest.php@ 3c9166b

debian/bullseye
Last change on this file since 3c9166b was 26f77a6, checked in by Joachim Langenbach <joachim.langenbach@…>, 9 years ago
  • Fixed wrong nmea 0183 position formats. They are now (d: degrees, m: minutes):
    • Latitude: ddmm.mmmm
    • Longitude: dddmm.mmmm
  • Added checkums-fix to gnuboat-log-converter to fix checksums of nmea sentences during conversion, if needed
  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[86442cb]1<?php
2/*
3 Copyright (C) 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19// enable in php 7
20// declare(Strict_types=1);
21
[008bce9]22namespace GnuBoat\Nmea
[86442cb]23{
24
25 /**
[008bce9]26 * @brief Covers Parser.php
27 */
28 final class NmeaTest extends \PHPUnit_Framework_TestCase
[86442cb]29 {
[008bce9]30 /**
31 * @dataProvider formatsProvider
32 */
33 public function testFormats($format)
34 {
35 $parser = new Parser(0);
36 $formats = $parser->formatsSupported();
37 $this->assertInternalType('array', $formats);
38 $this->assertContains($format, $formats);
39 }
40
41 public function formatsProvider()
42 {
43 return [["0183"]];
44 }
45
46 /**
47 * @dataProvider nmeaSentenceProvider
48 */
49 public function testNmeaSentence($format, $sentence, $classType, $valid)
50 {
51 $parser = new Parser(0);
52 $sentence = $parser->parseSentence($sentence, $format);
53 if($classType == null)
54 $this->assertNull($sentence);
55 else{
56 $this->assertInstanceOf($classType, $sentence);
57 $message = "";
58 $result = $sentence->valid($message);
59 $this->assertEquals($valid, $result, $message);
60 }
61 }
62
63 public function nmeaSentenceProvider()
64 {
65 return [
66 "empty" => ['0183', '', null, false],
67 "unsupported_format" => ['abc', '', null, false],
[26f77a6]68 "rmc0183" => ['0183', '$GNRMC,122548,A,4735.4480,N,01042.6240,E,00.0,115.6,110917,,,A*50', Nmea0183\Nmea0183Rmc::class, true],
[008bce9]69 "dpt0183" => ['0183', '$SDDPT,00.71,00.00*51', Nmea0183\Nmea0183Dpt::class, true],
70 "mtw0183" => ['0183', '$YXMTW,26.3,C*15', Nmea0183\Nmea0183Mtw::class, true],
[26f77a6]71 "rmc0183timestamp" => ['0183', '2017-09-11 13:20:42: $GNRMC,122548,A,4735.4480,N,01042.6240,E,00.0,115.6,110917,,,A*50', Nmea0183\Nmea0183Rmc::class, true],
[008bce9]72 ];
73 }
74
75 /**
76 * @dataProvider nmeaFileProvider
77 */
78 public function testNmeaFile($file, $format, $count)
79 {
80 $parser = new Parser(0);
81 $sentences = $parser->parseFile($file, $format);
82 $this->assertInternalType('array', $sentences);
83 $this->assertCount($count, $sentences);
84 foreach($sentences as $sentence){
85 $this->assertNotNull($sentence);
86 $this->assertInstanceOf(NmeaSentence::class, $sentence);
87 $this->assertEquals(true, $sentence->valid());
88 }
89 }
90
91 public function nmeaFileProvider()
92 {
[a50c18f]93 return [["webservice/tests/logs/nmea0183.log", '0183', 2000]];
[86442cb]94 }
95 }
[008bce9]96
97 function error_log($msg)
[86442cb]98 {
[008bce9]99 echo "ERR Nmea: ". $msg ."\n";
[86442cb]100 }
[008bce9]101}
102
103namespace GnuBoat\Nmea\Nmea0183
104{
105 function error_log($msg)
[86442cb]106 {
[008bce9]107 echo "ERR Nmea0183: ". $msg ."\n";
[86442cb]108 }
109}
110
111?>
Note: See TracBrowser for help on using the repository browser.