add tests
authorLaurent Mazet <mazet@softndesign.org>
Mon, 7 Oct 2024 06:09:33 +0000 (08:09 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Mon, 7 Oct 2024 06:09:33 +0000 (08:09 +0200)
ndisplay.c

index 5b84610b84c24d9e9c01d0ae045f182da736d668..f6ed0b0a82611066fd9c93c7c9df52138a7b3296 100644 (file)
@@ -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: */