#!/bin/sh
#
# Script to test ippfind, ipptool, and ippeveprinter end-to-end.
#
# Copyright © 2022-2025 by OpenPrinting.
#
# Licensed under Apache License v2.0.  See the file "LICENSE" for more
# information.
#

cd ..

# Run ippeveprinter to provide an endpoint for testing...
name="Test Printer $(date +%H%M%S)"
status=0

rm -f tools/test.log tools/test-debug.log

echo "Running ippeveprinter..."
CUPS_DEBUG_LOG=tools/test-debug.log CUPS_DEBUG_LEVEL=4 CUPS_DEBUG_FILTER='^(http|_http|ipp|_ipp|cupsDNSSD|cupsCreate|cupsDo|cupsGet|cupsSend)' tools/ippeveprinter-static -vvv -a tools/test.conf -n localhost -L tools/test.log "$name" &
ippeveprinter=$!

# Test the instance...
echo "Running ippfind + ipptool..."
tools/ippfind-static -T 30 --literal-name "$name" --exec tools/ipptool-static -V 2.0 -tIf examples/document-letter.pdf '{}' examples/ipp-2.0.test examples/pwg5100.1.test examples/pwg5100.2.test examples/pwg5100.7.test examples/pwg5100.13.test \; || status=1

if test $status = 1; then
    echo "Unable to find test printer."
fi

# Clean up
kill $ippeveprinter

exit $status
