Пример #1
0
 public void OnError(Exception exception, StaticError error, string format, params object[] args)
 {
     if (!string.IsNullOrEmpty(format))
     {
         Console.WriteLine(format, args);
     }
     else
     {
         Console.WriteLine($"{exception?.Message}; {error}");
     }
     _FastServer.Close();
 }
Пример #2
0
        static ProcessorException WrapCompileException(Exception ex, IList errors)
        {
            StaticError err =
                errors.OfType <StaticError>().FirstOrDefault(s => !s.IsWarning)
                ?? ex as StaticError;

            if (err != null)
            {
                return(new SaxonException(err));
            }

            return(new SaxonException(ex.Message, ex));
        }
Пример #3
0
        public SaxonException(StaticError error)
            : base(error.Message, error)
        {
            this.LineNumber = error.LineNumber;

            if (!String.IsNullOrEmpty(error.ModuleUri))
            {
                this.ModuleUri = new Uri(error.ModuleUri);
            }

            if (error.ErrorCode != null)
            {
                this.ErrorCode = error.ErrorCode.ToXmlQualifiedName();
            }
        }
//	private  Dictionary<int, int> dict = new  Dictionary<int, int>();
	public static StaticError Instance()
	{
        if(_instance == null)
        {
            lock(lockHelper)
            {
                if(_instance == null)
				{
                     _instance = new StaticError();
//					#if UNITY_EDITOR
					_instance.readData();
//					#endif
				}
            }
        }
        return _instance;
    }
Пример #5
0
 public void OnError(Exception exception, StaticError error, string format, params object[] args)
 {
     throw new NotSupportedException();
 }
 public StatErrorException(Exception inner, StaticError error, string format, params object[] args)
     : base(inner, format, args)
 {
     _error = error;
 }
Пример #7
0
        /**
         * Run the tests
         * @param args command line arguments
         * @throws SAXException
         * @throws ParserConfigurationException
         * @throws XPathException
         * @throws IOException
         * @throws URISyntaxException
         */

        public void go(String[] args)
        {
            if (args.Length == 0 || args[0] == "-?")
            {
                Console.WriteLine("SchemaTestSuiteDriver testDir [-w] [-onwards] -c:contributor? -s:setName? -g:groupName?");
            }
            Processor processor = new Processor(true);

            Console.WriteLine("Testing Saxon " + processor.ProductVersion);

            testSuiteDir = args[0];
            if (testSuiteDir.EndsWith("/"))
            {
                testSuiteDir = testSuiteDir.Substring(0, testSuiteDir.Length - 1);
            }
            String    testSetPattern   = null;  // TODO use a regex
            String    testGroupPattern = null;
            String    contributor      = null;
            Hashtable exceptions       = new Hashtable();

            for (int i = 1; i < args.Length; i++)
            {
                if (args[i] == ("-w"))
                {
                    //showWarnings = true;
                }
                else if (args[i] == ("-onwards"))
                {
                    onwards = true;
                }
                else if (args[i].StartsWith("-c:"))
                {
                    contributor = args[i].Substring(3);
                }
                else if (args[i].StartsWith("-s:"))
                {
                    testSetPattern = args[i].Substring(3);
                }
                else if (args[i].StartsWith("-g:"))
                {
                    testGroupPattern = args[i].Substring(3);
                }
                else if (args[i] == "-?")
                {
                    Console.WriteLine("Usage: SchemaTestSuiteDriver testDir [-w] [-s:testSetPattern] [-g:testGroupPattern]");
                }
            }

            int total  = 39700;
            int passed = 0;
            int failed = 0;

            try {
                xlinkHref = new QName("xlink", "http://www.w3.org/1999/xlink", "href");

                QName testCaseNT = new QName("", "", "testcase");
                QName commentNT  = new QName("", "", "comment");

                QName testSetRefNT       = new QName(testNS, "testSetRef");
                QName testGroupNT        = new QName(testNS, "testGroup");
                QName testSetNT          = new QName(testNS, "testSet");
                QName schemaTestNT       = new QName(testNS, "schemaTest");
                QName instanceTestNT     = new QName(testNS, "instanceTest");
                QName schemaDocumentNT   = new QName(testNS, "schemaDocument");
                QName instanceDocumentNT = new QName(testNS, "instanceDocument");
                QName expectedNT         = new QName(testNS, "expected");
                QName currentNT          = new QName(testNS, "current");

                QName validityAtt        = new QName("", "", "validity");
                QName nameAtt            = new QName("", "", "name");
                QName contributorAtt     = new QName("", "", "contributor");
                QName setAtt             = new QName("", "", "set");
                QName groupAtt           = new QName("", "", "group");
                QName statusAtt          = new QName("", "", "status");
                QName bugzillaAtt        = new QName("", "", "bugzilla");
                QName targetNamespaceAtt = new QName("", "", "targetNamespace");
                QName schemaVersion      = new QName("saxon", "http://saxon.sf.net/", "schemaVersion");


                DocumentBuilder builder = processor.NewDocumentBuilder();
                builder.BaseUri = new Uri(testSuiteDir + "/");
                XdmNode catalog = builder.Build(
                    new FileStream(testSuiteDir + "/suite.xml", FileMode.Open, FileAccess.Read, FileShare.Read));

                results = new StreamWriter(testSuiteDir + "/saxon/SaxonResults"
                                           + processor.ProductVersion + "n.xml");

                results.Write("<testSuiteResults xmlns='" + testNS + "' xmlns:saxon='http://saxon.sf.net/' " +
                              "suite='TS_2006' " +
                              "processor='Saxon-SA (Java) 8.8++' submitDate='2007-01-05' publicationPermission='public'>\n");

                XdmNode exceptionsDoc = builder.Build(
                    new FileStream(testSuiteDir + "/saxon/exceptions.xml",
                                   FileMode.Open, FileAccess.Read, FileShare.Read));


                IEnumerator exceptionTestCases = exceptionsDoc.EnumerateAxis(XdmAxis.Descendant, new QName("", "testcase"));
                while (exceptionTestCases.MoveNext())
                {
                    XdmNode testCase = (XdmNode)exceptionTestCases.Current;
                    String  set      = testCase.GetAttributeValue(setAtt);
                    String  group    = testCase.GetAttributeValue(groupAtt);
                    String  comment  = getChildElement(testCase, commentNT).StringValue;
                    exceptions[set + "#" + group] = comment;
                }

                IEnumerator testSets = catalog.EnumerateAxis(XdmAxis.Descendant, testSetRefNT);
                while (testSets.MoveNext())
                {
                    XdmNode testSetRef     = (XdmNode)testSets.Current;
                    XdmNode testSetDoc     = getLinkedDocument(testSetRef, processor, false);
                    XdmNode testSetElement = getChildElement(testSetDoc, testSetNT);

                    if (testSetElement == null)
                    {
                        feedback.Message("test set doc has no TestSet child: " + testSetDoc.BaseUri, true);
                        continue;
                    }

                    String testSetName = testSetElement.GetAttributeValue(nameAtt);
                    if (testSetPattern != null && !testSetName.StartsWith(testSetPattern))
                    {
                        continue;
                    }
                    if (contributor != null && contributor != testSetElement.GetAttributeValue(contributorAtt))
                    {
                        continue;
                    }

                    bool needs11 = (testSetElement.GetAttributeValue(schemaVersion) == "1.1");

                    IEnumerator testGroups = testSetElement.EnumerateAxis(XdmAxis.Child, testGroupNT);
                    while (testGroups.MoveNext())
                    {
                        XdmNode testGroup = (XdmNode)testGroups.Current;

                        String testGroupName = testGroup.GetAttributeValue(nameAtt);
                        String exception     = (String)exceptions[testSetName + "#" + testGroupName];

                        if (testGroupPattern != null && !testGroupName.StartsWith(testGroupPattern))
                        {
                            continue;
                        }
                        Console.WriteLine("TEST SET " + testSetName + " GROUP " + testGroupName, false);
                        if (onwards)
                        {
                            testGroupPattern = null;
                            testSetPattern   = null;
                        }
                        Processor testConfig = new Processor(true);
                        if (needs11)
                        {
                            testConfig.SetProperty("http://saxon.sf.net/feature/xsd-version", "1.1");
                        }
                        SchemaManager schemaManager = testConfig.SchemaManager;


                        //testConfig.setHostLanguage(Configuration.XML_SCHEMA);
                        testConfig.SetProperty("http://saxon.sf.net/feature/validation-warnings", "true");
                        IEnumerator schemaTests   = testGroup.EnumerateAxis(XdmAxis.Child, schemaTestNT);
                        bool        schemaQueried = false;
                        String      bugzillaRef   = null;

                        while (schemaTests.MoveNext())
                        {
                            XdmNode schemaTest = (XdmNode)schemaTests.Current;
                            if (schemaTest == null)
                            {
                                break;
                            }
                            bugzillaRef = null;
                            String testName = schemaTest.GetAttributeValue(nameAtt);
                            if (exception != null)
                            {
                                results.Write("<testResult set='" + testSetName +
                                              "' group='" + testGroupName +
                                              "' test='" + testName +
                                              "' validity='notKnown' saxon:outcome='notRun' saxon:comment='" + exception +
                                              "'/>\n");
                                continue;
                            }
                            bool    queried       = false;
                            XdmNode statusElement = getChildElement(schemaTest, currentNT);
                            if (statusElement != null)
                            {
                                String status = statusElement.GetAttributeValue(statusAtt);
                                queried     = ("queried" == status);
                                bugzillaRef = statusElement.GetAttributeValue(bugzillaAtt);
                            }
                            if (queried)
                            {
                                schemaQueried = true;
                            }
                            Console.WriteLine("TEST SCHEMA " + testName + (queried ? " (queried)" : ""));
                            bool        success  = true;
                            IEnumerator schemata = schemaTest.EnumerateAxis(XdmAxis.Child, schemaDocumentNT);
                            while (schemata.MoveNext())
                            {
                                XdmNode schemaDocumentRef = (XdmNode)schemata.Current;
                                if (schemaDocumentRef == null)
                                {
                                    break;
                                }
                                Console.WriteLine("Loading schema at " + schemaDocumentRef.GetAttributeValue(xlinkHref));
                                XdmNode     schemaDoc     = getLinkedDocument(schemaDocumentRef, testConfig, false);
                                IEnumerator schemaDocKids = schemaDoc.EnumerateAxis(XdmAxis.Child);
                                XdmNode     schemaElement = null;
                                while (schemaDocKids.MoveNext())
                                {
                                    schemaElement = (XdmNode)schemaDocKids.Current;
                                    if (schemaElement.NodeKind == XmlNodeType.Element)
                                    {
                                        break;
                                    }
                                }
                                String targetNamespace = schemaElement.GetAttributeValue(targetNamespaceAtt);
                                //if (targetNamespace != null && schemaManager. isSchemaAvailable(targetNamespace)) {
                                // do nothing
                                // TODO: this is the only way I can get MS additional test addB132 to work.
                                // It's not ideal: addSchemaSource() ought to be a no-op if the schema components
                                // are already loaded, but in fact recompiling the imported schema document on its
                                // own is losing the substitution group membership that was defined in the
                                // importing document.
                                //} else {
                                IList <StaticError> errorList = new List <StaticError>();
                                schemaManager.ErrorList = errorList;
                                try
                                {
                                    schemaManager.Compile(schemaDoc);
                                }
                                catch (Exception e)
                                {
                                    if (errorList.Count == 0)
                                    {
                                        feedback.Message("In " + testName + ", exception thrown but no errors in ErrorList\n", true);
                                        results.Write("<!--" + e.Message + "-->");
                                        success = false;
                                    }
                                }
                                for (int i = 0; i < errorList.Count; i++)
                                {
                                    if (errorList[i] is StaticError)
                                    {
                                        StaticError err = (StaticError)errorList[i];
                                        if (!err.IsWarning)
                                        {
                                            success = false;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        feedback.Message("In " + testName + " wrong kind of error!" + errorList[i].GetType() + "\n", true);
                                    }
                                }
                            }
                            XdmNode expected        = getChildElement(schemaTest, expectedNT);
                            bool    expectedSuccess = expected == null ||
                                                      expected.GetAttributeValue(validityAtt) == "valid";
                            if (success == expectedSuccess)
                            {
                                passed++;
                            }
                            else
                            {
                                failed++;
                            }
                            feedback.Feedback(passed, failed, total);
                            results.Write("<testResult set='" + testSetName +
                                          "' group='" + testGroupName +
                                          "' test='" + testName +
                                          "' validity='" + (success ? "valid" : "invalid") +
                                          (queried ? "' saxon:queried='true' saxon:bugzilla='" + bugzillaRef : "") +
                                          "' saxon:outcome='" + (success == expectedSuccess ? "same" : "different") +
                                          "'/>\n");
                        }
                        IEnumerator instanceTests = testGroup.EnumerateAxis(XdmAxis.Child, instanceTestNT);
                        while (instanceTests.MoveNext())
                        {
                            XdmNode instanceTest = (XdmNode)instanceTests.Current;
                            String  testName     = instanceTest.GetAttributeValue(nameAtt);

                            if (exception != null)
                            {
                                results.Write("<testResult set='" + testSetName +
                                              "' group='" + testGroupName +
                                              "' test='" + testName +
                                              "' validity='notKnown' saxon:outcome='notRun' saxon:comment='" + exception +
                                              "'/>\n");
                                continue;
                            }

                            bool    queried       = false;
                            XdmNode statusElement = getChildElement(instanceTest, currentNT);
                            if (statusElement != null)
                            {
                                String status = statusElement.GetAttributeValue(statusAtt);
                                queried = ("queried" == status);
                                String instanceBug = statusElement.GetAttributeValue(bugzillaAtt);
                                if (instanceBug != null)
                                {
                                    bugzillaRef = instanceBug;
                                }
                            }
                            queried |= schemaQueried;

                            Console.WriteLine("TEST INSTANCE " + testName + (queried ? " (queried)" : ""));

                            XdmNode instanceDocument = getChildElement(instanceTest, instanceDocumentNT);

                            bool success = true;
                            try
                            {
                                XdmNode instanceDoc = getLinkedDocument(instanceDocument, testConfig, true);
                            }
                            catch (Exception)
                            {
                                success = false;
                            }

                            XdmNode expected        = getChildElement(instanceTest, expectedNT);
                            bool    expectedSuccess = expected == null ||
                                                      expected.GetAttributeValue(validityAtt) == "valid";
                            if (success == expectedSuccess)
                            {
                                passed++;
                            }
                            else
                            {
                                failed++;
                            }
                            feedback.Feedback(passed, failed, total);
                            results.Write("<testResult set='" + testSetName +
                                          "' group='" + testGroupName +
                                          "' test='" + testName +
                                          "' validity='" + (success ? "valid" : "invalid") +
                                          (queried ? "' saxon:queried='true' saxon:bugzilla='" + bugzillaRef : "") +
                                          "' saxon:outcome='" + (success == expectedSuccess ? "same" : "different") +
                                          "'/>\n");
                        }
                    }
                }

                results.Write("</testSuiteResults>");
                results.Close();
            } catch (Exception e) {
                feedback.Message("Test failed: " + e.Message, true);
            }
        }
Пример #8
0
 public StatErrorException(Exception inner, StaticError error, string format, params object[] args)
     : base(inner, format, args)
 {
     _error = error;
 }
Пример #9
0
 public void OnError(Exception exception, StaticError error, string format, params object[] args)
 {
 }
Пример #10
0
 public void OnError(Exception exception, StaticError error, string format, params object[] args)
 {
     throw new StatErrorException(exception, error, format, args);
 }
Пример #11
0
 public void OnError(Exception exception, StaticError error, string format, params object[] args)
 {
     Console.WriteLine(format, args);
 }
Пример #12
0
 public void OnError(Exception exception, StaticError error, string format, params object[] args)
 {
     throw new NotSupportedException();
 }
Пример #13
0
 public static Value ErrorToValue(StaticError err)
 {
     // Casting a `StaticError` to a `Value` like this throws an ExecutionException
     return(err);
 }
Пример #14
0
 public void OnError(Exception exception, StaticError error, string format, params object[] args)
 {
     Console.WriteLine(format, args);
 }
Пример #15
0
 public static ErrorInfoAttribute GetErrorInfo(this StaticError error)
 {
     return(Util.GetEnumSingleAttribute <ErrorInfoAttribute, StaticError>(error));
 }
Пример #16
0
 public void OnError(Exception exception, StaticError error, string format, params object[] args)
 {
 }
Пример #17
0
 public Outcome(StaticError exception)
 {
     this.staticException = exception;
 }
Пример #18
0
 public void OnError(Exception exception, StaticError error, string format, params object[] args)
 {
     throw new StatErrorException(exception, error, format, args);
 }