55#include "env-util.h"
66#include "errno-util.h"
77#include "string-util.h"
8+ #include "tests.h"
89
910static void _test_one (int line , const char * input , const char * output ) {
1011 CalendarSpec * c ;
@@ -67,7 +68,7 @@ static void _test_next(int line, const char *input, const char *new_tz, usec_t a
6768}
6869#define test_next (input , new_tz , after , expect ) _test_next(__LINE__, input,new_tz,after,expect)
6970
70- static void test_timestamp ( void ) {
71+ TEST ( timestamp ) {
7172 char buf [FORMAT_TIMESTAMP_MAX ];
7273 _cleanup_free_ char * t = NULL ;
7374 CalendarSpec * c ;
@@ -88,7 +89,7 @@ static void test_timestamp(void) {
8889 assert_se (y == x );
8990}
9091
91- static void test_hourly_bug_4031 ( void ) {
92+ TEST ( hourly_bug_4031 ) {
9293 CalendarSpec * c ;
9394 usec_t n , u , w ;
9495 int r ;
@@ -111,9 +112,7 @@ static void test_hourly_bug_4031(void) {
111112 calendar_spec_free (c );
112113}
113114
114- int main (int argc , char * argv []) {
115- CalendarSpec * c ;
116-
115+ TEST (calendar_spec_one ) {
117116 test_one ("Sat,Thu,Mon-Wed,Sat-Sun" , "Mon..Thu,Sat,Sun *-*-* 00:00:00" );
118117 test_one ("Sat,Thu,Mon..Wed,Sat..Sun" , "Mon..Thu,Sat,Sun *-*-* 00:00:00" );
119118 test_one ("Mon,Sun 12-*-* 2,1:23" , "Mon,Sun 2012-*-* 01,02:23:00" );
@@ -180,7 +179,9 @@ int main(int argc, char* argv[]) {
180179 test_one ("@0 UTC" , "1970-01-01 00:00:00 UTC" );
181180 test_one ("*:05..05" , "*-*-* *:05:00" );
182181 test_one ("*:05..10/6" , "*-*-* *:05:00" );
182+ }
183183
184+ TEST (calendar_spec_next ) {
184185 test_next ("2016-03-27 03:17:00" , "" , 12345 , 1459048620000000 );
185186 test_next ("2016-03-27 03:17:00" , "CET" , 12345 , 1459041420000000 );
186187 test_next ("2016-03-27 03:17:00" , "EET" , 12345 , -1 );
@@ -214,6 +215,10 @@ int main(int argc, char* argv[]) {
214215 /* Check that we don't start looping if mktime() moves us backwards */
215216 test_next ("Sun *-*-* 01:00:00 Europe/Dublin" , "" , 1616412478000000 , 1617494400000000 );
216217 test_next ("Sun *-*-* 01:00:00 Europe/Dublin" , "IST" , 1616412478000000 , 1617494400000000 );
218+ }
219+
220+ TEST (calendar_spec_from_string ) {
221+ CalendarSpec * c ;
217222
218223 assert_se (calendar_spec_from_string ("test" , & c ) < 0 );
219224 assert_se (calendar_spec_from_string (" utc" , & c ) < 0 );
@@ -240,9 +245,6 @@ int main(int argc, char* argv[]) {
240245 assert_se (calendar_spec_from_string ("00:00:2300" , & c ) < 0 );
241246 assert_se (calendar_spec_from_string ("00:00:18446744073709551615" , & c ) < 0 );
242247 assert_se (calendar_spec_from_string ("@88588582097858858" , & c ) == - ERANGE );
243-
244- test_timestamp ();
245- test_hourly_bug_4031 ();
246-
247- return 0 ;
248248}
249+
250+ DEFINE_TEST_MAIN (LOG_INFO );
0 commit comments