changeset 19717:f96671da51a6

record.m: Improve input validation * record.m: Improve input validation. Avoid attempting to record for zero duration. Add %!tests.
author Mike Miller <mtmiller@ieee.org>
date Sun, 08 Feb 2015 23:24:45 -0500
parents c2478360291f
children 2b93834e5ede
files scripts/audio/record.m
diffstat 1 files changed, 26 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/audio/record.m	Sun Feb 08 18:35:59 2015 -0500
+++ b/scripts/audio/record.m	Sun Feb 08 23:24:45 2015 -0500
@@ -35,15 +35,36 @@
     print_usage ();
   endif
 
-  rec = audiorecorder (fs, 16, 1);
+  if (! (isscalar (sec) && (sec >= 0)))
+    error ("record: recording duration SEC must be a non-negative number");
+  endif
+
+  if (! (isscalar (fs) && (fs > 0)))
+    error ("record: sample rate FS must be a positive number");
+  endif
+
+  x = [];
 
-  recordblocking (rec, sec);
+  if (sec > 0)
+
+    rec = audiorecorder (fs, 16, 1);
 
-  x = getaudiodata (rec);
+    recordblocking (rec, sec);
+
+    x = getaudiodata (rec);
+
+  endif
 
 endfunction
 
 
-## No test possible for recording audio.
-%!assert (1)
+## Tests of record must not actually record anything.
+
+%!assert (isempty (record (0)))
 
+%% Test input validation
+%!error record ()
+%!error record (1,2,3)
+%!error record (-1)
+%!error record (1, -1)
+