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 / anydbm.t next >
Encoding:
Text File  |  1995-10-30  |  2.5 KB  |  117 lines  |  [TEXT/McPL]

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