107 lines
3.5 KiB
Diff
107 lines
3.5 KiB
Diff
|
From 77adf957d514715ea23f0810c07253cf3b97156e Mon Sep 17 00:00:00 2001
|
||
|
From: Benjamin Berg <bberg@redhat.com>
|
||
|
Date: Wed, 4 Dec 2019 19:58:26 +0100
|
||
|
Subject: [PATCH 096/181] tests: Update helper functions for new virtual-image
|
||
|
features
|
||
|
|
||
|
This also changes the code to keep the connection open and adds
|
||
|
automatic mainloop iteration to ensure the driver processes the request.
|
||
|
This is important so we will not deadlock when we send multiple
|
||
|
requests.
|
||
|
---
|
||
|
tests/virtual-image.py | 65 +++++++++++++++++++++++++-----------------
|
||
|
1 file changed, 39 insertions(+), 26 deletions(-)
|
||
|
|
||
|
diff --git a/tests/virtual-image.py b/tests/virtual-image.py
|
||
|
index 363219a..86bd86d 100755
|
||
|
--- a/tests/virtual-image.py
|
||
|
+++ b/tests/virtual-image.py
|
||
|
@@ -24,20 +24,6 @@ if wrapper:
|
||
|
os.unsetenv('LIBFPRINT_TEST_WRAPPER')
|
||
|
sys.exit(subprocess.check_call(wrap_cmd))
|
||
|
|
||
|
-class Connection:
|
||
|
-
|
||
|
- def __init__(self, addr):
|
||
|
- self.addr = addr
|
||
|
-
|
||
|
- def __enter__(self):
|
||
|
- self.con = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||
|
- self.con.connect(self.addr)
|
||
|
- return self.con
|
||
|
-
|
||
|
- def __exit__(self, exc_type, exc_val, exc_tb):
|
||
|
- self.con.close()
|
||
|
- del self.con
|
||
|
-
|
||
|
def load_image(img):
|
||
|
png = cairo.ImageSurface.create_from_png(img)
|
||
|
|
||
|
@@ -101,24 +87,51 @@ class VirtualImage(unittest.TestCase):
|
||
|
def setUp(self):
|
||
|
self.dev.open_sync()
|
||
|
|
||
|
+ self.con = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||
|
+ self.con.connect(self.sockaddr)
|
||
|
+
|
||
|
def tearDown(self):
|
||
|
+ self.con.close()
|
||
|
+ del self.con
|
||
|
self.dev.close_sync()
|
||
|
|
||
|
- def report_finger(self, state):
|
||
|
- with Connection(self.sockaddr) as con:
|
||
|
- con.write(struct.pack('ii', -1, 1 if state else 0))
|
||
|
-
|
||
|
- def send_image(self, image):
|
||
|
+ def send_retry(self, retry_error=1, iterate=True):
|
||
|
+ # The default (1) is too-short
|
||
|
+ self.sendall(struct.pack('ii', -1, retry_error))
|
||
|
+ while iterate and ctx.pending():
|
||
|
+ ctx.iteration(False)
|
||
|
+
|
||
|
+ def send_error(self, device_error=0, iterate=True):
|
||
|
+ # The default (0) is a generic error
|
||
|
+ self.sendall(struct.pack('ii', -1, retry_error))
|
||
|
+ while iterate and ctx.pending():
|
||
|
+ ctx.iteration(False)
|
||
|
+
|
||
|
+ def send_finger_automatic(self, automatic, iterate=True):
|
||
|
+ # Set whether finger on/off is reported around images
|
||
|
+ self.con.sendall(struct.pack('ii', -3, 1 if automatic else 0))
|
||
|
+ while iterate and ctx.pending():
|
||
|
+ ctx.iteration(False)
|
||
|
+
|
||
|
+ def send_finger_report(self, has_finger, iterate=True):
|
||
|
+ # Send finger on/off
|
||
|
+ self.con.sendall(struct.pack('ii', -4, 1 if has_finger else 0))
|
||
|
+ while iterate and ctx.pending():
|
||
|
+ ctx.iteration(False)
|
||
|
+
|
||
|
+ def send_image(self, image, iterate=True):
|
||
|
img = self.prints[image]
|
||
|
- with Connection(self.sockaddr) as con:
|
||
|
- mem = img.get_data()
|
||
|
- mem = mem.tobytes()
|
||
|
- assert len(mem) == img.get_width() * img.get_height()
|
||
|
|
||
|
- encoded_img = struct.pack('ii', img.get_width(), img.get_height())
|
||
|
- encoded_img += mem
|
||
|
+ mem = img.get_data()
|
||
|
+ mem = mem.tobytes()
|
||
|
+ assert len(mem) == img.get_width() * img.get_height()
|
||
|
+
|
||
|
+ encoded_img = struct.pack('ii', img.get_width(), img.get_height())
|
||
|
+ encoded_img += mem
|
||
|
|
||
|
- con.sendall(encoded_img)
|
||
|
+ self.con.sendall(encoded_img)
|
||
|
+ while iterate and ctx.pending():
|
||
|
+ ctx.iteration(False)
|
||
|
|
||
|
def test_capture_prevents_close(self):
|
||
|
cancel = Gio.Cancellable()
|
||
|
--
|
||
|
2.24.1
|
||
|
|