home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl560.zip / os2 / OS2 / PrfDB / t / os2_prfdb.t
Encoding:
Text File  |  1999-07-20  |  4.9 KB  |  191 lines

  1. BEGIN {
  2.     chdir 't' if -d 't/lib';
  3.     @INC = '../lib' if -d 'lib';
  4.     require Config; import Config;
  5.     if (-d 'lib' and $Config{'extensions'} !~ /\bOS2(::|\/)PrfDB\b/) {
  6.     print "1..0\n";
  7.     exit 0;
  8.     }
  9. }
  10.  
  11. # Before `make install' is performed this script should be runnable with
  12. # `make test'. After `make install' it should work as `perl test.pl'
  13.  
  14. ######################### We start with some black magic to print on failure.
  15.  
  16. # Change 1..1 below to 1..last_test_to_print .
  17. # (It may become useful if the test is moved to ./t subdirectory.)
  18.  
  19. BEGIN { $| = 1; print "1..48\n"; }
  20. END {print "not ok 1\n" unless $loaded;}
  21. use OS2::PrfDB;
  22. $loaded = 1;
  23. use strict;
  24.  
  25. print "ok 1\n";
  26.  
  27. ######################### End of black magic.
  28.  
  29. # Insert your test code below (better if it prints "ok 13"
  30. # (correspondingly "not ok 13") depending on the success of chunk 13
  31. # of the test code):
  32.  
  33. my $inifile = "my.ini";
  34.  
  35. unlink $inifile if -w $inifile;
  36.  
  37. my $ini = OS2::Prf::Open($inifile);
  38. print( ($ini ? "": "not "), "ok 2\n# HINI=`$ini'\n");
  39.  
  40. print( (OS2::Prf::GetLength($ini,'aaa', 'bbb') != -1) ? 
  41.     "not ok 3\n# err: `$^E'\n" : "ok 3\n");
  42.  
  43.  
  44. print( OS2::Prf::Set($ini,'aaa', 'bbb','xyz') ? "ok 4\n" :
  45.     "not ok 4\n# err: `$^E'\n");
  46.  
  47. my $len = OS2::Prf::GetLength($ini,'aaa', 'bbb');
  48. print( $len == 3 ? "ok 5\n" : "not ok 5# len: `$len' err: `$^E'\n");
  49.  
  50. my $val = OS2::Prf::Get($ini,'aaa', 'bbb');
  51. print( $val eq 'xyz' ? "ok 6\n" : "not ok 6# val: `$val' err: `$^E'\n");
  52.  
  53. $val = OS2::Prf::Get($ini,'aaa', undef);
  54. print( $val eq "bbb\0" ? "ok 7\n" : "not ok 7# val: `$val' err: `$^E'\n");
  55.  
  56. $val = OS2::Prf::Get($ini, undef, undef);
  57. print( $val eq "aaa\0" ? "ok 8\n" : "not ok 8# val: `$val' err: `$^E'\n");
  58.  
  59. my $res = OS2::Prf::Set($ini,'aaa', 'bbb',undef);
  60. print( $res ? "ok 9\n" : "not ok 9# err: `$^E'\n");
  61.  
  62. $val = OS2::Prf::Get($ini, undef, undef);
  63. print( (! defined $val) ? "ok 10\n" : "not ok 10# val: `$val' err: `$^E'\n");
  64.  
  65. $val = OS2::Prf::Get($ini,'aaa', undef);
  66. print( (! defined $val) ? "ok 11\n" : "not ok 11# val: `$val' err: `$^E'\n");
  67.  
  68. print((OS2::Prf::Close($ini) ? "" : "not ") . "ok 12\n");
  69.  
  70. my $files = OS2::Prf::Profiles();
  71. print( (defined $files) ? "ok 13\n" : "not ok 13# err: `$^E'\n");
  72. print( (@$files == 2) ? "ok 14\n" : "not ok 14# `@$files' err: `$^E'\n");
  73. print "# `@$files'\n";
  74.  
  75. $ini = OS2::Prf::Open($inifile);
  76. print( ($ini ? "": "not "), "ok 15\n# HINI=`$ini'\n");
  77.  
  78.  
  79. print( OS2::Prf::Set($ini,'aaa', 'ccc','xyz') ? "ok 16\n" :
  80.     "not ok 16\n# err: `$^E'\n");
  81.  
  82. print( OS2::Prf::Set($ini,'aaa', 'ddd','123') ? "ok 17\n" :
  83.     "not ok 17\n# err: `$^E'\n");
  84.  
  85. print( OS2::Prf::Set($ini,'bbb', 'xxx','abc') ? "ok 18\n" :
  86.     "not ok 18\n# err: `$^E'\n");
  87.  
  88. print( OS2::Prf::Set($ini,'bbb', 'yyy','456') ? "ok 19\n" :
  89.     "not ok 19\n# err: `$^E'\n");
  90.  
  91. OS2::Prf::Close($ini);
  92.  
  93. my %hash1;
  94.  
  95. tie %hash1, 'OS2::PrfDB::Sub', $inifile, 'aaa';
  96. $OS2::PrfDB::Sub::debug = 1;
  97. print "ok 20\n";
  98.  
  99. my @a1 = keys %hash1;
  100. print (@a1 == 2 ? "ok 21\n" : "not ok 21\n# `@a1'\n");
  101.  
  102. my @a2 = sort @a1;
  103. print ("@a2" eq "ccc ddd" ? "ok 22\n" : "not ok 22\n# `@a2'\n");
  104.  
  105. $val = $hash1{ccc};
  106. print ($val eq "xyz" ? "ok 23\n" : "not ok 23\n# `$val'\n");
  107.  
  108. $val = $hash1{ddd};
  109. print ($val eq "123" ? "ok 24\n" : "not ok 24\n# `$val'\n");
  110.  
  111. print (exists $hash1{ccc} ? "ok 25\n" : "not ok 25\n# `$val'\n");
  112.  
  113. print (!exists $hash1{hhh} ? "ok 26\n" : "not ok 26\n# `$val'\n");
  114.  
  115. $hash1{hhh} = 12;
  116. print (exists $hash1{hhh} ? "ok 27\n" : "not ok 27\n# `$val'\n");
  117.  
  118. $val = $hash1{hhh};
  119. print ($val eq "12" ? "ok 28\n" : "not ok 28\n# `$val'\n");
  120.  
  121. delete $hash1{ccc};
  122.  
  123. untie %hash1;
  124. print "ok 29\n";
  125.  
  126. tie %hash1, 'OS2::PrfDB::Sub', $inifile, 'aaa';
  127. print "ok 30\n";
  128.  
  129. @a1 = keys %hash1;
  130. print (@a1 == 2 ? "ok 31\n" : "not ok 31\n# `@a1'\n");
  131.  
  132. @a2 = sort @a1;
  133. print ("@a2" eq "ddd hhh" ? "ok 32\n" : "not ok 32\n# `@a2'\n");
  134.  
  135. print (exists $hash1{hhh} ? "ok 33\n" : "not ok 33\n# `$val'\n");
  136.  
  137. $val = $hash1{hhh};
  138. print ($val eq "12" ? "ok 34\n" : "not ok 34\n# `$val'\n");
  139.  
  140. %hash1 = ();
  141. print "ok 35\n";
  142.  
  143. %hash1 = ( hhh => 12, ddd => 5);
  144.  
  145. untie %hash1;
  146.  
  147. my %hash;
  148.  
  149. tie %hash, 'OS2::PrfDB', $inifile;
  150. print "ok 36\n";
  151.  
  152. @a1 = keys %hash;
  153. print (@a1 == 2 ? "ok 37\n" : "not ok 37\n# `@a1'\n");
  154.  
  155. @a2 = sort @a1;
  156. print ("@a2" eq "aaa bbb" ? "ok 38\n" : "not ok 38\n# `@a2'\n");
  157.  
  158. print (exists $hash{aaa} ? "ok 39\n" : "not ok 39\n# `$val'\n");
  159.  
  160. $val = $hash{aaa};
  161. print (ref $val eq "HASH" ? "ok 40\n" : "not ok 40\n# `$val'\n");
  162.  
  163. %hash1 = %$val;
  164. print "ok 41\n";
  165.  
  166. @a1 = keys %hash1;
  167. print (@a1 == 2 ? "ok 42\n" : "not ok 31\n# `@a1'\n");
  168.  
  169. @a2 = sort @a1;
  170. print ("@a2" eq "ddd hhh" ? "ok 43\n" : "not ok 43\n# `@a2'\n");
  171.  
  172. print (exists $hash1{hhh} ? "ok 44\n" : "not ok 44\n# `$val'\n");
  173.  
  174. $val = $hash1{hhh};
  175. print ($val eq "12" ? "ok 45\n" : "not ok 45\n# `$val'\n");
  176.  
  177. $hash{nnn}{mmm} = 67;
  178. print "ok 46\n";
  179.  
  180. untie %hash;
  181.  
  182. my %hash2;
  183.  
  184. tie %hash2, 'OS2::PrfDB', $inifile;
  185. print "ok 47\n";
  186.  
  187. print ($hash2{nnn}->{mmm} eq "67" ? "ok 48\n" : "not ok 48\n# `$val'\n");
  188.  
  189. untie %hash2;
  190. unlink $inifile;
  191.