public bool compareExpectedError(XdmNode assertion) { string expectedError = assertion.GetAttributeValue(new QName("code")); QName expectedErrorQ; if (expectedError.Equals("*")) { expectedErrorQ = null; } else if (expectedError.StartsWith("Q{")) { expectedErrorQ = QName.FromEQName(expectedError); } else { expectedErrorQ = new QName("err", JNamespaceConstant.ERR, expectedError); } //noinspection ThrowableResultOfMethodCallIgnored bool ok = (expectedError.Equals("*") || (GetErrorCode() != null && GetErrorCode().LocalName.Equals(expectedErrorQ.LocalName)) || (HasReportedError(new QName(expectedError)))); if (ok) { wrongError = null; } else if (expectedErrorQ != null && errorsReported != null && errorsReported.Count != 0) { JFastStringBuffer fsb = new JFastStringBuffer(100); fsb.append("Expected "); fsb.append(expectedErrorQ.LocalName); fsb.append("; got "); foreach (QName e in errorsReported) { fsb.append(e.LocalName); fsb.append("|"); } fsb.setLength(fsb.length() - 1); wrongError = fsb.ToString(); } return(ok); }
private bool TestAssertion2(XdmNode assertion, SingleResultDoc result, XPathCompiler assertXpc, XPathCompiler catalogXpc, bool debug) { string tag = assertion.NodeName.LocalName; if (tag.Equals("assert-eq")) { return(assertEq(assertion, result, assertXpc)); } else if (tag.Equals("assert-deep-eq")) { return(assertDeepEq(assertion, result, assertXpc)); } else if (tag.Equals("assert-permutation")) { return(assertPermutation(assertion, result, assertXpc)); } else if (tag.Equals("assert-xml")) { return(assertXml(assertion, result, assertXpc, catalogXpc, debug)); } else if (tag.Equals("serialization-matches")) { return(AssertSerializationMatches(assertion, result, catalogXpc)); } else if (tag.Equals("assert-serialization-error")) { return(AssertSerializationError(assertion, result, assertXpc)); } else if (tag.Equals("assert-empty")) { return(assertEmpty(result.value)); } else if (tag.Equals("assert-count")) { return(assertCount(assertion, result)); } else if (tag.Equals("assert")) { return(AssertXPath(assertion, result, assertXpc, debug)); } else if (tag.Equals("assert-string-value")) { return(AssertstringValue(assertion, result, debug)); } else if (tag.Equals("assert-serialization")) { return(AssertSerialization(assertion, result, catalogXpc, debug)); } else if (tag.Equals("assert-type")) { return(AssertType(assertion, result, assertXpc)); } else if (tag.Equals("assert-true")) { return(AssertTrue(result)); } else if (tag.Equals("assert-false")) { return(AssertFalse(result)); } else if (tag.Equals("assert-warning")) { return(AssertWarning()); } else if (tag.Equals("assert-message")) { XdmNode subAssertion = (XdmNode)catalogXpc.EvaluateSingle("*", assertion); foreach (XdmNode message in xslMessages) { if (TestAssertion2(subAssertion, new SingleResultDoc(message, ""), assertXpc, catalogXpc, debug)) { return(true); } } return(false); } else if (tag.Equals("assert-result-document")) { XdmNode subAssertion = (XdmNode)catalogXpc.EvaluateSingle("*", assertion); XmlUrlResolver res = new XmlUrlResolver(); Uri uri = new Uri(driver.getResultsDir() + "/results/output.xml"); uri = res.ResolveUri(uri, assertion.GetAttributeValue(new QName("uri"))); SingleResultDoc doc = GetSecondaryResult(uri); if (doc == null) { System.Console.WriteLine("**** No output document found for " + uri); return(false); } bool ok = TestAssertion2(subAssertion, doc, assertXpc, catalogXpc, debug); if (!ok) { System.Console.WriteLine("**** Assertion failed for result-document " + uri); } return(ok); } else if (tag.Equals("error")) { bool b = false; try { b = IsException() && compareExpectedError(assertion); } catch (Exception) { if (GetException() is StaticError) { string expectedError = assertion.GetAttributeValue(new QName("code")); QName expectedErrorQ; if (expectedError.Equals("*")) { expectedErrorQ = null; } else if (expectedError.StartsWith("Q{")) { expectedErrorQ = QName.FromEQName(expectedError); } else { expectedErrorQ = new QName("err", JNamespaceConstant.ERR, expectedError); } JFastStringBuffer fsb = new JFastStringBuffer(100); fsb.append("Expected "); fsb.append(expectedErrorQ.LocalName); fsb.append("; got "); fsb.append("err:XXX"); fsb.setLength(fsb.length() - 1); wrongError = fsb.ToString(); return(true); } if (GetException() is DynamicError) { string expectedError = assertion.GetAttributeValue(new QName("code")); QName expectedErrorQ; if (expectedError.Equals("*")) { expectedErrorQ = null; } else if (expectedError.StartsWith("Q{")) { expectedErrorQ = QName.FromEQName(expectedError); } else { expectedErrorQ = new QName("err", JNamespaceConstant.ERR, expectedError); } JFastStringBuffer fsb = new JFastStringBuffer(100); fsb.append("Expected "); fsb.append(expectedErrorQ.LocalName); fsb.append("; got "); fsb.append("err:XXX"); fsb.setLength(fsb.length() - 1); wrongError = fsb.ToString(); return(true); } } return(b); } else if (tag.Equals("all-of")) { foreach (XdmItem child in catalogXpc.Evaluate("*", assertion)) { if (!TestAssertion((XdmNode)child, result, assertXpc, catalogXpc, debug)) { return(false); } } return(true); } else if (tag.Equals("any-of")) { bool partialSuccess = false; foreach (XdmItem child in catalogXpc.Evaluate("*", assertion)) { if (TestAssertion((XdmNode)child, result, assertXpc, catalogXpc, debug)) { if (wrongError != null) { partialSuccess = true; continue; } return(true); } } return(partialSuccess); } else if (tag.Equals("not")) { XdmNode subAssertion = (XdmNode)catalogXpc.EvaluateSingle("*", assertion); return(!TestAssertion(subAssertion, result, assertXpc, catalogXpc, debug)); } throw new Exception("Unknown assertion element " + tag); }