#!/bin/sh
# Make sure that the examples compile and run

cd $AUTOPKGTEST_TMP

set -e

EXAMPLES_DIR=/usr/share/doc/libnxml0-dev/examples

# Ignoring easy.c as it tries to pull from a dead website
for f in new ; do
  gcc ${EXAMPLES_DIR}/${f}.c -lnxml -o $f && ./${f}
  rm ${f}
done

# File used in xml examples
echo "<a><b>b</b><c><c1>c1</c1><c2>c2</c2></c></a>" > example.xml

# namespace and parser
for f in namespace parser ; do
  gcc ${EXAMPLES_DIR}/${f}.c -lnxml -o $f && ./${f} example.xml
  rm ${f}
done

# write
gcc ${EXAMPLES_DIR}/write.c -lnxml -o write
./write example.xml write_output.xml
rm write

# Double-checking that the output of write is the expected one
cat > write_output_ref.xml << __EOF__
<?xml version="1.0" standalone="yes"?>

<a>
  <b>b</b>
  <c>
    <c1>c1</c1>
    <c2>c2</c2>
  </c>
</a>
__EOF__
diff write_output.xml write_output_ref.xml

rm example.xml write_output.xml write_output_ref.xml
