Blame SOURCES/0176-tests-Add-error-reporting-tests-based-on-virtual-dri.patch

73b847
From 2ce87cc7a8c662b12900acb9697d74bee0f143f4 Mon Sep 17 00:00:00 2001
73b847
From: Benjamin Berg <bberg@redhat.com>
73b847
Date: Mon, 13 Jan 2020 17:57:31 +0100
73b847
Subject: [PATCH 176/181] tests: Add error reporting tests based on virtual
73b847
 driver
73b847
73b847
We were not testing the image device error reporting functions yet
73b847
inside libfprint (fprintd already had such tests). Add tests to make
73b847
sure we catch errors earlier.
73b847
---
73b847
 tests/virtual-image.py | 61 ++++++++++++++++++++++++++++++++++--------
73b847
 1 file changed, 50 insertions(+), 11 deletions(-)
73b847
73b847
diff --git a/tests/virtual-image.py b/tests/virtual-image.py
73b847
index 11ec8ae..a6bf6d2 100755
73b847
--- a/tests/virtual-image.py
73b847
+++ b/tests/virtual-image.py
73b847
@@ -99,13 +99,13 @@ class VirtualImage(unittest.TestCase):
73b847
 
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
+        self.con.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
+        self.con.sendall(struct.pack('ii', -2, device_error))
73b847
         while iterate and ctx.pending():
73b847
             ctx.iteration(False)
73b847
 
73b847
@@ -212,9 +212,10 @@ class VirtualImage(unittest.TestCase):
73b847
         done = False
73b847
 
73b847
         def verify_cb(dev, res):
73b847
-            match, fp = dev.verify_finish(res)
73b847
-            self._verify_match = match
73b847
-            self._verify_fp = fp
73b847
+            try:
73b847
+                self._verify_match, self._verify_fp = dev.verify_finish(res)
73b847
+            except gi.repository.GLib.Error as e:
73b847
+                self._verify_error = e
73b847
 
73b847
         fp_whorl = self.enroll_print('whorl')
73b847
 
73b847
@@ -234,20 +235,39 @@ class VirtualImage(unittest.TestCase):
73b847
             ctx.iteration(True)
73b847
         assert(not self._verify_match)
73b847
 
73b847
+        # Test verify error cases
73b847
+        self._verify_fp = None
73b847
+        self._verify_error = None
73b847
+        self.dev.verify(fp_whorl, callback=verify_cb)
73b847
+        self.send_retry()
73b847
+        while self._verify_fp is None and self._verify_error is None:
73b847
+            ctx.iteration(True)
73b847
+        assert(self._verify_error is not None)
73b847
+        assert(self._verify_error.matches(FPrint.device_retry_quark(), FPrint.DeviceRetry.TOO_SHORT))
73b847
+
73b847
+        self._verify_fp = None
73b847
+        self._verify_error = None
73b847
+        self.dev.verify(fp_whorl, callback=verify_cb)
73b847
+        self.send_error()
73b847
+        while self._verify_fp is None and self._verify_error is None:
73b847
+            ctx.iteration(True)
73b847
+        assert(self._verify_error is not None)
73b847
+        print(self._verify_error)
73b847
+        assert(self._verify_error.matches(FPrint.device_error_quark(), FPrint.DeviceError.GENERAL))
73b847
+
73b847
     def test_identify(self):
73b847
         done = False
73b847
 
73b847
-        def verify_cb(dev, res):
73b847
-            r, fp = dev.verify_finish(res)
73b847
-            self._verify_match = r
73b847
-            self._verify_fp = fp
73b847
-
73b847
         fp_whorl = self.enroll_print('whorl')
73b847
         fp_tented_arch = self.enroll_print('tented_arch')
73b847
 
73b847
         def identify_cb(dev, res):
73b847
             print('Identify finished')
73b847
-            self._identify_match, self._identify_fp = self.dev.identify_finish(res)
73b847
+            try:
73b847
+                self._identify_match, self._identify_fp = self.dev.identify_finish(res)
73b847
+            except gi.repository.GLib.Error as e:
73b847
+                print(e)
73b847
+                self._identify_error = e
73b847
 
73b847
         self._identify_fp = None
73b847
         self.dev.identify([fp_whorl, fp_tented_arch], None, identify_cb)
73b847
@@ -263,6 +283,25 @@ class VirtualImage(unittest.TestCase):
73b847
             ctx.iteration(True)
73b847
         assert(self._identify_match is fp_whorl)
73b847
 
73b847
+        # Test error cases
73b847
+        self._identify_fp = None
73b847
+        self._identify_error = None
73b847
+        self.dev.identify([fp_whorl, fp_tented_arch], callback=identify_cb)
73b847
+        self.send_retry()
73b847
+        while self._identify_fp is None and self._identify_error is None:
73b847
+            ctx.iteration(True)
73b847
+        assert(self._identify_error is not None)
73b847
+        assert(self._identify_error.matches(FPrint.device_retry_quark(), FPrint.DeviceRetry.TOO_SHORT))
73b847
+
73b847
+        self._identify_fp = None
73b847
+        self._identify_error = None
73b847
+        self.dev.identify([fp_whorl, fp_tented_arch], callback=identify_cb)
73b847
+        self.send_error()
73b847
+        while self._identify_fp is None and self._identify_error is None:
73b847
+            ctx.iteration(True)
73b847
+        assert(self._identify_error is not None)
73b847
+        assert(self._identify_error.matches(FPrint.device_error_quark(), FPrint.DeviceError.GENERAL))
73b847
+
73b847
     def test_verify_serialized(self):
73b847
         done = False
73b847
 
73b847
-- 
73b847
2.24.1
73b847