tests: Add error reporting tests based on virtual driver
We were not testing the image device error reporting functions yet inside libfprint (fprintd already had such tests). Add tests to make sure we catch errors earlier.
This commit is contained in:
parent
54286c7603
commit
29a13a9b4a
1 changed files with 50 additions and 11 deletions
|
@ -99,13 +99,13 @@ class VirtualImage(unittest.TestCase):
|
||||||
|
|
||||||
def send_retry(self, retry_error=1, iterate=True):
|
def send_retry(self, retry_error=1, iterate=True):
|
||||||
# The default (1) is too-short
|
# The default (1) is too-short
|
||||||
self.sendall(struct.pack('ii', -1, retry_error))
|
self.con.sendall(struct.pack('ii', -1, retry_error))
|
||||||
while iterate and ctx.pending():
|
while iterate and ctx.pending():
|
||||||
ctx.iteration(False)
|
ctx.iteration(False)
|
||||||
|
|
||||||
def send_error(self, device_error=0, iterate=True):
|
def send_error(self, device_error=0, iterate=True):
|
||||||
# The default (0) is a generic error
|
# The default (0) is a generic error
|
||||||
self.sendall(struct.pack('ii', -1, retry_error))
|
self.con.sendall(struct.pack('ii', -2, device_error))
|
||||||
while iterate and ctx.pending():
|
while iterate and ctx.pending():
|
||||||
ctx.iteration(False)
|
ctx.iteration(False)
|
||||||
|
|
||||||
|
@ -212,9 +212,10 @@ class VirtualImage(unittest.TestCase):
|
||||||
done = False
|
done = False
|
||||||
|
|
||||||
def verify_cb(dev, res):
|
def verify_cb(dev, res):
|
||||||
match, fp = dev.verify_finish(res)
|
try:
|
||||||
self._verify_match = match
|
self._verify_match, self._verify_fp = dev.verify_finish(res)
|
||||||
self._verify_fp = fp
|
except gi.repository.GLib.Error as e:
|
||||||
|
self._verify_error = e
|
||||||
|
|
||||||
fp_whorl = self.enroll_print('whorl')
|
fp_whorl = self.enroll_print('whorl')
|
||||||
|
|
||||||
|
@ -234,20 +235,39 @@ class VirtualImage(unittest.TestCase):
|
||||||
ctx.iteration(True)
|
ctx.iteration(True)
|
||||||
assert(not self._verify_match)
|
assert(not self._verify_match)
|
||||||
|
|
||||||
|
# Test verify error cases
|
||||||
|
self._verify_fp = None
|
||||||
|
self._verify_error = None
|
||||||
|
self.dev.verify(fp_whorl, callback=verify_cb)
|
||||||
|
self.send_retry()
|
||||||
|
while self._verify_fp is None and self._verify_error is None:
|
||||||
|
ctx.iteration(True)
|
||||||
|
assert(self._verify_error is not None)
|
||||||
|
assert(self._verify_error.matches(FPrint.device_retry_quark(), FPrint.DeviceRetry.TOO_SHORT))
|
||||||
|
|
||||||
|
self._verify_fp = None
|
||||||
|
self._verify_error = None
|
||||||
|
self.dev.verify(fp_whorl, callback=verify_cb)
|
||||||
|
self.send_error()
|
||||||
|
while self._verify_fp is None and self._verify_error is None:
|
||||||
|
ctx.iteration(True)
|
||||||
|
assert(self._verify_error is not None)
|
||||||
|
print(self._verify_error)
|
||||||
|
assert(self._verify_error.matches(FPrint.device_error_quark(), FPrint.DeviceError.GENERAL))
|
||||||
|
|
||||||
def test_identify(self):
|
def test_identify(self):
|
||||||
done = False
|
done = False
|
||||||
|
|
||||||
def verify_cb(dev, res):
|
|
||||||
r, fp = dev.verify_finish(res)
|
|
||||||
self._verify_match = r
|
|
||||||
self._verify_fp = fp
|
|
||||||
|
|
||||||
fp_whorl = self.enroll_print('whorl')
|
fp_whorl = self.enroll_print('whorl')
|
||||||
fp_tented_arch = self.enroll_print('tented_arch')
|
fp_tented_arch = self.enroll_print('tented_arch')
|
||||||
|
|
||||||
def identify_cb(dev, res):
|
def identify_cb(dev, res):
|
||||||
print('Identify finished')
|
print('Identify finished')
|
||||||
|
try:
|
||||||
self._identify_match, self._identify_fp = self.dev.identify_finish(res)
|
self._identify_match, self._identify_fp = self.dev.identify_finish(res)
|
||||||
|
except gi.repository.GLib.Error as e:
|
||||||
|
print(e)
|
||||||
|
self._identify_error = e
|
||||||
|
|
||||||
self._identify_fp = None
|
self._identify_fp = None
|
||||||
self.dev.identify([fp_whorl, fp_tented_arch], callback=identify_cb)
|
self.dev.identify([fp_whorl, fp_tented_arch], callback=identify_cb)
|
||||||
|
@ -263,6 +283,25 @@ class VirtualImage(unittest.TestCase):
|
||||||
ctx.iteration(True)
|
ctx.iteration(True)
|
||||||
assert(self._identify_match is fp_whorl)
|
assert(self._identify_match is fp_whorl)
|
||||||
|
|
||||||
|
# Test error cases
|
||||||
|
self._identify_fp = None
|
||||||
|
self._identify_error = None
|
||||||
|
self.dev.identify([fp_whorl, fp_tented_arch], callback=identify_cb)
|
||||||
|
self.send_retry()
|
||||||
|
while self._identify_fp is None and self._identify_error is None:
|
||||||
|
ctx.iteration(True)
|
||||||
|
assert(self._identify_error is not None)
|
||||||
|
assert(self._identify_error.matches(FPrint.device_retry_quark(), FPrint.DeviceRetry.TOO_SHORT))
|
||||||
|
|
||||||
|
self._identify_fp = None
|
||||||
|
self._identify_error = None
|
||||||
|
self.dev.identify([fp_whorl, fp_tented_arch], callback=identify_cb)
|
||||||
|
self.send_error()
|
||||||
|
while self._identify_fp is None and self._identify_error is None:
|
||||||
|
ctx.iteration(True)
|
||||||
|
assert(self._identify_error is not None)
|
||||||
|
assert(self._identify_error.matches(FPrint.device_error_quark(), FPrint.DeviceError.GENERAL))
|
||||||
|
|
||||||
def test_verify_serialized(self):
|
def test_verify_serialized(self):
|
||||||
done = False
|
done = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue