testcases/FS/blobs.pm

filter: Statementstmt 37.2% 19 / 51 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 38.4% 25 / 65 SCAR 25.2
CC
5
Cov
33%
test_charsets
24.9
BEGIN
1.0
BEGIN
1.0
CRAP 12.4
« testcases/FS/index.pm ↑ Summary DO/FS/Glue/Base.pm »
1 package XAO::testcases::FS::blobs;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use XAO::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use XAO::Objects;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Error qw(:try);
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 ###############################################################################
10  
11 sub test_charsets {
12 0 ▶ my $self=shift;
Subroutine test_charsets: not called CC=5 SCAR=32.2
Pod undocumented
13  
14 0 my $odb=$self->get_odb();
15  
16 0 my $list=$odb->fetch('/Customers');
17 0 $self->assert(ref($list), "Failure getting c1 reference");
18  
19 1 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 0 ▶ for(my $len=3; $len<=999999; $len*=10) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len <= 999999) 0 0 0
21 ### dprint "Testing blobs, length=$len";
22 0 my $obj=$list->get_new;
23  
24 0 $obj->add_placeholder(
25 name => 'blob',
26 type => 'blob',
27 maxlength => $len,
28 );
29  
30 0 my %expect;
31 0 ▶ for(my $t=1; $t<5; ++$t) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t < 5) 0 0 0
32 0 my $data='';
33 0 ▶ for(my $i=0; $i<$len; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
34 0 $data.=chr(int(rand(256)));
35 }
36 0 $self->assert(length($data)==$len,
37 "Data block we built for len=$len is actually ".length($data)." long");
38 0 $obj->put(blob => $data);
39 0 my $id=$list->put($obj);
40 0 $expect{$id}=$data;
41 }
42  
43 0 foreach my $id (keys %expect) {
44 0 my $got=$list->get($id)->get('blob');
45 0 $self->assert($got eq $expect{$id},
46 "Got wrong blob content for id=$id, len=$len");
47 }
48  
49 0 $obj->drop_placeholder('blob');
50 }
51  
52 # Checking if storing a unicode string works and that we get
53 # back bytes even after storing unicode.
54 #
55 0 if(1) {
56 0 my $obj=$list->get_new;
57  
58 0 $obj->add_placeholder(
59 name => 'blob',
60 type => 'blob',
61 maxlength => 100,
62 );
63  
64 0 my $ta=Encode::decode('utf8',"L\x{e1}minas");
65 0 $obj->put(blob => $ta);
66  
67 0 my $id=$list->put($obj);
68 0 $obj=$list->get($id);
69  
70 0 my $tb=$obj->get('blob');
71  
72 ### dprint "ta=$ta u8.a=".Encode::is_utf8($ta)." tb=$tb u8.b=".Encode::is_utf8($tb);
73  
74 0 $self->assert(Encode::is_utf8($ta),
75 "Expected the initial string '$ta' to be Unicode");
76 0 $self->assert(!Encode::is_utf8($tb),
77 "Expected retrieved string '$tb' to be bytes");
78 0 $self->assert(Encode::encode('utf8',$ta) eq $tb,
79 "Expected strings to match in byte representation");
80  
81 0 $obj->drop_placeholder('blob');
82 }
83 }
84  
85 ###############################################################################
86 1 1;
« testcases/FS/index.pm ↑ Summary DO/FS/Glue/Base.pm »