Skip to content

Commit

Permalink
test: add tool multi-user integration test
Browse files Browse the repository at this point in the history
Rather hacked up quickly but does the job for now...
  • Loading branch information
bk138 committed Mar 29, 2024
1 parent 2ff2061 commit 728c8b1
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
send_input
20 changes: 20 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Gromit-MPX Integration Tests

## Tool Multi-User Test

What this quick and dirty shell script does is:

- start Gromit-MPX
- add two new XI2 pointer-keyboard pairs
- simultaneously do an action with both of them
- remove them again

Launch with `./test-tool-multi-user.sh <path to gromit-mpx> <tool>`, e.g.

`./test-tool-multi-user.sh ../build/gromit-mpx PEN`

or

`./test-tool-multi-user.sh ../build/gromit-mpx RECT`

or any other tool.
48 changes: 48 additions & 0 deletions test/send_input.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
if (argc != 3) {
printf("Usage: %s <device_id> <offset>\n", argv[0]);
return 1;
}

Display *display = XOpenDisplay(NULL);
if (!display) {
fprintf(stderr, "Unable to open display.\n");
return 1;
}

int device_id = atoi(argv[1]);
XDevice xdev;
xdev.device_id = device_id;

int offset = atoi(argv[2]);

// Move the pointer to (100+offset, 100)
int axes[] = {100 + offset, 100};
XTestFakeDeviceMotionEvent(display, &xdev, 0, 0, axes, 2, 0);

// Press the left button.
XTestFakeDeviceButtonEvent(display, &xdev, 1, True, NULL, 0, 0);

// Move the pointer to (300+offset, 300) in steps of 10
for(int i = 0; i < 20; ++i) {
axes[0] += 10;
axes[1] += 10;
XTestFakeDeviceMotionEvent(display, &xdev, 0, 0, axes, 2, 0);
usleep(100*1000);
XFlush(display);
}

// Release the left button.
XTestFakeDeviceButtonEvent(display, &xdev, 1, False, NULL, 0, 0);

// Close the display connection.
XCloseDisplay(display);

return 0;
}
63 changes: 63 additions & 0 deletions test/test-tool-multi-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh
#
# Quick and dirty tool tester.
#
# Things to improve:
# - get rid of user cfg modification
# - get rid of sleep's
# - move more/all functionality to native code


GROMIT_MPX="$1"
TOOL="$2"

[ -z "$GROMIT_MPX" ] || [ -z "$TOOL" ] && {
echo "./test-tool-multi-user.sh <path to gromit-mpx> <tool>"
exit 1
}

mv ~/.config/gromit-mpx.cfg ~/.config/gromit-mpx.cfg.bak
echo \
'
"test-tool" = '"$TOOL"' (size=5 color="green");
"default" = "test-tool";
' > ~/.config/gromit-mpx.cfg

echo "\033[32mbuilding helper\033[0m"
cc -o send_input send_input.c -lX11 -lXtst

echo "\033[32mlaunching gromit-mpx\033[0m"
$GROMIT_MPX &
PID=$!

sleep 1

echo "\033[32mcreating test devices\033[0m"
xinput create-master one 2>/dev/null
xinput create-master two 2>/dev/null

ID_ONE=$(xinput list --id-only "one pointer" 2>/dev/null)
ID_TWO=$(xinput list --id-only "two pointer" 2>/dev/null)

XTEST_ID_ONE=$(xinput list --id-only "one XTEST pointer" 2>/dev/null)
XTEST_ID_TWO=$(xinput list --id-only "two XTEST pointer" 2>/dev/null)

echo "\033[32mtesting, you should see something in the upper left of the screen; you can also draw manually\033[0m"
$GROMIT_MPX -t
sleep 1
./send_input $XTEST_ID_ONE 100 &
./send_input $XTEST_ID_TWO 300 &
sleep 3
$GROMIT_MPX -t

sleep 1

echo "\033[32mcleaning up\033[0m"
xinput remove-master $ID_ONE 2>/dev/null
xinput remove-master $ID_TWO 2>/dev/null

kill $PID

mv ~/.config/gromit-mpx.cfg.bak ~/.config/gromit-mpx.cfg

echo "\033[32mdone\033[0m"

0 comments on commit 728c8b1

Please sign in to comment.