diff --git a/test-peers.sh b/test-peers.sh new file mode 100755 index 0000000..0ed9bbd --- /dev/null +++ b/test-peers.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# Test peer-to-peer agent communication +# Run while the daemon is running: make run +set -e + +SERVICE="org.ollie.SessionManager" +OBJ="/org/ollie/SessionManager" +IFACE="org.ollie.SessionManager" + +echo "=== Create session A ===" +A=$(dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.CreateSession string:"$HOME" string:"" string:"" string:"default" | grep 'string "' | head -1 | sed 's/.*string "//;s/"//') +echo "A: $A" + +echo "=== Create session B ===" +B=$(dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.CreateSession string:"$HOME" string:"" string:"" string:"default" | grep 'string "' | head -1 | sed 's/.*string "//;s/"//') +echo "B: $B" + +echo "" +echo "=== PeerAdd: A registers B ===" +dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.PeerAdd string:"$A" string:"$B" + +echo "" +echo "=== PeerList ===" +dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.PeerList string:"$A" + +echo "" +echo "=== PeerSubmit: A sends to B ===" +dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.PeerSubmit string:"$A" string:"$B" \ + string:"Reply with exactly: PEER_OK" + +echo "" +echo "=== Waiting 8s for B to respond... ===" +sleep 8 + +echo "" +echo "=== B's chat ===" +dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.GetChat string:"$B" int64:0 + +echo "" +echo "=== PeerRemove ===" +dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.PeerRemove string:"$A" string:"$B" + +echo "" +echo "=== Cleanup ===" +dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.KillSession string:"$A" > /dev/null +dbus-send --session --dest=$SERVICE --type=method_call --print-reply \ + $OBJ $IFACE.KillSession string:"$B" > /dev/null +echo "=== DONE ==="