#!/bin/sh

oneTimeSetUp () {

  # ensure temporary directory exists
  if [ -z "$AUTOPKGTEST_TMP" ] ; then
    AUTOPKGTEST_TMP=$( mktemp -d )
  fi

  # setup test environment
  cp -r debian/tests/expected $AUTOPKGTEST_TMP
  mkdir -p $HOME/.xplanet/images
  cp debian/tests/clouds.jpg $HOME/.xplanet/images


  ## generate new images
  for conf in /etc/xplanet/config/* ; do
    filename=${conf##*/}
    xplanet -geometry 1024x768 -config $conf -date 20220826.163000 -num_times 1 -fontsize=36 -font=FreeMonoBold.ttf -output $AUTOPKGTEST_TMP/$filename.jpeg
    xplanet -geometry 1024x768 -config $conf -date 20220826.163000 -num_times 1 -fontsize=36 -font=FreeMonoBold.ttf -output $AUTOPKGTEST_TMP/$filename.png
  done
}


# then we check the created images with the ones we created and verified earlier
test_compare_images () {
  for conf in /etc/xplanet/config/* ; do
    filename=${conf##*/}
    echo "comparing $filename.jpg"
    compare -metric ncc $AUTOPKGTEST_TMP/expected/$filename.jpeg $AUTOPKGTEST_TMP/$filename.jpeg $AUTOPKGTEST_TMP/diff.jpg 2>&1
    echo
    assertEquals "Comparing $filename.jpg" "0" "$?"
    echo "comparing $filename.png"
    compare -metric ncc $AUTOPKGTEST_TMP/expected/$filename.png $AUTOPKGTEST_TMP/$filename.png $AUTOPKGTEST_TMP/diff.png 2>&1
    echo
    assertEquals "Comparing $filename.png" "0" "$?"
  done
}

. shunit2

