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