source: src/webapp/webservice/tests/Nmea0183RmcTest.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: 5.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
22/**
23 * @brief Covers Nmea0183Rmc.php
24 */
25final class Nmea0183RmcTest extends PHPUnit_Framework_TestCase
26{
27 /**
28 * @dataProvider rmcProvider
29 */
30 public function testRmc($sentence, $talker, $type, $dateTimeUtc, $status, $latitude, $latitudeDirection,
31 $longitude, $longitudeDirection, $speedOverGround, $courseOverGround,
32 $magneticalDeclination, $magneticalDeclinationDirection, $signalIntegrity,
33 $checksum, $valid)
34 {
35 $format = 'Y-m-d H:i:s';
36
37 $parser = new GnuBoat\Nmea\Parser();
38 $sentence = $parser->parseSentence($sentence, "0183");
39 $this->assertInstanceOf(GnuBoat\Nmea\Nmea0183\Nmea0183Rmc::class, $sentence);
40 $this->assertEquals($talker, $sentence->talker());
41 $this->assertEquals($type, $sentence->type());
42 $dateTime = $sentence->dateTime();
43 if($dateTimeUtc == null)
44 $this->assertNull($dateTime);
45 else{
46 $this->assertInstanceOf(DateTime::class, $dateTime);
47 $this->assertEquals($dateTimeUtc->format($format), $dateTime->format($format));
48 }
49 $this->assertEquals($sentence->status(), $status);
50 $this->assertEquals($latitude, $sentence->latitude());
51 $this->assertEquals($latitudeDirection, $sentence->latitudeDirection());
52 $this->assertEquals($longitude, $sentence->longitude());
53 $this->assertEquals($longitudeDirection, $sentence->longitudeDirection());
54 $this->assertEquals($speedOverGround, $sentence->speedOverGround());
55 $this->assertEquals($courseOverGround, $sentence->courseOverGround());
56 $this->assertEquals($magneticalDeclination, $sentence->magneticDeclination());
57 $this->assertEquals($magneticalDeclinationDirection, $sentence->magneticDeclinationDirection());
58 $this->assertEquals($signalIntegrity, $sentence->signalIntegrity());
59 $this->assertEquals($checksum, $sentence->checksum());
60 $message = "";
61 $result = $sentence->valid($message);
62 $this->assertEquals($valid, $result, $message);
63 }
64
65 public function rmcProvider()
66 {
67 $format = 'Y-m-d H:i:s';
68 $formatMilli = 'Y-m-d H:i:s.u';
69
70 return [
71 "wrong_data_count" => [
72 '$GPRMC,162614,A,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13',
73 "GP", "RMC", null,
74 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::V, 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
75 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
76 0, 0, 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
77 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::DataNotValid, 13, false
78 ],
79 "wrong_checksum" => [
80 '$GPRMC,162614,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*22',
81 "GP", "RMC", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),
82 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 5230.59, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
83 1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
84 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
85 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 22, false
86 ],
87 "valid1" => [
88 '$GPRMC,162614,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13',
89 "GP", "RMC", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),
90 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 5230.59, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
91 1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
92 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
93 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 13, true
94 ],
95 "valid2" => [
96 '!GPRMC,162614,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13',
97 "GP", "RMC", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),
98 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 5230.59, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
99 1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
100 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
101 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 13, true
102 ],
103 "valid3" => [
104 '$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*d',
105 "GP", "RMC", DateTime::createFromFormat($formatMilli, "2006-10-13 16:26:14.123", new DateTimeZone("UTC")),
106 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 5230.59, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
107 1322.39, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
108 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
109 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 'd', true
110 ]
111 ];
112 }
113}
114
115?>
Note: See TracBrowser for help on using the repository browser.