[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/net/tests/cases/ -> lmbIpTest.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  lmb_require('limb/net/src/lmbIp.class.php');
  10  
  11  class lmbIpTest extends UnitTestCase
  12  {
  13    var $ip = null;
  14  
  15    function setUp()
  16    {
  17      $this->ip = new lmbIp();
  18    }
  19  
  20    function testIsValid()
  21    {
  22      $this->assertTrue(lmbIp :: isValid('127.0.0.1'));
  23      $this->assertTrue(lmbIp :: isValid('255.255.255.255'));
  24  
  25      $this->assertFalse(lmbIp :: isValid('wow'));
  26      $this->assertFalse(lmbIp :: isValid('256.255.255.255'));
  27    }
  28  
  29    function testEncodeIpRangeFailure()
  30    {
  31      try
  32      {
  33        $this->ip->encodeIpRange('bla', 'foo');
  34        $this->assertTrue(false);
  35      }
  36      catch(lmbException $e){}
  37  
  38      try
  39      {
  40        $this->ip->encodeIpRange('127.0.0.1', 'foo');
  41        $this->assertTrue(false);
  42      }
  43      catch(lmbException $e){}
  44  
  45      try
  46      {
  47        $this->ip->encodeIpRange('bla', '127.0.0.1');
  48        $this->assertTrue(false);
  49      }
  50      catch(lmbException $e){}
  51    }
  52  
  53    function testEncodeIpRange()
  54    {
  55      $ip_list = $this->ip->encodeIpRange('192.168.0.1', '192.168.10.10');
  56  
  57      $this->assertNotIdentical(false, array_search($this->ip->encode('192.168.0.1'), $ip_list));
  58      $this->assertNotIdentical(false, array_search($this->ip->encode('192.168.10.10'), $ip_list));
  59    }
  60  
  61    function testEncodeDecode()
  62    {
  63      $this->assertEqual(lmbIp :: encode('127.0.0.1'), ip2long('127.0.0.1'));
  64      $this->assertEqual(lmbIp :: decode(ip2long('127.0.0.1')), '127.0.0.1');
  65    }
  66  }
  67  
  68  ?>


Generated: Tue Oct 7 05:02:03 2008 Cross-referenced by PHPXref 0.7