DBIx-Custom / t / tmp / dbix-custom-basic-sqlite.t /
Newer Older
69 lines | 1.916kb
Simplify key search
yuki-kimoto authored on 2010-02-11
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
my $ret_val;
48

            
49
use DBIx::Custom::Basic;
50

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

            
56
$ret_val = $dbi->utf8_filter_on;
57
is($dbi->bind_filter, $dbi->filters->{encode_utf8}, 'default bind filter');
58
is($dbi->fetch_filter, $dbi->filters->{decode_utf8}, 'default fetch filter');
59
is(ref $ret_val, 'DBIx::Custom::Basic', "$test : retern value");
60

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

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