home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / perl-5.003-src.tgz / tar.out / fsf / perl / t / lib / sdbm.t < prev    next >
Text File  |  1996-09-28  |  3KB  |  120 lines

  1. #!./perl
  2.  
  3. # $RCSfile: dbm.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:43 $
  4.  
  5. BEGIN {
  6.     chdir 't' if -d 't';
  7.     @INC = '../lib';
  8.     require Config; import Config;
  9.     if ($Config{'extensions'} !~ /\bSDBM_File\b/) {
  10.     print "1..0\n";
  11.     exit 0;
  12.     }
  13. }
  14. require SDBM_File;
  15. #If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT
  16. use Fcntl;
  17.  
  18. print "1..12\n";
  19.  
  20. unlink <Op.dbmx*>;
  21.  
  22. umask(0);
  23. print (tie(%h,SDBM_File,'Op.dbmx', O_RDWR|O_CREAT, 0640) ? "ok 1\n" : "not ok 1\n");
  24.  
  25. $Dfile = "Op.dbmx.pag";
  26. if (! -e $Dfile) {
  27.     ($Dfile) = <Op.dbmx*>;
  28. }
  29. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
  30.    $blksize,$blocks) = stat($Dfile);
  31. print (($mode & 0777) == 0640 ? "ok 2\n" : "not ok 2\n");
  32. while (($key,$value) = each(%h)) {
  33.     $i++;
  34. }
  35. print (!$i ? "ok 3\n" : "not ok 3\n");
  36.  
  37. $h{'goner1'} = 'snork';
  38.  
  39. $h{'abc'} = 'ABC';
  40. $h{'def'} = 'DEF';
  41. $h{'jkl','mno'} = "JKL\034MNO";
  42. $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
  43. $h{'a'} = 'A';
  44. $h{'b'} = 'B';
  45. $h{'c'} = 'C';
  46. $h{'d'} = 'D';
  47. $h{'e'} = 'E';
  48. $h{'f'} = 'F';
  49. $h{'g'} = 'G';
  50. $h{'h'} = 'H';
  51. $h{'i'} = 'I';
  52.  
  53. $h{'goner2'} = 'snork';
  54. delete $h{'goner2'};
  55.  
  56. untie(%h);
  57. print (tie(%h,SDBM_File,'Op.dbmx', O_RDWR, 0640) ? "ok 4\n" : "not ok 4\n");
  58.  
  59. $h{'j'} = 'J';
  60. $h{'k'} = 'K';
  61. $h{'l'} = 'L';
  62. $h{'m'} = 'M';
  63. $h{'n'} = 'N';
  64. $h{'o'} = 'O';
  65. $h{'p'} = 'P';
  66. $h{'q'} = 'Q';
  67. $h{'r'} = 'R';
  68. $h{'s'} = 'S';
  69. $h{'t'} = 'T';
  70. $h{'u'} = 'U';
  71. $h{'v'} = 'V';
  72. $h{'w'} = 'W';
  73. $h{'x'} = 'X';
  74. $h{'y'} = 'Y';
  75. $h{'z'} = 'Z';
  76.  
  77. $h{'goner3'} = 'snork';
  78.  
  79. delete $h{'goner1'};
  80. delete $h{'goner3'};
  81.  
  82. @keys = keys(%h);
  83. @values = values(%h);
  84.  
  85. if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";}
  86.  
  87. while (($key,$value) = each(h)) {
  88.     if ($key eq $keys[$i] && $value eq $values[$i] && $key gt $value) {
  89.     $key =~ y/a-z/A-Z/;
  90.     $i++ if $key eq $value;
  91.     }
  92. }
  93.  
  94. if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";}
  95.  
  96. @keys = ('blurfl', keys(h), 'dyick');
  97. if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";}
  98.  
  99. $h{'foo'} = '';
  100. $h{''} = 'bar';
  101.  
  102. # check cache overflow and numeric keys and contents
  103. $ok = 1;
  104. for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
  105. for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
  106. print ($ok ? "ok 8\n" : "not ok 8\n");
  107.  
  108. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
  109.    $blksize,$blocks) = stat($Dfile);
  110. print ($size > 0 ? "ok 9\n" : "not ok 9\n");
  111.  
  112. @h{0..200} = 200..400;
  113. @foo = @h{0..200};
  114. print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n";
  115.  
  116. print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n");
  117. print ($h{''} eq 'bar' ? "ok 12\n" : "not ok 12\n");
  118.  
  119. unlink 'Op.dbmx.dir', $Dfile;
  120.