diff --git a/tests/AllTests.php b/tests/AllTests.php index ad4d856..44e3084 100644 --- a/tests/AllTests.php +++ b/tests/AllTests.php @@ -1,4 +1,17 @@ + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $Id$ + * @link http://pear.php.net/package/Net_Wifi + */ if (!defined('PHPUnit_MAIN_METHOD')) { define('PHPUnit_MAIN_METHOD', 'Net_Wifi_AllTests::main'); } @@ -10,14 +23,34 @@ require_once 'Net_WifiTest.php'; +/** + * AllTests for the PEAR-wide test suite. + * "pear run-tests -u" also uses it. + * + * @category Networking + * @package Net_Wifi + * @subpackage Unittests + * @author Christian Weiske + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://pear.php.net/package/Net_Wifi + */ class Net_Wifi_AllTests { + /** + * Helper function to automatically run the suite with php. + * + * @return void + */ public static function main() { - PHPUnit_TextUI_TestRunner::run(self::suite()); } + /** + * Setup the Net_Wifi unit test suite and return it. + * + * @return PHPUnit_Framework_TestSuite Test suite + */ public static function suite() { $suite = new PHPUnit_Framework_TestSuite('Net_Wifi Tests'); diff --git a/tests/Net_WifiTest.php b/tests/Net_WifiTest.php index 899ac04..e7b6ad0 100644 --- a/tests/Net_WifiTest.php +++ b/tests/Net_WifiTest.php @@ -1,4 +1,17 @@ + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version SVN: $Id$ + * @link http://pear.php.net/package/Net_Wifi + */ // Call Net_WifiTest::main() if this source file is executed directly. if (!defined("PHPUnit_MAIN_METHOD")) { define("PHPUnit_MAIN_METHOD", "Net_WifiTest::main"); @@ -13,8 +26,14 @@ require_once 'Stream/Var.php'; /** - * Test class for Net_Wifi. - * Generated by PHPUnit_Util_Skeleton on 2007-06-19 at 07:44:36. + * Net_Wifi tests + * + * @category Networking + * @package Net_Wifi + * @subpackage Unittests + * @author Christian Weiske + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @link http://pear.php.net/package/Net_Wifi */ class Net_WifiTest extends PHPUnit_Framework_TestCase { @@ -22,19 +41,24 @@ class Net_WifiTest extends PHPUnit_Framework_TestCase * Runs the test methods of this class. * * @access public - * @static + * + * @return void */ - public static function main() { - require_once "PHPUnit/TextUI/TestRunner.php"; + public static function main() + { + include_once 'PHPUnit/TextUI/TestRunner.php'; - $suite = new PHPUnit_Framework_TestSuite("Net_WifiTest"); + $suite = new PHPUnit_Framework_TestSuite('Net_WifiTest'); $result = PHPUnit_TextUI_TestRunner::run($suite); } /** - * This method is called before the first test of this test class is run. + * This method is called before the first test of + * this test class is run. * * @since Method available since Release 3.4.0 + * + * @return void */ public static function setUpBeforeClass() { @@ -45,21 +69,13 @@ public static function setUpBeforeClass() * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. * - * @access protected + * @return void */ - protected function setUp() { + protected function setUp() + { $this->wls = new Net_Wifi(); } - /** - * Tears down the fixture, for example, close a network connection. - * This method is called after a test is executed. - * - * @access protected - */ - protected function tearDown() { - } - /** @@ -102,7 +118,7 @@ public function testGetSupportedInterfacesSingle() /** - * tests getSupportedInterfaces() method with multiple interfaces + * Tests getSupportedInterfaces() method with multiple interfaces. * * @return void */ @@ -122,60 +138,62 @@ public function testGetSupportedInterfacesMultiple() /** - * tests the "current config" parser + * Tests the "current config" parser. + * + * @return void */ function testParseCurrentConfig() { //not associated - $strConfig = - "eth1 unassociated ESSID:off/any\r\n" . - " Mode:Managed Channel=0 Access Point: 00:00:00:00:00:00\r\n" . - " Bit Rate=0 kb/s Tx-Power=20 dBm\r\n" . - " RTS thr:off Fragment thr:off\r\n" . - " Encryption key:off\r\n" . - " Power Management:off\r\n" . - " Link Quality:0 Signal level:0 Noise level:0\r\n" . - " Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0\r\n" . - " Tx excessive retries:0 Invalid misc:0 Missed beacon:0\r\n"; + $strConfig + = "eth1 unassociated ESSID:off/any\r\n" + . " Mode:Managed Channel=0 Access Point: 00:00:00:00:00:00\r\n" + . " Bit Rate=0 kb/s Tx-Power=20 dBm\r\n" + . " RTS thr:off Fragment thr:off\r\n" + . " Encryption key:off\r\n" + . " Power Management:off\r\n" + . " Link Quality:0 Signal level:0 Noise level:0\r\n" + . " Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0\r\n" + . " Tx excessive retries:0 Invalid misc:0 Missed beacon:0\r\n"; $objConfig = $this->wls->parseCurrentConfig($strConfig); $this->assertEquals('net_wifi_config', strtolower(get_class($objConfig))); - $this->assertFalse ($objConfig->associated); - $this->assertTrue ($objConfig->activated); - $this->assertEquals('00:00:00:00:00:00', $objConfig->ap); + $this->assertFalse($objConfig->associated); + $this->assertTrue($objConfig->activated); + $this->assertEquals('00:00:00:00:00:00', $objConfig->ap); //associated - $strConfig = - "eth1 IEEE 802.11g ESSID:\"wlan.informatik.uni-leipzig.de\" Nickname:\"bogo\"\r\n" . - " Mode:Managed Frequency:2.437 GHz Access Point: 00:07:40:A0:75:E2 \r\n" . - " Bit Rate=54 Mb/s Tx-Power=20 dBm \r\n" . - " RTS thr:off Fragment thr:off\r\n" . - " Power Management:off\r\n" . - " Link Quality=100/100 Signal level=-28 dBm \r\n" . - " Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0\r\n" . - " Tx excessive retries:0 Invalid misc:0 Missed beacon:102\r\n"; + $strConfig + = "eth1 IEEE 802.11g ESSID:\"wlan.informatik.uni-leipzig.de\" Nickname:\"bogo\"\r\n" + . " Mode:Managed Frequency:2.437 GHz Access Point: 00:07:40:A0:75:E2 \r\n" + . " Bit Rate=54 Mb/s Tx-Power=20 dBm \r\n" + . " RTS thr:off Fragment thr:off\r\n" + . " Power Management:off\r\n" + . " Link Quality=100/100 Signal level=-28 dBm \r\n" + . " Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0\r\n" + . " Tx excessive retries:0 Invalid misc:0 Missed beacon:102\r\n"; $objConfig = $this->wls->parseCurrentConfig($strConfig); - $this->assertTrue ($objConfig->associated); - $this->assertTrue ($objConfig->activated); - $this->assertEquals('00:07:40:A0:75:E2' , $objConfig->ap); - $this->assertEquals('wlan.informatik.uni-leipzig.de' , $objConfig->ssid); - $this->assertEquals('managed' , $objConfig->mode); - $this->assertEquals('bogo' , $objConfig->nick); - $this->assertEquals(54 , $objConfig->rate); - $this->assertEquals(20 , $objConfig->power); - $this->assertEquals('802.11g' , $objConfig->protocol); - $this->assertEquals(-28 , $objConfig->rssi); - $this->assertEquals(null , $objConfig->noise); - $this->assertEquals(0 , $objConfig->packages_invalid_misc); - $this->assertEquals(102 , $objConfig->packages_missed_beacon); - $this->assertEquals(0 , $objConfig->packages_rx_invalid_crypt); - $this->assertEquals(0 , $objConfig->packages_rx_invalid_frag); - $this->assertEquals(0 , $objConfig->packages_rx_invalid_nwid); - $this->assertEquals(0 , $objConfig->packages_tx_excessive_retries); + $this->assertTrue($objConfig->associated); + $this->assertTrue($objConfig->activated); + $this->assertEquals('00:07:40:A0:75:E2', $objConfig->ap); + $this->assertEquals('wlan.informatik.uni-leipzig.de', $objConfig->ssid); + $this->assertEquals('managed', $objConfig->mode); + $this->assertEquals('bogo', $objConfig->nick); + $this->assertEquals(54, $objConfig->rate); + $this->assertEquals(20, $objConfig->power); + $this->assertEquals('802.11g', $objConfig->protocol); + $this->assertEquals(-28, $objConfig->rssi); + $this->assertEquals(null, $objConfig->noise); + $this->assertEquals(0, $objConfig->packages_invalid_misc); + $this->assertEquals(102, $objConfig->packages_missed_beacon); + $this->assertEquals(0, $objConfig->packages_rx_invalid_crypt); + $this->assertEquals(0, $objConfig->packages_rx_invalid_frag); + $this->assertEquals(0, $objConfig->packages_rx_invalid_nwid); + $this->assertEquals(0, $objConfig->packages_tx_excessive_retries); //format changed a bit $strConfig = <<wls->parseCurrentConfig($strConfig); - $this->assertTrue ($objConfig->associated); - $this->assertTrue ($objConfig->activated); + $this->assertTrue($objConfig->associated); + $this->assertTrue($objConfig->activated); $this->assertEquals('00:07:40:A0:75:E2' , $objConfig->ap); $this->assertEquals('wlan.informatik.uni-leipzig.de' , $objConfig->ssid); $this->assertEquals('managed' , $objConfig->mode); @@ -203,25 +221,25 @@ function testParseCurrentConfig() $this->assertEquals(-89 , $objConfig->noise); //radio off = deactivated interface - $strConfig = - "eth1 radio off ESSID:\"phpconf\"\r\n" . - " Mode:Managed Channel:0 Access Point: 00:00:00:00:00:00\r\n" . - " Bit Rate=0 kb/s Tx-Power=off\r\n" . - " RTS thr:off Fragment thr:off\r\n" . - " Power Management:off\r\n" . - " Link Quality:0 Signal level:0 Noise level:0\r\n" . - " Rx invalid nwid:12 Rx invalid crypt:23 Rx invalid frag:42\r\n" . - " Tx excessive retries:332 Invalid misc:6 Missed beacon:923\r\n"; + $strConfig + = "eth1 radio off ESSID:\"phpconf\"\r\n" + . " Mode:Managed Channel:0 Access Point: 00:00:00:00:00:00\r\n" + . " Bit Rate=0 kb/s Tx-Power=off\r\n" + . " RTS thr:off Fragment thr:off\r\n" + . " Power Management:off\r\n" + . " Link Quality:0 Signal level:0 Noise level:0\r\n" + . " Rx invalid nwid:12 Rx invalid crypt:23 Rx invalid frag:42\r\n" + . " Tx excessive retries:332 Invalid misc:6 Missed beacon:923\r\n"; $objConfig = $this->wls->parseCurrentConfig($strConfig); - $this->assertFalse( $objConfig->associated); - $this->assertFalse( $objConfig->activated); - $this->assertEquals(6 , $objConfig->packages_invalid_misc); - $this->assertEquals(923 , $objConfig->packages_missed_beacon); - $this->assertEquals(23 , $objConfig->packages_rx_invalid_crypt); - $this->assertEquals(42 , $objConfig->packages_rx_invalid_frag); - $this->assertEquals(12 , $objConfig->packages_rx_invalid_nwid); - $this->assertEquals(332 , $objConfig->packages_tx_excessive_retries); + $this->assertFalse($objConfig->associated); + $this->assertFalse($objConfig->activated); + $this->assertEquals(6, $objConfig->packages_invalid_misc); + $this->assertEquals(923, $objConfig->packages_missed_beacon); + $this->assertEquals(23, $objConfig->packages_rx_invalid_crypt); + $this->assertEquals(42, $objConfig->packages_rx_invalid_frag); + $this->assertEquals(12, $objConfig->packages_rx_invalid_nwid); + $this->assertEquals(332, $objConfig->packages_tx_excessive_retries); //Bug #11343: fix preg_match for rssi value/signal strength @@ -236,23 +254,25 @@ function testParseCurrentConfig() Tx excessive retries:0 Invalid misc:0 Missed beacon:0 EOT; $objConfig = $this->wls->parseCurrentConfig($strConfig); - $this->assertEquals(-49 , $objConfig->rssi); - $this->assertEquals(-249 , $objConfig->noise); - $this->assertEquals('802.11b' , $objConfig->protocol); + $this->assertEquals(-49, $objConfig->rssi); + $this->assertEquals(-249, $objConfig->noise); + $this->assertEquals('802.11b', $objConfig->protocol); }//function testParseCurrentConfig() /** - * tests the "parseScan" function which - * scans the iwlist output + * tests the "parseScan" function which + * scans the iwlist output + * + * @return void */ function testParseScan() { //no peers $arLines = array("eth1 No scan results"); $arCells = $this->wls->parseScan($arLines); - $this->assertEquals( 0, count($arCells)); + $this->assertEquals(0, count($arCells)); //some peers //driver: ipw2200 0.21, acer travelmate 6003 @@ -485,7 +505,9 @@ function testParseScan() //ipw2200 kernel 2.18.1 (probably version 1.1.3) - $arLines = explode("\n", <<" @@ -509,8 +531,10 @@ function testParseScan() $this->assertEquals(-40 , $arCells[0]->rssi); $this->assertEquals(null , $arCells[0]->frequency); $this->assertEquals(54 , $arCells[0]->rate); - $this->assertEquals(array(1.,2.,5.5,6.,9.,11., - 12.,18.,24.,36.,48.,54.), $arCells[0]->rates); + $this->assertEquals( + array(1.,2.,5.5,6.,9.,11.,12.,18.,24.,36.,48.,54.), + $arCells[0]->rates + ); $this->assertEquals(false , $arCells[0]->encryption); $this->assertEquals(1472 , $arCells[0]->beacon); @@ -518,9 +542,16 @@ function testParseScan() + /** + * More scans on 2009-10-18 + * + * @return void + */ function testParseScan20091018() { - $arLines = explode("\n", <<assertEquals(-46 , $arCells[0]->rssi); $this->assertEquals('2.447 GHz' , $arCells[0]->frequency); $this->assertEquals(8 , $arCells[0]->channel); - $this->assertEquals(array(1.,2.,5.5,6.,9.,11., - 12.,18.,24.,36.,48.,54.), $arCells[0]->rates); + $this->assertEquals( + array(1.,2.,5.5,6.,9.,11.,12.,18.,24.,36.,48.,54.), + $arCells[0]->rates + ); $this->assertEquals(false , $arCells[0]->encryption); $this->assertEquals(1221684936 , $arCells[0]->beacon); @@ -587,8 +620,10 @@ function testParseScan20091018() $this->assertEquals(-77 , $arCells[1]->rssi); $this->assertEquals('2.437 GHz' , $arCells[1]->frequency); $this->assertEquals(6 , $arCells[1]->channel); - $this->assertEquals(array(1.,2.,5.5,6.,9.,11., - 12.,18.,24.,36.,48.,54.), $arCells[1]->rates); + $this->assertEquals( + array(1.,2.,5.5,6.,9.,11.,12.,18.,24.,36.,48.,54.), + $arCells[1]->rates + ); $this->assertEquals(false , $arCells[1]->encryption); $this->assertEquals(3560 , $arCells[1]->beacon); }