# HG changeset patch # User Mike Miller # Date 1411330105 14400 # Node ID b8bd0b55af45883fa7e6df46ce5716afe943335a # Parent 25ab600d16fd69ac0e8e86a47bcbd83262945c86 codesprint: Add tests to time handling functions * time.cc: Add tests and input validation for time, mktime, strftime, and strptime. diff -r 25ab600d16fd -r b8bd0b55af45 libinterp/corefcn/time.cc --- a/libinterp/corefcn/time.cc Sun Sep 21 12:56:25 2014 -0700 +++ b/libinterp/corefcn/time.cc Sun Sep 21 16:08:25 2014 -0400 @@ -123,6 +123,8 @@ /* %!assert (time () > 0) + +%!error time (1) */ DEFUN (gmtime, args, , @@ -299,7 +301,9 @@ %!assert (datestr (datenum (1795, 1, 1), 0), "01-Jan-1795 00:00:00") %!error mktime () +%!error mktime (1) %!error mktime (1, 2, 3) +%!error mktime (struct ("year", "foo")) */ DEFUN (strftime, args, , @@ -494,6 +498,8 @@ %!assert (ischar (strftime ("%m%U%w%W%x%y%Y", localtime (time ())))); %!error strftime () +%!error strftime ("foo", 1) +%!error strftime ("foo", struct ("year", "foo")) %!error strftime ("foo", localtime (time ()), 1) */ @@ -537,3 +543,23 @@ return retval; } + +/* +%!test +%! fmt = "%Y-%m-%d %H:%M:%S"; +%! s = strftime (fmt, localtime (time ())); +%! ts = strptime (s, fmt); +%! assert (isstruct (ts)); +%! assert (isfield (ts, "usec")); +%! assert (isfield (ts, "year")); +%! assert (isfield (ts, "mon")); +%! assert (isfield (ts, "mday")); +%! assert (isfield (ts, "sec")); +%! assert (isfield (ts, "min")); +%! assert (isfield (ts, "wday")); +%! assert (isfield (ts, "hour")); +%! assert (isfield (ts, "isdst")); +%! assert (isfield (ts, "yday")); + +%!error strptime () +*/