home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / test_drivers.php < prev    next >
Encoding:
PHP Script  |  2004-10-01  |  4.1 KB  |  123 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | Copyright (c) 2002-2003 Brent Cook                                        |
  5. // +----------------------------------------------------------------------+
  6. // | This library is free software; you can redistribute it and/or        |
  7. // | modify it under the terms of the GNU Lesser General Public           |
  8. // | License as published by the Free Software Foundation; either         |
  9. // | version 2.1 of the License, or (at your option) any later version.   |
  10. // |                                                                      |
  11. // | This library is distributed in the hope that it will be useful,      |
  12. // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  13. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
  14. // | Lesser General Public License for more details.                      |
  15. // |                                                                      |
  16. // | You should have received a copy of the GNU Lesser General Public     |
  17. // | License along with this library; if not, write to the Free Software  |
  18. // | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA|
  19. // +----------------------------------------------------------------------+
  20. // | Author: Brent Cook <busterb@mail.utexas.edu>                         |
  21. // +----------------------------------------------------------------------+
  22. //
  23. // $Id: test_drivers.php,v 1.4 2003/01/11 01:59:46 busterb Exp $
  24. //
  25.  
  26. // test functionality of the file-based dba driver
  27.  
  28. ini_set('include_path',ini_get('include_path').':../../');
  29. include 'PEAR.php';
  30. include 'DBA.php';
  31.  
  32. $testDataArray = array ('1', '22', '333', '4444', '55555', '666666',
  33.                         '7777777', '88888888', '999999999');
  34.  
  35. $maxDataIndex = sizeof($testDataArray)-1;
  36.  
  37. //$testDrivers = DBA::getDriverList();
  38. $testDrivers = array('file');
  39.  
  40. echo "Testing create/insert/replace/remove/drop/read/open/close functionality\n";
  41. foreach ($testDrivers as $driver) {
  42.     echo "Testing $driver driver\n\n";
  43.     $testDB =& DBA::create($driver);
  44.  
  45.     if (PEAR::isError($result=$testDB->open('test_db', 'c'))) {
  46.         echo $result->getMessage()."\n";
  47.         exit;
  48.     }
  49.  
  50.     // main testing loop
  51.     for ($i=0; $i<5000; ++$i) {
  52.         $testKey = rand (0, 200);
  53.         $testData = $testDataArray[rand(0, 8)];
  54.         switch (rand(0, 3)) {
  55.             case 0:
  56.                 if (!$testDB->exists($testKey)) {
  57.                     $result = $testDB->insert($testKey, $testData);
  58.                 }
  59.                 break;
  60.             case 1:
  61.                 if ($testDB->exists($testKey)) {
  62.                     $result = $testDB->remove($testKey);
  63.                 }
  64.                 break;
  65.             case 2:
  66.                 $result = $testDB->replace($testKey, $testData);
  67.                 break;
  68.             case 3:
  69.                 if ($testDB->exists($testKey)) {
  70.                     $result = $testDB->fetch($testKey);
  71.                 }
  72.         }
  73.         if (PEAR::isError($result)) {
  74.             echo $result->getMessage()."\n";
  75.         }
  76.     }
  77.  
  78.     if (PEAR::isError($result = $testDB->close())) {
  79.         echo $result->getMessage();
  80.         exit;
  81.     }
  82.  
  83.     if (PEAR::isError($result=$testDB->open('test_db', 'r'))) {
  84.         echo $result->getMessage()."\n";
  85.         exit;
  86.     }
  87.  
  88.     $key = $testDB->firstkey();
  89.     while ($key !== FALSE) {
  90.         echo "$key = ".$testDB->fetch($key)."\n";
  91.         $key = $testDB->nextkey($key);
  92.     }
  93.  
  94.     if (PEAR::isError($result = $testDB->close())) {
  95.         echo $result->getMessage();
  96.         exit;
  97.     }
  98.  
  99.     if (PEAR::isError($result = $testDB->drop())) {
  100.         echo $result->getMessage();
  101.         exit;
  102.     }
  103. }
  104.  
  105. echo "Testing static drop functionality\n";
  106. // test static drop
  107. foreach ($testDrivers as $driver) {
  108.     echo "Testing $driver driver\n\n";
  109.     $testDB =& DBA::create($driver);
  110.  
  111.     if (PEAR::isError($result=$testDB->open('test_db', 'c'))) {
  112.         echo $result->getMessage()."\n";
  113.         exit;
  114.     }
  115.  
  116.     if (PEAR::isError($result = DBA::db_drop('test_db', $driver))) {
  117.         echo $result->getMessage();
  118.         exit;
  119.     }
  120. }
  121.  
  122. ?>
  123.