]> granicus.if.org Git - graphviz/commitdiff
New test suite
authorerg <devnull@localhost>
Sat, 27 Oct 2007 21:31:24 +0000 (21:31 +0000)
committererg <devnull@localhost>
Sat, 27 Oct 2007 21:31:24 +0000 (21:31 +0000)
rtest/rtest.sh [new file with mode: 0755]
rtest/tests.txt [new file with mode: 0644]

diff --git a/rtest/rtest.sh b/rtest/rtest.sh
new file mode 100755 (executable)
index 0000000..a58f79a
--- /dev/null
@@ -0,0 +1,284 @@
+#! /bin/ksh
+# TODO:
+#  Fix to 
+
+TESTFILE=tests.txt     # Test specifications
+GRAPHDIR=graphs        # Directory of input graphs and data
+OUTDIR=ndata           # Directory for test output
+REFDIR=nshare          # Directory for expected test output
+GENERATE=              # If set, generate test data
+VERBOSE=               # If set, give verbose output
+NOOP=                  # If set, just print list of tests
+
+TESTNAME=   # name of test
+GRAPH=      # graph specification
+IDX=
+typeset -i i j SUBTESTCNT
+typeset -i LINECNT=0
+typeset -A TESTTYPES
+typeset ALG[10]
+typeset FMT[10]
+typeset FLAGS[10]
+TMPINFILE=tmp$$.dot
+TMPFILE=tmpout$$
+
+# Read single line, storing it in LINE and update count.
+# Return 0 on success.
+function readLine
+{
+  if read -u 3 LINE
+  then
+    (( LINECNT+=1 ))
+    return 0
+  else
+    return 1
+  fi
+}
+
+# Skip blank lines and comments (lines starting with #)
+# Use first real line as the test name
+function skipLines
+{
+  while readLine
+  do
+    if [[ -n $LINE && ${LINE:0:1} != \# ]]
+    then
+      return 0
+    fi
+  done
+  return 1
+}
+
+# Subtests have the form: layout format optional_flags
+# Store the 3 parts in the arrays ALG, FMT, FLAGS.
+# Stop at a blank line
+function readSubtests
+{
+  (( SUBTESTCNT=0 ))
+  while readLine
+  do
+    if [[ -z "$LINE" ]]
+    then
+      return
+    fi
+    if [[ ${LINE:0:1} != \# ]]
+    then
+      echo $LINE | read ALG0 FMT0 FLAGS0
+      ALG[$SUBTESTCNT]=$ALG0
+      FMT[$SUBTESTCNT]=$FMT0
+      FLAGS[$SUBTESTCNT]=$FLAGS0
+      (( SUBTESTCNT+=1 ))
+    fi
+  done
+}
+
+function readTest
+{
+  # read test name
+  if skipLines
+  then
+    TESTNAME=$LINE
+  else
+    return 1
+  fi
+
+  # read input graph
+  if skipLines
+  then
+    GRAPH=$LINE
+  else
+    return 1
+  fi
+
+  readSubtests
+  return 0
+}
+
+# newfile = $1
+# oldfile = $2
+# assume subscript indicates file type
+function strip {
+  case $1 in
+    *.ps )
+      awk -f strps.awk $1 > $TFILE1
+      awk -f strps.awk $2 > $TFILE2
+      ;;
+    *.svg )
+      sed '/^<!--/d' < $1 | sed '/-->$/d' > $TFILE1
+      sed '/^<!--/d' < $2 | sed '/-->$/d' > $TFILE2
+      ;;
+    * )
+      cp $1  $TFILE1
+      cp $2  $TFILE2
+      ;;
+  esac
+
+}
+
+# Compare old and new output and report if different.
+#  Args: testname index fmt
+function doDiff
+{
+   FILE1=$OUTDIR/$OUTFILE
+   FILE2=$REFDIR/$OUTFILE
+   case $3 in
+    ps )
+      mv $FILE1 $TMPFILE 
+      awk -f strps.awk $TMPFILE > $FILE1
+      awk -f strps.awk $FILE22 > $TMPFILE
+      diff -q $FILE1 $TMPFILE > /dev/null 
+      ;;
+    svg )
+      mv $FILE1 $TMPFILE 
+      sed '/^<!--/d' < $TMPFILE | sed '/-->$/d' > $FILE1
+      sed '/^<!--/d' < $FILE2 | sed '/-->$/d' > $TMPFILE
+      diff -q $FILE1 $TMPFILE > /dev/null 
+      ;;
+    png )
+      diffimg $FILE1 $FILE2 > /dev/null 
+      ;;
+    * )
+      diff -q $FILE1 $FILE2 > /dev/null 
+      ;;
+    esac
+    if [[ $? != 0 ]]
+    then
+      print -u 2 "Test $1:$2 : == Failed =="
+    fi
+}
+
+# Generate output file name given 3 parameters.
+#   testname layout format
+# If format ends in :*, remove this, change the colons to underscores,
+# and append to basename
+# If the last two parameters have been used before, add numeric suffix.
+function genOutname
+{
+  if [[ $3 == *:* ]]
+  then
+    FMT=${3%%:*}
+    XFMT=${3#$FMT}
+    XFMT=${XFMT/:/_}
+  else
+    FMT=$3
+    XFMT=""
+  fi
+
+  IDX="$2$XFMT$FMT"
+  j=${TESTTYPES[$IDX]}
+  if (( j == 0 ))
+  then
+    TESTTYPES[$IDX]=1
+    J=""
+  else
+    TESTTYPES[$IDX]=$(( j+1 ))
+    J=$j
+  fi 
+  OUTFILE="$1_$2$XFMT$J.$FMT"
+}
+
+function doTest
+{
+  if (( SUBTESTCNT == 0 ))
+  then
+    return
+  fi
+  case $GRAPH in
+    = )
+      INFILE=$GRAPHDIR/$TESTNAME.dot
+      ;;
+    graph* | digraph* )
+      INFILE=$TMPINFILE
+      echo "$GRAPH" > $INFILE
+      ;;
+    *.dot )
+      INFILE=$GRAPHDIR/$GRAPH
+      ;;
+    * )
+      echo "Unknown graph spec, test $TESTNAME - ignoring"
+      return
+      ;;
+  esac
+
+  # clear TESTTYPES
+  for x in ${!TESTYPES[@]}
+  do
+    TESTTYPES[$x]=0
+  done
+
+  for ((i=0;i<SUBTESTCNT;i++))
+  do
+    genOutname $TESTNAME ${ALG[$i]} ${FMT[$i]}
+    OUTPATH=$OUTDIR/$OUTFILE
+    if [[ -n "$VERBOSE" ]]
+    then
+      print dot -K${ALG[$i]} -T${FMT[$i]} ${FLAGS[$i]} -o$OUTPATH $INFILE
+    fi
+    if [[ $NOOP == 1 ]]
+    then
+      continue
+    fi
+    
+    dot -K${ALG[$i]} -T${FMT[$i]} ${FLAGS[$i]} -o$OUTPATH $INFILE 2> errout
+
+    if [[ $GENERATE == 1 ]]
+    then
+      continue
+    fi
+    
+    if [[ $? != 0 || -s errout ]]
+    then
+      print -u 2 "Test $TESTNAME:$i : == Crashed =="
+    else
+      doDiff $TESTNAME $i ${FMT[$i]}
+    fi
+  done
+}
+
+trap 'rm -f $TMPFILE $TMPINFILE errout; exit' 0 1 2 3 15
+
+Usage='rtest [-gvn]\n
+ -g : generate test data\n
+ -v : verbose\n
+ -n : print test'
+
+while getopts :gnv c
+do
+  case $c in
+  n )
+    VERBOSE=1
+    NOOP=1
+    ;;
+  v )
+    VERBOSE=1
+    ;;
+  g )
+    GENERATE=1
+    if [[! -d "$REFDIR" ]]
+    then
+               mkdir $REFDIR
+    fi
+    OUTDIR=$REFDIR
+    ;;
+  :)
+    echo $OPTARG requires a value
+    exit 2
+    ;;
+  \? )
+    if [[ "$OPTARG" == '?' ]]
+    then
+      echo $Usage
+      exit 0
+    else
+      echo "rtest: unknown flag $OPTARG - ignored"
+    fi
+    ;;
+  esac
+done
+shift $((OPTIND-1))
+
+exec 3< $TESTFILE
+while readTest
+do
+  doTest
+done
diff --git a/rtest/tests.txt b/rtest/tests.txt
new file mode 100644 (file)
index 0000000..2480f69
--- /dev/null
@@ -0,0 +1,258 @@
+# Graphviz test suite
+# Tests are separated by blank or comment lines.
+# Tests have the following syntax:
+#  testname
+#  Test input (one-line graph or name of dot file or =)
+#    In the last case, the input file is taken as testname.dot
+#  One or more subtests of the form: 
+#     layout_alg output_format additional_flags
+#  
+# For example, the test
+#   shapes
+#   shapes.dot
+#   dot ps
+#   neato png "-Gsize=3,3 -Ncolor=red"
+# specifies the "shapes" test, using shapes.dot as input, and
+# run "dot -Tps" and "neato -Tpng -Gsize=3,3 -Ncolor=red" on the input.
+
+shapes
+=
+dot dot
+dot ps
+
+crazy
+=
+dot png
+dot ps
+
+arrows
+=
+dot dot
+dot ps
+
+arrowsize
+=
+dot png
+
+center
+=
+dot ps
+dot png -Gmargin=1
+
+# color encodings
+# multiple edge colors
+color
+=
+dot png
+dot png - Gbgcolor = lightblue
+
+decorate
+=
+dot png
+
+record
+= 
+dot dot 
+dot ps 
+
+html 
+= 
+dot dot 
+dot ps 
+
+html2 
+= 
+dot dot 
+dot ps
+
+pslib
+=
+dot ps -lgraphs/sdl
+
+user_shapes
+=
+dot ps
+dot png:gd
+#dot png - doesn't work: Warning: No loadimage plugin for "gif:cairo"
+
+ps_user_shapes
+=
+dot ps -Nshapefile=graphs/dice.ps
+dot ps -Nshape=epsf -Nshapefile=graphs/dice.ps
+
+colorscheme
+=
+dot ps
+dot png
+
+compound
+=
+dot dot
+
+dir
+=
+dot ps
+
+clustlabel
+=
+dot ps "-Glabelloc=t -Glabeljust=r" 
+dot ps "-Glabelloc=b -Glabeljust=r" 
+dot ps "-Glabelloc=t -Glabeljust=l" 
+dot ps "-Glabelloc=b -Glabeljust=l" 
+dot ps "-Glabelloc=t -Glabeljust=c" 
+dot ps "-Glabelloc=b -Glabeljust=c" 
+dot ps "-Glabelloc=t"
+dot ps "-Glabelloc=b"
+
+rootlabel
+=
+dot ps "-Glabelloc=t -Glabeljust=r" 
+dot ps "-Glabelloc=b -Glabeljust=r" 
+dot ps "-Glabelloc=t -Glabeljust=l" 
+dot ps "-Glabelloc=b -Glabeljust=l" 
+dot ps "-Glabelloc=t -Glabeljust=c" 
+dot ps "-Glabelloc=b -Glabeljust=c" 
+dot ps "-Glabelloc=t"
+dot ps "-Glabelloc=b"
+
+layers
+=
+dot ps
+
+# check mode=hier
+mode
+=
+neato ps -Gmode=KK
+neato ps -Gmode=hier
+neato ps "-Gmode=hier -Glevelsgap=1"
+
+model
+mode.dot
+neato ps -Gmodel=circuit
+neato ps -Gmodel=subset
+
+# cairo versions have problems
+nojustify
+=
+dot png
+dot png:gd
+dot ps
+dot ps:cairo
+
+# bug
+ordering
+=
+dot dot -Gordering=in 
+dot dot -Gordering=out 
+
+overlap
+=
+neato dot -Goverlap=false
+neato dot -Goverlap=scale
+
+pack
+=
+neato dot
+neato dot -Gpack=20
+neato dot -Gpackmode=graph
+
+page
+mode.dot
+neato ps "-Gpage=8.5,11"
+neato ps "-Gpage=8.5,11 -Gpagedir=TL"
+neato ps "-Gpage=8.5,11 -Gpagedir=TR"
+
+# pencolor, fontcolor, fillcolor
+colors
+=
+dot ps
+
+ports
+=
+dot dot
+
+rotate
+crazy.dot
+dot png -Glandscape
+dot ps -Glandscape
+dot png -Grotate=90
+dot ps -Grotate=90
+
+rankdir
+crazy.dot
+dot dot -Grankdir=LR
+dot dot -Grankdir=BT
+dot dot -Grankdir=RL
+
+url
+=
+dot ps2
+dot svg -Gstylesheet=stylesheet
+dot imap
+dot cmapx
+dot imap_np
+dot cmapx_np
+
+viewport
+=
+neato png "-Gviewport=300,300 -n2"
+neato ps "-Gviewport=300,300 -n2"
+neato png "-Gviewport=300,300,1,200,620 -n2"
+neato ps "-Gviewport=300,300,1,200,620 -n2"
+neato png "-Gviewport=300,300,2,200,620 -n2"
+neato ps "-Gviewport=300,300,2,200,620 -n2"
+
+rowcolsep
+=
+dot dot -Tnodesep=0.5
+dot dot -Tranksep=1.5
+
+size
+mode.dot
+neato ps "-Gsize=5,5"
+neato png "-Gsize=5,5"
+
+# size with !
+size_ex
+root.dot
+dot ps "-Gsize=6,6!"
+dot png "-Gsize=6,6!"
+
+dotsplines
+size.dot
+dot dot -Gsplines=line
+dot dot -Gsplines=polyline
+#dot dot -Gsplines=ortho
+
+# bug with splines=polyline
+neatosplines
+overlap.dot
+neato dot -Goverlap=false -Gsplines=splines
+neato dot -Goverlap=false -Gsplines=polyline
+#neato dot -Goverlap=false -Gsplines=ortho
+
+style
+=
+dot ps
+dot png
+
+# edge clipping
+edgeclip
+=
+dot dot
+
+# edge weight
+weight
+=
+dot dot
+
+root
+=
+twopi dot
+circo dot
+
+cairo
+=
+dot -Tps:cairo 
+dot -Tpng:cairo 
+dot -Tsvg:cairo