@@ -206,6 +206,13 @@ static const char * const base64_tests[][2] =
206206 };
207207
208208
209+ //
210+ // Local functions...
211+ //
212+
213+ static bool test_date (time_t t );
214+
215+
209216//
210217// 'main()' - Main entry.
211218//
@@ -260,27 +267,14 @@ main(int argc, // I - Number of command-line arguments
260267 failures = 0 ;
261268
262269 // httpGetDateString()/httpGetDateTime()
263- testBegin ("httpGetDateString()/httpGetDateTime()" );
264-
265- start = time (NULL );
266- httpGetDateString (start , buffer , sizeof (buffer ));
267- current = httpGetDateTime (buffer );
268-
269- i = (int )(current - start );
270- if (i < 0 )
271- i = - i ;
272-
273- if (!i )
274- testEnd (true);
275- else
276- {
270+ if (!test_date (0 ))
271+ failures ++ ;
272+ if (!test_date (time (NULL )))
273+ failures ++ ;
274+ if (!test_date (INT_MAX ))
275+ failures ++ ;
276+ if (!test_date (UINT_MAX ))
277277 failures ++ ;
278- testEnd (false);
279- testError ("Difference is %d seconds, %02d:%02d:%02d." , i , i / 3600 , (i / 60 ) % 60 , i % 60 );
280- testError ("httpGetDateString(%d) returned \"%s\"" , (int )start , buffer );
281- testError ("httpGetDateTime(\"%s\") returned %d" , buffer , (int )current );
282- testError ("httpGetDateString(%d) returned \"%s\"" , (int )current , httpGetDateString (current , buffer , sizeof (buffer )));
283- }
284278
285279 // httpDecode64()/httpEncode64()
286280 testBegin ("httpDecode64()/httpEncode64()" );
@@ -872,3 +866,39 @@ main(int argc, // I - Number of command-line arguments
872866
873867 return (0 );
874868}
869+
870+
871+ //
872+ // 'test_date()' - Test the date/time functions for a specific time.
873+ //
874+
875+ static bool // O - `true` on success, `false` on failure
876+ test_date (time_t t ) // I - Time in seconds since Jan 1, 1970
877+ {
878+ char dateval [256 ]; // Date string
879+ time_t timeval ; // Time value
880+
881+
882+ testBegin ("httpGetDateString(%ld)" , (long )t );
883+ if (httpGetDateString (t , dateval , sizeof (dateval )))
884+ {
885+ testEndMessage (true, dateval );
886+ }
887+ else
888+ {
889+ testEnd (false);
890+ return (false);
891+ }
892+
893+ testBegin ("httpGetDateTime(\"%s\")" , dateval );
894+ if ((timeval = httpGetDateTime (dateval )) == t )
895+ {
896+ testEnd (true);
897+ return (true);
898+ }
899+ else
900+ {
901+ testEndMessage (false, "got %ld, expected %ld" , timeval , t );
902+ return (false);
903+ }
904+ }
0 commit comments