DBIx-Custom / t / dbi-custom-basic-sqlite.t /
Newer Older
67 lines | 1.827kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
use Test::More;
2
use strict;
3
use warnings;
4
use utf8;
5
use Encode qw/decode encode/;
6

            
7
BEGIN {
8
    eval { require DBD::SQLite; 1 }
9
        or plan skip_all => 'DBD::SQLite required';
10
    eval { DBD::SQLite->VERSION >= 1 }
11
        or plan skip_all => 'DBD::SQLite >= 1.00 required';
12

            
13
    plan 'no_plan';
14
    use_ok('DBIx::Custom');
15
}
16

            
17
# Function for test name
18
my $test;
19
sub test {
20
    $test = shift;
21
}
22

            
23
# Constant varialbes for test
24
my $CREATE_TABLE = {
25
    0 => 'create table table1 (key1 char(255), key2 char(255));',
26
    1 => 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));',
27
    2 => 'create table table2 (key1 char(255), key3 char(255));'
28
};
29

            
30
my $SELECT_TMPL = {
31
    0 => 'select * from table1;'
32
};
33

            
34
my $DROP_TABLE = {
35
    0 => 'drop table table1'
36
};
37

            
38
my $NEW_ARGS = {
39
    0 => {data_source => 'dbi:SQLite:dbname=:memory:'}
40
};
41

            
42
# Variables for test
43
my $dbi;
44
my $decoded_str;
45
my $encoded_str;
46
my $array;
47

            
48
use DBIx::Custom::Basic;
49

            
50
test 'Filter';
51
$dbi = DBIx::Custom::Basic->new($NEW_ARGS->{0});
52
ok($dbi->filters->{encode_utf8}, "$test : exists default_bind_filter");
53
ok($dbi->filters->{decode_utf8}, "$test : exists default_fetch_filter");
54

            
55
$dbi->utf8_filter_on;
56
is($dbi->bind_filter, $dbi->filters->{encode_utf8}, 'default bind filter');
57
is($dbi->fetch_filter, $dbi->filters->{decode_utf8}, 'default fetch filter');
58

            
59
$decoded_str = 'あ';
60
$encoded_str = $dbi->bind_filter->($decoded_str);
61
is($encoded_str, encode('UTF-8', $decoded_str), "$test : encode utf8");
62
is($decoded_str, $dbi->fetch_filter->($encoded_str), "$test : fetch_filter");
63

            
64
$decoded_str = 'a';
65
$encoded_str = $dbi->bind_filter->($decoded_str);
66
is($encoded_str, encode('UTF-8', $decoded_str), "$test : upgrade and encode utf8");
67
is($decoded_str, $dbi->fetch_filter->($encoded_str), "$test : fetch_filter");