feat: Add dummy game utility and enhance testing capabilities
- also improve argument handling
This commit is contained in:
BIN
tests/assets/sample.jpg
Normal file
BIN
tests/assets/sample.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 652 KiB |
83
tests/test_cli.sh
Executable file
83
tests/test_cli.sh
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
# A test suite for testing CLI argument permutations of gsplash
|
||||
|
||||
GSPLASH="./build/gsplash"
|
||||
GAME="/bin/true"
|
||||
IMAGE="nonexistent.png"
|
||||
|
||||
if [ ! -f "$GSPLASH" ]; then
|
||||
echo "Please run 'make' first to build gsplash."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export SDL_VIDEODRIVER=dummy
|
||||
|
||||
pass=0
|
||||
fail=0
|
||||
|
||||
run_test() {
|
||||
local expected_status=$1
|
||||
shift
|
||||
local expected_log="$1"
|
||||
shift
|
||||
local desc="$1"
|
||||
shift
|
||||
|
||||
printf "Test: %-45s " "$desc"
|
||||
|
||||
# Run the command and capture output
|
||||
local output
|
||||
output=$($GSPLASH "$@" 2>&1)
|
||||
local status=$?
|
||||
|
||||
local passed=true
|
||||
local error_msg=""
|
||||
|
||||
if [ $status -ne $expected_status ]; then
|
||||
passed=false
|
||||
error_msg="Expected status $expected_status, got $status"
|
||||
elif [ -n "$expected_log" ]; then
|
||||
if ! echo "$output" | grep -q "$expected_log"; then
|
||||
passed=false
|
||||
error_msg="Expected log missing: $expected_log"
|
||||
fi
|
||||
fi
|
||||
|
||||
if $passed; then
|
||||
echo "PASS"
|
||||
pass=$((pass+1))
|
||||
else
|
||||
echo "FAIL ($error_msg)"
|
||||
fail=$((fail+1))
|
||||
fi
|
||||
}
|
||||
|
||||
echo "=== Running CLI Argument Tests ==="
|
||||
|
||||
# Valid combinations (0=STRETCH, 1=CENTER, 2=CROP)
|
||||
run_test 0 "mode=1" "Basic invocation" $IMAGE $GAME
|
||||
run_test 0 "mode=0" "Long mode: stretch" --mode=stretch $IMAGE $GAME
|
||||
run_test 0 "mode=1" "Long mode: center" --mode=center $IMAGE $GAME
|
||||
run_test 0 "mode=2" "Long mode: crop" --mode=crop $IMAGE $GAME
|
||||
run_test 0 "mode=0" "Long mode: fallback to stretch" --mode=invalid $IMAGE $GAME
|
||||
run_test 0 "mode=0" "Short mode: stretch" -m stretch $IMAGE $GAME
|
||||
run_test 0 "mode=1" "Short mode: center" -m center $IMAGE $GAME
|
||||
run_test 0 "mode=2" "Short mode: crop" -m crop $IMAGE $GAME
|
||||
run_test 0 "mode=0" "Short mode: fallback to stretch" -m whatever $IMAGE $GAME
|
||||
run_test 0 "mode=1" "With game arguments" $IMAGE $GAME arg1 arg2
|
||||
run_test 0 "mode=2" "Mode and game arguments" -m crop $IMAGE $GAME arg1 arg2
|
||||
|
||||
# Invalid combinations (Usage errors, so we just check for status 1, no specific log needed)
|
||||
run_test 1 "" "No arguments"
|
||||
run_test 1 "" "Only image" $IMAGE
|
||||
run_test 1 "" "Missing arg for short mode (-m only)" -m $IMAGE
|
||||
run_test 1 "" "Missing game for short mode" -m stretch $IMAGE
|
||||
|
||||
echo "================================================="
|
||||
echo "Tests completed: $pass passed, $fail failed."
|
||||
|
||||
if [ $fail -gt 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
69
tests/test_interactive.sh
Executable file
69
tests/test_interactive.sh
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
|
||||
GSPLASH="./build/gsplash"
|
||||
DUMMY="./build/dummy_game"
|
||||
|
||||
if [ ! -f "$GSPLASH" ] || [ ! -f "$DUMMY" ]; then
|
||||
echo "Please run 'make' first to build gsplash and dummy_game."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 <path_to_test_image_or_video>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
IMAGE="$1"
|
||||
if [ ! -f "$IMAGE" ]; then
|
||||
echo "Error: File '$IMAGE' not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "=== Interactive gsplash Visual Test ==="
|
||||
echo "This will physically display the splash screen using different modes."
|
||||
echo "You will be asked to confirm if it looked correct after each test."
|
||||
echo ""
|
||||
|
||||
pass=0
|
||||
fail=0
|
||||
|
||||
run_interactive_test() {
|
||||
local mode="$1"
|
||||
|
||||
echo "------------------------------------------------"
|
||||
echo "Testing mode: $mode"
|
||||
echo "Launching in 2 seconds (it will stay open for 3 seconds)..."
|
||||
sleep 2
|
||||
|
||||
# Run gsplash with a 3-second dummy game
|
||||
$GSPLASH --mode="$mode" "$IMAGE" "$DUMMY" 3
|
||||
|
||||
# Prompt the user interactively
|
||||
while true; do
|
||||
read -p "Did it display correctly for mode '$mode'? [y/N] " response
|
||||
case "$response" in
|
||||
[yY][eE][sS]|[yY])
|
||||
echo "=> PASS recorded."
|
||||
pass=$((pass+1))
|
||||
break
|
||||
;;
|
||||
[nN][oO]|[nN]|"")
|
||||
echo "=> FAIL recorded."
|
||||
fail=$((fail+1))
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Please answer y or n."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
run_interactive_test "stretch"
|
||||
run_interactive_test "center"
|
||||
run_interactive_test "crop"
|
||||
|
||||
echo "================================================"
|
||||
echo "Interactive Testing Complete!"
|
||||
echo "Passed: $pass"
|
||||
echo "Failed: $fail"
|
||||
Reference in New Issue
Block a user