home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / language / perl / Test / T / Op / Dbm < prev    next >
Encoding:
Text File  |  1991-02-10  |  2.0 KB  |  93 lines

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