1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
use Test; |
4 |
|
|
BEGIN { plan tests => 48 } |
5 |
|
|
|
6 |
|
|
use Message::DOM::StringExtended qw/find_offset16 find_offset32/; |
7 |
|
|
use Message::Util::Error; |
8 |
|
|
|
9 |
|
|
{ |
10 |
|
|
my @data = ( |
11 |
|
|
'', # 0 |
12 |
|
|
'a', # 1 |
13 |
|
|
'AbEdwerErsArw', # 2 |
14 |
|
|
"A\x{10000}BC", # 3 |
15 |
|
|
"\x{12001}", # 4 |
16 |
|
|
); |
17 |
|
|
|
18 |
|
|
for my $testdata ( |
19 |
|
|
# data, 32, 16 |
20 |
|
|
[0, 0, 0], |
21 |
|
|
[0, 1], |
22 |
|
|
[0, 2], |
23 |
|
|
[0, -1], |
24 |
|
|
[0, -2], |
25 |
|
|
[1, 0, 0], |
26 |
|
|
[1, 1, 1], |
27 |
|
|
[1, 2], |
28 |
|
|
[1, -1], |
29 |
|
|
[1, -2], |
30 |
|
|
[2, 0, 0], |
31 |
|
|
[2, 1, 1], |
32 |
|
|
[2, 13, 13], |
33 |
|
|
[2, 14], |
34 |
|
|
[3, 0, 0], |
35 |
|
|
[3, 1, 1], |
36 |
|
|
[3, 2, 3], |
37 |
|
|
[3, 3, 4], |
38 |
|
|
[3, 4, 5], |
39 |
|
|
[3, 5], |
40 |
|
|
[4, 0, 0], |
41 |
|
|
[4, 1, 2], |
42 |
|
|
[4, 2], |
43 |
|
|
) { |
44 |
|
|
my $label = $testdata->[0] . '.' . $testdata->[1]; |
45 |
|
|
if (defined $testdata->[2]) { |
46 |
|
|
my $return = find_offset16 $data[$testdata->[0]], $testdata->[1]; |
47 |
|
|
ok $return, $testdata->[2], "find_offset16 $label"; |
48 |
|
|
} else { |
49 |
|
|
try { |
50 |
|
|
find_offset16 $data[$testdata->[0]], $testdata->[1]; |
51 |
|
|
} catch Error::Simple with { |
52 |
|
|
my $err = shift; |
53 |
|
|
ok $err->text, "String index out of bounds\n", "find_offset16 $label"; |
54 |
|
|
}; |
55 |
|
|
} |
56 |
|
|
} |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
{ |
60 |
|
|
my @data = ( |
61 |
|
|
'', # 0 |
62 |
|
|
'a', # 1 |
63 |
|
|
'AbEdwerErsArw', # 2 |
64 |
|
|
"A\x{10000}BC", # 3 |
65 |
|
|
"\x{12001}", # 4 |
66 |
|
|
); |
67 |
|
|
|
68 |
|
|
for my $testdata ( |
69 |
|
|
# data, 16, 32 |
70 |
|
|
[0, 0, 0], |
71 |
|
|
[0, 1], |
72 |
|
|
[0, 2], |
73 |
|
|
[0, -1], |
74 |
|
|
[0, -2], |
75 |
|
|
[1, 0, 0], |
76 |
|
|
[1, 1, 1], |
77 |
|
|
[1, 2], |
78 |
|
|
[1, -1], |
79 |
|
|
[1, -2], |
80 |
|
|
[2, 0, 0], |
81 |
|
|
[2, 1, 1], |
82 |
|
|
[2, 13, 13], |
83 |
|
|
[2, 14], |
84 |
|
|
[3, 0, 0], |
85 |
|
|
[3, 1, 1], |
86 |
|
|
[3, 2, 2], |
87 |
|
|
[3, 3, 2], |
88 |
|
|
[3, 4, 3], |
89 |
|
|
[3, 5, 4], |
90 |
|
|
[3, 6], |
91 |
|
|
[4, 0, 0], |
92 |
|
|
[4, 1, 1], |
93 |
|
|
[4, 2, 1], |
94 |
|
|
[4, 3], |
95 |
|
|
) { |
96 |
|
|
my $label = $testdata->[0] . '.' . $testdata->[1]; |
97 |
|
|
if (defined $testdata->[2]) { |
98 |
|
|
my $return = find_offset32 $data[$testdata->[0]], $testdata->[1]; |
99 |
|
|
ok $return, $testdata->[2], "find_offset32 $label"; |
100 |
|
|
} else { |
101 |
|
|
try { |
102 |
|
|
find_offset32 $data[$testdata->[0]], $testdata->[1]; |
103 |
|
|
} catch Error::Simple with { |
104 |
|
|
my $err = shift; |
105 |
|
|
ok $err->text, "String index out of bounds\n", "find_offset32 $label"; |
106 |
|
|
}; |
107 |
|
|
} |
108 |
|
|
} |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
=head1 LICENSE |
112 |
|
|
|
113 |
|
|
Copyright 2007 Wakaba <w@suika.fam.cx> |
114 |
|
|
|
115 |
|
|
This program is free software; you can redistribute it and/or |
116 |
|
|
modify it under the same terms as Perl itself. |
117 |
|
|
|
118 |
|
|
=cut |
119 |
|
|
|
120 |
|
|
## $Date: 2007/06/17 13:37:42 $ |