public XmlTestFactory(PrecisionModel pm, IGeometryOperation geometryOperation, IResultMatcher resultMatcher)
 {
     ObjGeometryFactory = new GeometryFactory(pm);
     _geometryOperation = geometryOperation;
     _resultMatcher     = resultMatcher;
     _objReader         = new WKTOrWKBReader(ObjGeometryFactory);
 }
 public XmlTestFactory(PrecisionModel pm, IGeometryOperation geometryOperation, IResultMatcher resultMatcher)
 {
     ObjGeometryFactory = new GeometryFactory(pm);
     _geometryOperation = geometryOperation;
     _resultMatcher = resultMatcher;
     _objReader = new WKTOrWKBReader(ObjGeometryFactory);
 }
        public XmlTestFactory(PrecisionModel pm, IGeometryOperation geometryOperation, IResultMatcher resultMatcher)
        {
            var gs = new NtsGeometryServices(pm, 0);

            //ObjGeometryFactory = gs.CreateGeometryFactory();
            _geometryOperation = geometryOperation;
            _resultMatcher     = resultMatcher;
            _objReader         = new MultiFormatReader(gs);
        }
Пример #4
0
	    public virtual bool RunTest()
        {
            if (_geometryOperation != null)
            {
                var arguments = ToArguments();

                IResult expectedResult = null;
                var returnType = _geometryOperation.GetReturnType(_enumTestType);
                if (returnType == typeof(int))
                    expectedResult = new IntegerResult((int)Result);
                else if (returnType == typeof(bool))
                    expectedResult = new BooleanResult((bool)Result);
                else if (returnType == typeof(double))
                    expectedResult = new DoubleResult((int)Result);
                else if (returnType == typeof(IGeometry))
                    expectedResult = new GeometryResult((IGeometry)Result);
                else
                {
                    Debug.Assert(false);
                }

                var result = _geometryOperation.Invoke(_enumTestType, IsDefaultTarget ? _objGeometryA : _objGeometryB, ToArguments());
                if (_resultMatcher == null)
                    _resultMatcher = CreateEqualityResultMatcher(returnType);
                                         {
                return _resultMatcher.IsMatch(IsDefaultTarget ? _objGeometryA : _objGeometryB, _enumTestType.ToString(),
                                           arguments, result, expectedResult, _dTolerance);
                }
            }
            
            switch (_enumTestType) 
            {
                case XmlTestType.Area:
                    return TestArea();

                case XmlTestType.Boundary:
                    return TestBoundary();

                case XmlTestType.BoundaryDimension:
                    return TestBoundaryDimension();

                case XmlTestType.Buffer:
                    return TestBuffer();

                case XmlTestType.BufferMitredJoin:
                    return TestBufferMitredJoin();

                case XmlTestType.Centroid:
                    return TestCentroid();

                case XmlTestType.Contains:
                    return TestContains();

                case XmlTestType.ConvexHull:
                    return TestConvexHull();

                case XmlTestType.Crosses:
                    return TestCrosses();

                case XmlTestType.Densify:
                    return TestDensify();

                case XmlTestType.Difference:
                    return TestDifference();

                case XmlTestType.Dimension:
                    return TestDimension();

                case XmlTestType.Disjoint:
                    return TestDisjoint();

                case XmlTestType.Distance:
                    return TestDistance();

                case XmlTestType.Envelope:
                    return TestEnvelope();

                case XmlTestType.Equals:
                    return TestEquals();

                case XmlTestType.InteriorPoint:
                    return TestInteriorPoint();

                case XmlTestType.Intersection:
                    return TestIntersection();

                case XmlTestType.Intersects:
                    return TestIntersects();

                case XmlTestType.IsEmpty:
                    return TestIsEmpty();

                case XmlTestType.IsSimple:
                    return TestIsSimple();

                case XmlTestType.IsValid:
                    return TestIsValid();

                case XmlTestType.IsWithinDistance:
                    return TestIsWithinDistance();

                case XmlTestType.Length:
                    return TestLength();

                case XmlTestType.NumPoints:
                    return TestNumPoints();

                case XmlTestType.Overlaps:
                    return TestOverlaps();

                case XmlTestType.Relate:
                    return TestRelate();

                case XmlTestType.SRID:
                    return TestSRID();

                case XmlTestType.SymmetricDifference:
                    return TestSymDifference();

                case XmlTestType.Touches:
                    return TestTouches();

                case XmlTestType.Union:
                    return TestUnion();

                case XmlTestType.Within:
                    return TestWithin();

                case XmlTestType.Covers:
                    return TestCovers();

                case XmlTestType.CoveredBy:
                    return TestCoveredBy();

                case XmlTestType.EqualsExact:
                    return TestEqualsExact();

                case XmlTestType.EqualsNorm:
                    return TestEqualsNorm();

                case XmlTestType.MinClearance:
                    return TestMinClearance();

                case XmlTestType.MinClearanceLine:
                    return TestMinClearanceLine();
                
                case XmlTestType.EqualsTopo:
                    return TestEqualsTopo();

                default:
                    string format = String.Format("Test not implemented: {0}", this._enumTestType);
                    throw new NotImplementedException(format);
            }
        }
Пример #5
0
        public XmlTest(string description, bool bIsDefaultTarget, double tolerance, IGeometryOperation geometryOperation, IResultMatcher resultMatcher)
		{
            if (!string.IsNullOrEmpty(description))
            {
                _strDescription = description;
            }
            else
            {
                _strDescription = "Untitled" + _nCount.ToString();

                ++_nCount;
            }

            _bIsDefaultTarget = bIsDefaultTarget;
            _dTolerance       = tolerance;
            _geometryOperation = geometryOperation;
            _resultMatcher = resultMatcher;
		}
Пример #6
0
        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);
            }
        }