freerdp2/debian/tests/compare
2024-10-03 09:54:40 -04:00

41 lines
1.7 KiB
Bash

#!/bin/sh
set -x
screenshot=xrdp-screenshot.png
magickout=match-matrix
testdir=$(dirname "$0")
sudo systemctl start xrdp
# Start XRDP and try to connect to it via Freerdp2, the package being tested.
# Take a screenshot of the X virtual framebuffer, which should contain the
# login screen.
xvfb-run -l "$testdir/connect-and-capture" "$screenshot"
# Try to remove the background to leave just the login window in the image
cp -a "$screenshot" "${screenshot}.before.mogrify.png"
mogrify -fuzz 4% -define trim:percent-background=0% -trim +repage -format png "$screenshot"
# Resize the search image to match nearly the really displayed size
convert -resize 50% /usr/share/xrdp/xrdp_logo.bmp xrdp_logo_50percent.png
# Confirm that the XRDP logo is in the log in screen (so as to confirm that the
# login screen is really there).
# https://stackoverflow.com/questions/31867093/how-to-search-an-image-for-subimages-using-linux-console
# compare creates two output files, $magickout-{0,1}; The latter
# is a grayscale pattern, in which a white pixel represents a match.
# If the images don't even resemble each other in any way, the compare
# will fail but we don't need to check that specifically, because so
# will the if below.
compare -metric RMSE -subimage-search \
"$screenshot" xrdp_logo_50percent.png png:"$magickout"
# In case of match, output will be like
# "520,347: (255,255,255) #FFFFFF gray(255)"
# in which the first field is the coordinates of the match.
if ! convert "$magickout-1" -threshold 95% txt: | grep -qi '#FFFFFF'; then
2>&1 printf "%s\n" "Imagemagick did not find any occurence of the XRDP" \
"logo inside the screenshot of the remote desktop." \
"This test therefore failed."
exit 2
fi