]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-calendarspec.c
timedatectl: improve english language DST change texts a bit
[thirdparty/systemd.git] / src / test / test-calendarspec.c
CommitLineData
36697dc0
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2012 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <string.h>
23
24#include "calendarspec.h"
25#include "util.h"
26
27static void test_one(const char *input, const char *output) {
28 CalendarSpec *c;
29 char *p;
30 usec_t u;
31 char buf[FORMAT_TIMESTAMP_MAX];
32 int r;
33
34 assert_se(calendar_spec_from_string(input, &c) >= 0);
35
36 assert_se(calendar_spec_to_string(c, &p) >= 0);
37 printf("\"%s\" → \"%s\"\n", input, p);
38
39 assert_se(streq(p, output));
40 free(p);
41
42 u = now(CLOCK_REALTIME);
43 r = calendar_spec_next_usec(c, u, &u);
44 printf("Next: %s\n", r < 0 ? strerror(-r) : format_timestamp(buf, sizeof(buf), u));
45
46 calendar_spec_free(c);
47}
48
49int main(int argc, char* argv[]) {
50 CalendarSpec *c;
51
52 test_one("Sat,Thu,Mon-Wed,Sat-Sun", "Mon-Thu,Sat,Sun *-*-* 00:00:00");
53 test_one("Mon,Sun 12-*-* 2,1:23", "Mon,Sun 2012-*-* 01,02:23:00");
54 test_one("Wed *-1", "Wed *-*-01 00:00:00");
55 test_one("Wed-Wed,Wed *-1", "Wed *-*-01 00:00:00");
56 test_one("Wed, 17:48", "Wed *-*-* 17:48:00");
57 test_one("Wed-Sat,Tue 12-10-15 1:2:3", "Tue-Sat 2012-10-15 01:02:03");
58 test_one("*-*-7 0:0:0", "*-*-07 00:00:00");
59 test_one("10-15", "*-10-15 00:00:00");
60 test_one("monday *-12-* 17:00", "Mon *-12-* 17:00:00");
61 test_one("Mon,Fri *-*-3,1,2 *:30:45", "Mon,Fri *-*-01,02,03 *:30:45");
62 test_one("12,14,13,12:20,10,30", "*-*-* 12,13,14:10,20,30:00");
63 test_one("mon,fri *-1/2-1,3 *:30:45", "Mon,Fri *-01/2-01,03 *:30:45");
64 test_one("03-05 08:05:40", "*-03-05 08:05:40");
65 test_one("08:05:40", "*-*-* 08:05:40");
66 test_one("05:40", "*-*-* 05:40:00");
67 test_one("Sat,Sun 12-05 08:05:40", "Sat,Sun *-12-05 08:05:40");
68 test_one("Sat,Sun 08:05:40", "Sat,Sun *-*-* 08:05:40");
69 test_one("2003-03-05 05:40", "2003-03-05 05:40:00");
70 test_one("2003-03-05", "2003-03-05 00:00:00");
71 test_one("03-05", "*-03-05 00:00:00");
72 test_one("hourly", "*-*-* *:00:00");
73 test_one("daily", "*-*-* 00:00:00");
74 test_one("monthly", "*-*-01 00:00:00");
75 test_one("weekly", "Mon *-*-* 00:00:00");
76 test_one("*:2/3", "*-*-* *:02/3:00");
77
78 assert_se(calendar_spec_from_string("test", &c) < 0);
79 assert_se(calendar_spec_from_string("", &c) < 0);
80 assert_se(calendar_spec_from_string("7", &c) < 0);
81 assert_se(calendar_spec_from_string("121212:1:2", &c) < 0);
82
83 return 0;
84}