source: src/webapp/webservice/tests/Nmea0183RmcTest.php@ d3bfa78

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

Fixed nmea 0183 position handling in webservice php classes

  • Property mode set to 100644
File size: 5.0 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
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(), '', 0.0001);
51 $this->assertEquals($longitude, $sentence->longitude(), '', 0.0001);
52 $this->assertEquals($speedOverGround, $sentence->speedOverGround());
53 $this->assertEquals($courseOverGround, $sentence->courseOverGround());
54 $this->assertEquals($magneticalDeclination, $sentence->magneticDeclination());
55 $this->assertEquals($magneticalDeclinationDirection, $sentence->magneticDeclinationDirection());
56 $this->assertEquals($signalIntegrity, $sentence->signalIntegrity());
57 $this->assertEquals($checksum, $sentence->checksum());
58 $message = "";
59 $result = $sentence->valid($message);
60 $this->assertEquals($valid, $result, $message);
61 }
62
63 public function rmcProvider()
64 {
65 $format = 'Y-m-d H:i:s';
66 $formatMilli = 'Y-m-d H:i:s.u';
67
68 return [
69 "wrong_data_count" => [
70 '$GPRMC,162614,A,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13',
71 "GP", "rmc", null,
72 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::V, 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
73 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
74 0, 0, 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
75 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::DataNotValid, 13, false
76 ],
77 "wrong_checksum" => [
78 '$GPRMC,162614,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*22',
79 "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),
80 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 52.5098, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
81 13.3731, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
82 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
83 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 22, false
84 ],
85 "valid1" => [
86 '$GPRMC,122548,A,4735.4480,N,1042.6240,E,10.0,115.6,131006,1.2,E,A*1D',
87 "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 12:25:48", new DateTimeZone("UTC")),
88 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 47.5908, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
89 10.7104, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
90 10, 115.6, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
91 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, '1d', true
92 ],
93 "valid2" => [
94 '!GPRMC,162614,A,4735.4480,S,1042.6240,E,10.0,90,131006,,,A*42',
95 "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),
96 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, -47.5908, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::South,
97 10.7104, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
98 10, 90, 0, false,
99 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, '42', true
100 ],
101 "valid3" => [
102 '$GNRMC,162614,A,735.4480,N,01042.6240,W,10.0,90,131006,1.2,E,A*3F',
103 "GN", "rmc", DateTime::createFromFormat($formatMilli, "2006-10-13 16:26:14.123", new DateTimeZone("UTC")),
104 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 7.5908, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
105 -10.7104, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::West,
106 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
107 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, '3f', true
108 ]
109 ];
110 }
111}
112
113?>
Note: See TracBrowser for help on using the repository browser.