# HG changeset patch # User Mike Miller # Date 1423455885 18000 # Node ID f96671da51a6490c19ccf8c69700a0a0ecab2375 # Parent c2478360291f7b963219954ce8e1ef88bc953262 record.m: Improve input validation * record.m: Improve input validation. Avoid attempting to record for zero duration. Add %!tests. diff -r c2478360291f -r f96671da51a6 scripts/audio/record.m --- 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) +