testcases/FS/charsets.pm

filter: Statementstmt 15.8% 16 / 101 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 45.4% 5 / 11 Podpod 0.0% 0 / 4 totaltotal 14.7% 21 / 142 SCAR 48.2
CC
13
Cov
13%
test_charsets
42.0
test_result_charset
20.0
test_native_utf8
20.0
CRAP 124.3
« DO/FS/List.pm ↑ Summary testcases/FS/collection.pm »
1 package XAO::testcases::FS::charsets;
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_result_charset {
12 0 ▶ my $self=shift;
Subroutine test_result_charset: not called CC=4 SCAR=30.0
Pod undocumented
13  
14 0 eval 'use Encode';
15 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
16 0 print STDERR "Encode not available, support for charset is probably broken, not testing\n";
17 0 return;
18 }
19  
20 0 my $odb=$self->get_odb();
21  
22 0 my $cust_list=$odb->fetch('/Customers');
23 0 $cust_list->get_new->add_placeholder(
24 name => 'text1',
25 type => 'text',
26 maxlength => 50,
27 charset => 'utf8',
28 );
29 0 $cust_list->get_new->add_placeholder(
30 name => 'text2',
31 type => 'text',
32 maxlength => 50,
33 charset => 'utf8',
34 );
35  
36 0 my $text1="Smile - \x{263a}";
37 0 my $text2="Omega - \x{03a9}";
38 0 $cust_list->get('c1')->put(
39 text1 => $text1,
40 text2 => $text2,
41 );
42  
43 0 my $sr=$cust_list->search(
44 'text1','ne','',
45 { result => [ qw(text2 text1) ] }
46 );
47  
48 0 ▶ $self->assert(ref $sr && ref $sr eq 'ARRAY',
Condition0%0/3
ref $sr && ref $sr eq 'ARRAY'
!ll&&!rl&&r
000
MC/DC0%0/2
ref $sr && ref $sr eq 'ARRAY'
ref $sr ref $sr eq 'ARRAY'
Truth table0%0/3
A && B
A= ref $srB= ref $sr eq 'ARRAY'
ABresult
0X0
100
111
49 "Expected to get ARRAY ref, got $sr");
50 0 $self->assert(@$sr==1,
51 "Expected to get 1 result, got ".scalar(@$sr));
52 0 ▶ $self->assert(ref $sr->[0] && ref $sr->[0] eq 'ARRAY',
Condition0%0/3
ref $sr->[0] && ref $sr->[0] eq 'ARRAY'
!ll&&!rl&&r
000
MC/DC0%0/2
ref $sr->[0] && ref $sr->[0] eq 'ARRAY'
ref $sr->[0] ref $sr->[0] eq 'ARRAY'
Truth table0%0/3
A && B
A= ref $sr->[0]B= ref $sr->[0] eq 'ARRAY'
ABresult
0X0
100
111
53 "Expected to get and ARR/ARR, got $sr->[0]");
54 0 $self->assert(Encode::is_utf8($sr->[0]->[0]),
55 "Expected to get unicode, got $sr->[0]->[0]");
56 0 $self->assert($sr->[0]->[0] eq $text2,
57 "Expected to get '$text2', got $sr->[0]->[0]");
58 0 $self->assert($sr->[0]->[1] eq $text1,
59 "Expected to get '$text1', got $sr->[0]->[1]");
60 }
61  
62 ###############################################################################
63  
64 sub test_maxlength {
65 0 ▶ my $self=shift;
Subroutine test_maxlength: not called CC=2 SCAR=17.9
Pod undocumented
66  
67 0 eval 'use Encode';
68 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
69 0 print STDERR "Encode not available, support for charset is probably broken, not testing\n";
70 0 return;
71 }
72  
73 0 my $odb=$self->get_odb();
74  
75 0 my $global=$odb->fetch('/');
76 0 $self->assert(ref($global), "Failure getting / reference");
77  
78 0 $global->add_placeholder(
79 name => 'utf8',
80 type => 'text',
81 maxlength => 10,
82 charset => 'utf8',
83 );
84  
85 0 my $text="\x{263a}" x 10;
86 0 $self->assert(length($text) == 10,
87 "Expected the length of '$text' to be 10, got ".length($text)." (perl error?)");
88  
89 0 my $stored;
90 try {
91 0 ▶ $global->put(utf8 => $text);
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 0 $stored=1;
93 }
94 otherwise {
95 0 ▶ my $e=shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 0 dprint "Error storing: $e";
97 0 };
98  
99 0 $self->assert($stored,
100 "Could not store 10 UTF characters into a maxlength=10 field");
101  
102 0 my $got=$global->get('utf8');
103 0 $self->assert($got eq $text,
104 "Expected '$text', got '$got'");
105 }
106  
107 ###############################################################################
108  
109 # as of 6/09/2006 we are supposed to get back perl Unicode strings for
110 # text fields in non-binary encodings.
111  
112 sub test_native_utf8 {
113 0 ▶ my $self=shift;
Subroutine test_native_utf8: not called CC=4 SCAR=30.0
Pod undocumented
114  
115 0 eval 'use Encode';
116 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
117 0 print STDERR "Encode not available, support for charset is probably broken, not testing\n";
118 0 return;
119 }
120  
121 0 my $odb=$self->get_odb();
122  
123 0 my $global=$odb->fetch('/');
124 0 $self->assert(ref($global), "Failure getting / reference");
125  
126 0 my %data=(
127 latin1 => decode('latin1',"Latin1\xC4\xC5\xC6\xC7"),
128 utf8 => "Smile - \x{263a} - omega - \x{03a9}",
129 );
130 0 ▶ if(Encode::resolve_alias('koi8r')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Encode::resolve_alias("koi8r")) 0 0 0
131 0 $data{'koi8r'}="Russian - \x{0430}\x{0431}\x{0432}\x{0433}";
132 }
133  
134 0 foreach my $charset (keys %data) {
135 0 $global->add_placeholder(
136 name => 'text1',
137 type => 'text',
138 maxlength => 50,
139 charset => $charset,
140 );
141 0 $global->add_placeholder(
142 name => 'text2',
143 type => 'text',
144 maxlength => 50,
145 charset => $charset,
146 );
147  
148 0 my $expect=$data{$charset};
149 0 $global->put(text1 => $expect);
150 0 my $got=$global->get('text1');
151  
152 0 $self->assert(Encode::is_utf8($got),
153 "Charset '$charset' - expected perl unicode ($got)");
154 0 $self->assert($got eq $expect,
155 "Charset '$charset' - expected '$expect', got '$got'");
156  
157 0 $global->put(text1 => $expect, text2 => $expect);
158 0 my ($got1,$got2)=$global->get(qw(text1 text2));
159  
160 0 $self->assert($got1 eq $got2,
161 "Charset '$charset' - expected equal results ($got1)<>($got2)");
162 0 $self->assert(Encode::is_utf8($got2),
163 "Charset '$charset' - expected perl unicode ($got2)");
164 0 $self->assert($got2 eq $expect,
165 "Charset '$charset' - expected '$expect', got '$got2'");
166  
167 0 $global->drop_placeholder('text1');
168 0 $global->drop_placeholder('text2');
169 }
170 }
171  
172 ###############################################################################
173  
174 sub test_charsets {
175 0 ▶ my $self=shift;
Subroutine test_charsets: not called CC=6 SCAR=37.4
Pod undocumented
176  
177 0 eval 'use Encode';
178 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
179 0 print STDERR "Encode not available, support for charset is probably broken, not testing\n";
180 0 return;
181 }
182  
183 0 my $odb=$self->get_odb();
184  
185 0 my $global=$odb->fetch('/');
186 0 $self->assert(ref($global), "Failure getting / reference");
187  
188 0 my @charset_list=qw(latin1 utf8 binary);
189 0 ▶ push(@charset_list,'koi8r') if Encode::resolve_alias('koi8r');
Branch: 1 branch
BranchTrueFalseTotal
if &Encode::resolve_alias("koi8r") 0 0 0
190  
191 #TODO: my @charset_list=$odb->charset_list;
192  
193 0 foreach my $charset (@charset_list) {
194 0 $global->add_placeholder(
195 name => 'text',
196 type => 'text',
197 maxlength => 50,
198 charset => $charset,
199 );
200  
201 0 my $text="Smile - \x{263a} - \xe1\xe2\xe3\xe4";
202 0 ▶ my $expect=$charset eq 'binary' ? Encode::encode('utf8',$text)
Branch: 1 branch
BranchTrueFalseTotal
$charset eq 'binary' ? : 0 0 0
203 : Encode::encode($charset,$text);
204  
205 0 $global->put(text => $expect);
206 0 my $got=$global->get('text');
207  
208 0 ▶ if($charset ne 'binary') {
Branch: 1 branch
BranchTrueFalseTotal
if ($charset ne "binary") 0 0 0
209 0 $got=Encode::encode($charset,$got);
210 }
211  
212 0 $self->assert($got eq $expect,
213 "Charset '$charset' - expected '$expect', got '$got'");
214  
215 0 $global->drop_placeholder('text');
216 }
217 }
218  
219 ###############################################################################
220 1 1;
« DO/FS/List.pm ↑ Summary testcases/FS/collection.pm »