# HG changeset patch # User John W. Eaton # Date 1287813891 14400 # Node ID 461ae8d58cdb7bbdedb9f4230d7f348409e8f1cd # Parent 195cffc2d0a39e065ecf48821a674d23aa3e11f5 tests for is_valid_file_id diff -r 195cffc2d0a3 -r 461ae8d58cdb scripts/ChangeLog --- a/scripts/ChangeLog Sat Oct 23 13:59:30 2010 +0800 +++ b/scripts/ChangeLog Sat Oct 23 02:04:51 2010 -0400 @@ -1,3 +1,8 @@ +2010-10-23 John W. Eaton + + * io/is_valid_file_id.m: Ensure that FID is a scalar before + calling fopen to get info. New tests. + 2010-10-23 John W. Eaton * io/is_valid_file_id.m: New function. diff -r 195cffc2d0a3 -r 461ae8d58cdb scripts/io/is_valid_file_id.m --- a/scripts/io/is_valid_file_id.m Sat Oct 23 13:59:30 2010 +0800 +++ b/scripts/io/is_valid_file_id.m Sat Oct 23 02:04:51 2010 -0400 @@ -28,11 +28,19 @@ if (nargin == 1) try - [file, mode, arch] = fopen (fid); - retval = ! isempty (file); + if (isscalar (fid)) + [file, mode, arch] = fopen (fid); + retval = ! isempty (file); + endif end_try_catch else print_usage (); endif endfunction + +%!assert (is_valid_file_id (stdout)) +%!assert (! is_valid_file_id ([1,2;3,4])) +%!assert (! is_valid_file_id ("not_a_file_id")) +%!assert (! is_valid_file_id (-1)) +%!assert (! is_valid_file_id (pi))