File Coverage

blib/lib/XAO/testcases/FS/blobs.pm
Criterion Covered Total %
statement 18 50 36.0
branch n/a
condition n/a
subroutine 6 7 85.7
pod 0 1 0.0
total 24 58 41.3


line stmt bran cond sub pod time code
1             package XAO::testcases::FS::blobs;
2 1     1   682 use strict;
  1         2  
  1         31  
3 1     1   478 use XAO::Utils;
  1         18889  
  1         70  
4 1     1   556 use XAO::Objects;
  1         5828  
  1         45  
5 1     1   7 use Error qw(:try);
  1         3  
  1         6  
6              
7 1     1   131 use base qw(XAO::testcases::FS::base);
  1         3  
  1         473  
8              
9             ###############################################################################
10              
11             sub test_charsets {
12 0     0 0   my $self=shift;
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     1   9 use bytes;
  1         12  
  1         7  
20 0           for(my $len=3; $len<=999999; $len*=10) {
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) {
32 0           my $data='';
33 0           for(my $i=0; $i<$len; ++$i) {
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;