#!/bin/bash
# Simple D-Bus Communication Test for apt-ostree

echo "=== apt-ostree D-Bus Communication Test ==="
echo

# Check if daemon is running
echo "1. Checking if daemon is running..."
if systemctl is-active --quiet apt-ostreed.service; then
    echo "✓ Daemon is running"
else
    echo "✗ Daemon is not running"
    exit 1
fi

# Check if D-Bus service is registered
echo
echo "2. Checking if D-Bus service is registered..."
if gdbus list --system 2>/dev/null | grep -q org.aptostree.dev; then
    echo "✓ D-Bus service is registered"
else
    echo "✗ D-Bus service is not registered"
    echo "Available services:"
    gdbus list --system 2>/dev/null | head -10
fi

# Test D-Bus introspection
echo
echo "3. Testing D-Bus introspection..."
if gdbus introspect --system --dest org.aptostree.dev --object-path /org/aptostree/dev 2>/dev/null | head -20; then
    echo "✓ D-Bus introspection works"
else
    echo "✗ D-Bus introspection failed"
fi

# Test Ping method
echo
echo "4. Testing Ping method..."
if gdbus call --system --dest org.aptostree.dev --object-path /org/aptostree/dev --method org.aptostree.dev.Daemon.Ping 2>/dev/null; then
    echo "✓ Ping method works"
else
    echo "✗ Ping method failed"
fi

# Test client-daemon communication
echo
echo "5. Testing client-daemon communication..."
if apt-ostree daemon-ping 2>/dev/null; then
    echo "✓ Client-daemon communication works"
else
    echo "✗ Client-daemon communication failed"
fi

echo
echo "=== Test Complete ===" 