source: src/webapp/webservice/tests/NmeaTest.php@ 86442cb

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

Added Nmea0183 Parsers to the PHP webservice to allow the user to load a logfile into the map
(loading the logfile and display it on the map is not implemented yet)

  • Property mode set to 100644
File size: 2.7 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
22/**
23 * @brief Covers Parser.php
24 */
25final class NmeaTest extends PHPUnit_Framework_TestCase
26{
27 /**
28 * @dataProvider formatsProvider
29 */
30 public function testFormats($format)
31 {
32 $parser = new GnuBoat\Nmea\Parser(0);
33 $formats = $parser->formatsSupported();
34 $this->assertInternalType('array', $formats);
35 $this->assertContains($format, $formats);
36 }
37
38 public function formatsProvider()
39 {
40 return [["0183"]];
41 }
42
43 /**
44 * @dataProvider nmeaSentenceProvider
45 */
46 public function testNmeaSentence($format, $sentence, $classType, $valid)
47 {
48 $parser = new GnuBoat\Nmea\Parser(0);
49 $sentence = $parser->parseSentence($sentence, $format);
50 if($classType == null)
51 $this->assertNull($sentence);
52 else{
53 $this->assertInstanceOf($classType, $sentence);
54 $message = "";
55 $result = $sentence->valid($message);
56 $this->assertEquals($valid, $result, $message);
57 }
58 }
59
60 public function nmeaSentenceProvider()
61 {
62 return [
63 "empty" => ['0183', '', null, false],
64 "unsupported_format" => ['abc', '', null, false],
65 "rmc0183" => ['0183', '$GNRMC,173658,A,0047.589,N,00010.713,E,01.1,147.4,260817,,,A*5F', GnuBoat\Nmea\Nmea0183\Nmea0183Rmc::class, true],
66 "dpt0183" => ['0183', '$SDDPT,00.71,00.00*51', GnuBoat\Nmea\Nmea0183\Nmea0183Dpt::class, true],
67 "mtw0183" => ['0183', '$YXMTW,26.3,C*15', GnuBoat\Nmea\Nmea0183\Nmea0183Mtw::class, true],
68 ];
69 }
70
71 /**
72 * @dataProvider nmeaFileProvider
73 */
74 public function testNmeaFile($file, $format, $count)
75 {
76 $parser = new GnuBoat\Nmea\Parser(0);
77 $sentences = $parser->parseFile($file, $format);
78 $this->assertInternalType('array', $sentences);
79 $this->assertCount($count, $sentences);
80 foreach($sentences as $sentence){
81 $this->assertNotNull($sentence);
82 $this->assertInstanceOf(GnuBoat\Nmea\NmeaSentence::class, $sentence);
83 $this->assertEquals(true, $sentence->valid());
84 }
85 }
86
87 public function nmeaFileProvider()
88 {
89 return [["webservice/tests/data/nmea0183.log", '0183', 2000]];
90 }
91}
92
93?>
Note: See TracBrowser for help on using the repository browser.