libamxp  1.4.0
Patterns C Implementation
test_cron.c
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2023 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or without modification,
8 ** are permitted provided that the following conditions are met:
9 **
10 ** 1. Redistributions of source code must retain the above copyright notice,
11 ** this list of conditions and the following disclaimer.
12 **
13 ** 2. Redistributions in binary form must reproduce the above copyright notice,
14 ** this list of conditions and the following disclaimer in the documentation
15 ** and/or other materials provided with the distribution.
16 **
17 ** Subject to the terms and conditions of this license, each copyright holder
18 ** and contributor hereby grants to those receiving rights under this license
19 ** a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
20 ** (except for failure to satisfy the conditions of this license) patent license
21 ** to make, have made, use, offer to sell, sell, import, and otherwise transfer
22 ** this software, where such license applies only to those patent claims, already
23 ** acquired or hereafter acquired, licensable by such copyright holder or contributor
24 ** that are necessarily infringed by:
25 **
26 ** (a) their Contribution(s) (the licensed copyrights of copyright holders and
27 ** non-copyrightable additions of contributors, in source or binary form) alone;
28 ** or
29 **
30 ** (b) combination of their Contribution(s) with the work of authorship to which
31 ** such Contribution(s) was added by such copyright holder or contributor, if,
32 ** at the time the Contribution is added, such addition causes such combination
33 ** to be necessarily infringed. The patent license shall not apply to any other
34 ** combinations which include the Contribution.
35 **
36 ** Except as expressly stated above, no rights or licenses from any copyright
37 ** holder or contributor is granted under this license, whether expressly, by
38 ** implication, estoppel or otherwise.
39 **
40 ** DISCLAIMER
41 **
42 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
51 ** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 **
53 ****************************************************************************/
54 #include <sys/time.h>
55 #include <sys/resource.h>
56 
57 #include <string.h>
58 #include <stdlib.h>
59 #include <stdio.h>
60 #include <stdarg.h>
61 #include <stddef.h>
62 #include <setjmp.h>
63 #include <inttypes.h>
64 #include <limits.h>
65 #include <unistd.h>
66 #include <fcntl.h>
67 #include <cmocka.h>
68 
69 #include <amxc/amxc_macros.h>
70 #include <amxc/amxc.h>
71 #include <amxp/amxp_cron.h>
72 
73 #include "test_cron.h"
74 
75 void test_cron_expr_parser(UNUSED void** state) {
76  amxp_cron_expr_t cron_expr;
77  amxp_cron_init(&cron_expr);
78 
79  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "* * * * * *", NULL), 0);
80  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "* * * ? * *", NULL), 0);
81  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "* * * * * ?", NULL), 0);
82  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "* * * 1/10 JAN,JUN,JUL ?", NULL), 0);
83  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "* * * ? JAN,JUN,JUL MON,WED,FRI", NULL), 0);
84  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "0 10-12 10/10 * * *", NULL), 0);
85  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "0 10-12 10/10 1-5/1 * *", NULL), 0);
86  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "0 0,10,20,30,40,50 12 * * *", NULL), 0);
87  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "* * 10/10 * * 0", NULL), 0);
88  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "* * 10/10 * * 7", NULL), 0);
89  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "0 0 12 ? * SAT,SUN", NULL), 0);
90 
91  amxp_cron_clean(&cron_expr);
92 }
93 
94 void test_cron_expr_build_weekly(UNUSED void** state) {
95  amxp_cron_expr_t cron_expr;
96  amxp_cron_init(&cron_expr);
97 
98  assert_int_equal(amxp_cron_build_weekly(&cron_expr, "15:15", "MONDAY"), 0);
99  assert_int_equal(amxp_cron_build_weekly(&cron_expr, "12:00", "MONDAY,TUESDAY,wednesday,thursday,friday"), 0);
100  assert_int_equal(amxp_cron_build_weekly(&cron_expr, "16:15:20", "monday-friday"), 0);
101  assert_int_equal(amxp_cron_build_weekly(&cron_expr, "", "monday-friday"), 0);
102 
103  amxp_cron_clean(&cron_expr);
104 }
105 
107  amxp_cron_expr_t cron_expr;
108  const char* error = NULL;
109  amxp_cron_init(&cron_expr);
110 
111  assert_int_not_equal(amxp_cron_parse_expr(&cron_expr, "Invalid expression", &error), 0);
112  assert_non_null(error);
113 
114  error = NULL;
115  assert_int_not_equal(amxp_cron_parse_expr(&cron_expr, "* * *", &error), 0);
116  assert_non_null(error);
117 
118  error = NULL;
119  assert_int_not_equal(amxp_cron_parse_expr(NULL, "* * *", &error), 0);
120  assert_non_null(error);
121 
122  error = NULL;
123  assert_int_not_equal(amxp_cron_parse_expr(&cron_expr, NULL, &error), 0);
124  assert_non_null(error);
125 
126  amxp_cron_clean(&cron_expr);
127 }
128 
130  amxp_cron_expr_t cron_expr;
131  const char* error = NULL;
132  amxp_cron_init(&cron_expr);
133 
134  assert_int_not_equal(amxp_cron_parse_expr(&cron_expr, "0 10-12 10/0 * * *", &error), 0);
135  assert_non_null(error);
136 
137  error = NULL;
138  assert_int_not_equal(amxp_cron_parse_expr(&cron_expr, "0 10-12 10/AB * * *", &error), 0);
139  assert_non_null(error);
140 
141  error = NULL;
142  assert_int_not_equal(amxp_cron_parse_expr(&cron_expr, "0 10-12 10/2/3 * * *", &error), 0);
143  assert_non_null(error);
144 
145  error = NULL;
146  assert_int_not_equal(amxp_cron_parse_expr(&cron_expr, "0 10/-12 10 * * *", &error), 0);
147  assert_non_null(error);
148 
149  amxp_cron_clean(&cron_expr);
150 }
151 
153  amxp_cron_expr_t* cron_expr = NULL;
154  const char* error = NULL;
155  amxp_cron_new(&cron_expr);
156  assert_non_null(cron_expr);
157 
158  error = NULL;
159  assert_int_not_equal(amxp_cron_parse_expr(cron_expr, "0 30-12 10 * * *", &error), 0);
160  assert_non_null(error);
161 
162  error = NULL;
163  assert_int_not_equal(amxp_cron_parse_expr(cron_expr, "0 8-40 30-40 * * *", &error), 0);
164  assert_non_null(error);
165 
166  error = NULL;
167  assert_int_not_equal(amxp_cron_parse_expr(cron_expr, "0 12-10 10/2 * * *", &error), 0);
168  assert_non_null(error);
169 
170  error = NULL;
171  assert_int_not_equal(amxp_cron_parse_expr(cron_expr, "0 5-Z 10/2 * * *", &error), 0);
172  assert_non_null(error);
173 
174  error = NULL;
175  assert_int_not_equal(amxp_cron_parse_expr(cron_expr, "0 A-10 10/2 * * *", &error), 0);
176  assert_non_null(error);
177 
178  error = NULL;
179  assert_int_not_equal(amxp_cron_parse_expr(cron_expr, "0 A-B 10/2 * * *", &error), 0);
180  assert_non_null(error);
181 
182  error = NULL;
183  assert_int_not_equal(amxp_cron_parse_expr(cron_expr, "0 10-12-14 10/2 * * *", &error), 0);
184  assert_non_null(error);
185 
186  error = NULL;
187  assert_int_not_equal(amxp_cron_parse_expr(cron_expr, "-5 10-12 10/2 * * *", &error), 0);
188  assert_non_null(error);
189 
190  error = NULL;
191  assert_int_not_equal(amxp_cron_parse_expr(cron_expr, "0 10-12 10/10 0-5/1 * *", &error), 0);
192  assert_non_null(error);
193 
194  amxp_cron_delete(&cron_expr);
195 }
196 
198  amxp_cron_expr_t* cron_expr = NULL;
199  amxc_ts_t start = { 0, 0, 0 };
200  amxc_ts_t next = { 0, 0, 0 };
201  char str_ts[40];
202 
203  amxp_cron_new(&cron_expr);
204  assert_non_null(cron_expr);
205 
206  assert_int_equal(amxp_cron_parse_expr(cron_expr, "* 0 12 1 JAN-DEC/2 *", NULL), 0);
207  assert_non_null(cron_expr);
208 
209  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
210  amxc_ts_format(&start, str_ts, 40);
211  printf("%s\n", str_ts);
212 
213  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
214  amxc_ts_format(&next, str_ts, 40);
215  printf("%s\n", str_ts);
216  assert_string_equal(str_ts, "2023-07-01T12:00:00Z");
217 
218  start = next;
219  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
220  amxc_ts_format(&next, str_ts, 40);
221  printf("%s\n", str_ts);
222  assert_string_equal(str_ts, "2023-07-01T12:00:01Z");
223 
224  start = next;
225  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
226  amxc_ts_format(&next, str_ts, 40);
227  printf("%s\n", str_ts);
228  assert_string_equal(str_ts, "2023-07-01T12:00:02Z");
229 
230  start = next;
231  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
232  amxc_ts_format(&next, str_ts, 40);
233  printf("%s\n", str_ts);
234  assert_string_equal(str_ts, "2023-07-01T12:00:03Z");
235 
236  start = next;
237  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
238  amxc_ts_format(&next, str_ts, 40);
239  printf("%s\n", str_ts);
240  assert_string_equal(str_ts, "2023-07-01T12:00:04Z");
241 
242  start = next;
243  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
244  amxc_ts_format(&next, str_ts, 40);
245  printf("%s\n", str_ts);
246  assert_string_equal(str_ts, "2023-07-01T12:00:05Z");
247 
248  amxp_cron_delete(&cron_expr);
249 }
250 
252  amxp_cron_expr_t* cron_expr = NULL;
253  amxc_ts_t start = { 0, 0, 0 };
254  amxc_ts_t next = { 0, 0, 0 };
255  char str_ts[40];
256 
257  amxp_cron_new(&cron_expr);
258  assert_non_null(cron_expr);
259 
260  assert_int_equal(amxp_cron_parse_expr(cron_expr, "* 0 12 1 JAN-DEC/2 *", NULL), 0);
261  assert_non_null(cron_expr);
262 
263  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
264  amxc_ts_format(&start, str_ts, 40);
265  printf("%s\n", str_ts);
266 
267  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
268  amxc_ts_format(&next, str_ts, 40);
269  printf("%s\n", str_ts);
270  assert_string_equal(str_ts, "2023-05-01T12:00:59Z");
271 
272  start = next;
273  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
274  amxc_ts_format(&next, str_ts, 40);
275  printf("%s\n", str_ts);
276  assert_string_equal(str_ts, "2023-05-01T12:00:58Z");
277 
278  start = next;
279  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
280  amxc_ts_format(&next, str_ts, 40);
281  printf("%s\n", str_ts);
282  assert_string_equal(str_ts, "2023-05-01T12:00:57Z");
283 
284  start = next;
285  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
286  amxc_ts_format(&next, str_ts, 40);
287  printf("%s\n", str_ts);
288  assert_string_equal(str_ts, "2023-05-01T12:00:56Z");
289 
290  start = next;
291  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
292  amxc_ts_format(&next, str_ts, 40);
293  printf("%s\n", str_ts);
294  assert_string_equal(str_ts, "2023-05-01T12:00:55Z");
295 
296  start = next;
297  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
298  amxc_ts_format(&next, str_ts, 40);
299  printf("%s\n", str_ts);
300  assert_string_equal(str_ts, "2023-05-01T12:00:54Z");
301 
302  amxp_cron_delete(&cron_expr);
303 }
304 
306  amxp_cron_expr_t cron_expr;
307  amxc_ts_t start = { 0, 0, 0 };
308  amxc_ts_t next = { 0, 0, 0 };
309  char str_ts[40];
310 
311  amxp_cron_init(&cron_expr);
312 
313  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "0 0,10,20,30,40,50 * * * *", NULL), 0);
314 
315  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
316  amxc_ts_format(&start, str_ts, 40);
317  printf("%s\n", str_ts);
318 
319  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
320  amxc_ts_format(&next, str_ts, 40);
321  printf("%s\n", str_ts);
322  assert_string_equal(str_ts, "2023-05-18T10:10:00Z");
323 
324  start = next;
325  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
326  amxc_ts_format(&next, str_ts, 40);
327  printf("%s\n", str_ts);
328  assert_string_equal(str_ts, "2023-05-18T10:20:00Z");
329 
330  start = next;
331  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
332  amxc_ts_format(&next, str_ts, 40);
333  printf("%s\n", str_ts);
334  assert_string_equal(str_ts, "2023-05-18T10:30:00Z");
335 
336  start = next;
337  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
338  amxc_ts_format(&next, str_ts, 40);
339  printf("%s\n", str_ts);
340  assert_string_equal(str_ts, "2023-05-18T10:40:00Z");
341 
342  start = next;
343  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
344  amxc_ts_format(&next, str_ts, 40);
345  printf("%s\n", str_ts);
346  assert_string_equal(str_ts, "2023-05-18T10:50:00Z");
347 
348  start = next;
349  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
350  amxc_ts_format(&next, str_ts, 40);
351  printf("%s\n", str_ts);
352  assert_string_equal(str_ts, "2023-05-18T11:00:00Z");
353 
354  amxp_cron_clean(&cron_expr);
355 }
356 
358  amxp_cron_expr_t cron_expr;
359  amxc_ts_t start = { 0, 0, 0 };
360  amxc_ts_t next = { 0, 0, 0 };
361  char str_ts[40];
362 
363  amxp_cron_init(&cron_expr);
364 
365  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "0 0,10,20,30,40,50 * * * *", NULL), 0);
366 
367  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
368  amxc_ts_format(&start, str_ts, 40);
369  printf("%s\n", str_ts);
370 
371  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
372  amxc_ts_format(&next, str_ts, 40);
373  printf("%s\n", str_ts);
374  assert_string_equal(str_ts, "2023-05-18T10:00:00Z");
375 
376  start = next;
377  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
378  amxc_ts_format(&next, str_ts, 40);
379  printf("%s\n", str_ts);
380  assert_string_equal(str_ts, "2023-05-18T09:50:00Z");
381 
382  start = next;
383  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
384  amxc_ts_format(&next, str_ts, 40);
385  printf("%s\n", str_ts);
386  assert_string_equal(str_ts, "2023-05-18T09:40:00Z");
387 
388  start = next;
389  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
390  amxc_ts_format(&next, str_ts, 40);
391  printf("%s\n", str_ts);
392  assert_string_equal(str_ts, "2023-05-18T09:30:00Z");
393 
394  start = next;
395  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
396  amxc_ts_format(&next, str_ts, 40);
397  printf("%s\n", str_ts);
398  assert_string_equal(str_ts, "2023-05-18T09:20:00Z");
399 
400  start = next;
401  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
402  amxc_ts_format(&next, str_ts, 40);
403  printf("%s\n", str_ts);
404  assert_string_equal(str_ts, "2023-05-18T09:10:00Z");
405 
406  amxp_cron_clean(&cron_expr);
407 }
408 
410  amxp_cron_expr_t cron_expr;
411  amxc_ts_t start = { 0, 0, 0 };
412  amxc_ts_t next = { 0, 0, 0 };
413  char str_ts[40];
414 
415  amxp_cron_init(&cron_expr);
416 
417  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "0 15 10,12,14 * * *", NULL), 0);
418 
419  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
420  amxc_ts_format(&start, str_ts, 40);
421  printf("%s\n", str_ts);
422 
423  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
424  amxc_ts_format(&next, str_ts, 40);
425  printf("%s\n", str_ts);
426  assert_string_equal(str_ts, "2023-05-18T10:15:00Z");
427 
428  start = next;
429  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
430  amxc_ts_format(&next, str_ts, 40);
431  printf("%s\n", str_ts);
432  assert_string_equal(str_ts, "2023-05-18T12:15:00Z");
433 
434  start = next;
435  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
436  amxc_ts_format(&next, str_ts, 40);
437  printf("%s\n", str_ts);
438  assert_string_equal(str_ts, "2023-05-18T14:15:00Z");
439 
440  start = next;
441  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
442  amxc_ts_format(&next, str_ts, 40);
443  printf("%s\n", str_ts);
444  assert_string_equal(str_ts, "2023-05-19T10:15:00Z");
445 
446  printf("=== USING LOCAL TIME ===\n");
447  amxc_ts_parse(&start, "2023-05-19T12:25:00+02:00", 25);
448  amxc_ts_format(&start, str_ts, 40);
449  printf("%s\n", str_ts);
450 
451  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
452  amxc_ts_format(&next, str_ts, 40);
453  printf("%s\n", str_ts);
454  assert_string_equal(str_ts, "2023-05-19T14:15:00+02:00");
455 
456  start = next;
457  assert_int_equal(amxp_cron_next(&cron_expr, &start, &next), 0);
458  amxc_ts_format(&next, str_ts, 40);
459  printf("%s\n", str_ts);
460  assert_string_equal(str_ts, "2023-05-20T10:15:00+02:00");
461 
462  amxp_cron_clean(&cron_expr);
463 }
464 
466  amxp_cron_expr_t cron_expr;
467  amxc_ts_t start = { 0, 0, 0 };
468  amxc_ts_t next = { 0, 0, 0 };
469  char str_ts[40];
470 
471  amxp_cron_init(&cron_expr);
472 
473  assert_int_equal(amxp_cron_parse_expr(&cron_expr, "0 15 10,12,14 * * *", NULL), 0);
474 
475  amxc_ts_parse(&start, "2023-05-17T14:15:00Z", 20);
476  amxc_ts_format(&start, str_ts, 40);
477  printf("%s\n", str_ts);
478 
479  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
480  amxc_ts_format(&next, str_ts, 40);
481  printf("%s\n", str_ts);
482  assert_string_equal(str_ts, "2023-05-17T12:15:00Z");
483 
484  start = next;
485  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
486  amxc_ts_format(&next, str_ts, 40);
487  printf("%s\n", str_ts);
488  assert_string_equal(str_ts, "2023-05-17T10:15:00Z");
489 
490  start = next;
491  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
492  amxc_ts_format(&next, str_ts, 40);
493  printf("%s\n", str_ts);
494  assert_string_equal(str_ts, "2023-05-16T14:15:00Z");
495 
496  start = next;
497  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
498  amxc_ts_format(&next, str_ts, 40);
499  printf("%s\n", str_ts);
500  assert_string_equal(str_ts, "2023-05-16T12:15:00Z");
501 
502  printf("=== USING LOCAL TIME ===\n");
503  amxc_ts_parse(&start, "2023-05-19T12:25:00+02:00", 25);
504  amxc_ts_format(&start, str_ts, 40);
505  printf("%s\n", str_ts);
506 
507  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
508  amxc_ts_format(&next, str_ts, 40);
509  printf("%s\n", str_ts);
510  assert_string_equal(str_ts, "2023-05-19T12:15:00+02:00");
511 
512  start = next;
513  assert_int_equal(amxp_cron_prev(&cron_expr, &start, &next), 0);
514  amxc_ts_format(&next, str_ts, 40);
515  printf("%s\n", str_ts);
516  assert_string_equal(str_ts, "2023-05-19T10:15:00+02:00");
517 
518  amxp_cron_clean(&cron_expr);
519 }
520 
522  amxp_cron_expr_t* cron_expr = NULL;
523  amxc_ts_t start = { 0, 0, 0 };
524  amxc_ts_t next = { 0, 0, 0 };
525  char str_ts[40];
526 
527  amxp_cron_new(&cron_expr);
528  assert_non_null(cron_expr);
529 
530  assert_int_equal(amxp_cron_parse_expr(cron_expr, "0 0 12 1-31/4 * *", NULL), 0);
531  assert_non_null(cron_expr);
532 
533  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
534  amxc_ts_format(&start, str_ts, 40);
535  printf("%s\n", str_ts);
536 
537  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
538  amxc_ts_format(&next, str_ts, 40);
539  printf("%s\n", str_ts);
540  assert_string_equal(str_ts, "2023-05-21T12:00:00Z");
541 
542  start = next;
543  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
544  amxc_ts_format(&next, str_ts, 40);
545  printf("%s\n", str_ts);
546  assert_string_equal(str_ts, "2023-05-25T12:00:00Z");
547 
548  start = next;
549  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
550  amxc_ts_format(&next, str_ts, 40);
551  printf("%s\n", str_ts);
552  assert_string_equal(str_ts, "2023-05-29T12:00:00Z");
553 
554  start = next;
555  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
556  amxc_ts_format(&next, str_ts, 40);
557  printf("%s\n", str_ts);
558  assert_string_equal(str_ts, "2023-06-01T12:00:00Z");
559 
560  start = next;
561  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
562  amxc_ts_format(&next, str_ts, 40);
563  printf("%s\n", str_ts);
564  assert_string_equal(str_ts, "2023-06-05T12:00:00Z");
565 
566  start = next;
567  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
568  amxc_ts_format(&next, str_ts, 40);
569  printf("%s\n", str_ts);
570  assert_string_equal(str_ts, "2023-06-09T12:00:00Z");
571 
572  amxp_cron_delete(&cron_expr);
573 }
574 
576  amxp_cron_expr_t* cron_expr = NULL;
577  amxc_ts_t start = { 0, 0, 0 };
578  amxc_ts_t next = { 0, 0, 0 };
579  char str_ts[40];
580 
581  amxp_cron_new(&cron_expr);
582  assert_non_null(cron_expr);
583 
584  assert_int_equal(amxp_cron_parse_expr(cron_expr, "0 0 12 1-31/4 * *", NULL), 0);
585  assert_non_null(cron_expr);
586 
587  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
588  amxc_ts_format(&start, str_ts, 40);
589  printf("%s\n", str_ts);
590 
591  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
592  amxc_ts_format(&next, str_ts, 40);
593  printf("%s\n", str_ts);
594  assert_string_equal(str_ts, "2023-05-17T12:00:00Z");
595 
596  start = next;
597  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
598  amxc_ts_format(&next, str_ts, 40);
599  printf("%s\n", str_ts);
600  assert_string_equal(str_ts, "2023-05-13T12:00:00Z");
601 
602  start = next;
603  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
604  amxc_ts_format(&next, str_ts, 40);
605  printf("%s\n", str_ts);
606  assert_string_equal(str_ts, "2023-05-09T12:00:00Z");
607 
608  start = next;
609  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
610  amxc_ts_format(&next, str_ts, 40);
611  printf("%s\n", str_ts);
612  assert_string_equal(str_ts, "2023-05-05T12:00:00Z");
613 
614  start = next;
615  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
616  amxc_ts_format(&next, str_ts, 40);
617  printf("%s\n", str_ts);
618  assert_string_equal(str_ts, "2023-05-01T12:00:00Z");
619 
620  start = next;
621  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
622  amxc_ts_format(&next, str_ts, 40);
623  printf("%s\n", str_ts);
624  assert_string_equal(str_ts, "2023-04-29T12:00:00Z");
625 
626  amxp_cron_delete(&cron_expr);
627 }
628 
630  amxp_cron_expr_t* cron_expr = NULL;
631  amxc_ts_t start = { 0, 0, 0 };
632  amxc_ts_t next = { 0, 0, 0 };
633  char str_ts[40];
634 
635  amxp_cron_new(&cron_expr);
636  assert_non_null(cron_expr);
637 
638  assert_int_equal(amxp_cron_parse_expr(cron_expr, "0 0 12 ? * SAT,SUN", NULL), 0);
639  assert_non_null(cron_expr);
640 
641  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
642  amxc_ts_format(&start, str_ts, 40);
643  printf("%s\n", str_ts);
644 
645  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
646  amxc_ts_format(&next, str_ts, 40);
647  printf("%s\n", str_ts);
648  assert_string_equal(str_ts, "2023-05-20T12:00:00Z");
649 
650  start = next;
651  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
652  amxc_ts_format(&next, str_ts, 40);
653  printf("%s\n", str_ts);
654  assert_string_equal(str_ts, "2023-05-21T12:00:00Z");
655 
656  start = next;
657  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
658  amxc_ts_format(&next, str_ts, 40);
659  printf("%s\n", str_ts);
660  assert_string_equal(str_ts, "2023-05-27T12:00:00Z");
661 
662  start = next;
663  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
664  amxc_ts_format(&next, str_ts, 40);
665  printf("%s\n", str_ts);
666  assert_string_equal(str_ts, "2023-05-28T12:00:00Z");
667 
668  start = next;
669  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
670  amxc_ts_format(&next, str_ts, 40);
671  printf("%s\n", str_ts);
672  assert_string_equal(str_ts, "2023-06-03T12:00:00Z");
673 
674  start = next;
675  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
676  amxc_ts_format(&next, str_ts, 40);
677  printf("%s\n", str_ts);
678  assert_string_equal(str_ts, "2023-06-04T12:00:00Z");
679 
680  amxp_cron_delete(&cron_expr);
681 }
682 
684  amxp_cron_expr_t* cron_expr = NULL;
685  amxc_ts_t start = { 0, 0, 0 };
686  amxc_ts_t next = { 0, 0, 0 };
687  char str_ts[40];
688 
689  amxp_cron_new(&cron_expr);
690  assert_non_null(cron_expr);
691 
692  assert_int_equal(amxp_cron_parse_expr(cron_expr, "0 0 12 ? * SAT,SUN", NULL), 0);
693  assert_non_null(cron_expr);
694 
695  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
696  amxc_ts_format(&start, str_ts, 40);
697  printf("%s\n", str_ts);
698 
699  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
700  amxc_ts_format(&next, str_ts, 40);
701  printf("%s\n", str_ts);
702  assert_string_equal(str_ts, "2023-05-14T12:00:00Z");
703 
704  start = next;
705  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
706  amxc_ts_format(&next, str_ts, 40);
707  printf("%s\n", str_ts);
708  assert_string_equal(str_ts, "2023-05-13T12:00:00Z");
709 
710  start = next;
711  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
712  amxc_ts_format(&next, str_ts, 40);
713  printf("%s\n", str_ts);
714  assert_string_equal(str_ts, "2023-05-07T12:00:00Z");
715 
716  start = next;
717  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
718  amxc_ts_format(&next, str_ts, 40);
719  printf("%s\n", str_ts);
720  assert_string_equal(str_ts, "2023-05-06T12:00:00Z");
721 
722  start = next;
723  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
724  amxc_ts_format(&next, str_ts, 40);
725  printf("%s\n", str_ts);
726  assert_string_equal(str_ts, "2023-04-30T12:00:00Z");
727 
728  start = next;
729  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
730  amxc_ts_format(&next, str_ts, 40);
731  printf("%s\n", str_ts);
732  assert_string_equal(str_ts, "2023-04-29T12:00:00Z");
733 
734  amxp_cron_delete(&cron_expr);
735 }
736 
738  amxp_cron_expr_t* cron_expr = NULL;
739  amxc_ts_t start = { 0, 0, 0 };
740  amxc_ts_t next = { 0, 0, 0 };
741  char str_ts[40];
742 
743  amxp_cron_new(&cron_expr);
744  assert_non_null(cron_expr);
745 
746  assert_int_equal(amxp_cron_parse_expr(cron_expr, "0 0 12 1 JAN-DEC/2 *", NULL), 0);
747  assert_non_null(cron_expr);
748 
749  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
750  amxc_ts_format(&start, str_ts, 40);
751  printf("%s\n", str_ts);
752 
753  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
754  amxc_ts_format(&next, str_ts, 40);
755  printf("%s\n", str_ts);
756  assert_string_equal(str_ts, "2023-07-01T12:00:00Z");
757 
758  start = next;
759  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
760  amxc_ts_format(&next, str_ts, 40);
761  printf("%s\n", str_ts);
762  assert_string_equal(str_ts, "2023-09-01T12:00:00Z");
763 
764  start = next;
765  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
766  amxc_ts_format(&next, str_ts, 40);
767  printf("%s\n", str_ts);
768  assert_string_equal(str_ts, "2023-11-01T12:00:00Z");
769 
770  start = next;
771  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
772  amxc_ts_format(&next, str_ts, 40);
773  printf("%s\n", str_ts);
774  assert_string_equal(str_ts, "2024-01-01T12:00:00Z");
775 
776  start = next;
777  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
778  amxc_ts_format(&next, str_ts, 40);
779  printf("%s\n", str_ts);
780  assert_string_equal(str_ts, "2024-03-01T12:00:00Z");
781 
782  start = next;
783  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
784  amxc_ts_format(&next, str_ts, 40);
785  printf("%s\n", str_ts);
786  assert_string_equal(str_ts, "2024-05-01T12:00:00Z");
787 
788  start = next;
789  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
790  amxc_ts_format(&next, str_ts, 40);
791  printf("%s\n", str_ts);
792  assert_string_equal(str_ts, "2024-07-01T12:00:00Z");
793 
794  start = next;
795  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
796  amxc_ts_format(&next, str_ts, 40);
797  printf("%s\n", str_ts);
798  assert_string_equal(str_ts, "2024-09-01T12:00:00Z");
799 
800  amxp_cron_delete(&cron_expr);
801 }
802 
804  amxp_cron_expr_t* cron_expr = NULL;
805  amxc_ts_t start = { 0, 0, 0 };
806  amxc_ts_t next = { 0, 0, 0 };
807  char str_ts[40];
808 
809  amxp_cron_new(&cron_expr);
810  assert_non_null(cron_expr);
811 
812  assert_int_equal(amxp_cron_parse_expr(cron_expr, "0 0 12 1 JAN-DEC/2 *", NULL), 0);
813  assert_non_null(cron_expr);
814 
815  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
816  amxc_ts_format(&start, str_ts, 40);
817  printf("%s\n", str_ts);
818 
819  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
820  amxc_ts_format(&next, str_ts, 40);
821  printf("%s\n", str_ts);
822  assert_string_equal(str_ts, "2023-05-01T12:00:00Z");
823 
824  start = next;
825  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
826  amxc_ts_format(&next, str_ts, 40);
827  printf("%s\n", str_ts);
828  assert_string_equal(str_ts, "2023-03-01T12:00:00Z");
829 
830  start = next;
831  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
832  amxc_ts_format(&next, str_ts, 40);
833  printf("%s\n", str_ts);
834  assert_string_equal(str_ts, "2023-01-01T12:00:00Z");
835 
836  start = next;
837  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
838  amxc_ts_format(&next, str_ts, 40);
839  printf("%s\n", str_ts);
840  assert_string_equal(str_ts, "2022-11-01T12:00:00Z");
841 
842  start = next;
843  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
844  amxc_ts_format(&next, str_ts, 40);
845  printf("%s\n", str_ts);
846  assert_string_equal(str_ts, "2022-09-01T12:00:00Z");
847 
848  start = next;
849  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
850  amxc_ts_format(&next, str_ts, 40);
851  printf("%s\n", str_ts);
852  assert_string_equal(str_ts, "2022-07-01T12:00:00Z");
853 
854  start = next;
855  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
856  amxc_ts_format(&next, str_ts, 40);
857  printf("%s\n", str_ts);
858  assert_string_equal(str_ts, "2022-05-01T12:00:00Z");
859 
860  start = next;
861  assert_int_equal(amxp_cron_prev(cron_expr, &start, &next), 0);
862  amxc_ts_format(&next, str_ts, 40);
863  printf("%s\n", str_ts);
864  assert_string_equal(str_ts, "2022-03-01T12:00:00Z");
865 
866  amxp_cron_delete(&cron_expr);
867 }
868 
870  amxp_cron_expr_t* cron_expr = NULL;
871  amxc_ts_t start = { 0, 0, 0 };
872  amxc_ts_t next = { 0, 0, 0 };
873  char str_ts[40];
874 
875  amxp_cron_new(&cron_expr);
876  assert_non_null(cron_expr);
877 
878  assert_int_equal(amxp_cron_parse_expr(cron_expr, "0 0 0 1-7 JAN-DEC MON", NULL), 0);
879  assert_non_null(cron_expr);
880 
881  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
882  amxc_ts_format(&start, str_ts, 40);
883  printf("%s\n", str_ts);
884 
885  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
886  amxc_ts_format(&next, str_ts, 40);
887  printf("%s\n", str_ts);
888  assert_string_equal(str_ts, "2023-06-05T00:00:00Z");
889 
890  start = next;
891  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
892  amxc_ts_format(&next, str_ts, 40);
893  printf("%s\n", str_ts);
894  assert_string_equal(str_ts, "2023-07-03T00:00:00Z");
895 
896  start = next;
897  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
898  amxc_ts_format(&next, str_ts, 40);
899  printf("%s\n", str_ts);
900  assert_string_equal(str_ts, "2023-08-07T00:00:00Z");
901 
902  start = next;
903  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
904  amxc_ts_format(&next, str_ts, 40);
905  printf("%s\n", str_ts);
906  assert_string_equal(str_ts, "2023-09-04T00:00:00Z");
907 
908  start = next;
909  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
910  amxc_ts_format(&next, str_ts, 40);
911  printf("%s\n", str_ts);
912  assert_string_equal(str_ts, "2023-10-02T00:00:00Z");
913 
914  start = next;
915  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
916  amxc_ts_format(&next, str_ts, 40);
917  printf("%s\n", str_ts);
918  assert_string_equal(str_ts, "2023-11-06T00:00:00Z");
919 
920  amxp_cron_delete(&cron_expr);
921 }
922 
923 void test_cron_expr_weekly(UNUSED void** state) {
924  amxp_cron_expr_t* cron_expr = NULL;
925  amxc_ts_t start = { 0, 0, 0 };
926  amxc_ts_t next = { 0, 0, 0 };
927  char str_ts[40];
928 
929  amxp_cron_new(&cron_expr);
930  assert_non_null(cron_expr);
931 
932  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
933  amxc_ts_format(&start, str_ts, 40);
934  printf("%s\n", str_ts);
935 
936  amxp_cron_build_weekly(cron_expr, "18:00", "monday,tuesday,thursday,friday");
937  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
938  amxc_ts_format(&next, str_ts, 40);
939  printf("%s\n", str_ts);
940  assert_string_equal(str_ts, "2023-05-18T18:00:00Z");
941 
942  start = next;
943  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
944  amxc_ts_format(&next, str_ts, 40);
945  printf("%s\n", str_ts);
946  assert_string_equal(str_ts, "2023-05-19T18:00:00Z");
947 
948  start = next;
949  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
950  amxc_ts_format(&next, str_ts, 40);
951  printf("%s\n", str_ts);
952  assert_string_equal(str_ts, "2023-05-22T18:00:00Z");
953 
954  start = next;
955  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
956  amxc_ts_format(&next, str_ts, 40);
957  printf("%s\n", str_ts);
958  assert_string_equal(str_ts, "2023-05-23T18:00:00Z");
959 
960  start = next;
961  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
962  amxc_ts_format(&next, str_ts, 40);
963  printf("%s\n", str_ts);
964  assert_string_equal(str_ts, "2023-05-25T18:00:00Z");
965 
966  start = next;
967  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
968  amxc_ts_format(&next, str_ts, 40);
969  printf("%s\n", str_ts);
970  assert_string_equal(str_ts, "2023-05-26T18:00:00Z");
971 
972  start = next;
973  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
974  amxc_ts_format(&next, str_ts, 40);
975  printf("%s\n", str_ts);
976  assert_string_equal(str_ts, "2023-05-29T18:00:00Z");
977 
978  amxp_cron_delete(&cron_expr);
979 }
980 
981 void test_cron_expr_next_empty(UNUSED void** state) {
982  amxp_cron_expr_t* cron_expr = NULL;
983  amxc_ts_t start = { 0, 0, 0 };
984  amxc_ts_t next = { 0, 0, 0 };
985  char str_ts[40];
986 
987  amxp_cron_new(&cron_expr);
988  assert_non_null(cron_expr);
989 
990  amxc_ts_parse(&start, "2023-05-18T10:07:24Z", 20);
991  amxc_ts_format(&start, str_ts, 40);
992  printf("%s\n", str_ts);
993 
994  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
995  amxc_ts_format(&next, str_ts, 40);
996  printf("%s\n", str_ts);
997  assert_string_equal(str_ts, "2023-05-18T10:07:25Z");
998 
999  start = next;
1000  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
1001  amxc_ts_format(&next, str_ts, 40);
1002  printf("%s\n", str_ts);
1003  assert_string_equal(str_ts, "2023-05-18T10:07:26Z");
1004 
1005  start = next;
1006  assert_int_equal(amxp_cron_next(cron_expr, &start, &next), 0);
1007  amxc_ts_format(&next, str_ts, 40);
1008  printf("%s\n", str_ts);
1009  assert_string_equal(str_ts, "2023-05-18T10:07:27Z");
1010 
1011  assert_int_equal(amxp_cron_time_until_next(cron_expr, false), 1);
1012  assert_int_equal(amxp_cron_time_until_next(cron_expr, true), 1);
1013 
1014  amxp_cron_delete(&cron_expr);
1015 }
1016 
1018  amxp_cron_expr_t* cron_expr = NULL;
1019  amxc_ts_t start = { 0, 0, 0 };
1020  amxc_ts_t next = { 0, 0, 0 };
1021 
1022  amxp_cron_new(&cron_expr);
1023  assert_non_null(cron_expr);
1024 
1025  assert_int_not_equal(amxp_cron_next(NULL, &start, &next), 0);
1026 
1027  assert_int_equal(amxp_cron_parse_expr(cron_expr, "* 0 12 1 JAN-DEC/2 *", NULL), 0);
1028  assert_non_null(cron_expr);
1029  assert_int_not_equal(amxp_cron_next(cron_expr, NULL, &next), 0);
1030  assert_int_not_equal(amxp_cron_next(cron_expr, &start, NULL), 0);
1031 
1032  start.sec = -1;
1033  assert_int_not_equal(amxp_cron_next(cron_expr, &start, NULL), 0);
1034 
1035  amxp_cron_delete(&cron_expr);
1036 }
Ambiorix cron expression parser.
#define UNUSED
Definition: main.c:68
int amxp_cron_build_weekly(amxp_cron_expr_t *target, const char *time, const char *days_of_week)
Builds a weekly cron expression that is triggered at a certain time on certain days of the week.
Definition: amxp_cron.c:531
int amxp_cron_init(amxp_cron_expr_t *cron_expr)
Initializes an amxp_cron_expr_t structures to every second.
Definition: amxp_cron.c:466
int64_t amxp_cron_time_until_next(const amxp_cron_expr_t *expr, bool local)
Calculates the time in seconds until next trigger of a parsed cron expression occurs.
Definition: amxp_cron.c:673
int amxp_cron_new(amxp_cron_expr_t **cron_expr)
Allocates an amxp_cron_expr_t structures and initializes it to every second.
Definition: amxp_cron.c:440
int amxp_cron_parse_expr(amxp_cron_expr_t *target, const char *expression, const char **error)
Allocates and initializes an amxp_cron_expr_t structures and parses the given cron expression.
Definition: amxp_cron.c:486
void amxp_cron_clean(amxp_cron_expr_t *cron_expr)
Resets the amxp_cron_expr_t structure to the initialized state.
Definition: amxp_cron.c:477
int amxp_cron_prev(const amxp_cron_expr_t *expr, const amxc_ts_t *ref, amxc_ts_t *next)
Calculates the previous trigger time for a parsed cron expression.
Definition: amxp_cron.c:588
void amxp_cron_delete(amxp_cron_expr_t **cron_expr)
Frees the previously allocated amxp_cron_expr_t structure.
Definition: amxp_cron.c:453
int amxp_cron_next(const amxp_cron_expr_t *expr, const amxc_ts_t *ref, amxc_ts_t *next)
Calculates the next trigger time for a parsed cron expression.
Definition: amxp_cron.c:631
Structure containing parsed cron expression.
Definition: amxp_cron.h:103
void test_cron_expr_can_calculate_prev_minutes(UNUSED void **state)
Definition: test_cron.c:357
void test_cron_expr_can_calculate_next_hours(UNUSED void **state)
Definition: test_cron.c:409
void test_cron_expr_can_calculate_prev_day(UNUSED void **state)
Definition: test_cron.c:575
void test_cron_expr_weekly(UNUSED void **state)
Definition: test_cron.c:923
void test_cron_expr_can_calculate_prev_month(UNUSED void **state)
Definition: test_cron.c:803
void test_cron_expr_can_calculate_next_day_of_week(UNUSED void **state)
Definition: test_cron.c:629
void test_cron_expr_can_calculate_first_monday_of_month(UNUSED void **state)
Definition: test_cron.c:869
void test_cron_expr_can_calculate_next_minutes(UNUSED void **state)
Definition: test_cron.c:305
void test_cron_expr_build_weekly(UNUSED void **state)
Definition: test_cron.c:94
void test_cron_expr_can_calculate_next_second(UNUSED void **state)
Definition: test_cron.c:197
void test_cron_expr_can_calculate_prev_hours(UNUSED void **state)
Definition: test_cron.c:465
void test_cron_expr_parser_invalid_increment(UNUSED void **state)
Definition: test_cron.c:129
void test_cron_expr_parser_invalid_range(UNUSED void **state)
Definition: test_cron.c:152
void test_cron_expr_can_calculate_prev_second(UNUSED void **state)
Definition: test_cron.c:251
void test_cron_expr_can_calculate_next_day(UNUSED void **state)
Definition: test_cron.c:521
void test_cron_expr_next_invalid(UNUSED void **state)
Definition: test_cron.c:1017
void test_cron_expr_can_calculate_prev_day_of_week(UNUSED void **state)
Definition: test_cron.c:683
void test_cron_expr_parser_invalid_expression(UNUSED void **state)
Definition: test_cron.c:106
void test_cron_expr_can_calculate_next_month(UNUSED void **state)
Definition: test_cron.c:737
void test_cron_expr_next_empty(UNUSED void **state)
Definition: test_cron.c:981
void test_cron_expr_parser(UNUSED void **state)
Definition: test_cron.c:75