Mercurial > hg > octave-nkf
changeset 16967:52c1b832d98e
imread: make sure test file is removed if imread() errors.
* imread.m: file removal is made before the test so it occurs even
if test fails. However, if imread() errors, file was never removed.
Fixed with use of unwind_protect block. Also, use tmpnam() to
choose filename instead of current working directory.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Fri, 12 Jul 2013 18:06:20 +0100 |
parents | 269e96910ae9 |
children | e424cdb2ef96 |
files | scripts/image/imread.m |
diffstat | 1 files changed, 9 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/imread.m +++ b/scripts/image/imread.m @@ -93,11 +93,15 @@ %! 16, 28, 160, 16, 0, 197, 214, 13, 34, 74, ... %! 117, 213, 17, 0, 0, 0, 0, 73, 69, 78, ... %! 68, 174, 66, 96, 130]; -%! fid = fopen ("test.png", "wb"); -%! fwrite (fid, vpng); -%! fclose (fid); -%! A = imread ("test.png"); -%! delete ("test.png"); +%! filename = [tmpnam() ".png"]; +%! unwind_protect +%! fid = fopen (filename, "wb"); +%! fwrite (fid, vpng); +%! fclose (fid); +%! A = imread (filename); +%! unwind_protect_cleanup +%! unlink (filename); +%! end_unwind_protect %! assert (A(:,:,1), uint8 ([0, 255, 0; 255, 237, 255; 0, 255, 0])); %! assert (A(:,:,2), uint8 ([0, 255, 0; 255, 28, 255; 0, 255, 0])); %! assert (A(:,:,3), uint8 ([0, 255, 0; 255, 36, 255; 0, 255, 0]));