#!/bin/bash

set -e

readonly input_dia=./samples/chronograms.dia
readonly output_svg=chronograms.svg
readonly err=dia.err

# Export a dia file to SVG
dia --export=$output_svg $input_dia 2> $err

# The previous commands writes to stderr. To not trigger autopkgtest failure,
# write to a file and dump its content to stderr, without the expected line
grep -v "$input_dia --> $output_svg" $err 1>&2 || true


# Do not compare the content of the generated SVG file, because few numbers
# change a bit on different architectures...
file_out=$(file $output_svg)
expected_out="$output_svg: SVG "
if [[ "$file_out" != "$expected_out"* ]]
then
    echo "Wrong file type. Got '$file_out', expected something starting with '$expected_out'"
    exit 1
fi

nb_lines=$(cat $output_svg | wc -l)
expected_nb_lines=77
if [ $nb_lines != $expected_nb_lines ]
then
    echo "Wrong number of lines in generated SVG. Got $nb_lines, expected $expected_nb_lines"
    exit 1
fi
