#!/bin/sh
# autopkgtest check: Build and run a program against libpoppler, to verify that the
# headers and pkg-config file are installed correctly
# (C) 2012 Canonical Ltd.
# Author: Daniel Kessel <d.kessel@gmx.de>

set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR
cat <<EOF > libpopplertest.c
#include <poppler.h>

int main()
{
#if !defined(GLIB_VERSION_2_36)
    g_type_init();
#endif
    PopplerDocument* doc = poppler_document_new_from_file("file:///usr/share/cups/data/default-testpage.pdf", NULL, NULL);
    g_assert(doc != NULL);

    int n_pages = poppler_document_get_n_pages(doc);
    g_assert_cmpint(n_pages, == , 1);

    return 0;
}
EOF

gcc -o libpopplertest libpopplertest.c `pkg-config --cflags --libs poppler-glib` -Wall -Werror
echo "build: OK"
[ -x libpopplertest ]
./libpopplertest
echo "run: OK"
