Commit | Line | Data |
0e9b1cbd |
1 | |
2 | use strict; |
3 | use warnings; |
4 | use Carp; |
5 | |
6 | BEGIN |
7 | { |
8 | |
9 | eval { require Encode; }; |
10 | |
11 | if ($@) { |
12 | print "1..0 # Skip: Encode is not available\n"; |
13 | exit 0; |
14 | } |
15 | } |
16 | |
17 | require "dbm_filter_util.pl"; |
18 | |
19 | use Test::More tests => 20; |
20 | |
21 | BEGIN { use_ok('DBM_Filter') }; |
22 | BEGIN { use_ok('SDBM_File') }; |
23 | BEGIN { use_ok('Fcntl') }; |
24 | BEGIN { use_ok('charnames', qw{greek})}; |
25 | |
26 | use charnames qw{greek}; |
27 | |
28 | unlink <Op_dbmx*>; |
29 | END { unlink <Op_dbmx*>; } |
30 | |
31 | my %h1 = () ; |
32 | my $db1 = tie(%h1, 'SDBM_File','Op_dbmx', O_RDWR|O_CREAT, 0640) ; |
33 | |
34 | ok $db1, "tied to SDBM_File"; |
35 | |
36 | eval { $db1->Filter_Push('utf8') }; |
37 | is $@, '', "push a 'utf8' filter" ; |
38 | |
39 | { |
40 | no warnings 'uninitialized'; |
41 | StoreData(\%h1, |
42 | { |
43 | undef() => undef(), |
44 | "beta" => "\N{beta}", |
45 | 'alpha' => "\N{alpha}", |
46 | "\N{gamma}"=> "gamma", |
47 | }); |
48 | |
49 | } |
50 | |
51 | VerifyData(\%h1, |
52 | { |
53 | 'alpha' => "\N{alpha}", |
54 | "beta" => "\N{beta}", |
55 | "\N{gamma}"=> "gamma", |
56 | "" => "", |
57 | }); |
58 | |
59 | undef $db1; |
60 | { |
61 | use warnings FATAL => 'untie'; |
62 | eval { untie %h1 }; |
63 | is $@, '', "untie without inner references" ; |
64 | } |
65 | |
66 | # read the dbm file without the filter |
67 | my %h2 = () ; |
68 | my $db2 = tie(%h2, 'SDBM_File','Op_dbmx', O_RDWR|O_CREAT, 0640) ; |
69 | |
70 | ok $db2, "tied to SDBM_File"; |
71 | |
72 | VerifyData(\%h2, |
73 | { |
74 | 'alpha' => "\xCE\xB1", |
75 | 'beta' => "\xCE\xB2", |
76 | "\xCE\xB3"=> "gamma", |
77 | "" => "", |
78 | }); |
79 | |
80 | undef $db2; |
81 | { |
82 | use warnings FATAL => 'untie'; |
83 | eval { untie %h2 }; |
84 | is $@, '', "untie without inner references" ; |
85 | } |
86 | |