From 092f0e6cdabf6a9b3cd61b93540e7d7330d80eae Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Mon, 7 Oct 2024 08:09:33 +0200 Subject: [PATCH] add tests --- ndisplay.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/ndisplay.c b/ndisplay.c index 5b84610..f6ed0b0 100644 --- a/ndisplay.c +++ b/ndisplay.c @@ -128,9 +128,15 @@ int main (int argc, char *argv[]) return 1; } - /* main process */ + /* read file */ image_t *images[MAXSCALE + 1] = {0}; images[1] = readpnm (filename); + if (!images[1]) { + VERBOSE (ERROR, fprintf (stderr, "can't read PNM file '%s'\n", filename)); + return 1; + } + + /* pre-calculate expanded and shrinked images */ for (i = 2; i <= MAXSCALE; i++) { images[i] = shrinkimage (images[1], i); } @@ -262,17 +268,35 @@ int main (int argc, char *argv[]) /* cleaning before quiting */ endwin (); - for (i = 0; i <= scale; i++) { + for (i = 0; i <= MAXSCALE; i++) { freeimage (images[i]); } return 0; } +/* test: ndisplay.exe 2>&1 | grep 'no file specified' */ /* test: ndisplay.exe -h | grep usage */ -/* test: ndisplay.exe -s 2>&1 | grep 'no scale' */ -/* test: ndisplay.exe -s 4 2>&1 | grep incorrect */ /* test: ndisplay.exe -v 2>&1 | grep missing */ -/* test: ndisplay.exe _ 2>&1 | grep invalid */ +/* test: ndisplay.exe image/bogus1.ppm 2>&1 | grep "can't read PNM file" */ +/* test: ndisplay.exe image/bogus2.ppm 2>&1 | grep "can't read PNM file" */ +/* test: ndisplay.exe image/bogus3.pbm 2>&1 | grep "can't read PNM file" */ +/* test: ndisplay.exe image/bogus4.pbm 2>&1 | grep "can't read PNM file" */ +/* test: ndisplay.exe image/bogus5.pbm 2>&1 | grep "can't read PNM file" */ +/* test: ndisplay.exe image/bogus6.pbm 2>&1 | grep "can't read PNM file" */ +/* test: ndisplay.exe image/bogus7.pbm 2>&1 | grep "can't read PNM file" */ +/* test: ndisplay.exe image/bogus8.pgm 2>&1 | grep "can't read PNM file" */ +/* test: ndisplay.exe image/bogus9.pbm 2>&1 | grep "can't read PNM file" */ +/* test: { echo kkkk; sleep 1; echo i; sleep 1; echo q; } | ndisplay.exe image/laurent4p.pbm */ +/* test: { echo u; sleep 1; echo lll; sleep 1; echo j; sleep 1; echo q; } | ndisplay.exe image/laurent4p.pgm */ +/* test: { echo o; sleep 1; echo o; sleep 1; echo q; } | ndisplay.exe image/laurent4p.ppm */ +/* test: { echo oooo; sleep 1; echo u; sleep 1; echo q; } | ndisplay.exe image/laurent4.pbm */ +/* test: { sleep 1; echo q; } | ndisplay.exe image/laurent4.pgm */ +/* test: { sleep 1; echo q; } | ndisplay.exe image/laurent4b.pgm */ +/* test: { sleep 1; echo q; } | ndisplay.exe image/laurent4.ppm -g 1.2:3:1 */ +/* test: { sleep 1; echo q; } | ndisplay.exe image/debian.ppm -v 3 */ +/* test: { sleep 1; echo q; } | ndisplay.exe image/debian.ppm -g 4 */ +/* test: { sleep 1; echo q; } | ndisplay.exe image/python3.ppm -t */ +/* test: { sleep 1; echo q; } | ndisplay.exe image/python3.ppm -w */ /* vim: set ts=4 sw=4 et: */ -- 2.30.2