| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Copyright (C) 2017 - 2018 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 | use PHPUnit\Framework\TestCase;
|
|---|
| 22 |
|
|---|
| 23 | namespace GnuBoat\Nmea
|
|---|
| 24 | {
|
|---|
| 25 |
|
|---|
| 26 | /**
|
|---|
| 27 | * @brief Covers Parser.php
|
|---|
| 28 | */
|
|---|
| 29 | final class NmeaTest extends \PHPUnit\Framework\TestCase
|
|---|
| 30 | {
|
|---|
| 31 | /**
|
|---|
| 32 | * @dataProvider formatsProvider
|
|---|
| 33 | */
|
|---|
| 34 | public function testFormats($format)
|
|---|
| 35 | {
|
|---|
| 36 | $parser = new Parser(0);
|
|---|
| 37 | $formats = $parser->formatsSupported();
|
|---|
| 38 | $this->assertInternalType('array', $formats);
|
|---|
| 39 | $this->assertContains($format, $formats);
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | public function formatsProvider()
|
|---|
| 43 | {
|
|---|
| 44 | return [["0183"]];
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | /**
|
|---|
| 48 | * @dataProvider nmeaSentenceProvider
|
|---|
| 49 | */
|
|---|
| 50 | public function testNmeaSentence($format, $sentence, $classType, $valid)
|
|---|
| 51 | {
|
|---|
| 52 | $parser = new Parser(0);
|
|---|
| 53 | $sentence = $parser->parseSentence($sentence, $format);
|
|---|
| 54 | if($classType == null)
|
|---|
| 55 | $this->assertNull($sentence);
|
|---|
| 56 | else{
|
|---|
| 57 | $this->assertInstanceOf($classType, $sentence);
|
|---|
| 58 | $message = "";
|
|---|
| 59 | $result = $sentence->valid($message);
|
|---|
| 60 | $this->assertEquals($valid, $result, $message);
|
|---|
| 61 | }
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | public function nmeaSentenceProvider()
|
|---|
| 65 | {
|
|---|
| 66 | return [
|
|---|
| 67 | "empty" => ['0183', '', null, false],
|
|---|
| 68 | "unsupported_format" => ['abc', '', null, false],
|
|---|
| 69 | "rmc0183" => ['0183', '$GNRMC,122548,A,4735.4480,N,01042.6240,E,00.0,115.6,110917,,,A*50', Nmea0183\Nmea0183Rmc::class, true],
|
|---|
| 70 | "dpt0183" => ['0183', '$SDDPT,00.71,00.00*51', Nmea0183\Nmea0183Dpt::class, true],
|
|---|
| 71 | "mtw0183" => ['0183', '$YXMTW,26.3,C*15', Nmea0183\Nmea0183Mtw::class, true],
|
|---|
| 72 | "rmc0183timestamp" => ['0183', '2017-09-11 13:20:42: $GNRMC,122548,A,4735.4480,N,01042.6240,E,00.0,115.6,110917,,,A*50', Nmea0183\Nmea0183Rmc::class, true],
|
|---|
| 73 | ];
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | /**
|
|---|
| 77 | * @dataProvider nmeaFileProvider
|
|---|
| 78 | */
|
|---|
| 79 | public function testNmeaFile($file, $format, $count)
|
|---|
| 80 | {
|
|---|
| 81 | $parser = new Parser(0);
|
|---|
| 82 | $sentences = $parser->parseFile($file, $format);
|
|---|
| 83 | $this->assertInternalType('array', $sentences);
|
|---|
| 84 | $this->assertCount($count, $sentences);
|
|---|
| 85 | foreach($sentences as $sentence){
|
|---|
| 86 | $this->assertNotNull($sentence);
|
|---|
| 87 | $this->assertInstanceOf(NmeaSentence::class, $sentence);
|
|---|
| 88 | $this->assertEquals(true, $sentence->valid());
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | public function nmeaFileProvider()
|
|---|
| 93 | {
|
|---|
| 94 | return [["webservice/tests/logs/nmea0183.log", '0183', 2000]];
|
|---|
| 95 | }
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | function error_log($msg)
|
|---|
| 99 | {
|
|---|
| 100 | echo "ERR Nmea: ". $msg ."\n";
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | namespace GnuBoat\Nmea\Nmea0183
|
|---|
| 105 | {
|
|---|
| 106 | function error_log($msg)
|
|---|
| 107 | {
|
|---|
| 108 | echo "ERR Nmea0183: ". $msg ."\n";
|
|---|
| 109 | }
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | ?>
|
|---|