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