protected bool ParseGeometry(Target targetType, string targetText, XmlTest xmlTestItem) { IGeometry geom = null; try { geom = m_objReader.Read(targetText); } catch (Exception ex) { xmlTestItem.Thrown = ex; XmlTestExceptionManager.Publish(ex); return(false); } if (geom == null) { return(false); } switch (targetType) { case Target.A: xmlTestItem.A = geom; break; case Target.B: xmlTestItem.B = geom; break; } return(true); }
public bool Run() { try { m_bSuccess = this.RunTest(); if (!m_bSuccess) { // DEBUG ERRORS: retry to launch the test and analyze... Console.WriteLine(); Console.WriteLine("Retry failed test: " + Description); Console.WriteLine(Argument1); Console.WriteLine(Argument2); Console.WriteLine(A); Console.WriteLine(B); Console.WriteLine("Test type: " + TestType); m_bSuccess = RunTest(); Console.WriteLine(String.Format("Result expected is {0}, but was {1}", true, m_bSuccess)); Console.WriteLine(); } return(m_bSuccess); } catch (Exception ex) { m_objException = ex; Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); XmlTestExceptionManager.Publish(ex); return(false); } }
public bool GetFiles(string directory) { if (m_listFileNames == null) { m_listFileNames = new StringCollection(); } try { string[] dirs = Directory.GetFiles(directory, "*.xml"); foreach (string dir in dirs) { m_listFileNames.Add(dir); } return(true); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); } return(false); }
protected bool ParseResult(string result, XmlTest xmlTestItem) { switch (xmlTestItem.TestType) { // Here we expect double case XmlTestType.Area: case XmlTestType.Distance: case XmlTestType.Length: { try { xmlTestItem.Result = Double.Parse(result, GetNumberFormatInfo()); return(true); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); return(false); } } // Here we expect integer case XmlTestType.BoundaryDimension: case XmlTestType.Dimension: case XmlTestType.NumPoints: case XmlTestType.SRID: { try { xmlTestItem.Result = Int32.Parse(result); return(true); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); return(false); } } // Here we expect a point case XmlTestType.Boundary: case XmlTestType.Buffer: case XmlTestType.Centroid: case XmlTestType.ConvexHull: case XmlTestType.Difference: case XmlTestType.Envelope: case XmlTestType.InteriorPoint: case XmlTestType.Intersection: case XmlTestType.SymmetricDifference: case XmlTestType.Union: { try { xmlTestItem.Result = m_objReader.Read(result); return(true); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); return(false); } } // Here we expect boolean case XmlTestType.Contains: case XmlTestType.Crosses: case XmlTestType.Disjoint: case XmlTestType.Equals: case XmlTestType.Intersects: case XmlTestType.IsEmpty: case XmlTestType.IsSimple: case XmlTestType.IsValid: case XmlTestType.IsWithinDistance: case XmlTestType.Overlaps: case XmlTestType.Relate: case XmlTestType.Touches: case XmlTestType.Within: case XmlTestType.Covers: case XmlTestType.CoveredBy: { try { xmlTestItem.Result = Boolean.Parse(result); return(true); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); return(false); } } default: break; } return(false); }
public bool LoadFile(string fileName) { if (!File.Exists(fileName)) { throw new ArgumentException(fileName, "The file does not exits or the 'fileName' is not valid."); } try { var xmldoc = new XmlDocument(); xmldoc.Load(fileName); var root = xmldoc.DocumentElement; // Retrieve the "desc" tag, if any. XmlNode desc = root["desc"]; string strTestDescription = string.Empty; if (desc != null && desc.InnerText.Length > 0) { strTestDescription = desc.InnerText; } else { strTestDescription = Path.GetFileNameWithoutExtension(fileName); } // Retrieve the "workspace", if any. XmlNode workspace = root["workspace"]; if (workspace != null) { var workspaceAttributes = workspace.Attributes; if (workspaceAttributes != null && workspaceAttributes.Count > 0) { m_strTestWorkspace = workspaceAttributes["dir"].InnerText; } } // Retrieve the "tolerance" attribute, if any. XmlNode tolerance = root["tolerance"]; double dTolerance = 0.0; if (tolerance != null) { string strTolerance = tolerance.InnerText; try { dTolerance = double.Parse(strTolerance, GetNumberFormatInfo()); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); } } // Retrieve the precisionName" tag, if any. PrecisionModel pm = null; XmlNode precision = root["precisionModel"]; if (precision != null) { var precisionAttributes = precision.Attributes; if (precisionAttributes != null && precisionAttributes.Count > 0) { var attribute = precisionAttributes["type"]; if (attribute != null) { string strPrecision = attribute.InnerText; if (strPrecision == "FIXED" && precisionAttributes.Count == 4) { try { double scale = double.Parse(precisionAttributes["scale"].InnerText, GetNumberFormatInfo()); double offsetx = double.Parse(precisionAttributes["offsetx"].InnerText, GetNumberFormatInfo()); double offsety = double.Parse(precisionAttributes["offsety"].InnerText, GetNumberFormatInfo()); pm = new PrecisionModel(scale); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); } } else { pm = new PrecisionModel(); } } else { if (precisionAttributes.Count == 3) { double scale = double.Parse(precisionAttributes["scale"].InnerText, GetNumberFormatInfo()); double offsetx = double.Parse(precisionAttributes["offsetx"].InnerText, GetNumberFormatInfo()); double offsety = double.Parse(precisionAttributes["offsety"].InnerText, GetNumberFormatInfo()); pm = new PrecisionModel(scale); } } } } if (pm == null) { pm = new PrecisionModel(); } IGeometryOperation geometryOperation = null; XmlNode go = root["geometryOperation"]; if (go != null) { go = go.FirstChild; switch (go.Value) { case "com.vividsolutions.jtstest.geomop.PreparedGeometryOperation": geometryOperation = new PreparedGeometryOperation(); break; case "com.vividsolutions.jtstest.geomop.BufferValidatedGeometryOperation": geometryOperation = new BufferValidatedGeometryOperation(); break; case "com.vividsolutions.jtstest.geomop.OverlayValidatedGeometryOperation": geometryOperation = new OverlayValidatedGeometryOperation(); break; default: Console.WriteLine(string.Format("\n *** {0} *** \n", go.Value)); Console.ReadKey(true); geometryOperation = new GeometryMethodOperation(); break; } } IResultMatcher resultMatcher = null; XmlNode rm = root["resultMatcher"]; if (rm != null) { rm = rm.FirstChild; if (rm.Value.EndsWith("BufferResultMatcher", StringComparison.InvariantCultureIgnoreCase)) { resultMatcher = new BufferResultMatcher(); } else { throw new NotSupportedException(); } } m_objFactory = new XmlTestFactory(pm, geometryOperation, resultMatcher); m_listCurTests = new XmlTestCollection(); m_listCurTests.Name = strTestDescription; // Now, handle the "case" nodes var elemList = xmldoc.GetElementsByTagName("case"); for (int i = 0; i < elemList.Count; i++) { ParseCaseNode(elemList[i], dTolerance); } m_listarrTests.Add(m_listCurTests); return(true); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); return(false); } }
protected bool ParseResult(string result, XmlTest xmlTestItem) { switch (xmlTestItem.TestType) { // Here we expect double case XmlTestType.Area: case XmlTestType.Distance: case XmlTestType.Length: case XmlTestType.MinClearance: { try { xmlTestItem.Result = double.Parse(result, GetNumberFormatInfo()); return(true); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); return(false); } } // Here we expect integer case XmlTestType.BoundaryDimension: case XmlTestType.Dimension: case XmlTestType.NumPoints: case XmlTestType.SRID: { try { xmlTestItem.Result = int.Parse(result); return(true); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); return(false); } } // Here we expect a point case XmlTestType.Boundary: case XmlTestType.Buffer: case XmlTestType.BufferMitredJoin: case XmlTestType.Centroid: case XmlTestType.ConvexHull: case XmlTestType.Densify: case XmlTestType.Difference: case XmlTestType.Envelope: case XmlTestType.InteriorPoint: case XmlTestType.Intersection: case XmlTestType.SymmetricDifference: case XmlTestType.Union: case XmlTestType.MinClearanceLine: { try { xmlTestItem.Result = _objReader.Read(result); return(true); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); return(false); } } // Here we expect boolean case XmlTestType.Contains: case XmlTestType.Crosses: case XmlTestType.Disjoint: case XmlTestType.Equals: case XmlTestType.Intersects: case XmlTestType.IsEmpty: case XmlTestType.IsSimple: case XmlTestType.IsValid: case XmlTestType.IsWithinDistance: case XmlTestType.Overlaps: case XmlTestType.Relate: case XmlTestType.Touches: case XmlTestType.Within: case XmlTestType.Covers: case XmlTestType.CoveredBy: case XmlTestType.EqualsExact: case XmlTestType.EqualsNorm: case XmlTestType.EqualsTopo: { try { xmlTestItem.Result = bool.Parse(result); return(true); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); return(false); } } default: string format = string.Format("Test not implemented: {0}", xmlTestItem.TestType); throw new NotImplementedException(format); } }
public bool LoadFile(string fileName) { if (!File.Exists(fileName)) { throw new ArgumentException(fileName, "The file does not exits or the 'fileName' is not valid."); } try { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(fileName); XmlElement root = xmldoc.DocumentElement; // Retrieve the "desc" tag, if any. XmlNode desc = root["desc"]; string strTestDescription = String.Empty; if (desc != null && desc.InnerText.Length > 0) { strTestDescription = desc.InnerText; } else { strTestDescription = Path.GetFileNameWithoutExtension(fileName); } // Retrieve the "workspace", if any. XmlNode workspace = root["workspace"]; if (workspace != null) { XmlAttributeCollection workspaceAttributes = workspace.Attributes; if (workspaceAttributes != null && workspaceAttributes.Count > 0) { m_strTestWorkspace = workspaceAttributes["dir"].InnerText; } } // Retrieve the "tolerance" attribute, if any. XmlNode tolerance = root["tolerance"]; double dTolerance = 0.0; if (tolerance != null) { string strTolerance = tolerance.InnerText; try { dTolerance = Double.Parse(strTolerance, GetNumberFormatInfo()); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); } } // Retrieve the precisionName" tag, if any. PrecisionModel pm = null; XmlNode precision = root["precisionModel"]; if (precision != null) { XmlAttributeCollection precisionAttributes = precision.Attributes; if (precisionAttributes != null && precisionAttributes.Count > 0) { XmlAttribute attribute = precisionAttributes["type"]; if (attribute != null) { string strPrecision = attribute.InnerText; if (strPrecision == "FIXED" && precisionAttributes.Count == 4) { try { double scale = Double.Parse(precisionAttributes["scale"].InnerText, GetNumberFormatInfo()); double offsetx = Double.Parse(precisionAttributes["offsetx"].InnerText, GetNumberFormatInfo()); double offsety = Double.Parse(precisionAttributes["offsety"].InnerText, GetNumberFormatInfo()); pm = new PrecisionModel(scale); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); } } else { pm = new PrecisionModel(); } } else { if (precisionAttributes.Count == 3) { double scale = Double.Parse(precisionAttributes["scale"].InnerText, GetNumberFormatInfo()); double offsetx = Double.Parse(precisionAttributes["offsetx"].InnerText, GetNumberFormatInfo()); double offsety = Double.Parse(precisionAttributes["offsety"].InnerText, GetNumberFormatInfo()); pm = new PrecisionModel(scale); } } } } if (pm == null) { pm = new PrecisionModel(); } m_objFactory = new XmlTestFactory(pm); m_listCurTests = new XmlTestCollection(); m_listCurTests.Name = strTestDescription; // Now, handle the "case" nodes XmlNodeList elemList = xmldoc.GetElementsByTagName("case"); for (int i = 0; i < elemList.Count; i++) { ParseCaseNode(elemList[i], dTolerance); } m_listarrTests.Add(m_listCurTests); return(true); } catch (Exception ex) { XmlTestExceptionManager.Publish(ex); return(false); } }