Mercurial > hg > octave-nkf
changeset 19334:b8bd0b55af45
codesprint: Add tests to time handling functions
* time.cc: Add tests and input validation for time, mktime, strftime, and
strptime.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Sun, 21 Sep 2014 16:08:25 -0400 |
parents | 25ab600d16fd |
children | faa6a98f8d4b |
files | libinterp/corefcn/time.cc |
diffstat | 1 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/time.cc +++ b/libinterp/corefcn/time.cc @@ -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 () +*/