home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl560.zip / t / lib / anydbm.t < prev    next >
Text File  |  2000-03-02  |  4KB  |  152 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.     unshift @INC, '../lib';
  8. }
  9. require AnyDBM_File;
  10. #If Fcntl is not available, try 0x202 or 0x102 for O_RDWR|O_CREAT
  11. use Fcntl;
  12.  
  13. print "1..12\n";
  14.  
  15. $Is_Dosish = ($^O eq 'amigaos' || $^O eq 'MSWin32' or $^O eq 'dos' or
  16.           $^O eq 'os2' or $^O eq 'mint');
  17.  
  18. unlink <Op_dbmx*>;
  19.  
  20. umask(0);
  21. print (tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR|O_CREAT, 0640)
  22.        ? "ok 1\n" : "not ok 1\n");
  23.  
  24. $Dfile = "Op_dbmx.pag";
  25. if (! -e $Dfile) {
  26.     ($Dfile) = <Op_dbmx*>;
  27. }
  28. if ($Is_Dosish) {
  29.     print "ok 2 # Skipped: different file permission semantics\n";
  30. }
  31. else {
  32.     ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
  33.      $blksize,$blocks) = stat($Dfile);
  34.     print (($mode & 0777) == 0640 ? "ok 2\n" : "not ok 2\n");
  35. }
  36. while (($key,$value) = each(%h)) {
  37.     $i++;
  38. }
  39. print (!$i ? "ok 3\n" : "not ok 3 # i=$i\n\n");
  40.  
  41. $h{'goner1'} = 'snork';
  42.  
  43. $h{'abc'} = 'ABC';
  44. $h{'def'} = 'DEF';
  45. $h{'jkl','mno'} = "JKL\034MNO";
  46. $h{'a',2,3,4,5} = join("\034",'A',2,3,4,5);
  47. $h{'a'} = 'A';
  48. $h{'b'} = 'B';
  49. $h{'c'} = 'C';
  50. $h{'d'} = 'D';
  51. $h{'e'} = 'E';
  52. $h{'f'} = 'F';
  53. $h{'g'} = 'G';
  54. $h{'h'} = 'H';
  55. $h{'i'} = 'I';
  56.  
  57. $h{'goner2'} = 'snork';
  58. delete $h{'goner2'};
  59.  
  60. untie(%h);
  61. print (tie(%h,AnyDBM_File,'Op_dbmx', O_RDWR, 0640) ? "ok 4\n" : "not ok 4\n");
  62.  
  63. $h{'j'} = 'J';
  64. $h{'k'} = 'K';
  65. $h{'l'} = 'L';
  66. $h{'m'} = 'M';
  67. $h{'n'} = 'N';
  68. $h{'o'} = 'O';
  69. $h{'p'} = 'P';
  70. $h{'q'} = 'Q';
  71. $h{'r'} = 'R';
  72. $h{'s'} = 'S';
  73. $h{'t'} = 'T';
  74. $h{'u'} = 'U';
  75. $h{'v'} = 'V';
  76. $h{'w'} = 'W';
  77. $h{'x'} = 'X';
  78. $h{'y'} = 'Y';
  79. $h{'z'} = 'Z';
  80.  
  81. $h{'goner3'} = 'snork';
  82.  
  83. delete $h{'goner1'};
  84. delete $h{'goner3'};
  85.  
  86. @keys = keys(%h);
  87. @values = values(%h);
  88.  
  89. if ($#keys == 29 && $#values == 29) {print "ok 5\n";} else {print "not ok 5\n";}
  90.  
  91. while (($key,$value) = each(%h)) {
  92.     if ($key eq $keys[$i] && $value eq $values[$i] && $key eq lc($value)) {
  93.     $key =~ y/a-z/A-Z/;
  94.     $i++ if $key eq $value;
  95.     }
  96. }
  97.  
  98. if ($i == 30) {print "ok 6\n";} else {print "not ok 6\n";}
  99.  
  100. @keys = ('blurfl', keys(%h), 'dyick');
  101. if ($#keys == 31) {print "ok 7\n";} else {print "not ok 7\n";}
  102.  
  103. $h{'foo'} = '';
  104. $h{''} = 'bar';
  105.  
  106. # check cache overflow and numeric keys and contents
  107. $ok = 1;
  108. for ($i = 1; $i < 200; $i++) { $h{$i + 0} = $i + 0; }
  109. for ($i = 1; $i < 200; $i++) { $ok = 0 unless $h{$i} == $i; }
  110. print ($ok ? "ok 8\n" : "not ok 8\n");
  111.  
  112. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
  113.    $blksize,$blocks) = stat($Dfile);
  114. print ($size > 0 ? "ok 9\n" : "not ok 9\n");
  115.  
  116. @h{0..200} = 200..400;
  117. @foo = @h{0..200};
  118. print join(':',200..400) eq join(':',@foo) ? "ok 10\n" : "not ok 10\n";
  119.  
  120. print ($h{'foo'} eq '' ? "ok 11\n" : "not ok 11\n");
  121. if ($h{''} eq 'bar') {
  122.    print "ok 12\n" ;
  123. }
  124. else {
  125.    if ($AnyDBM_File::ISA[0] eq 'DB_File' && $DB_File::db_ver >= 2.004010) {
  126.      ($major, $minor, $patch) = ($DB_File::db_ver =~ /^(\d+)\.(\d\d\d)(\d\d\d)/) ;
  127.      $major =~ s/^0+// ;
  128.      $minor =~ s/^0+// ;
  129.      $patch =~ s/^0+// ;
  130.      $compact = "$major.$minor.$patch" ;
  131.      #
  132.      # anydbm.t test 12 will fail when AnyDBM_File uses the combination of
  133.      # DB_File and Berkeley DB 2.4.10 (or greater). 
  134.      # You are using DB_File $DB_File::VERSION and Berkeley DB $compact
  135.      #
  136.      # Berkeley DB 2 from version 2.4.10 onwards does not allow null keys.
  137.      # This feature will be reenabled in a future version of Berkeley DB.
  138.      #
  139.      print "ok 12 # skipped: db v$compact, no null key support\n" ;
  140.    }
  141.    else {
  142.      print "not ok 12\n" ;
  143.    }
  144. }
  145.  
  146. untie %h;
  147. if ($^O eq 'VMS') {
  148.   unlink 'Op_dbmx.sdbm_dir', $Dfile;
  149. } else {
  150.   unlink 'Op_dbmx.dir', $Dfile;  
  151. }
  152.