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