| 1 | #!/bin/bash |
| 2 | # Test script for garfield-portal |
| 3 | # |
| 4 | # This script verifies that the portal is working correctly. |
| 5 | |
| 6 | set -e |
| 7 | |
| 8 | RED='\033[0;31m' |
| 9 | GREEN='\033[0;32m' |
| 10 | YELLOW='\033[1;33m' |
| 11 | NC='\033[0m' |
| 12 | |
| 13 | print_status() { echo -e "${GREEN}[PASS]${NC} $1"; } |
| 14 | print_warning() { echo -e "${YELLOW}[WARN]${NC} $1"; } |
| 15 | print_error() { echo -e "${RED}[FAIL]${NC} $1"; } |
| 16 | |
| 17 | echo "Testing garfield-portal..." |
| 18 | echo "" |
| 19 | |
| 20 | # Test 1: Check if D-Bus name is registered |
| 21 | echo "1. Checking D-Bus registration..." |
| 22 | if busctl --user status org.freedesktop.impl.portal.desktop.garfield &>/dev/null; then |
| 23 | print_status "D-Bus name registered" |
| 24 | else |
| 25 | print_error "D-Bus name not registered" |
| 26 | echo " Try: systemctl --user start garfield-portal" |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | # Test 2: Check if FileChooser interface is available |
| 31 | echo "" |
| 32 | echo "2. Checking FileChooser interface..." |
| 33 | if busctl --user introspect org.freedesktop.impl.portal.desktop.garfield /org/freedesktop/portal/desktop 2>/dev/null | grep -q "OpenFile"; then |
| 34 | print_status "FileChooser.OpenFile method available" |
| 35 | else |
| 36 | print_error "FileChooser interface not found" |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | # Test 3: Check portal config |
| 41 | echo "" |
| 42 | echo "3. Checking portal configuration..." |
| 43 | if [[ -f /usr/share/xdg-desktop-portal/portals/garfield.portal ]] || \ |
| 44 | [[ -f ~/.local/share/xdg-desktop-portal/portals/garfield.portal ]]; then |
| 45 | print_status "Portal config file exists" |
| 46 | else |
| 47 | print_error "Portal config not found" |
| 48 | exit 1 |
| 49 | fi |
| 50 | |
| 51 | # Test 4: Check if garfield binary is available |
| 52 | echo "" |
| 53 | echo "4. Checking garfield binary..." |
| 54 | if command -v garfield &>/dev/null; then |
| 55 | print_status "garfield binary found: $(command -v garfield)" |
| 56 | else |
| 57 | print_warning "garfield not in PATH (needed for picker mode)" |
| 58 | fi |
| 59 | |
| 60 | echo "" |
| 61 | echo "All tests passed!" |
| 62 | echo "" |
| 63 | echo "To test with a real application:" |
| 64 | echo "" |
| 65 | echo " # With GTK apps:" |
| 66 | echo " GTK_USE_PORTAL=1 gedit" |
| 67 | echo " GTK_USE_PORTAL=1 firefox" |
| 68 | echo "" |
| 69 | echo " # With Qt apps (KDE):" |
| 70 | echo " QT_QPA_PLATFORMTHEME=xdgdesktopportal dolphin" |
| 71 | echo "" |
| 72 | echo " # With Flatpak apps:" |
| 73 | echo " flatpak run org.gnome.TextEditor" |
| 74 | echo "" |
| 75 | echo "To use garfield as the default file picker in gar desktop," |
| 76 | echo "set XDG_CURRENT_DESKTOP=gar in your session." |