Enhanced DBM Filters
[p5sagit/p5-mst-13.2.git] / lib / DBM_Filter / t / utf8.t
CommitLineData
0e9b1cbd 1
2use strict;
3use warnings;
4use Carp;
5
6BEGIN
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
17require "dbm_filter_util.pl";
18
19use Test::More tests => 20;
20
21BEGIN { use_ok('DBM_Filter') };
22BEGIN { use_ok('SDBM_File') };
23BEGIN { use_ok('Fcntl') };
24BEGIN { use_ok('charnames', qw{greek})};
25
26use charnames qw{greek};
27
28unlink <Op_dbmx*>;
29END { unlink <Op_dbmx*>; }
30
31my %h1 = () ;
32my $db1 = tie(%h1, 'SDBM_File','Op_dbmx', O_RDWR|O_CREAT, 0640) ;
33
34ok $db1, "tied to SDBM_File";
35
36eval { $db1->Filter_Push('utf8') };
37is $@, '', "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
51VerifyData(\%h1,
52 {
53 'alpha' => "\N{alpha}",
54 "beta" => "\N{beta}",
55 "\N{gamma}"=> "gamma",
56 "" => "",
57 });
58
59undef $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
67my %h2 = () ;
68my $db2 = tie(%h2, 'SDBM_File','Op_dbmx', O_RDWR|O_CREAT, 0640) ;
69
70ok $db2, "tied to SDBM_File";
71
72VerifyData(\%h2,
73 {
74 'alpha' => "\xCE\xB1",
75 'beta' => "\xCE\xB2",
76 "\xCE\xB3"=> "gamma",
77 "" => "",
78 });
79
80undef $db2;
81{
82 use warnings FATAL => 'untie';
83 eval { untie %h2 };
84 is $@, '', "untie without inner references" ;
85}
86