home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / MacPerl Source ƒ / Perl5 / t / lib / ndbm.t < prev    next >
Encoding:
Text File  |  1995-10-30  |  2.6 KB  |  123 lines  |  [TEXT/MPS ]

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