private void DoTestFinaliseTemplate() { using (Fake.CreateScope()) { // PREPARE m_Monitor.Reset(); IEnumerable <MinutiaRecord> minutae = m_ViewModel.Minutae.ToArray(); // Record the input minutia type before the operation MinutiaType inputType = m_ViewModel.InputMinutiaType; // EXECUTE: byte[] template = m_IViewModel.FinaliseTemplate(); // ASSERT: // First check that the template is correctly converted CollectionAssert.AreEqual( IsoTemplateHelper.ToIsoTemplate(minutae), template); // Check the workspace is cleared Assert.AreEqual(CAPTURE_NO_TEMPLATE, m_ViewModel.Capture); Assert.IsTrue(m_IViewModel.IsSaveTemplatePermitted); Assert.AreEqual(minutae.Count(), m_ViewModel.Minutae.Count()); Assert.AreEqual(0, m_Monitor.GetEventResponses <UserActionRequiredEventArgs>("UserActionRequired").Count()); Assert.AreEqual(0, m_Monitor.GetEventResponses <PropertyChangedEventArgs>("PropertyChanged").Count()); Assert.AreEqual(inputType, m_ViewModel.InputMinutiaType); } }
public override void BeginTemplating(CaptureInfo capture) { // Prepare to start templating a new capture // Clear the UI of any previous work Outer.m_DispatcherHelper.Invoke(new Action(() => { Outer.Minutae.Clear(); })); // Record the new capture Outer.Capture = capture; if (Outer.Capture.TemplateData != null) { // If there is a template in the capture info, load it. IEnumerable <MinutiaRecord> template = IsoTemplateHelper .ToMinutae(Outer.Capture.TemplateData); foreach (MinutiaRecord rec in template) { // Ensure we use the UI thread to add to the ObservableCollection. App.Current.Dispatcher.Invoke(new Action(() => { Outer.Minutae.Add(rec); })); } } TransitionTo(typeof(WaitLocation)); }
private void TestToIsoTemplate(IEnumerable <MinutiaRecord> minutae, string isoTemplateHex) { // Get the IsoTemplate byte[] template = IsoTemplateHelper.ToIsoTemplate(minutae); // Convert the IsoTemplate back to a list of minutia (loss of data in casting) IEnumerable <MinutiaRecord> convert_minutae = IsoTemplateHelper.ToMinutae(template); // Convert it to Hex for comparison string templateHex = BitConverter.ToString(template); templateHex = templateHex.Replace("-", String.Empty); // Assertions CollectionAssert.AreEqual(IsoTemplateHelper.ToByteArray(isoTemplateHex), template); Assert.AreEqual(minutae.Count(), convert_minutae.Count()); for (int i = 0; i < convert_minutae.Count(); i++) { MinutiaRecord real_minutia = minutae.ElementAt(i); MinutiaRecord converted_minutia = convert_minutae.ElementAt(i); Assert.AreEqual((int)real_minutia.Position.X, converted_minutia.Position.X); Assert.AreEqual((int)real_minutia.Position.Y, converted_minutia.Position.Y); // y(x,a) = ax - floor(ax) // max(y(x,a)) = 1, min(y(x,a)) = 0 // e(x,a) = x - x_hat = 1/a * floor(ax) = 1/a * y(x,a) // Thus max(e(x,a)) = 1/a, min(e(x,a)) = 0 Assert.IsTrue(real_minutia.Angle - converted_minutia.Angle < 1.0 / (256 / 360)); } }
public void TestConvertNullToIsoTemplate() { SimTemplateException m_Exception = null; try { byte[] template = IsoTemplateHelper.ToIsoTemplate(null); } catch (SimTemplateException ex) { m_Exception = ex; } Assert.IsNotNull(m_Exception); }
public static CaptureInfo ToCaptureInfo(XElement captureEl) { XElement imageLocationEl = captureEl.Element(ELEMENT_IMAGE_LOCATION); XElement dbIdEl = captureEl.Element(ELEMENT_DB_ID); XElement templateEl = captureEl.Element(ELEMENT_TEMPLATE); // Assert xml structure is as expected CheckElementNotNull(imageLocationEl, ELEMENT_IMAGE_LOCATION); CheckElementNotNull(dbIdEl, ELEMENT_DB_ID); CheckElementNotNull(templateEl, ELEMENT_TEMPLATE); // Get info from elements Uri imageLocation; bool isUriParsed = Uri.TryCreate(imageLocationEl.Value, UriKind.Absolute, out imageLocation); if (!isUriParsed) { throw new SimTemplateException( String.Format("Failed to parse image URL string ({0}) to Uri", imageLocationEl.Value)); } long dbId; bool isIdParsed = long.TryParse(dbIdEl.Value, out dbId); if (!isIdParsed) { throw new SimTemplateException( String.Format("Failed to parse capture ID string ({0}) to long", dbIdEl.Value)); } byte[] templateData = null; if (!String.IsNullOrEmpty(templateEl.Value)) { templateData = IsoTemplateHelper.ToByteArray(templateEl.Value); } byte[] imageData; // Get image file from url using (WebClient webClient = new WebClient()) { imageData = webClient.DownloadData(imageLocation); } return(new CaptureInfo(dbId, imageData, templateData)); }
public override byte[] GetTemplate() { // Return template in ISO template format. return(IsoTemplateHelper.ToIsoTemplate(Outer.Minutae)); }