changeset 11144:461ae8d58cdb

tests for is_valid_file_id
author John W. Eaton <jwe@octave.org>
date Sat, 23 Oct 2010 02:04:51 -0400
parents 195cffc2d0a3
children 3735abe5ebbe
files scripts/ChangeLog scripts/io/is_valid_file_id.m
diffstat 2 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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  <jwe@octave.org>
+
+	* 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  <jwe@octave.org>
 
 	* io/is_valid_file_id.m: New function.
--- 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))