Blame SOURCES/0096-tests-Update-helper-functions-for-new-virtual-image-.patch

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