home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / test_result_parsers.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  7.7 KB  |  217 lines

  1. <?php
  2.   /* Usage: php test_result_parsers.php */
  3.  
  4. error_reporting(E_ALL);
  5. require_once "../Ping.php";
  6.  
  7. $err = false;
  8.  
  9. function failure($os, $function)
  10. {
  11.   global $err;
  12.  
  13.   $err = true;
  14.   return "Failure parsing ".$os." result: ".$function."\n";
  15. }
  16.  
  17. //$oses = array('linux', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'hpux', 'aix', 'windows');
  18. $oses = array('hpux', 'aix', 'darwin', 'freebsd', 'netbsd');
  19.  
  20. $result['netbsd'][] ="PING example.com (192.0.34.166): 56 data bytes";
  21. $result['netbsd'][] ="64 bytes from 192.0.34.166: icmp_seq=0 ttl=53 time=385.571 ms";
  22. $result['netbsd'][] ="64 bytes from 192.0.34.166: icmp_seq=1 ttl=53 time=173.176 ms";
  23. $result['netbsd'][] ="64 bytes from 192.0.34.166: icmp_seq=2 ttl=53 time=173.338 ms";
  24. $result['netbsd'][] ="64 bytes from 192.0.34.166: icmp_seq=3 ttl=53 time=173.915 ms";
  25. $result['netbsd'][] ="64 bytes from 192.0.34.166: icmp_seq=4 ttl=53 time=172.543 ms";
  26. $result['netbsd'][] ="";
  27. $result['netbsd'][] ="----example.com PING Statistics----";
  28. $result['netbsd'][] ="5 packets transmitted, 5 packets received, 0.0% packet loss";
  29. $result['netbsd'][] ="round-trip min/avg/max/stddev = 172.543/215.709/385.571/94.957 ms";
  30.  
  31. $expect['netbsd']['min'] = 172.543;
  32. $expect['netbsd']['avg'] = 215.709;
  33. $expect['netbsd']['max'] = 385.571;
  34. $expect['netbsd']['stddev'] = 94.957;
  35. $expect['netbsd']['ttl'] = 53;
  36. $expect['netbsd']['bytesperreq'] = 64;
  37. $expect['netbsd']['received'] = 5;
  38. $expect['netbsd']['transmitted'] = 5;
  39. $expect['netbsd']['loss'] = 0;
  40. $expect['netbsd']['bytestotal'] = 320;
  41. $expect['netbsd']['targetip'] = '192.0.34.166';
  42.  
  43.  
  44.  
  45. $result['freebsd'][] = "PING example.com (192.0.34.166): 56 data bytes";
  46. $result['freebsd'][] = "64 bytes from 192.0.34.166: icmp_seq=0 ttl=49 time=174.300 ms";
  47. $result['freebsd'][] = "64 bytes from 192.0.34.166: icmp_seq=1 ttl=49 time=174.174 ms";
  48. $result['freebsd'][] = "64 bytes from 192.0.34.166: icmp_seq=2 ttl=49 time=181.501 ms";
  49. $result['freebsd'][] = "64 bytes from 192.0.34.166: icmp_seq=3 ttl=49 time=184.189 ms";
  50. $result['freebsd'][] = "64 bytes from 192.0.34.166: icmp_seq=4 ttl=49 time=205.475 ms";
  51. $result['freebsd'][] = "";
  52. $result['freebsd'][] = "--- example.com ping statistics ---";
  53. $result['freebsd'][] = "5 packets transmitted, 5 packets received, 0% packet loss";
  54. $result['freebsd'][] = "round-trip min/avg/max/stddev = 174.174/183.928/205.475/11.472 ms";
  55.  
  56. $expect['freebsd']['min'] = 174.174;
  57. $expect['freebsd']['avg'] = 183.928;
  58. $expect['freebsd']['max'] = 205.475;
  59. $expect['freebsd']['stddev'] = 11.472;
  60. $expect['freebsd']['ttl'] = 49;
  61. $expect['freebsd']['bytesperreq'] = 64;
  62. $expect['freebsd']['received'] = 5;
  63. $expect['freebsd']['transmitted'] = 5;
  64. $expect['freebsd']['loss'] = 0;
  65. $expect['freebsd']['bytestotal'] = 320;
  66. $expect['freebsd']['targetip'] = '192.0.34.166';
  67.  
  68.  
  69.  
  70. $result['darwin'][] = "PING example.com (192.0.34.166): 56 data bytes";
  71. $result['darwin'][] = "64 bytes from 192.0.34.166: icmp_seq=0 ttl=49 time=255.62 ms";
  72. $result['darwin'][] = "64 bytes from 192.0.34.166: icmp_seq=1 ttl=49 time=277.685 ms";
  73. $result['darwin'][] = "64 bytes from 192.0.34.166: icmp_seq=2 ttl=49 time=342.039 ms";
  74. $result['darwin'][] = "64 bytes from 192.0.34.166: icmp_seq=3 ttl=49 time=290.769 ms";
  75. $result['darwin'][] = "";
  76. $result['darwin'][] = "--- example.com ping statistics ---";
  77. $result['darwin'][] = "4 packets transmitted, 4 packets received, 0% packet loss";
  78. $result['darwin'][] = "round-trip min/avg/max = 255.62/291.528/342.039 ms";
  79.  
  80. $expect['darwin']['min'] = 255.62;
  81. $expect['darwin']['avg'] = 291.528;
  82. $expect['darwin']['max'] = 342.039;
  83. $expect['darwin']['stddev'] = NULL;
  84. $expect['darwin']['ttl'] = 49;
  85. $expect['darwin']['bytesperreq'] = 64;
  86. $expect['darwin']['received'] = 4;
  87. $expect['darwin']['transmitted'] = 4;
  88. $expect['darwin']['loss'] = 0;
  89. $expect['darwin']['bytestotal'] = 256;
  90. $expect['darwin']['targetip'] = '192.0.34.166';
  91.  
  92.  
  93.  
  94. $result['aix'][] = "PING oracle.com: (148.87.9.44): 56 data bytes";
  95. $result['aix'][] = "64 bytes from 148.87.9.44: icmp_seq=0 ttl=245 time=891 ms";
  96. $result['aix'][] = "64 bytes from 148.87.9.44: icmp_seq=1 ttl=245 time=882 ms";
  97. $result['aix'][] = "64 bytes from 148.87.9.44: icmp_seq=2 ttl=245 time=868 ms";
  98. $result['aix'][] = "64 bytes from 148.87.9.44: icmp_seq=3 ttl=245 time=848 ms";
  99. $result['aix'][] = "64 bytes from 148.87.9.44: icmp_seq=4 ttl=245 time=863 ms";
  100. $result['aix'][] = "64 bytes from 148.87.9.44: icmp_seq=5 ttl=245 time=820 ms";
  101. $result['aix'][] = "64 bytes from 148.87.9.44: icmp_seq=6 ttl=245 time=816 ms";
  102. $result['aix'][] = "64 bytes from 148.87.9.44: icmp_seq=7 ttl=245 time=773 ms";
  103. $result['aix'][] = "64 bytes from 148.87.9.44: icmp_seq=8 ttl=245 time=855 ms";
  104. $result['aix'][] = "64 bytes from 148.87.9.44: icmp_seq=9 ttl=245 time=865 ms";
  105. $result['aix'][] = "";-
  106. $result['aix'][] = "---oracle.com PING Statistics----";
  107. $result['aix'][] = "10 packets transmitted, 10 packets received, 0% packet loss";
  108. $result['aix'][] = "round-trip min/avg/max = 773/848/891 ms";
  109.  
  110. $expect['aix']['min'] = 773;
  111. $expect['aix']['avg'] = 848;
  112. $expect['aix']['max'] = 891;
  113. $expect['aix']['stddev'] = NULL;
  114. $expect['aix']['ttl'] = 245;
  115. $expect['aix']['bytesperreq'] = 64;
  116. $expect['aix']['received'] = 10;
  117. $expect['aix']['transmitted'] = 10;
  118. $expect['aix']['loss'] = 0;
  119. $expect['aix']['bytestotal'] = 640;
  120. $expect['aix']['targetip'] = '148.87.9.44';
  121.  
  122.  
  123.  
  124. $result['hpux'][]="PING example.com: 64 byte packets";
  125. $result['hpux'][]="64 bytes from 192.0.34.166: icmp_seq=0. time=257. ms";
  126. $result['hpux'][]="64 bytes from 192.0.34.166: icmp_seq=1. time=280. ms";
  127. $result['hpux'][]="64 bytes from 192.0.34.166: icmp_seq=2. time=231. ms";
  128. $result['hpux'][]="";
  129. $result['hpux'][]="----example.com PING Statistics----";
  130. $result['hpux'][]="3 packets transmitted, 3 packets received, 0% packet loss";
  131. $result['hpux'][]="round-trip (ms)  min/avg/max = 231/256/280";
  132.  
  133. $expect['hpux']['min'] = 231;
  134. $expect['hpux']['max'] = 280;
  135. $expect['hpux']['avg'] = 256;
  136. $expect['hpux']['stddev'] = NULL;
  137. $expect['hpux']['ttl'] = NULL;
  138. $expect['hpux']['bytesperreq'] = 64;
  139. $expect['hpux']['received'] = 3;
  140. $expect['hpux']['transmitted'] = 3;
  141. $expect['hpux']['loss'] = 0;
  142. $expect['hpux']['bytestotal'] = 192;
  143. $expect['hpux']['targetip'] = NULL;
  144.  
  145. function test_net_ping($os, $result, $expect)
  146. {
  147.   $ping = Net_Ping_Result::factory($result, $os);
  148.  
  149.   if(PEAR::isError($ping) ) {
  150.     echo failure($os, "factory(): ".$ping->getMessage());
  151.   }
  152.  
  153.   if( $expect['min'] !== $ping->getMin() ) {
  154.     echo failure($os, "getMin()");
  155.   }
  156.  
  157.   if( $expect['avg'] !== $ping->getAvg() ) {
  158.     echo failure($os, "getAvg()");
  159.   }
  160.  
  161.   if( $expect['max'] !== $ping->getMax() ) {
  162.     echo failure($os, "getMax()");
  163.   }
  164.  
  165.   if( $expect['stddev'] !== $ping->getStddev() ) {
  166.     echo failure($os, "getStddev()");
  167.   }
  168.  
  169.   if( $os !== $ping->getSystemName() ) {
  170.     echo failure($os, "getSystemName()");
  171.   }
  172.  
  173.   if( $expect['ttl'] !== $ping->getTTL() ) {
  174.     echo failure($os, "getTTL()");
  175.   }
  176.  
  177.   if( !is_array($ping->getICMPSequence()) ) {
  178.     echo failure($os, "getICMPSequence()");
  179.   }
  180.  
  181.   if( $expect['transmitted'] !== $ping->getTransmitted() ) {
  182.     echo failure($os, "getTransmitted()");
  183.   }
  184.  
  185.   if( $expect['received'] !== $ping->getReceived() ) {
  186.     echo failure($os, "getReceived()");
  187.   }
  188.  
  189.   if( $expect['bytesperreq'] !== $ping->getBytesPerRequest() ) {
  190.     echo failure($os, "getBytesPerRequest()");
  191.   }
  192.  
  193.   if( $expect['bytestotal'] !== $ping->getBytesTotal() ) {
  194.     echo failure($os, "getBytesTotal()");
  195.   }
  196.  
  197.   if( $expect['targetip'] !== $ping->getTargetIp() ) {
  198.     echo failure($os, "getTargetIp()");
  199.   }
  200.  
  201.   if( $expect['loss'] !== $ping->getLoss() ) {
  202.     echo failure($os, "getLoss()");
  203.   }
  204.  
  205.   unset($ping);
  206. }
  207.  
  208. foreach($oses AS $os) {
  209.   test_net_ping($os, $result[$os], $expect[$os]);
  210. }
  211.  
  212. if (true == $err) {
  213.   echo "Testcases failed, see the errors above for details\n";
  214. } else {
  215.   echo "Testcases went through just fine, just go ahead :)\n";
  216. }
  217. ?>