summaryrefslogtreecommitdiff
path: root/os2/OS2/PrfDB/t/os2_prfdb.t
blob: a8c9752d36a0dd715d503636bd171d5b6ea5b092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
BEGIN {
    chdir 't' if -d 't/lib';
    @INC = '../lib' if -d 'lib';
    require Config; import Config;
    if (-d 'lib' and $Config{'extensions'} !~ /\bOS2(::|\/)PrfDB\b/) {
	print "1..0\n";
	exit 0;
    }
}

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

######################### We start with some black magic to print on failure.

# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)

BEGIN { $| = 1; print "1..48\n"; }
END {print "not ok 1\n" unless $loaded;}
use OS2::PrfDB;
$loaded = 1;
use strict;

print "ok 1\n";

######################### End of black magic.

# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):

my $inifile = "my.ini";

unlink $inifile if -w $inifile;

my $ini = OS2::Prf::Open($inifile);
print( ($ini ? "": "not "), "ok 2\n# HINI=`$ini'\n");

print( (OS2::Prf::GetLength($ini,'aaa', 'bbb') != -1) ? 
    "not ok 3\n# err: `$^E'\n" : "ok 3\n");


print( OS2::Prf::Set($ini,'aaa', 'bbb','xyz') ? "ok 4\n" :
    "not ok 4\n# err: `$^E'\n");

my $len = OS2::Prf::GetLength($ini,'aaa', 'bbb');
print( $len == 3 ? "ok 5\n" : "not ok 5# len: `$len' err: `$^E'\n");

my $val = OS2::Prf::Get($ini,'aaa', 'bbb');
print( $val eq 'xyz' ? "ok 6\n" : "not ok 6# val: `$val' err: `$^E'\n");

$val = OS2::Prf::Get($ini,'aaa', undef);
print( $val eq "bbb\0" ? "ok 7\n" : "not ok 7# val: `$val' err: `$^E'\n");

$val = OS2::Prf::Get($ini, undef, undef);
print( $val eq "aaa\0" ? "ok 8\n" : "not ok 8# val: `$val' err: `$^E'\n");

my $res = OS2::Prf::Set($ini,'aaa', 'bbb',undef);
print( $res ? "ok 9\n" : "not ok 9# err: `$^E'\n");

$val = OS2::Prf::Get($ini, undef, undef);
print( (! defined $val) ? "ok 10\n" : "not ok 10# val: `$val' err: `$^E'\n");

$val = OS2::Prf::Get($ini,'aaa', undef);
print( (! defined $val) ? "ok 11\n" : "not ok 11# val: `$val' err: `$^E'\n");

print((OS2::Prf::Close($ini) ? "" : "not ") . "ok 12\n");

my $files = OS2::Prf::Profiles();
print( (defined $files) ? "ok 13\n" : "not ok 13# err: `$^E'\n");
print( (@$files == 2) ? "ok 14\n" : "not ok 14# `@$files' err: `$^E'\n");
print "# `@$files'\n";

$ini = OS2::Prf::Open($inifile);
print( ($ini ? "": "not "), "ok 15\n# HINI=`$ini'\n");


print( OS2::Prf::Set($ini,'aaa', 'ccc','xyz') ? "ok 16\n" :
    "not ok 16\n# err: `$^E'\n");

print( OS2::Prf::Set($ini,'aaa', 'ddd','123') ? "ok 17\n" :
    "not ok 17\n# err: `$^E'\n");

print( OS2::Prf::Set($ini,'bbb', 'xxx','abc') ? "ok 18\n" :
    "not ok 18\n# err: `$^E'\n");

print( OS2::Prf::Set($ini,'bbb', 'yyy','456') ? "ok 19\n" :
    "not ok 19\n# err: `$^E'\n");

my %hash1;

tie %hash1, 'OS2::PrfDB::Sub', $inifile, 'aaa';
$OS2::PrfDB::Sub::debug = 1;
print "ok 20\n";

my @a1 = keys %hash1;
print (@a1 == 2 ? "ok 21\n" : "not ok 21\n# `@a1'\n");

my @a2 = sort @a1;
print ("@a2" eq "ccc ddd" ? "ok 22\n" : "not ok 22\n# `@a2'\n");

$val = $hash1{ccc};
print ($val eq "xyz" ? "ok 23\n" : "not ok 23\n# `$val'\n");

$val = $hash1{ddd};
print ($val eq "123" ? "ok 24\n" : "not ok 24\n# `$val'\n");

print (exists $hash1{ccc} ? "ok 25\n" : "not ok 25\n# `$val'\n");

print (!exists $hash1{hhh} ? "ok 26\n" : "not ok 26\n# `$val'\n");

$hash1{hhh} = 12;
print (exists $hash1{hhh} ? "ok 27\n" : "not ok 27\n# `$val'\n");

$val = $hash1{hhh};
print ($val eq "12" ? "ok 28\n" : "not ok 28\n# `$val'\n");

delete $hash1{ccc};

untie %hash1;
print "ok 29\n";

tie %hash1, 'OS2::PrfDB::Sub', $inifile, 'aaa';
print "ok 30\n";

@a1 = keys %hash1;
print (@a1 == 2 ? "ok 31\n" : "not ok 31\n# `@a1'\n");

@a2 = sort @a1;
print ("@a2" eq "ddd hhh" ? "ok 32\n" : "not ok 32\n# `@a2'\n");

print (exists $hash1{hhh} ? "ok 33\n" : "not ok 33\n# `$val'\n");

$val = $hash1{hhh};
print ($val eq "12" ? "ok 34\n" : "not ok 34\n# `$val'\n");

%hash1 = ();
print "ok 35\n";

%hash1 = ( hhh => 12, ddd => 5);

untie %hash1;

my %hash;

tie %hash, 'OS2::PrfDB', $inifile;
print "ok 36\n";

@a1 = keys %hash;
print (@a1 == 2 ? "ok 37\n" : "not ok 37\n# `@a1'\n");

@a2 = sort @a1;
print ("@a2" eq "aaa bbb" ? "ok 38\n" : "not ok 38\n# `@a2'\n");

print (exists $hash{aaa} ? "ok 39\n" : "not ok 39\n# `$val'\n");

$val = $hash{aaa};
print (ref $val eq "HASH" ? "ok 40\n" : "not ok 40\n# `$val'\n");

%hash1 = %$val;
print "ok 41\n";

@a1 = keys %hash1;
print (@a1 == 2 ? "ok 42\n" : "not ok 31\n# `@a1'\n");

@a2 = sort @a1;
print ("@a2" eq "ddd hhh" ? "ok 43\n" : "not ok 43\n# `@a2'\n");

print (exists $hash1{hhh} ? "ok 44\n" : "not ok 44\n# `$val'\n");

$val = $hash1{hhh};
print ($val eq "12" ? "ok 45\n" : "not ok 45\n# `$val'\n");

$hash{nnn}{mmm} = 67;
print "ok 46\n";

untie %hash;

my %hash2;

tie %hash2, 'OS2::PrfDB', $inifile;
print "ok 47\n";

print ($hash2{nnn}->{mmm} eq "67" ? "ok 48\n" : "not ok 48\n# `$val'\n");

untie %hash2;
unlink $inifile;