OSDN Git Service

is_ip()
authorhenoheno <henoheno>
Sat, 27 Dec 2008 14:50:00 +0000 (23:50 +0900)
committerhenoheno <henoheno>
Sat, 27 Dec 2008 14:50:00 +0000 (23:50 +0900)
spam/SpamTest.php

index 882480b..b2b273f 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-// $Id: SpamTest.php,v 1.22 2008/12/27 11:20:06 henoheno Exp $
+// $Id: SpamTest.php,v 1.23 2008/12/27 14:50:00 henoheno Exp $
 // Copyright (C) 2007 heno
 //
 // Design test case for spam.php (called from runner.php)
@@ -344,6 +344,38 @@ class SpamTest extends PHPUnit_TestCase
                //$this->assertEquals('192\.168\.',       generate_host_regex('192.168.'));
        }
 
+       function testFunc_is_ip()
+       {
+               // 1st argument: Null
+               foreach($this->setup_string_null() as $key => $value){
+                       $this->assertEquals(FALSE, is_ip($value), $key);
+               }
+
+               // IPv4
+               foreach(array(
+                               '192.168.1.1',
+                       ) as $value){
+                       $this->assertEquals(4,  is_ip($value), $key, '[' . $value . ']');
+               }
+
+               // IPv6
+               foreach(array(
+                               '::',                           // 0:0:0:0:0:0:0:0
+                               '::192.168.1.1',        // IPv4 within IPv6 network
+                       ) as $value){
+                       $this->assertEquals(6,  is_ip($value), $key, '[' . $value . ']');
+               }
+
+               // Invalid
+               foreach(array(
+                               '',
+                               '.',
+                       ) as $value){
+                       $this->assertEquals(FALSE,      is_ip($value), $key, '[' . $value . ']');
+               }
+
+       }
+
        function testFunc_get_blocklist()
        {
                if (! defined('SPAM_INI_FILE') || ! file_exists(SPAM_INI_FILE)) {