about summary refs log tree commit diff
path: root/test
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-12-26 06:13:41 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-12-26 06:13:41 +0000
commit51ffbae51ba9379bad460566cdf9babaa63b14c3 (patch)
tree441f6e9297c478261bdce544497decaf6abc31a4 /test
parentd6f45222d7b29adb9defdd79dd8ad1dbc97bb3e1 (diff)
downloadnetpbm-mirror-51ffbae51ba9379bad460566cdf9babaa63b14c3.tar.gz
netpbm-mirror-51ffbae51ba9379bad460566cdf9babaa63b14c3.tar.xz
netpbm-mirror-51ffbae51ba9379bad460566cdf9babaa63b14c3.zip
Update to current Development release - 10.65.00
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@2083 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'test')
-rwxr-xr-xtest/Execute-Tests25
-rw-r--r--test/Makefile24
-rw-r--r--test/Test-Order2
-rw-r--r--test/pnmshear.ok1
-rw-r--r--test/pnmshear.test19
-rw-r--r--test/ps-alt-roundtrip.ok3
-rwxr-xr-xtest/ps-alt-roundtrip.test46
-rw-r--r--test/ps-roundtrip.ok14
-rwxr-xr-xtest/ps-roundtrip.test76
-rw-r--r--test/testrandom.c130
10 files changed, 306 insertions, 34 deletions
diff --git a/test/Execute-Tests b/test/Execute-Tests
index 047cf4a3..7a1a3793 100755
--- a/test/Execute-Tests
+++ b/test/Execute-Tests
@@ -39,17 +39,10 @@ fi
 # export PBM_BINPREFIX=""
 export PBM_BINPREFIX=${PBM_TESTPREFIX}
 
-# Add PBM_BINPREFIX to PATH.
-# This is necessary for Netpbm programs (mosly scripts) that call
-# other Netpbm programs.
-
-if [ ! -z $PBM_BINPREFIX ]
-  then
-  export PATH=${PBM_BINPREFIX}:$PATH
-fi
-
-# Set srcdir, which is the directory which contains Execute-Tests
-# (this script), Test-Order *.test and *.ok files.
+# Set srcdir, which is the directory which contains Execute-Tests (this
+# script), programs that run the test, including *.test and helpers that they
+# invoke, the list of tests to run ('Test-Order'), and *.ok files that
+# indicate the expected results of tests.
 
 srcdir=$(dirname $0)
 
@@ -101,6 +94,16 @@ if [ ! -f ./testimg.ppm ]
   then cp -v ${srcdir}/testimg.ppm  ./testimg.ppm 
 fi
 
+# Add PBM_BINPREFIX to PATH.
+# This is necessary for Netpbm programs that call other Netpbm programs.
+
+if [ ! -z $PBM_BINPREFIX ]
+  then
+  export PATH=${PBM_BINPREFIX}:$PATH
+fi
+
+export PATH=${srcdir}:$PATH
+
 # Execute the tests, as described in the "Test-Order" file.
 #
 # Each test outputs a ".out" file, which is compared against a
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 00000000..4d44285f
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,24 @@
+ifeq ($(SRCDIR)x,x)
+  SRCDIR = $(CURDIR)/..
+  BUILDDIR = $(SRCDIR)
+endif
+SUBDIR = test
+VPATH = .:$(SRCDIR)/$(SUBDIR)
+include $(BUILDDIR)/config.mk
+
+MERGE_OBJECTS =
+
+PROGS = testrandom
+
+all: $(PROGS)
+
+PORTBINARIES = testrandom
+OBJECTS = $(PORTBINARIES:%=%.o)
+
+OMIT_TEST_RULE = 1
+include $(SRCDIR)/common.mk
+
+distclean clean: cleanlocal
+.PHONY: cleanlocal
+cleanlocal:
+	rm -f $(PROGS)
diff --git a/test/Test-Order b/test/Test-Order
index 698552b9..31cd5324 100644
--- a/test/Test-Order
+++ b/test/Test-Order
@@ -63,6 +63,7 @@ ppmbrighten.test
 ppmdither.test
 pamedge.test
 ppmdim.test
+pnmshear.test
 
 ppmmix.test
 
@@ -109,6 +110,7 @@ mrf-roundtrip.test
 pfm-roundtrip.test
 png-roundtrip.test
 ps-roundtrip.test
+ps-alt-roundtrip.test
 sunrast-roundtrip.test
 targa-roundtrip.test
 tiff-roundtrip.test
diff --git a/test/pnmshear.ok b/test/pnmshear.ok
new file mode 100644
index 00000000..d701faaf
--- /dev/null
+++ b/test/pnmshear.ok
@@ -0,0 +1 @@
+2080980136 22
diff --git a/test/pnmshear.test b/test/pnmshear.test
new file mode 100644
index 00000000..276e3e22
--- /dev/null
+++ b/test/pnmshear.test
@@ -0,0 +1,19 @@
+#! /bin/bash
+# This script tests: pnmshear
+# Also requires: pbmmake
+
+# Test.  Should produce 2080980136 22
+${PBM_BINPREFIX}pbmmake -g 7 7 | \
+   ${PBM_TESTPREFIX}pnmshear 45 -noantialias  | cksum
+
+# Output of above, in pbm plain format
+#
+# P1
+# 14 7
+# 01010101111111
+# 10101011111111
+# 10101010111111
+# 11101010111111
+# 11101010101111
+# 11111010101111
+# 11111010101011
diff --git a/test/ps-alt-roundtrip.ok b/test/ps-alt-roundtrip.ok
new file mode 100644
index 00000000..1cd73f75
--- /dev/null
+++ b/test/ps-alt-roundtrip.ok
@@ -0,0 +1,3 @@
+2425386270 41
+2425386270 41
+2916080186 235
diff --git a/test/ps-alt-roundtrip.test b/test/ps-alt-roundtrip.test
new file mode 100755
index 00000000..8ce1689d
--- /dev/null
+++ b/test/ps-alt-roundtrip.test
@@ -0,0 +1,46 @@
+#! /bin/bash
+# This script tests: pbmtoepsi pbmtopsg3 pbmtolps psidtopgm pstopnm
+# Also requires: gs pnmtopnm pnmcrop
+
+# This script is for testing alternative (or minor) utilities that
+# read/write Postscript and encapsulated Postscript:
+# pbmtoepsi, pbmtopsg3, pbmtolps and psidtopgm.
+#
+# We keep these tests separate from those for pnmtops and pstopnm
+# which are far more popular.
+#
+# pbmtopsg3 and pbmtolps produce output that require pstopnm for decoding.
+#
+# If ps-roundtrip.test succeeds and this test fails, it is most likely
+# a problem with one of the minor utilities, and vice versa.
+
+
+# Test 1. Should print: 2425386270 41
+${PBM_TESTPREFIX}pbmtopsg3 -dpi=72 testgrid.pbm \
+     > ${tmpdir}/testgrid1.ps && \
+${PBM_TESTPREFIX}pstopnm -xborder=0 -yborder=0 -llx=0 -lly=-16 -urx=14 \
+    -dpi=72 -stdout -quiet -pbm ${tmpdir}/testgrid1.ps | \
+    ${PBM_BINPREFIX}pnmcrop | cksum
+
+
+# Test 2. Should print: 2425386270 41
+${PBM_TESTPREFIX}pbmtolps -dpi 72 testgrid.pbm \
+     > ${tmpdir}/testgrid2.ps && \
+${PBM_TESTPREFIX}pstopnm -xborder=0 -yborder=0 -dpi=72 -stdout \
+    -quiet ${tmpdir}/testgrid2.ps -pbm | \
+  ${PBM_BINPREFIX}pnmcrop | cksum
+
+
+# Test 3. Should print: 2916080186 235
+# Output is pgm maxval=1 with black and white inverted.
+#
+${PBM_TESTPREFIX}pbmtoepsi testgrid.pbm > ${tmpdir}/testgrid.epsi && \
+xysizebps=`awk  '/BeginPreview/ {print $2,$3,$4}' \
+    ${tmpdir}/testgrid.epsi` && \
+awk '/^%%BeginPreview:/ { p=1; next } /^%%EndImage/ { p=0; next } \
+  p==1 && /%[ \t0-9a-fA-F]+/ { print substr($0,2); next } \
+  p==1 {print "!"$0}' \
+    ${tmpdir}/testgrid.epsi | ${PBM_TESTPREFIX}psidtopgm $xysizebps | cksum
+
+
+rm ${tmpdir}/testgrid[12].ps  ${tmpdir}/testgrid.epsi 
diff --git a/test/ps-roundtrip.ok b/test/ps-roundtrip.ok
index a267f7eb..0ebfb94a 100644
--- a/test/ps-roundtrip.ok
+++ b/test/ps-roundtrip.ok
@@ -1,3 +1,15 @@
 1926073387 101484
-2425386270 41
+1926073387 101484
+1926073387 101484
+1926073387 101484
+1926073387 101484
+2918318199 62
+2918318199 62
+2918318199 62
+2918318199 62
+2918318199 62
+2918318199 62
+2918318199 62
+1386192571 507420
+1386192571 507420
 1386192571 507420
diff --git a/test/ps-roundtrip.test b/test/ps-roundtrip.test
index 60ecf60a..b7aa816c 100755
--- a/test/ps-roundtrip.test
+++ b/test/ps-roundtrip.test
@@ -1,38 +1,70 @@
 #! /bin/bash
 # This script tests: pnmtops pstopnm
-# Also requires: pnmtopnm pamtopnm gs
+# Also requires: pnmtopnm pamtopnm gs pbmmake pnmshear pnmpad pnmcat
 
-# Test 1.  Should print: 1926073387 101484
-${PBM_TESTPREFIX}pnmtops -nocenter -equalpixels -dpi 72 -noturn testimg.ppm \
-  > ${tmpdir}/testimg.ps
-xysize1=`awk  '/BoundingBox/ {print "-xsize="$4,"-ysize="$5}' \
-  ${tmpdir}/testimg.ps` 
-${PBM_TESTPREFIX}pstopnm -xborder=0 -yborder=0 $xysize1 -stdout \
-  -quiet ${tmpdir}/testimg.ps | \
-  ${PBM_BINPREFIX}pnmtopnm | cksum
+# Test 1.  Should print: 1926073387 101484 five times
+# *NOTE* Fifth iteration fails if pnmtops was compiled without zlib
+# (flate compression) support.
+for flag in "" "-ps" "-rle" "-ps -ascii" "-ps -flate"
+  do
+  ${PBM_TESTPREFIX}pnmtops -nocenter -equalpixels -dpi 72 -noturn \
+    ${flag} testimg.ppm \
+    > ${tmpdir}/testimg.ps
+  xysize1=`awk  '/BoundingBox/ {print "-xsize="$4,"-ysize="$5}' \
+    ${tmpdir}/testimg.ps` 
+  ${PBM_TESTPREFIX}pstopnm -xborder=0 -yborder=0 $xysize1 -stdout \
+    -quiet ${tmpdir}/testimg.ps | \
+    ${PBM_BINPREFIX}pnmtopnm | cksum
+  done
 
 
-# Test 2.  Should print: 2425386270 41
-${PBM_TESTPREFIX}pnmtops -nocenter -equalpixels -dpi 72 -noturn \
-  testgrid.pbm  > ${tmpdir}/testgrid.ps &&
-xysize2=`awk  '/BoundingBox/ {print "-xsize="$4,"-ysize="$5}' \
-  ${tmpdir}/testgrid.ps`
-${PBM_TESTPREFIX}pstopnm -xborder=0 -yborder=0 $xysize2 -stdout \
-  -quiet ${tmpdir}/testgrid.ps -pbm | \
-  ${PBM_BINPREFIX}pnmtopnm | cksum
+# Test 2.  Should print: 2918318199 62 seven times
+# Test image designed to detect problems with run-length compression
+#
+${PBM_BINPREFIX}pbmmake -g 2 2 > ${tmpdir}/g.pbm
+${PBM_BINPREFIX}pbmmake -g 8 4 | \
+  ${PBM_BINPREFIX}pnmshear 45 -noantialias -background=black | \
+  ${PBM_BINPREFIX}pnmpad -right 60 | \
+  ${PBM_BINPREFIX}pnmcat -tb -jright - ${tmpdir}/g.pbm > ${tmpdir}/t.pbm &&
+for flag in "" "-rle" "-ps -rle -ascii" \
+            "-bitspersample=2 -rle" "-ps -bitspersample=4 -rle" \
+            "-bitspersample=8 -rle" "-ps -bitspersample=12 -rle -dict" 
+  do
+  ${PBM_TESTPREFIX}pnmtops -nocenter -equalpixels -dpi 72 -noturn \
+    ${flag} ${tmpdir}/t.pbm  > ${tmpdir}/testgrid.ps &&
+  xysize2=`awk  '/BoundingBox/ {print "-xsize="$4,"-ysize="$5}' \
+    ${tmpdir}/testgrid.ps`
+  ${PBM_TESTPREFIX}pstopnm -xborder=0 -yborder=0 $xysize2 -stdout \
+    -quiet ${tmpdir}/testgrid.ps -pbm | \
+    ${PBM_BINPREFIX}pnmtopnm | cksum
+  done
 
 
-#Test 3. Should print: 1386192571 507420
+#Test 3. Should print: 1386192571 507420 three times
+# *NOTE* Second iteration fails if pnmtops was compiled without zlib
+# (flate compression) support.
+#
+# Special care is needed when conducting round-trips with multiple-image
+# files as input.
+# (1) pnmtops: -setpage is mandatory
+# (2) awk: xy values are taken from the first "BoundingBox" encountered.
+#          Subsequent BoundingBox values are ignored.
+# (3) pstopnm: input must be an ordinary file.  Input from stdin
+#     (by pipe or input redirection: "< file" ) does not work.              
+#
+for flag in "" "-ps" \
+            "-ps -bitspersample=12 -flate -rle -vmreclaim"
+  do
 cat testimg.ppm testimg.ppm testimg.ppm testgrid.pbm testgrid.pbm | \
 ${PBM_TESTPREFIX}pnmtops -nocenter -equalpixels -dpi 72 -noturn -setpage \
-  > ${tmpdir}/testimg5.ps
+  ${flag}  > ${tmpdir}/testimg5.ps
 xysize3=`awk  '/BoundingBox/ {print "-xsize="$4,"-ysize="$5 ; exit}' \
   ${tmpdir}/testimg5.ps`
 ${PBM_TESTPREFIX}pstopnm -xborder=0 -yborder=0 $xysize3 \
     -stdout  ${tmpdir}/testimg5.ps | \
   ${PBM_BINPREFIX}pnmtopnm | cksum
+  done
 
 
-#rm  ${tmpdir}/testgrid.ps  ${tmpdir}/testimg.ps  ${tmpdir}/testimg5.ps
-rm   ${tmpdir}/testimg.ps  ${tmpdir}/testimg5.ps
-mv ${tmpdir}/testgrid.ps /tmp
+rm ${tmpdir}/testgrid.ps  ${tmpdir}/testimg.ps  ${tmpdir}/testimg5.ps \
+   ${tmpdir}/t.pbm
diff --git a/test/testrandom.c b/test/testrandom.c
new file mode 100644
index 00000000..3f65f0d2
--- /dev/null
+++ b/test/testrandom.c
@@ -0,0 +1,130 @@
+/*=============================================================================
+                                   testrandom
+===============================================================================
+  Test for the random number generator type by generating 5 values with rand()
+  and comparing them against values in a table.
+
+  Currently only recognizes ISO glibc rand().
+
+  Options:
+    -q : quiet mode
+    -v : verbose mode : Use to generate values for new table 
+=============================================================================*/
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Exit values */
+#define EXIT_ERROR 1
+#define EXIT_UNKNOWN 80
+#define ISO_GLIBC 81
+/* 82-90: reserved */
+
+typedef enum {QUIET=0, NORMAL=1, VERBOSE=2} VerbosityLevel;
+
+/* On some Sun systems RAND_MAX is not defined */
+#ifndef RAND_MAX
+#define RAND_MAX 0
+#endif
+
+#define SEED 3791
+
+static struct { 
+    int          const type;
+        /* Exit value for this rand() function  */
+    int          const randMax;
+        /* Usually 0x7fffffff, sometimes 0x7fff */
+        /* Other values are possible; 0 means undefined */
+    unsigned int const res[5];
+        /* Sample values returned from our tests */
+    const char * const name;
+        /* Name for this rand() function */
+} rTable[2] = {
+    { ISO_GLIBC,  /* glibc rand() */ 
+      0x7fffffff, /* 31 bits */ 
+      { 217313873, 969144303, 1757357552, 1096307597, 818311031 },
+      "ISO C glibc rand() or equivalent" },
+    
+    /* Insert additional entries here */
+    
+    { 0,   /* terminating code */
+      0,
+      {0, 0, 0, 0, 0}, NULL  /* unknown type */}
+};
+
+
+
+static void
+parseCommandLine(int              const argc,
+                 const char *     const argv[],
+                 VerbosityLevel * const verbosityP) {
+
+    *verbosityP = NORMAL; /* Initial value */
+
+    if (argc == 2) {
+        if (argv[1][0] == '-' && argv[1][2] == '\0') {
+            switch ( argv[1][1] ) {
+            case 'v' : *verbosityP = VERBOSE; break;
+            case 'q' : *verbosityP = QUIET  ; break;
+            default :  fprintf (stderr,
+                                "Error: Unrecognized argument: %s\n", argv[1]);
+                exit (EXIT_ERROR);
+            }
+        } 
+    }
+    if (argc > 2 ) {
+        fprintf (stderr, "Error: Too many arguments.\n");
+        exit (EXIT_ERROR);
+    }
+}
+
+
+
+int
+main(int const argc, const char * const argv[]) {
+
+    unsigned int i;
+    unsigned int res[5];
+    VerbosityLevel verbosity;
+
+    parseCommandLine(argc, argv, &verbosity);
+
+    if (verbosity == VERBOSE) {
+        if (RAND_MAX > 0)
+            fprintf(stderr, "RAND_MAX = 0x%x (%d)\n", RAND_MAX, RAND_MAX);
+        else
+            fprintf(stderr, "RAND_MAX is undefined\n");
+    }
+
+    /* Set seed for pseudo-random number generator */
+    if (verbosity == VERBOSE)
+        fprintf(stderr, "Generating samples. Seed=%u\n", SEED);
+
+    srand(SEED);
+
+    /*  Generate five samples and store in array res[] */
+    for (i = 0; i < 5; ++i) {
+        res[i] = rand();
+        if (verbosity == VERBOSE)
+            fprintf (stderr, "%d\n",res[i]);
+    }
+
+    /*  Look for a match in table */
+    for (i = 0; rTable[i].type != 0; ++i) {
+        if (rTable[i].randMax == RAND_MAX && rTable[i].res[0] == res[0] &&
+            rTable[i].res[1] == res[1] &&    rTable[i].res[2] == res[2] &&
+            rTable[i].res[3] == res[3] &&    rTable[i].res[4] == res[4]) {
+            if (verbosity != QUIET)
+                fprintf(stderr,
+                        "Random number generator is %s.\n", rTable[i].name);
+
+            exit(rTable[i].type);
+        }
+    }
+    /* No matches */
+    if (verbosity != QUIET)   
+        fprintf(stderr, "Random number generator is of unknown type.\n");
+    exit(EXIT_UNKNOWN);
+}
+
+
+