Test patches for OS/2
[p5sagit/p5-mst-13.2.git] / os2 / OS2 / PrfDB / t / os2_prfdb.t
CommitLineData
760ac839 1BEGIN {
2 chdir 't' if -d 't/lib';
3 @INC = '../lib' if -d 'lib';
4 require Config; import Config;
bbad3607 5 if (-d 'lib' and $Config{'extensions'} !~ /\bOS2(::|\/)PrfDB\b/) {
760ac839 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
91my %hash1;
92
93tie %hash1, 'OS2::PrfDB::Sub', $inifile, 'aaa';
94$OS2::PrfDB::Sub::debug = 1;
95print "ok 20\n";
96
97my @a1 = keys %hash1;
98print (@a1 == 2 ? "ok 21\n" : "not ok 21\n# `@a1'\n");
99
100my @a2 = sort @a1;
101print ("@a2" eq "ccc ddd" ? "ok 22\n" : "not ok 22\n# `@a2'\n");
102
103$val = $hash1{ccc};
104print ($val eq "xyz" ? "ok 23\n" : "not ok 23\n# `$val'\n");
105
106$val = $hash1{ddd};
107print ($val eq "123" ? "ok 24\n" : "not ok 24\n# `$val'\n");
108
109print (exists $hash1{ccc} ? "ok 25\n" : "not ok 25\n# `$val'\n");
110
111print (!exists $hash1{hhh} ? "ok 26\n" : "not ok 26\n# `$val'\n");
112
113$hash1{hhh} = 12;
114print (exists $hash1{hhh} ? "ok 27\n" : "not ok 27\n# `$val'\n");
115
116$val = $hash1{hhh};
117print ($val eq "12" ? "ok 28\n" : "not ok 28\n# `$val'\n");
118
119delete $hash1{ccc};
120
121untie %hash1;
122print "ok 29\n";
123
124tie %hash1, 'OS2::PrfDB::Sub', $inifile, 'aaa';
125print "ok 30\n";
126
127@a1 = keys %hash1;
128print (@a1 == 2 ? "ok 31\n" : "not ok 31\n# `@a1'\n");
129
130@a2 = sort @a1;
131print ("@a2" eq "ddd hhh" ? "ok 32\n" : "not ok 32\n# `@a2'\n");
132
133print (exists $hash1{hhh} ? "ok 33\n" : "not ok 33\n# `$val'\n");
134
135$val = $hash1{hhh};
136print ($val eq "12" ? "ok 34\n" : "not ok 34\n# `$val'\n");
137
138%hash1 = ();
139print "ok 35\n";
140
141%hash1 = ( hhh => 12, ddd => 5);
142
143untie %hash1;
144
145my %hash;
146
147tie %hash, 'OS2::PrfDB', $inifile;
148print "ok 36\n";
149
150@a1 = keys %hash;
151print (@a1 == 2 ? "ok 37\n" : "not ok 37\n# `@a1'\n");
152
153@a2 = sort @a1;
154print ("@a2" eq "aaa bbb" ? "ok 38\n" : "not ok 38\n# `@a2'\n");
155
156print (exists $hash{aaa} ? "ok 39\n" : "not ok 39\n# `$val'\n");
157
158$val = $hash{aaa};
159print (ref $val eq "HASH" ? "ok 40\n" : "not ok 40\n# `$val'\n");
160
161%hash1 = %$val;
162print "ok 41\n";
163
164@a1 = keys %hash1;
165print (@a1 == 2 ? "ok 42\n" : "not ok 31\n# `@a1'\n");
166
167@a2 = sort @a1;
168print ("@a2" eq "ddd hhh" ? "ok 43\n" : "not ok 43\n# `@a2'\n");
169
170print (exists $hash1{hhh} ? "ok 44\n" : "not ok 44\n# `$val'\n");
171
172$val = $hash1{hhh};
173print ($val eq "12" ? "ok 45\n" : "not ok 45\n# `$val'\n");
174
175$hash{nnn}{mmm} = 67;
176print "ok 46\n";
177
178untie %hash;
179
180my %hash2;
181
182tie %hash2, 'OS2::PrfDB', $inifile;
183print "ok 47\n";
184
185print ($hash2{nnn}->{mmm} eq "67" ? "ok 48\n" : "not ok 48\n# `$val'\n");
bbad3607 186
187untie %hash2;
188unlink $inifile;