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

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | Copyright (c) 2002 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.1 2002/09/30 03:21:19 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. foreach (DBA::getDriverList() as $driver) {
  38. echo "Testing $driver\n\n";
  39. $testDB =& DBA::create($driver);
  40.  
  41. if (PEAR::isError($error=$testDB->open('file_test', 'c'))) {
  42.     echo $error->getMessage()."\n";
  43.     exit;
  44. }
  45.  
  46. // main testing loop
  47. for ($i=0; $i<5000; ++$i) {
  48.     $testKey = rand (0, 200);
  49.     $testData = $testDataArray[rand(0, 8)];
  50.     switch (rand(0, 3)) {
  51.         case 0:
  52.             if (!$testDB->exists($testKey)) {
  53.                 $result = $testDB->insert($testKey, $testData);
  54.             }
  55.             break;
  56.         case 1:
  57.             if ($testDB->exists($testKey)) {
  58.                 $result = $testDB->remove($testKey);
  59.             }
  60.             break;
  61.         case 2:
  62.             $result = $testDB->replace($testKey, $testData);
  63.             break;
  64.         case 3:
  65.             if ($testDB->exists($testKey)) {
  66.                 $result = $testDB->fetch($testKey);
  67.             }
  68.     }
  69.     if (PEAR::isError($result)) {
  70.         echo $result->getMessage()."\n";
  71.     }
  72. }
  73. $result = $testDB->close();
  74. if (PEAR::isError($result)) {
  75.     echo $result->getMessage();
  76.     exit;
  77. }
  78.  
  79. $testDB->open('file_test', 'r');
  80. $key = $testDB->firstkey();
  81. while ($key !== FALSE) {
  82.     echo "$key = ".$testDB->fetch($key)."\n";
  83.     $key = $testDB->nextkey($key);
  84. }
  85.  
  86. $result = $testDB->close();
  87. if (PEAR::isError($result)) {
  88.     echo $result->getMessage();
  89.     exit;
  90. }
  91. $result = $testDB->drop();
  92. if (PEAR::isError($result)) {
  93.     echo $result->getMessage();
  94.     exit;
  95. }
  96. }
  97.  
  98. ?>
  99.