| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XAO::testcases::FS::lists; |
|
2
|
1
|
|
|
1
|
|
626
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
3
|
1
|
|
|
1
|
|
573
|
use Error qw(:try); |
|
|
1
|
|
|
|
|
3905
|
|
|
|
1
|
|
|
|
|
5
|
|
|
4
|
1
|
|
|
1
|
|
655
|
use XAO::Utils; |
|
|
1
|
|
|
|
|
14507
|
|
|
|
1
|
|
|
|
|
62
|
|
|
5
|
1
|
|
|
1
|
|
522
|
use XAO::Objects; |
|
|
1
|
|
|
|
|
5259
|
|
|
|
1
|
|
|
|
|
33
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use base qw(XAO::testcases::FS::base); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
446
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new_cust { |
|
10
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
11
|
0
|
|
|
|
|
|
my $nref=shift; |
|
12
|
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
my $odb=$self->get_odb(); |
|
14
|
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $newcust=XAO::Objects->new(objname => 'Data::Customer', |
|
16
|
|
|
|
|
|
|
glue => $odb); |
|
17
|
0
|
|
|
|
|
|
$self->assert(ref($newcust), 'Detached customer creation failure'); |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
$$nref='New Customer - ' . sprintf('%5.2f',rand(100)); |
|
20
|
0
|
|
|
|
|
|
$newcust->put(name => $$nref); |
|
21
|
0
|
|
|
|
|
|
my $got=$newcust->get('name'); |
|
22
|
0
|
|
|
|
|
|
$self->assert($$nref eq $got, "We got ($got) not what we stored ($$nref)"); |
|
23
|
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
$newcust; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
## |
|
28
|
|
|
|
|
|
|
# Checks that two customer objects are different. |
|
29
|
|
|
|
|
|
|
# |
|
30
|
|
|
|
|
|
|
sub check_separation { |
|
31
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
32
|
0
|
|
|
|
|
|
my ($cust1,$clist,$c2id)=@_; |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $cust2=$clist->get($c2id); |
|
35
|
0
|
|
|
|
|
|
$self->assert(ref($cust2), |
|
36
|
|
|
|
|
|
|
"Failure retrieving customer ($c2id)"); |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $name1='c1 name 11'; |
|
39
|
0
|
|
|
|
|
|
my $name2='c2 name 2222'; |
|
40
|
0
|
|
|
|
|
|
$cust1->put(name => $name1); |
|
41
|
0
|
|
|
|
|
|
$cust2->put(name => $name2); |
|
42
|
0
|
|
|
|
|
|
my $got1=$cust1->get('name'); |
|
43
|
0
|
|
|
|
|
|
my $got2=$cust2->get('name'); |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$self->assert($got1 eq $name1, |
|
46
|
|
|
|
|
|
|
"Got ($got1) not what we stored ($name1) (1)"); |
|
47
|
0
|
|
|
|
|
|
$self->assert($got2 eq $name2, |
|
48
|
|
|
|
|
|
|
"Got ($got2) not what we stored ($name2) (2)"); |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$cust2->put(name => $name2); |
|
51
|
0
|
|
|
|
|
|
$cust1->put(name => $name1); |
|
52
|
0
|
|
|
|
|
|
$got1=$cust1->get('name'); |
|
53
|
0
|
|
|
|
|
|
$got2=$cust2->get('name'); |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$self->assert($got1 eq $name1, |
|
56
|
|
|
|
|
|
|
"Got ($got1) not what we stored ($name1) (3)"); |
|
57
|
0
|
|
|
|
|
|
$self->assert($got2 eq $name2, |
|
58
|
|
|
|
|
|
|
"Got ($got2) not what we stored ($name2) (4)"); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
## |
|
62
|
|
|
|
|
|
|
# Puts new hash object into storage under generated name. Checks various |
|
63
|
|
|
|
|
|
|
# key formats. |
|
64
|
|
|
|
|
|
|
# |
|
65
|
|
|
|
|
|
|
sub test_store_nameless_object { |
|
66
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $odb=$self->get_odb(); |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $name; |
|
71
|
0
|
|
|
|
|
|
my $newcust=$self->new_cust(\$name); |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $clist=$odb->fetch('/Customers'); |
|
74
|
0
|
|
|
|
|
|
$self->assert(ref($clist), |
|
75
|
|
|
|
|
|
|
"Can't fetch('Customers')"); |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $id=$clist->put($newcust); |
|
78
|
0
|
|
0
|
|
|
|
$self->assert(defined($id) && $id && $id=~/^\w{1,20}$/, |
|
79
|
|
|
|
|
|
|
"Wrong ID generated ($id)"); |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $got=$odb->fetch("/Customers/$id/name"); |
|
82
|
0
|
|
|
|
|
|
$self->assert($name eq $got, |
|
83
|
|
|
|
|
|
|
"We fetched ($got) not what we stored ($name)"); |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$self->check_separation($newcust,$clist,$id); |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my %matrix=( |
|
88
|
|
|
|
|
|
|
'<$RANDOM$>' => qr/^\w{8}$/, |
|
89
|
|
|
|
|
|
|
'<$RANDOM/20$>' => qr/^\w{20}$/, |
|
90
|
|
|
|
|
|
|
'<$AUTOINC$>' => qr/^\d+$/, |
|
91
|
|
|
|
|
|
|
'X<$AUTOINC/10$>Y' => qr/^X\d{10}Y$/, |
|
92
|
|
|
|
|
|
|
'<$GMTIME$>_<$RANDOM$>' => qr/^\d+_\w{8}$/, |
|
93
|
|
|
|
|
|
|
'RND<$RANDOM$>X<$DATE$>'=> qr/RND\w{8}X\d{14}/, |
|
94
|
|
|
|
|
|
|
); |
|
95
|
0
|
|
|
|
|
|
my $root=$odb->fetch('/'); |
|
96
|
0
|
|
|
|
|
|
foreach my $key_format (keys %matrix) { |
|
97
|
0
|
|
|
|
|
|
my $re=$matrix{$key_format}; |
|
98
|
0
|
|
|
|
|
|
$root->drop_placeholder('Customers'); |
|
99
|
0
|
|
|
|
|
|
$root->build_structure( |
|
100
|
|
|
|
|
|
|
Customers => { |
|
101
|
|
|
|
|
|
|
type => 'list', |
|
102
|
|
|
|
|
|
|
class => 'Data::Customer', |
|
103
|
|
|
|
|
|
|
key => 'customer_id', |
|
104
|
|
|
|
|
|
|
key_format => $key_format, |
|
105
|
|
|
|
|
|
|
structure => { |
|
106
|
|
|
|
|
|
|
name => { |
|
107
|
|
|
|
|
|
|
type => 'text', |
|
108
|
|
|
|
|
|
|
maxlength => 100, |
|
109
|
|
|
|
|
|
|
}, |
|
110
|
|
|
|
|
|
|
}, |
|
111
|
|
|
|
|
|
|
}, |
|
112
|
|
|
|
|
|
|
); |
|
113
|
0
|
|
|
|
|
|
$clist=$root->get('Customers'); |
|
114
|
0
|
|
|
|
|
|
$newcust=$self->new_cust(\$name); |
|
115
|
0
|
|
|
|
|
|
$id=$clist->put($newcust); |
|
116
|
0
|
|
|
|
|
|
$self->assert($id=~$re, |
|
117
|
|
|
|
|
|
|
"Wrong ID generated ($id)"); |
|
118
|
0
|
|
|
|
|
|
$got=$odb->fetch("/Customers/$id/name"); |
|
119
|
0
|
|
|
|
|
|
$self->assert($name eq $got, |
|
120
|
|
|
|
|
|
|
"We fetched ($got) not what we stored ($name)"); |
|
121
|
0
|
|
|
|
|
|
$self->check_separation($newcust,$clist,$id); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
## |
|
126
|
|
|
|
|
|
|
# Puts new hash object into storage under given name |
|
127
|
|
|
|
|
|
|
# |
|
128
|
|
|
|
|
|
|
sub test_store_named_object { |
|
129
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
130
|
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $odb=$self->get_odb(); |
|
132
|
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
my $name; |
|
134
|
0
|
|
|
|
|
|
my $newcust=$self->new_cust(\$name); |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
my $clist=$odb->fetch('/Customers'); |
|
137
|
0
|
|
|
|
|
|
$self->assert(ref($clist), "Can't fetch('Customers')"); |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$clist->put(newcust => $newcust); |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $got=$odb->fetch('/Customers/newcust/name'); |
|
142
|
0
|
|
|
|
|
|
$self->assert($name eq $got, |
|
143
|
|
|
|
|
|
|
"We fetched ($got) not what we stored ($name)"); |
|
144
|
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
$self->check_separation($newcust,$clist,'newcust'); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
## |
|
148
|
|
|
|
|
|
|
# Now checking how replacement works as 'newcust' already exists at |
|
149
|
|
|
|
|
|
|
# this point. |
|
150
|
|
|
|
|
|
|
# |
|
151
|
0
|
|
|
|
|
|
$name='new name'; |
|
152
|
0
|
|
|
|
|
|
$newcust->put(name => $name); |
|
153
|
0
|
|
|
|
|
|
$clist->put(newcust => $newcust); |
|
154
|
0
|
|
|
|
|
|
$got=$odb->fetch('/Customers/newcust/name'); |
|
155
|
0
|
|
|
|
|
|
$self->assert($name eq $got, |
|
156
|
|
|
|
|
|
|
"We fetched ($got) not what we stored ($name)"); |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
$self->check_separation($newcust,$clist,'newcust'); |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub test_cloning { |
|
162
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my $odb=$self->get_odb(); |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
my $c1=$odb->fetch('/Customers/c1'); |
|
167
|
0
|
|
|
|
|
|
$self->assert(ref($c1), "Can't fetch('Customers/c1')"); |
|
168
|
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
my $clist=$odb->fetch('/Customers'); |
|
170
|
0
|
|
|
|
|
|
$self->assert(ref($clist), "Can't fetch('Customers')"); |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
my $id=$clist->put($c1); |
|
173
|
0
|
|
|
|
|
|
my $n1=$c1->get('name'); |
|
174
|
0
|
|
|
|
|
|
my $c2=$clist->get($id); |
|
175
|
0
|
|
|
|
|
|
my $n2=$c2->get('name'); |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
$self->assert($n1 eq $n2, |
|
178
|
|
|
|
|
|
|
"Cloned name ($n2) differs from the original ($n1) (1)"); |
|
179
|
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
$self->check_separation($c1,$clist,$id); |
|
181
|
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
$id=$clist->put(c3 => $c1); |
|
183
|
0
|
|
|
|
|
|
$n1=$c1->get('name'); |
|
184
|
0
|
|
|
|
|
|
$c2=$clist->get($id); |
|
185
|
0
|
|
|
|
|
|
$n2=$c2->get('name'); |
|
186
|
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
$self->assert($n1 eq $n2, |
|
188
|
|
|
|
|
|
|
"Cloned name ($n2) differs from the original ($n1) (2)"); |
|
189
|
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
$self->check_separation($c1,$clist,$id); |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub test_container_key { |
|
194
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
195
|
0
|
|
|
|
|
|
my $odb=$self->get_odb(); |
|
196
|
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
my $clist=$odb->fetch('/Customers'); |
|
198
|
0
|
|
|
|
|
|
my $name=$clist->container_key(); |
|
199
|
0
|
|
|
|
|
|
$self->assert($name eq 'Customers', |
|
200
|
|
|
|
|
|
|
"Container_key returned wrong value ('$name'!='Customers')"); |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub test_keys { |
|
204
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
205
|
0
|
|
|
|
|
|
my $odb=$self->get_odb(); |
|
206
|
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
my $clist=$odb->fetch('/Customers'); |
|
208
|
0
|
|
|
|
|
|
my $keys=join(',',sort $clist->keys); |
|
209
|
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
$self->assert($keys eq 'c1,c2', |
|
211
|
|
|
|
|
|
|
"Customers->keys returned wrong value ('$keys'!='c1,c2')"); |
|
212
|
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
my @v=$clist->values(); |
|
214
|
0
|
|
|
|
|
|
$self->assert(@v == 2, |
|
215
|
|
|
|
|
|
|
"Customers->values returned wrong number of items"); |
|
216
|
|
|
|
|
|
|
} |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub test_exists { |
|
219
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
220
|
0
|
|
|
|
|
|
my $odb=$self->get_odb(); |
|
221
|
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
my $clist=$odb->fetch('/Customers'); |
|
223
|
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
$self->assert($clist->exists('c1'), |
|
225
|
|
|
|
|
|
|
"Exists() returned wrong value for 'c1'"); |
|
226
|
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
$self->assert(! $clist->exists('nonexistent'), |
|
228
|
|
|
|
|
|
|
"Exists() returned wrong value fro 'nonexistent'"); |
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub test_list_describe { |
|
232
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
233
|
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
my $odb = $self->{odb}; |
|
235
|
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
my $list=$odb->fetch('/Customers'); |
|
237
|
|
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
$self->assert($list, "Can't fetch List object"); |
|
239
|
|
|
|
|
|
|
|
|
240
|
0
|
|
|
|
|
|
$self->assert(defined($list->can('describe')), |
|
241
|
|
|
|
|
|
|
"Can't call function 'describe()' on the List object"); |
|
242
|
|
|
|
|
|
|
|
|
243
|
0
|
|
|
|
|
|
my $desc=$list->describe(); |
|
244
|
0
|
|
|
|
|
|
$self->assert(ref($desc) eq 'HASH', |
|
245
|
|
|
|
|
|
|
"List description is not a hash reference"); |
|
246
|
0
|
|
|
|
|
|
$self->assert($desc->{type} eq 'list', |
|
247
|
|
|
|
|
|
|
"Type of Customers is not 'list'"); |
|
248
|
0
|
|
|
|
|
|
$self->assert($desc->{class} eq 'Data::Customer', |
|
249
|
|
|
|
|
|
|
"Class of Customers is not 'Data::Customer'"); |
|
250
|
0
|
|
|
|
|
|
$self->assert($desc->{key} => 'customer_id', |
|
251
|
|
|
|
|
|
|
"Key for Customers is not 'customer_id'"); |
|
252
|
|
|
|
|
|
|
} |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
sub test_wrong_name { |
|
255
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
256
|
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
|
my $odb = $self->{odb}; |
|
258
|
0
|
|
|
|
|
|
my $list=$odb->fetch('/Customers'); |
|
259
|
0
|
|
|
|
|
|
$self->assert($list, "Can't fetch List object"); |
|
260
|
|
|
|
|
|
|
|
|
261
|
0
|
|
|
|
|
|
my $c=$list->get_new; |
|
262
|
|
|
|
|
|
|
|
|
263
|
0
|
|
|
|
|
|
my $flag=0; |
|
264
|
|
|
|
|
|
|
try { |
|
265
|
0
|
|
|
0
|
|
|
$list->put('123-456+789' => $c); |
|
266
|
0
|
|
|
|
|
|
$flag++; |
|
267
|
0
|
|
|
|
|
|
$list->put('123.456#789' => $c); |
|
268
|
0
|
|
|
|
|
|
$flag++; |
|
269
|
0
|
|
|
|
|
|
$list->put('123@456/789' => $c); |
|
270
|
0
|
|
|
|
|
|
$flag++; |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
otherwise { |
|
273
|
0
|
|
|
0
|
|
|
$flag=0; |
|
274
|
0
|
|
|
|
|
|
}; |
|
275
|
|
|
|
|
|
|
|
|
276
|
0
|
|
|
|
|
|
$self->assert($flag == 0, |
|
277
|
|
|
|
|
|
|
"Succeeded in storing under wrong name (flag=$flag)"); |
|
278
|
|
|
|
|
|
|
} |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
1; |