testcases/FS/lists.pm

filter: Statementstmt 11.1% 16 / 144 Branchbran n/a Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 29.4% 5 / 17 Podpod 0.0% 0 / 10 totaltotal 11.6% 21 / 180 SCAR 27.3
CC
4
Cov
11%
test_store_nameless_object
20.0
new_cust
2.0
check_separation
2.0
CRAP 15.4
« testcases/FS/base.pm ↑ Summary testcases/FS/index.pm »
1 package XAO::testcases::FS::lists;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Error qw(:try);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use XAO::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use XAO::Objects;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use base qw(XAO::testcases::FS::base);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new_cust {
10 0 ▶ my $self=shift;
Subroutine new_cust: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶ my $self=shift;
Subroutine check_separation: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶ my $self=shift;
Subroutine test_store_nameless_object: not called CC=4 SCAR=30.0
Pod undocumented
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 ▶ $self->assert(defined($id) && $id && $id=~/^\w{1,20}$/,
Condition0%0/6
defined $id && $id && $id =~ /^\w{1,20}$/
!ll&&!rl&&r
000
defined $id and $id
!ll&&!rl&&r
000
MC/DC0%0/3
defined $id && $id && $id =~ /^\w{1,20}$/
defined $id $id $id =~ /^\w{1,20}$/
Truth table0%0/4
A and B && C
A= defined $idB= $idC= $id =~ /^\w{1,20}$/
ABCresult
0XX0
10X0
1100
1111
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 ▶ my $self=shift;
Subroutine test_store_named_object: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶ my $self=shift;
Subroutine test_cloning: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶ my $self=shift;
Subroutine test_container_key: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶ my $self=shift;
Subroutine test_keys: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶ my $self=shift;
Subroutine test_exists: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶ my $self=shift;
Subroutine test_list_describe: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶ my $self=shift;
Subroutine test_wrong_name: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶ $list->put('123-456+789' => $c);
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 ▶ $flag=0;
Subroutine __ANON__: not called CC=1 SCAR=6.9
274 0 };
275  
276 0 $self->assert($flag == 0,
277 "Succeeded in storing under wrong name (flag=$flag)");
278 }
279  
280 1 1;
« testcases/FS/base.pm ↑ Summary testcases/FS/index.pm »