home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / p / perl4036.zip / t / op / dbm.t < prev    next >
Text File  |  1993-02-26  |  2KB  |  101 lines

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