home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / perl / os2perl / dbm.t < prev    next >
Text File  |  1991-04-12  |  2KB  |  106 lines

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