AT_INIT
AT_COPYRIGHT([Copyright(C) 2014 George Williams & Contributors])

#--------------------------------------------------------------------------
# Fontforge Native Scripting test functions

m4_defun([run_pedit],[(${abs_top_builddir}/fontforgeexe/fontforge -lang ff -script "${abs_srcdir}/$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" || /bin/false)])

# check_file( destination_variable, file_name )
# Check if the input file exists, first checking the build folder, then
# falling back to the source folder. If neither exist, skip the test.
m4_defun([check_file],[
  m4_ifblank([$2], [], [
    if test -r "${abs_builddir}/fonts/$2"; then
      $1="${abs_builddir}/fonts/$2"
    elif test -r "${abs_srcdir}/fonts/$2"; then
      $1="${abs_srcdir}/fonts/$2"
    else
      AT_SKIP_IF([true])
    fi
  ])
])

# check_pedit( name_of_test=$1, use test#=$2, skip_if_file_not_exist=$3 )
# Test FontForge Native Scripting commands using various testXXXX.pe files.
# $1 descriptive title of test
# $2 is test to run (skipped if FontForge built without python scripting)
# $3... file for this test (some files are external and need to be imported)
m4_defun([check_pedit],[
AT_SETUP([$1])
AT_SKIP_IF([test ! -r "${abs_srcdir}/$2"])
check_file([test_input1], [$3])
check_file([test_input2], [$4])
check_file([test_input3], [$5])
check_file([test_input4], [$6])
check_file([test_input5], [$7])
check_file([test_input6], [$8])
check_file([test_input7], [$9])
AT_CHECK([run_pedit([$2],[$test_input1],[$test_input2],[$test_input3],[$test_input4],[$test_input5],[$test_input6],[$test_input7])],[0],[ignore],[ignore])
AT_CLEANUP
])

#--------------------------------------------------------------------------
# Fontforge Python Scripting test functions

m4_defun([run_python_ff],[(${abs_top_builddir}/fontforgeexe/fontforge -lang py -script "${abs_srcdir}/$1" "$2" || /bin/false)])

# check_python( name_of_test=$1, use test#=$2, skip_if_file_not_exist=$3 )
# Test FontForge Python Scripting commands using various testXXXX.py files.
# $1 descriptive title of test
# $2 is test to run (skipped if FontForge built without python scripting)
# $3 test for this file
m4_defun([check_python_ff],[
AT_SETUP([$1 [(with FontForge)]])
AT_SKIP_IF([test ! -r "${abs_srcdir}/$2"])
AT_SKIP_IF([test ! -z "$FONTFORGE_NO_PYTHON"])
check_file([test_input], [$3])
AT_CHECK([run_python_ff([$2],[$test_input])],[0],[ignore],[ignore])
AT_CLEANUP
])

m4_defun([run_python_py],[(PATH="${abs_top_builddir}/fontforge/.libs:${abs_top_builddir}/gutils/.libs:${abs_top_builddir}/Unicode/.libs:$PATH" PYTHONPATH="${abs_top_builddir}/pyhook/.libs" ${python_exec} -Ss "${abs_srcdir}/$1" "$2" || /bin/false)])

m4_defun([check_python_py],[
AT_SETUP([$1 [(with Python)]])
AT_SKIP_IF([test ! -r "${abs_srcdir}/$2"])
AT_SKIP_IF([test ! -z "$FONTFORGE_NO_PYTHON_EXTENSION"])
check_file([test_input], [$3])
AT_CHECK([run_python_py([$2],[$test_input])],[0],[ignore],[ignore])
AT_CLEANUP
])

m4_defun([check_python],[check_python_ff([$1],[$2],[$3]),check_python_py([$1],[$2],[$3])])

#--------------------------------------------------------------------------

AT_COLOR_TESTS

AT_BANNER([FontForge Native Scripting Tests])

check_pedit([Generate a few font files],[test001.pe],[Caliban.sfd],[Zapfino-4.0d3.dfont],[Zapfino-4.1d6.dfont])
check_pedit([OTF CID font check],[test002.pe],[HanSans-Bold.otf])
check_pedit([Non-OTF CID font check],[test003.pe],[MunhwaGothic-Bold])
check_pedit([Chunk of memory check],[test004.pe],[mingliu.ttc])
check_pedit([Kerning information checks],[test005.pe],[VKern.sfd])
check_pedit([Incorrect names and count checks],[test006.pe],[mingliu.ttc],[GillSans.dfont],[ItalicHand.sfd],[ItalicHand.svg],[MunhwaGothic-Bold],[Caliban.otf])
check_pedit([Contextual chaining tables don't crash],[test007.pe],[FormalScript.sfd],[dvng10a-crash.sfd])
check_pedit([Contextual chaining tables don't crash],[test008.pe],[n019003l.pfb])
check_pedit([Read and generate Type3 fonts],[test009.pe],[Ambrosia.pt3])
check_pedit([Generate some error messages],[test010.pe],[GillSans.dfont])
check_pedit([Check for unexpected endif],[test101.pe])
check_pedit([Infinite loop test on 0 length spline],[test102.pe],[AHBugs.sfd])
check_pedit([Copy/Paste clipboard test for crash],[test103.pe])
check_pedit([Remove overlap test #1],[test104.pe],[SplineOverlapBug1.sfd])
check_pedit([while loop check, loop 10x],[test105.pe])
check_pedit([Simple 'Bad Kerning' check],[test106.pe],[OmittedCharBugs.sfd])
check_pedit([Generate a font family],[test107.pe],[Ambrosia.sfd],[AmbrosiaBold.sfd],[AmbrosiaItalic.sfd]) # also calls 'helper107.pe'
check_pedit([Make GPOS, GSUB, morx without crashing],[test108.pe],[ItalicHand.sfd])
check_pedit([Remove overlap test #2],[test109.pe],[OverlapBugs.sfd],[feta20.pfb])
check_pedit([Test simplify],[test110.pe],[SimplifyBugs.sfd])
check_pedit([Test merge fonts],[test111.pe],[cmbsy10.pfb])
check_pedit([Test quadratic conversion],[test112.pe],[CourierNew.ttf])
check_pedit([Count contour points properly],[test113.pe],[CourierNew.ttf])
check_pedit([Generate, save and open a .pfa file],[test114.pe],[CaslonMM.sfd])
check_pedit([Replace with reference],[test115.pe],[n019003l.pfb])
check_pedit([Merged],[test116.pe],[merged.cff])
check_pedit([Merge kern],[test117.pe],[ecrm1000.pfb],[ecrm1000.tfm])
check_pedit([Test Unicode encodings],[test118.pe],[NimbusLGCUni-Regular.sfd]) 'also uses helper118A.pe helper118B.pe
check_pedit([The 'i' glyph test],[test119.pe],[DejaVuSerif.sfd])
check_pedit([Another deja-vu point number],[test120.pe],[NumberPoints.sfd])
check_pedit([Don't distort the curve (by much)],[test121.pe],[AddExtremumTest.sfd])
#check_pedit([Check AutoHint works and retains hints],[test122.pe],[Hinting.sfd])
check_pedit([Produce equivalent font in CFF check],[test123.pe],[MinionPro-Regular.otf])
check_pedit([Check that detach glyph works #1],[test124.pe])
check_pedit([Check that detach glyph works #2],[test125.pe],[MinionPro-Regular.fea])
check_pedit([Try SVG and PT3],[test126.pe],[DataURI.sfd])
check_pedit([Test generation of TrueType instructions],[test127.pe],[Ambrosia.sfd])
#check_pedit([],[svg2ttf.pe])
check_pedit([Test StrSplit overrun],[test128.pe])
check_pedit([Ligatures and Fractions Table Lookups],[test129.pe])
check_pedit([TTC loading],[test130.pe],[NotoSans-Regular.ttc])
check_pedit([libnameslist checks],[test131.pe])
check_pedit([WOFF2 round tripping],[test132.pe],[Ambrosia.woff2])
check_pedit([Allowed characters in glyph class names],[test133.pe],[test133.fea])
check_pedit([Short-hand contextual multiple substitution],[test134.pe],[test134.fea])
check_pedit([GDEF glyph classes],[test135.pe],[test135.fea])
check_pedit([Re-using mark filtering set],[test136.pe],[test136.fea])
check_pedit([file:// protocol],[test137.pe],[Ambrosia.sfd])
check_pedit([Array sanity checking], [test138.pe])

AT_BANNER([FontForge Python Scripting Tests])

check_python([FontForge .sfd file open check],[test0001.py],[Ambrosia.sfd])
check_python([Loading duplicate name list],[test0002.py],[AGL For New Fonts.txt])
check_python([FontForge .ttc file open check],[test0101.py],[NotoSans-Regular.ttc])
check_python([Generate several font files],[test1001.py],[Caliban.sfd])
check_python([Point count check],[test1001a.py],[Zapfino-4.0d3.dfont])
check_python([Odd morx test without crashing],[test1001b.py],[Zapfino-4.1d6.dfont])
check_python([Make new font],[test1001c.py])
check_python([WOFF major minor meta check],[test1002.py],[nuvo-medium-woff-demo.woff])
check_python_ff([Various stroke tests],[test1003.py],[StrokeTests.sfd])
check_python([Clockwise direction test],[test1004.py],[DirectionTest.sfd])
check_python([Generate duplicate fonts test],[test1005.py],[AddExtremaTest2.sfd])
check_python([Math table test],[test1006.py])
check_python([Check for splinestroke 0 len fail],[test1007.py],[ayn+meem.init.svg])
check_python([PythonAPI: font glyph iteration],[test1008.py],[OverlapBugs.sfd])
check_python([Ligatures and Fractions Table Lookups],[test1009.py])
check_python([libnameslist checks],[test1010.py])
check_python([Feature file kerning with r2l lookup flag],[test1011.py],[test1011.fea])
check_python([GPOS kerning with r2l lookup flag],[test1012.py],[test1012.otf])
check_python([Read glyph names from unusual post table],[test1013.py],[NotoSerifTibetan-Regular.ttf])
#check_python([find overlap bug],[findoverlapbugs.py])
check_python([Validate WOFF output],[test926.py],[DejaVuSerif.sfd])
check_python([WOFF2 round tripping],[test927.py],[Ambrosia.woff2])
check_python([String Conversion],[test928.py],[DejaVuSerif.sfd])
check_python([Open Subfonts],[test929.py],[NotoSans-Regular.ttc])
check_python([Point, contour, and Layer fidelity],[test930.py])
check_python([Point type conversion tests],[test931.py])
check_python([Round-trip point selection tests],[test932.py])

#--------------------------------------------------------------------------
