]>
git.proxmox.com Git - pve-common.git/blob - test/calendar_event_test.pl
11 use PVE
::CalendarEvent
;
13 # Time tests should run in a controlled setting
17 my $alldays = [0,1,2,3,4,5,6];
21 { h
=> '*', m
=> '*', dow
=> $alldays },
31 { h
=> '*', m
=> [0, 10, 20, 30, 40, 50], dow
=> $alldays },
41 { h
=> [0, 12], m
=> [0], dow
=> $alldays },
49 { h
=> [1, 13], m
=> [0, 15, 30, 45], dow
=> $alldays },
53 [3600+16*60, 3600+30*60 ],
54 [3600+30*60, 3600+45*60 ],
55 [3600+45*60, 3600+12*3600],
56 [13*3600 + 1, 13*3600+15*60],
57 [13*3600 + 15*60, 13*3600+30*60],
58 [13*3600 + 30*60, 13*3600+45*60],
59 [13*3600 + 45*60, 25*3600],
64 { h
=> '*', m
=> [1, 4, 6], dow
=> $alldays},
74 { h
=> '*', m
=> [ 0, 1, 2, 3 ], dow
=> $alldays },
78 { h
=> [ 23 ], m
=> [ 0, 1, 2, 3 ], dow
=> $alldays },
82 { h
=> [0], m
=> [0], dow
=> [1] },
84 [0, 4*86400], # Note: Epoch 0 is Thursday, 1. January 1970
91 { h
=> [0], m
=> [0], dow
=> [0, 6] },
100 { h
=> [0], m
=> [0], dow
=> $alldays },
104 { error
=> "wrong order in range 'Fri..Mon'" },
108 { h
=> [0], m
=> [0], dow
=> [ 1, 2, 3, 5] },
112 { h
=> '*', m
=> [0, 15, 30, 45], dow
=> [1]},
116 { h
=> [22, 23], m
=> [0], dow
=> $alldays },
119 [22*60*60, 23*60*60],
120 [22*60*60 + 59*60, 23*60*60]
125 { h
=> [0,2,4,6,8,10,12,14,16,18,20,22], m
=> '*', dow
=> $alldays },
129 [2*60*60, 2*60*60 + 60]
134 { h
=> [20,21,22], m
=> [0,30], dow
=> $alldays },
137 [20*60*60, 20*60*60 + 30*60],
138 [22*60*60 + 30*60, 44*60*60]
143 { error
=> "value '61' out of range" },
147 { error
=> "repetition '61' out of range" },
151 { error
=> "range end '80' out of range" },
155 { error
=> "unable to parse calendar event - unused parts" },
159 { error
=> "unable to parse calendar event - event is empty" },
163 { error
=> "unable to parse calendar event - unused parts" },
167 { h
=> '*', m
=> [0,1,3,4,5], dow
=> $alldays },
176 { h
=> [2,4], m
=> [0,1,3,4,5], dow
=> $alldays },
179 [2*60*60 + 60, 2*60*60 + 3*60],
180 [2*60*60 + 5*60, 4*60*60]
185 foreach my $test (@$tests) {
186 my ($t, $expect, $nextsync) = @$test;
189 eval { $timespec = PVE
::CalendarEvent
::parse_calendar_event
($t); };
191 delete $timespec->{utc
};
193 if ($expect->{error
}) {
195 $timespec = { error
=> $err } if $err;
196 is_deeply
($timespec, $expect, "expect parse error on '$t' - $expect->{error}");
197 die "unable to execute nextsync tests" if $nextsync;
199 is_deeply
($timespec, $expect, "parse '$t'");
204 foreach my $nt (@$nextsync) {
205 my ($last, $expect_next) = @$nt;
206 my $msg = "next event '$t' $last => ${expect_next}";
207 $timespec->{utc
} = 1;
208 my $next = PVE
::CalendarEvent
::compute_next_event
($timespec, $last);
209 is($next, $expect_next, $msg);
214 my ($calspec, $last) = @_;
215 my $spec = PVE
::CalendarEvent
::parse_calendar_event
($calspec);
216 return PVE
::CalendarEvent
::compute_next_event
($spec, $last);
219 # Test loop termination at CEST/CET switch (cannot happen here in UTC)
220 is(tztest
('mon..fri', timelocal
(0, 0, 0, 28, 9, 2018)),
221 timelocal
(0, 0, 0, 29, 9, 2018));
222 is(tztest
('mon..fri UTC', timelocal
(0, 0, 0, 28, 9, 2018)),
223 timelocal
(0, 0, 0, 29, 9, 2018));
225 # Now in the affected time zone
226 $ENV{TZ
} = ':Europe/Vienna';
228 is(tztest
('mon..fri', timelocal
(0, 0, 0, 28, 9, 2018)),
229 timelocal
(0, 0, 0, 29, 9, 2018));
230 # Specifically requesting UTC in the calendar spec means the resulting output
231 # time as seen locally (timelocal() as opposed to timegm()) is shifted by 1
233 is(tztest
('mon..fri UTC', timelocal
(0, 0, 0, 28, 9, 2018)),
234 timelocal
(0, 0, 1, 29, 9, 2018));