source: src/webapp/webservice/tests/NmeaTest.php@ 008bce9

0.5 debian/bullseye debian/jessie
Last change on this file since 008bce9 was 008bce9, checked in by Joachim Langenbach <joachim.langenbach@…>, 9 years ago

First more or less working version of visualising logfiles on the map

  • Property mode set to 100644
File size: 2.9 KB
Line 
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
22namespace GnuBoat\Nmea
23{
24
25 /**
26 * @brief Covers Parser.php
27 */
28 final class NmeaTest extends \PHPUnit_Framework_TestCase
29 {
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],
68 "rmc0183" => ['0183', '$GNRMC,173658,A,0047.589,N,00010.713,E,01.1,147.4,260817,,,A*5F', Nmea0183\Nmea0183Rmc::class, true],
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],
71 ];
72 }
73
74 /**
75 * @dataProvider nmeaFileProvider
76 */
77 public function testNmeaFile($file, $format, $count)
78 {
79 $parser = new Parser(0);
80 $sentences = $parser->parseFile($file, $format);
81 $this->assertInternalType('array', $sentences);
82 $this->assertCount($count, $sentences);
83 foreach($sentences as $sentence){
84 $this->assertNotNull($sentence);
85 $this->assertInstanceOf(NmeaSentence::class, $sentence);
86 $this->assertEquals(true, $sentence->valid());
87 }
88 }
89
90 public function nmeaFileProvider()
91 {
92 return [["webservice/tests/data/nmea0183.log", '0183', 2000]];
93 }
94 }
95
96 function error_log($msg)
97 {
98 echo "ERR Nmea: ". $msg ."\n";
99 }
100}
101
102namespace GnuBoat\Nmea\Nmea0183
103{
104 function error_log($msg)
105 {
106 echo "ERR Nmea0183: ". $msg ."\n";
107 }
108}
109
110?>
Note: See TracBrowser for help on using the repository browser.