counter-interaction.sh
raw
#!/usr/bin/env bash
# Counter interaction test (example name as $1, default m2_counter): drives the counter example under quibble and asserts
# 1. an idle window renders zero frames (the dirty-tracking guarantee),
# 2. ten clicks produce count=10,
# 3. hover in/out repaints, but a bounded number of times.
#
# Requires: quibble + quibblectl on PATH. Exits nonzero on any failure.
set -euo pipefail
cd "$(dirname "$0")/.."
EXAMPLE="${1:-m2_counter}"
cargo build -p guiduck --example "$EXAMPLE"
workdir=$(mktemp -d)
sock="$workdir/quibble.sock"
cleanup() {
quibblectl --socket "$sock" quit >/dev/null 2>&1 || true
rm -rf "$workdir"
}
trap cleanup EXIT
# Fixed output size; the counter sample's unit test pins the button to
# contain this click point at this viewport.
CLICK_X=76
CLICK_Y=80
GUIDUCK_BACKEND=software GUIDUCK_TRACE_FRAMES=1 \
quibble --socket "$sock" --width 400 --height 300 \
"target/debug/examples/$EXAMPLE" \
>"$workdir/out.log" 2>"$workdir/err.log" &
for _ in $(seq 1 50); do
quibblectl --socket "$sock" ping >/dev/null 2>&1 && break
sleep 0.2
done
quibblectl --socket "$sock" wait-window --timeout-ms 30000 >/dev/null
sleep 1
frames() { grep -c '^guiduck-frame' "$workdir/err.log" || true; }
fail=0
# 1: idle renders nothing.
before=$(frames)
sleep 3
after=$(frames)
echo "idle frames: $before -> $after"
if [ "$before" != "$after" ]; then
echo "FAIL: idle window rendered $((after - before)) frames" >&2
fail=1
fi
# 2: ten clicks -> count=10.
quibblectl --socket "$sock" pointer-move $CLICK_X $CLICK_Y >/dev/null
for _ in $(seq 1 10); do
quibblectl --socket "$sock" click >/dev/null
done
sleep 1
quibblectl --socket "$sock" screenshot -o "$workdir/after-clicks.png" >/dev/null
if grep -q '^count=10$' "$workdir/out.log"; then
echo "clicks: count=10 reached"
else
echo "FAIL: expected count=10; got: $(grep '^count=' "$workdir/out.log" | tail -3 | tr '\n' ' ')" >&2
fail=1
fi
# 3: hover in/out repaints a bounded number of times.
h0=$(frames)
for _ in 1 2 3; do
quibblectl --socket "$sock" pointer-move $CLICK_X $CLICK_Y >/dev/null
sleep 0.2
quibblectl --socket "$sock" pointer-move 350 250 >/dev/null
sleep 0.2
done
sleep 1
h1=$(frames)
hover_frames=$((h1 - h0))
echo "hover frames for 3 in/out cycles: $hover_frames"
if [ "$hover_frames" -lt 1 ] || [ "$hover_frames" -gt 12 ]; then
echo "FAIL: expected 1..12 hover frames, got $hover_frames" >&2
fail=1
fi
# 4: quiescent again after interaction.
q0=$(frames)
sleep 2
q1=$(frames)
echo "post-interaction idle frames: $q0 -> $q1"
if [ "$q0" != "$q1" ]; then
echo "FAIL: window kept rendering after interaction stopped" >&2
fail=1
fi
cp "$workdir/after-clicks.png" "target/$EXAMPLE-after-clicks.png" 2>/dev/null || true
if [ "$fail" -eq 0 ]; then
echo "counter interaction test ($EXAMPLE) PASSED (screenshot: "target/$EXAMPLE-after-clicks.png")"
fi
exit $fail