# The URI is the whole of what viewer decides, and VIEWER=echo reports
# it without a client anywhere. The guests here are emulated.

"$VMM" create vw1 64M >/dev/null 2>&1

exits 2 "viewer of an unknown VM exits 2" viewer nosuchvm
exits 3 "viewer of a stopped VM exits 3" viewer vw1

cfg vw1 <<EOF
MEM=256
CPUS=1
HWACCEL=no
EOF
if "$VMM" start vw1 >/dev/null 2>&1; then
	refuses 'has no display' "GRAPHICS=no leaves nothing to view" viewer vw1
	"$VMM" kill vw1 >/dev/null 2>&1 || :
else
	skip 1 "vw1 did not start"
fi

# The URI names the socket that is really there, not what the config
# says, so a display that failed to appear is an error rather than a
# client left dialling nothing.
for g in vnc spice; do
	cfg vw1 <<EOF
MEM=256
CPUS=1
HWACCEL=no
GRAPHICS=$g
EOF
	if ! "$VMM" start vw1 >/dev/null 2>&1; then
		skip 2 "this qemu cannot do GRAPHICS=$g"
		continue
	fi
	out=$(env VIEWER=echo "$VMM" viewer vw1 2>&1) && got=0 || got=$?
	if [ "$got" = 0 ] && [ "$out" = "$g+unix://$VMMDIR/vw1/$g.sock" ]; then
		ok "$g is handed to the client as $g+unix"
	else
		notok "$g is handed to the client as $g+unix" \
			"exit $got, wanted $g+unix://$VMMDIR/vw1/$g.sock" "got: $out"
	fi
	"$VMM" kill vw1 >/dev/null 2>&1 || :
	exits 3 "and the killed $g guest has nothing to view" viewer vw1
done
