aboutsummaryrefslogtreecommitdiffstats
path: root/t/04-Shared_TimeZone.t
blob: c96165a4b742e6810e1fa8698e2beaf2ab0db3bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use 5.006;
use strict;
use warnings FATAL => 'all';
use Test::More;
use Data::Dumper;
use Time::Piece;

BEGIN {
    use_ok( 'ManaTools::Shared::TimeZone' ) || print "ManaTools::Shared::TimeZone failed!\n";
}

    ok( my $tz = ManaTools::Shared::TimeZone->new(), 'create');
    is( $tz->get_timezone_prefix(), '/usr/share/zoneinfo', 'get_timezone_prefix' );
    ok (my @l = $tz->getTimeZones(), 'getTimeZones');
    ok (my $h = $tz->readConfiguration(), 'readConfiguration');
    diag Dumper($h);
    ok (my $services = $tz->ntpServiceList(), 'ntpServiceList');
    diag Dumper($services);
    ok ($tz->refreshNTPServiceList(), 'refreshNTPServiceList');
    ok ($services = $tz->ntpServiceList(), 'ntpServiceList after refresh');
    diag Dumper($services);
    ok (my $currService = $tz->ntp_program(), 'ntp_program');
    diag "ntp_program got: < " . $currService . " >";
    ok (my $a = ($tz->isNTPRunning() ? "running" : "not running"), 'isNTPRunning');
    diag "Check if " . $currService . " is running got: < " . $a . " >";
    ok (my $s = $tz->ntpCurrentServer(), 'currentNTPServer');
    diag "ntpCurrentServer got: < " . ($s ? $s : "none") . " >";
    ok (my @pairs = $tz->ntpServiceConfigPairs(), 'ntpServiceConfigPairs');
    diag Dumper(@pairs);
    for my $pair (@pairs) {
        is ($tz->getNTPServiceConfig($pair->[0]), $pair->[1], "ntpServiceConfigPairs $pair->[0]");
    }

    SKIP: {
        #remember to skip the right number of tests
        skip "To enable dialog tests set TEST_SET_DBUS", 3, unless $ENV{TEST_SET_DBUS};
        eval {$tz->setLocalRTC(!$h->{UTC})};
        is ($@, "", 'setLocalRTC' );
        eval {$tz->setTimeZone($h->{ZONE})};
        is ($@, "", 'setTimeZone');
        my $t = localtime;
        eval {$tz->setTime($t->epoch())};
        is ($@, "", 'setTime');
    }
done_testing;