| [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 | */
|
|---|
| 25 | final 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);
|
|---|
| [f29f4d3] | 50 | $this->assertEquals($latitude, $sentence->latitude(), '', 0.0001);
|
|---|
| 51 | $this->assertEquals($longitude, $sentence->longitude(), '', 0.0001);
|
|---|
| [86442cb] | 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',
|
|---|
| [008bce9] | 71 | "GP", "rmc", null,
|
|---|
| [86442cb] | 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',
|
|---|
| [008bce9] | 79 | "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),
|
|---|
| [f29f4d3] | 80 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 52.5098, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
|
|---|
| 81 | 13.3731, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
|
|---|
| [86442cb] | 82 | 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
|
|---|
| 83 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 22, false
|
|---|
| 84 | ],
|
|---|
| [26f77a6] | 85 | "position_conversion" => [
|
|---|
| 86 | '$GPRMC,191410,A,4735.5634,N,00739.3538,E,0.0,0.0,181102,0.4,E,A*19',
|
|---|
| 87 | "GP", "rmc", DateTime::createFromFormat($format, "2002-11-18 19:14:10", new DateTimeZone("UTC")),
|
|---|
| 88 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 47.5927, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
|
|---|
| 89 | 7.6558, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
|
|---|
| 90 | 0, 0, 0.4, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
|
|---|
| 91 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 19, true
|
|---|
| 92 | ],
|
|---|
| 93 | "position_conversion_lon" => [
|
|---|
| 94 | '$GNRMC,133014,A,4825.64749998,N,01002.55130002,E,00.0,337.9,281017,,,A*51',
|
|---|
| 95 | "GN", "rmc", DateTime::createFromFormat($format, "2017-10-28 13:30:14", new DateTimeZone("UTC")),
|
|---|
| 96 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 48.4274, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
|
|---|
| 97 | 10.0425, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
|
|---|
| 98 | 0, 337.9, 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
|
|---|
| 99 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 51, true
|
|---|
| 100 | ],
|
|---|
| [86442cb] | 101 | "valid1" => [
|
|---|
| [26f77a6] | 102 | '$GPRMC,122548,A,4735.4480,N,01042.6240,E,10.0,115.6,131006,1.2,E,A*2D',
|
|---|
| [f29f4d3] | 103 | "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 12:25:48", new DateTimeZone("UTC")),
|
|---|
| 104 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 47.5908, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
|
|---|
| 105 | 10.7104, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
|
|---|
| 106 | 10, 115.6, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
|
|---|
| [26f77a6] | 107 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, '2d', true
|
|---|
| [86442cb] | 108 | ],
|
|---|
| 109 | "valid2" => [
|
|---|
| [26f77a6] | 110 | '!GPRMC,162614,A,4735.4480,S,01042.6240,E,10.0,90,131006,,,A*72',
|
|---|
| [008bce9] | 111 | "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),
|
|---|
| [f29f4d3] | 112 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, -47.5908, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::South,
|
|---|
| 113 | 10.7104, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
|
|---|
| 114 | 10, 90, 0, false,
|
|---|
| [26f77a6] | 115 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, '72', true
|
|---|
| [86442cb] | 116 | ],
|
|---|
| 117 | "valid3" => [
|
|---|
| [26f77a6] | 118 | '$GNRMC,162614,A,7305.4480,N,01042.6240,W,10.0,90,131006,1.2,E,A*F',
|
|---|
| [f29f4d3] | 119 | "GN", "rmc", DateTime::createFromFormat($formatMilli, "2006-10-13 16:26:14.123", new DateTimeZone("UTC")),
|
|---|
| [26f77a6] | 120 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 73.0908, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
|
|---|
| [f29f4d3] | 121 | -10.7104, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::West,
|
|---|
| [86442cb] | 122 | 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
|
|---|
| [26f77a6] | 123 | GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 'f', true
|
|---|
| [86442cb] | 124 | ]
|
|---|
| 125 | ];
|
|---|
| 126 | }
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | ?>
|
|---|