02-Common-Conf-File.t 1.67 KB
Newer Older
Yadd's avatar
Yadd committed
1
2
3
4
5
6
7
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Lemonldap-NG-Manager.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

Yadd's avatar
Yadd committed
8
9
use strict;
use Test::More;
Christophe Maudoux's avatar
Christophe Maudoux committed
10
use v5.20;
11
BEGIN { use_ok('Lemonldap::NG::Common::Conf') }
Yadd's avatar
Yadd committed
12
13
14
15
16
17

#########################

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

18
my $h;
19

20
ok(
21
    $h = new Lemonldap::NG::Common::Conf(
Yadd's avatar
Yadd committed
22
23
        {
            type    => 'File',
Yadd's avatar
Yadd committed
24
            dirName => "t/",
Yadd's avatar
Yadd committed
25
        }
26
27
    ),
    'type => file',
28
);
Yadd's avatar
Yadd committed
29
my $count = 2;
30

Yadd's avatar
Yadd committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
my @test = (

    #  simple ascii
    { cfgNum => 1, test => 'ascii' },

    #  utf-8
    { cfgNum => 1, test => 'Русский' },

    #  compatible utf8/latin-1 char but with different codes
    { cfgNum => 1, test => 'éà' }
);

for ( my $i = 0 ; $i < @test ; $i++ ) {
    ok( $h->store( $test[$i] ) == 1, "Test $i is stored" )
      or print STDERR "$Lemonldap::NG::Common::Conf::msg $!";
    $count++;
    if ( -x '/usr/bin/file' ) {
        eval {
49
            open F, 'file t/lmConf-1.json |';
Yadd's avatar
Yadd committed
50
51
            $_ = join( '', <F> );
            close F;
Christophe Maudoux's avatar
Christophe Maudoux committed
52
53
            ok( /(ascii|utf-?8)/si, "File is $1 encoded" );
            print STDERR "Result: $_\n";
Yadd's avatar
Yadd committed
54
55
56
57
58
59
            $count++;
        };
    }
    my $cfg;
    ok( $cfg = $h->load(1), "Test $i can be read" )
      or print STDERR $Lemonldap::NG::Common::Conf::msg;
Yadd's avatar
Yadd committed
60
61
    ok( $cfg->{test} eq $test[$i]->{test}, "Test $i is restored" )
      or print STDERR "Expect $cfg->{test} eq $test[$i]->{test}\n";
Yadd's avatar
Yadd committed
62
63
64
    $count += 2;
}

65
unlink 't/lmConf-1.json';
Yadd's avatar
Yadd committed
66
67

done_testing($count);