home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / Preinstalled MacPerl (FAT) / t / lib / sdbm.t < prev    next >
Encoding:
Text File  |  1995-10-30  |  2.6 KB  |  127 lines  |  [TEXT/McPL]

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