mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
committed by
Neil Lathwood
parent
44c3f1f00c
commit
0b7b24fd9d
@@ -924,7 +924,7 @@ function snmp_hexstring($hex)
|
||||
# Check if the supplied string is an SNMP hex string
|
||||
function isHexString($str)
|
||||
{
|
||||
return preg_match("/^[a-f0-9][a-f0-9]( [a-f0-9][a-f0-9])*$/is", trim($str));
|
||||
return (bool)preg_match("/^[a-f0-9][a-f0-9]( [a-f0-9][a-f0-9])*$/is", trim($str));
|
||||
}
|
||||
|
||||
# Include all .inc.php files in $dir
|
||||
|
53
tests/FunctionsTest.php
Normal file
53
tests/FunctionsTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* FunctionsTest.php
|
||||
*
|
||||
* tests functions in includes/functions.php
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Tests;
|
||||
|
||||
class FunctionsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMacCleanToReadable()
|
||||
{
|
||||
$this->assertEquals('de:ad:be:ef:a0:c3', mac_clean_to_readable('deadbeefa0c3'));
|
||||
}
|
||||
|
||||
public function testHex2Str()
|
||||
{
|
||||
$this->assertEquals('Big 10 UP', hex2str('426967203130205550'));
|
||||
}
|
||||
|
||||
public function testSnmpHexstring()
|
||||
{
|
||||
$input = '4c 61 72 70 69 6e 67 20 34 20 55 00 0a';
|
||||
$this->assertEquals("Larping 4 U\n", snmp_hexstring($input));
|
||||
}
|
||||
|
||||
public function testIsHexString()
|
||||
{
|
||||
$this->assertTrue(isHexString('af 28 02'));
|
||||
$this->assertTrue(isHexString('aF 28 02 CE'));
|
||||
$this->assertFalse(isHexString('a5 fj 53'));
|
||||
$this->assertFalse(isHexString('a5fe53'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user