Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -27,7 +27,6 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Security.Cryptography;
@@ -53,4 +52,3 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
}
#endif

View File

@@ -7,7 +7,6 @@
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
#if NET_2_0
using System;
using System.Collections;
@@ -296,4 +295,3 @@ namespace MonoTests.System.Security.Cryptography.Xml
}
}
}
#endif

View File

@@ -66,7 +66,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
static byte[] x509crl = { 0x30, 0x82, 0x01, 0x05, 0x30, 0x72, 0x02, 0x01, 0x01, 0x30, 0x0B, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x30, 0x51, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x0F, 0x55, 0x2E, 0x53, 0x2E, 0x20, 0x47, 0x6F, 0x76, 0x65, 0x72, 0x6E, 0x6D, 0x65, 0x6E, 0x74, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x03, 0x44, 0x6F, 0x44, 0x31, 0x1A, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x11, 0x41, 0x72, 0x6D, 0x65, 0x64, 0x20, 0x46, 0x6F, 0x72, 0x63, 0x65, 0x73, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x17, 0x0D, 0x30, 0x32, 0x31, 0x30, 0x31, 0x31, 0x31, 0x33, 0x31, 0x32, 0x35, 0x30, 0x5A, 0x30, 0x0B, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x03, 0x81, 0x81, 0x00, 0x7D, 0xA2, 0xD1, 0x19, 0x6D, 0x0F, 0x0F, 0xCB, 0xE4, 0xA3, 0xBE, 0xE0, 0x36, 0x0A, 0xF3, 0x4C, 0x9B, 0xAF, 0xE6, 0x4F, 0xF6, 0xE3, 0xAF, 0xCF, 0x55, 0xF3, 0xC6, 0xDB, 0xAB, 0x4C, 0x16, 0x32, 0xAA, 0x73, 0xAD, 0xCC, 0xDC, 0x32, 0x33, 0x60, 0xDF, 0x8B, 0xCC, 0x93, 0xB5, 0x4F, 0x6A, 0xEC, 0x70, 0x53, 0xAF, 0xCF, 0x07, 0x0F, 0xA0, 0xCD, 0x66, 0xAC, 0x00, 0x57, 0xC6, 0x5C, 0x5D, 0x21, 0xB1, 0xBD, 0x30, 0x89, 0x8E, 0x77, 0x8D, 0xD4, 0x69, 0x7E, 0xC0, 0x36, 0x7E, 0xD2, 0xD8, 0x20, 0x71, 0x08, 0x80, 0xD2, 0xCB, 0x74, 0x8B, 0xD8, 0x42, 0x17, 0x04, 0x99, 0x80, 0xA4, 0x52, 0x70, 0x2E, 0xC0, 0xE3, 0x8C, 0x0B, 0xFF, 0x79, 0xB7, 0x45, 0x77, 0xDC, 0xC5, 0xCF, 0x43, 0x98, 0x91, 0x7D, 0xF1, 0x01, 0xF7, 0x53, 0xD7, 0xC6, 0x51, 0x35, 0xF0, 0x89, 0xCC, 0xC1, 0xFF, 0xE2, 0x89 };
#if NET_2_0
[Test]
public void Constructor_Empty ()
{
@@ -85,40 +84,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
{
KeyInfoX509Data data = new KeyInfoX509Data ((X509Certificate)null);
}
#else
[Test]
[ExpectedException (typeof (CryptographicException))]
public void Constructor_Empty ()
{
KeyInfoX509Data data = new KeyInfoX509Data ();
XmlElement invalid = data.GetXml ();
}
[Test]
public void Constructor_X509Certificate_Null ()
{
KeyInfoX509Data data = new KeyInfoX509Data ((X509Certificate)null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
[Category ("NotWorking")]
public void Constructor_X509Certificate_Null_GetXml ()
{
KeyInfoX509Data data = new KeyInfoX509Data ((X509Certificate)null);
XmlElement invalid = data.GetXml ();
// note: even if we add a check in GetXml this will makes another unit
// test fails. We clearly are not doing this the same way as MS does.
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_X509CertificateByteArray_Null_GetXml ()
{
KeyInfoX509Data data = new KeyInfoX509Data ((byte[])null);
XmlElement invalid = data.GetXml ();
}
#endif
[Test]
public void Constructor_X509CertificateByteArray_Null ()
{
@@ -144,7 +109,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
Assert.AreEqual ((data2.GetXml ().OuterXml), (data3.GetXml ().OuterXml), "data2==data3");
}
#if NET_2_0
[Test]
public void Constructor_X509Certificate_X509IncludeOption ()
{
@@ -199,42 +163,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
KeyInfoX509Data data = new KeyInfoX509Data ();
data.AddIssuerSerial ("issuer", null);
}
#else
[Test]
public void AddCertificate_Null ()
{
KeyInfoX509Data data = new KeyInfoX509Data ();
data.AddCertificate (null);
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void AddCertificate_Null_GetXml ()
{
KeyInfoX509Data data = new KeyInfoX509Data ();
data.AddCertificate (null);
XmlElement empty = data.GetXml ();
}
[Test]
public void AddIssuerSerial_Null_Serial ()
{
KeyInfoX509Data data = new KeyInfoX509Data ();
data.AddIssuerSerial (null, "serial");
XmlElement empty = data.GetXml ();
Assert.AreEqual (empty.OuterXml, "<X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509IssuerSerial><X509IssuerName></X509IssuerName><X509SerialNumber>serial</X509SerialNumber></X509IssuerSerial></X509Data>");
}
[Test]
public void AddIssuerSerial_Issuer_Null ()
{
KeyInfoX509Data data = new KeyInfoX509Data ();
data.AddIssuerSerial ("issuer", null);
XmlElement empty = data.GetXml ();
Assert.AreEqual (empty.OuterXml, "<X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509IssuerSerial><X509IssuerName>issuer</X509IssuerName><X509SerialNumber></X509SerialNumber></X509IssuerSerial></X509Data>");
}
#endif
[Test]
public void AddSubjectKeyId_Byte_Null ()
@@ -249,7 +177,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
// beta2 bug - throw an ArgumentNullException (a little too late)
// Assert.AreEqual ("<X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", data.GetXml ().OuterXml);
}
#if NET_2_0
[Test]
[Category ("NotWorking")] // beta2 bug
[ExpectedException (typeof (NullReferenceException))]
@@ -272,7 +199,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
Assert.AreEqual (1, data.SubjectKeyIds.Count, "SubjectKeyIds");
Assert.IsNull (data.SubjectNames, "SubjectNames");
}
#endif
[Test]
public void AddSubjectName_Null ()
{

View File

@@ -158,11 +158,9 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if NET_2_0
[Category ("NotDotNet")]
// MS throws a NullReferenceException (reported as FDBK25886) but only when executed in NUnit
// http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=3596d1e3-362b-40bd-bca9-2e8be75261ff
#endif
public void AddAllTransforms ()
{
// adding an empty hash value

View File

@@ -147,11 +147,9 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if NET_2_0
// urn:foo is'nt accepted when calling GetXml
[ExpectedException (typeof (CryptographicException))]
[Category ("NotWorking")]
#endif
public void GetXmlWithSetProperty ()
{
XmlDocument doc = new XmlDocument ();

View File

@@ -75,10 +75,8 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if NET_2_0
[Ignore ("2.0 throws a NullReferenceException - reported as FDBK25892")]
// http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=02dd9730-d1ad-4170-8c82-36858c55fbe2
#endif
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_XmlDocument_Null ()
{
@@ -100,9 +98,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if !NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void Constructor_XmlElement_WithoutLoadXml ()
{
XmlDocument doc = new XmlDocument ();
@@ -213,6 +208,87 @@ namespace MonoTests.System.Security.Cryptography.Xml {
Assert.IsTrue (vrfy.CheckSignature (), "RSA-Compute/Verify");
}
// The same as MSDNSample(), but adding a few attributes
public SignedXml MSDNSampleMixedCaseAttributes ()
{
// Create example data to sign.
XmlDocument document = new XmlDocument ();
XmlNode node = document.CreateNode (XmlNodeType.Element, "", "MyElement", "samples");
node.InnerText = "This is some text";
XmlAttribute a1 = document.CreateAttribute ("Aa");
XmlAttribute a2 = document.CreateAttribute ("Bb");
XmlAttribute a3 = document.CreateAttribute ("aa");
XmlAttribute a4 = document.CreateAttribute ("bb");
a1.Value = "one";
a2.Value = "two";
a3.Value = "three";
a4.Value = "four";
node.Attributes.Append (a1);
node.Attributes.Append (a2);
node.Attributes.Append (a3);
node.Attributes.Append (a4);
document.AppendChild (node);
// Create the SignedXml message.
SignedXml signedXml = new SignedXml ();
// Create a data object to hold the data to sign.
DataObject dataObject = new DataObject ();
dataObject.Data = document.ChildNodes;
dataObject.Id = "MyObjectId";
// Add the data object to the signature.
signedXml.AddObject (dataObject);
// Create a reference to be able to package everything into the
// message.
Reference reference = new Reference ();
reference.Uri = "#MyObjectId";
// Add it to the message.
signedXml.AddReference (reference);
return signedXml;
}
public string AsymmetricRSAMixedCaseAttributes ()
{
SignedXml signedXml = MSDNSampleMixedCaseAttributes ();
RSA key = RSA.Create ();
signedXml.SigningKey = key;
// Add a KeyInfo.
KeyInfo keyInfo = new KeyInfo ();
keyInfo.AddClause (new RSAKeyValue (key));
signedXml.KeyInfo = keyInfo;
// Compute the signature.
signedXml.ComputeSignature ();
// Get the XML representation of the signature.
XmlElement xmlSignature = signedXml.GetXml ();
StringWriter sw = new StringWriter ();
XmlWriter w = new XmlTextWriter (sw);
xmlSignature.WriteTo (w);
return sw.ToString ();
}
// Example output from Windows for AsymmetricRSAMixedCaseAttributes()
private const string AsymmetricRSAMixedCaseAttributesResult = "<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\" /><Reference URI=\"#MyObjectId\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>0j1xLsePFtuRHfXEnVdTSLWtAm4=</DigestValue></Reference></SignedInfo><SignatureValue>hmrEBgns5Xx14aDhzqOyIh0qLNMUldtW8+fNPcvtD/2KtEhNZQGctnhs90CRa1NZ08TqzW2pUaEwmqvMAtF4v8KtWzC/zTuc1jH6nxQvQSQo0ABhuXdu7/hknZkXJ4yKBbdgbKjAsKfULwbWrP/PacLPoYfCO+wXSrt+wLMTTWU=</SignatureValue><KeyInfo><KeyValue><RSAKeyValue><Modulus>4h/rHDr54r6SZWk2IPCeHX7N+wR1za0VBLshuS6tq3RSWap4PY2BM8VdbKH2T9RzyZoiHufjng+1seUx430iMsXisOLUkPP+yGtMQOSZ3CQHAa+IYA+fplXipixI0rV1J1wJNXQm3HxXQqKWpIv5fkwBtj8o2k6CWMgPNgFCnxc=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue></KeyInfo><Object Id=\"MyObjectId\"><MyElement Aa=\"one\" Bb=\"two\" aa=\"three\" bb=\"four\" xmlns=\"samples\">This is some text</MyElement></Object></Signature>";
[Test]
public void AsymmetricRSAMixedCaseAttributesVerifyWindows ()
{
XmlDocument doc = new XmlDocument ();
doc.LoadXml (AsymmetricRSAMixedCaseAttributesResult);
SignedXml v1 = new SignedXml ();
v1.LoadXml (doc.DocumentElement);
Assert.IsTrue (v1.CheckSignature ());
}
[Test]
public void AsymmetricDSASignature ()
{
@@ -260,11 +336,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
// Compute the signature.
byte[] secretkey = Encoding.Default.GetBytes ("password");
HMACSHA1 hmac = new HMACSHA1 (secretkey);
#if NET_2_0
Assert.AreEqual (0, signedXml.KeyInfo.Count, "KeyInfo");
#else
Assert.IsNull (signedXml.KeyInfo, "KeyInfo");
#endif
Assert.IsNull (signedXml.SignatureLength, "SignatureLength");
Assert.IsNull (signedXml.SignatureMethod, "SignatureMethod");
Assert.IsNull (signedXml.SignatureValue, "SignatureValue");
@@ -272,11 +344,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
signedXml.ComputeSignature (hmac);
#if NET_2_0
Assert.AreEqual (0, signedXml.KeyInfo.Count, "KeyInfo");
#else
Assert.IsNull (signedXml.KeyInfo, "KeyInfo");
#endif
Assert.IsNull (signedXml.SignatureLength, "SignatureLength");
Assert.AreEqual (SignedXml.XmlDsigHMACSHA1Url, signedXml.SignatureMethod, "SignatureMethod");
Assert.AreEqual (20, signedXml.SignatureValue.Length, "SignatureValue");
@@ -399,7 +467,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
AsymmetricAlgorithm aa2 = sxe.PublicGetPublicKey ();
Assert.IsNull (aa2, "Second Public Key is null");
}
#if NET_2_0
[Test]
// [ExpectedException (typeof (ArgumentNullException))]
public void AddObject_Null ()
@@ -416,16 +483,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
SignedXml sx = new SignedXml ();
sx.AddReference (null);
}
#else
[Test]
public void Add_Null ()
{
SignedXml sx = new SignedXml ();
// no ArgumentNull exceptions for those
sx.AddObject (null);
sx.AddReference (null);
}
#endif
[Test]
[ExpectedException (typeof (CryptographicException))]
public void GetXml_WithoutInfo ()
@@ -472,9 +529,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if !NET_2_0
[ExpectedException (typeof (CryptographicException))]
#endif
public void CheckSignatureEmpty ()
{
SignedXml sx = new SignedXml ();
@@ -600,7 +654,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
Assert.IsNull (sign.GetIdElement (new XmlDocument (), null));
}
#if NET_2_0
[Test]
[Category ("NotWorking")] // bug #79483
public void DigestValue_CRLF ()
@@ -1293,7 +1346,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
// verify MS-generated signature
Assert.IsTrue (sign.CheckSignature (new HMACRIPEMD160 (hmackey)));
}
#endif
// CVE-2009-0217
// * a 0-length signature is the worse case - it accepts anything
// * between 1-7 bits length are considered invalid (not a multiple of 8)
@@ -1421,7 +1473,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
SignedXml sign = GetSignedXml (xml);
Assert.IsTrue (sign.CheckSignature (new HMACSHA1 (Encoding.ASCII.GetBytes ("secret"))));
}
#if NET_2_0
[Test]
[Category ("NotDotNet")] // will fail until a fix is available
public void VerifyHMAC_SmallerHalfLength ()
@@ -1440,7 +1491,6 @@ namespace MonoTests.System.Security.Cryptography.Xml {
SignedXml sign = GetSignedXml (xml);
Assert.IsTrue (sign.CheckSignature (new HMACSHA256 (Encoding.ASCII.GetBytes ("secret"))));
}
#endif
[Test]
public void VerifyHMAC_FullLength ()
{

View File

@@ -74,13 +74,11 @@ namespace MonoTests.System.Security.Cryptography.Xml {
[TestFixture]
public class TransformTest {
#if NET_2_0
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void GetDigestedOutput_Null ()
{
new ConcreteTransform ().GetDigestedOutput (null);
}
#endif
}
}

View File

@@ -26,7 +26,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
@@ -70,4 +69,3 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
}
#endif

View File

@@ -494,7 +494,19 @@ namespace MonoTests.System.Security.Cryptography.Xml {
Assert.AreEqual (new StreamReader (s, Encoding.UTF8).ReadToEnd (), expected);
}
#if NET_2_0
[Test]
public void OrdinalSortForAttributes ()
{
XmlDocument doc = new XmlDocument ();
string xml = "<foo Aa=\"one\" Bb=\"two\" aa=\"three\" bb=\"four\"><bar></bar></foo>";
doc.LoadXml (xml);
transform.LoadInput (doc);
Stream s = (Stream) transform.GetOutput ();
string output = Stream2String (s);
Assert.AreEqual (xml, output);
}
[Test]
public void PrefixlessNamespaceOutput ()
{
@@ -532,6 +544,5 @@ namespace MonoTests.System.Security.Cryptography.Xml {
{
new XmlDsigExcC14NTransform ().GetDigestedOutput (null);
}
#endif
}
}

View File

@@ -97,11 +97,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
Assert.AreEqual (null, xnl, "Default InnerXml");
}
#if NET_2_0
[ExpectedException (typeof (ArgumentException))]
#else
// LAMESPEC: input MUST be one of InputType - but no exception is thrown (not documented)
#endif
public void LoadInputWithUnsupportedType ()
{
byte[] bad = { 0xBA, 0xD };
@@ -129,19 +125,15 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (SecurityException))]
#endif
public void C14NSpecExample1_WithoutResolver ()
{
using (StreamWriter sw = new StreamWriter ("doc.dtd", false, Encoding.ASCII)) {
sw.Write ("<!-- presence, not content, required -->");
sw.Close ();
}
#if NET_2_0
if (!SecurityManager.SecurityEnabled)
NUnit.Framework.Assert.Ignore ("SecurityManager isn't enabled.");
#endif
string res = ExecuteXmlDSigC14NTransform (C14NSpecExample1Input, false);
Assert.AreEqual (C14NSpecExample1Output, res, "Example 1 from c14n spec - PIs, Comments, and Outside of Document Element (with comments)");
}
@@ -203,10 +195,8 @@ namespace MonoTests.System.Security.Cryptography.Xml {
vreader.ValidationType = ValidationType.None;
vreader.EntityHandling = EntityHandling.ExpandCharEntities;
doc.Load (vreader);
#if NET_2_0
if (resolver)
transform.Resolver = new XmlUrlResolver ();
#endif
transform.LoadInput (doc);
return Stream2String ((Stream)transform.GetOutput ());
}

View File

@@ -19,7 +19,6 @@
// output XML. So, they are *not* from c14n specification.
//
#if NET_2_0
using System;
using System.IO;
@@ -598,4 +597,3 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
}
#endif

View File

@@ -14,7 +14,6 @@
// (C) 2008 Gert Driesen
//
#if NET_2_0
using System;
using System.IO;
@@ -140,4 +139,3 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
}
#endif

View File

@@ -86,9 +86,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if NET_2_0
[Ignore ("throws a NullReferenceException - but it's (kind of internal)")]
#endif
public void GetInnerXml ()
{
XmlNodeList xnl = transform.UnprotectedGetInnerXml ();
@@ -97,17 +95,12 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if ONLY_1_1
[ExpectedException (typeof (NullReferenceException))]
#endif
public void OnlyInner ()
{
XmlNodeList inner = InnerXml (""); // empty
transform.LoadInnerXml (inner);
XmlNodeList xnl = (XmlNodeList) transform.GetOutput ();
#if NET_2_0
Assert.AreEqual (0, xnl.Count, "Count");
#endif
}
private XmlDocument GetDoc ()
@@ -132,9 +125,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if NET_2_0
[Category ("NotWorking")]
#endif
public void LoadInputAsXmlDocument ()
{
XmlDocument doc = GetDoc ();
@@ -142,11 +133,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
XmlNodeList inner = InnerXml ("//*/title");
transform.LoadInnerXml (inner);
XmlNodeList xnl = (XmlNodeList) transform.GetOutput ();
#if NET_2_0
Assert.AreEqual (73, xnl.Count);
#else
Assert.AreEqual (47, xnl.Count);
#endif
}
[Test]
@@ -182,9 +169,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if NET_2_0
[Category ("NotWorking")]
#endif
public void LoadInputAsStream ()
{
XmlDocument doc = GetDoc ();
@@ -196,11 +181,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
XmlNodeList inner = InnerXml ("//*/title");
transform.LoadInnerXml (inner);
XmlNodeList xnl = (XmlNodeList) transform.GetOutput ();
#if NET_2_0
Assert.AreEqual (73, xnl.Count);
#else
Assert.AreEqual (47, xnl.Count);
#endif
}
[Test]
@@ -291,39 +272,22 @@ namespace MonoTests.System.Security.Cryptography.Xml {
doc.LoadXml ("<element xmlns='urn:foo'><foo><bar>test</bar></foo></element>");
t.LoadInput (doc);
nl = (XmlNodeList) t.GetOutput ();
#if NET_2_0
Assert.AreEqual (0, nl.Count, "1");
#else
Assert.AreEqual (1, nl.Count, "1");
#endif
doc.LoadXml ("<element xmlns='urn:foo'><foo xmlns='urn:bar'><bar>test</bar></foo></element>");
t.LoadInput (doc);
nl = (XmlNodeList) t.GetOutput ();
#if NET_2_0
Assert.AreEqual (0, nl.Count, "2");
#else
Assert.AreEqual (2, nl.Count, "2");
#endif
doc.LoadXml ("<element xmlns='urn:foo' xmlns:x='urn:x'><foo xmlns='urn:bar'><bar>test</bar></foo></element>");
t.LoadInput (doc);
nl = (XmlNodeList) t.GetOutput ();
#if NET_2_0
Assert.AreEqual (0, nl.Count, "3");
#else
Assert.AreEqual (3, nl.Count, "3");
#endif
doc.LoadXml ("<envelope><Signature xmlns='http://www.w3.org/2000/09/xmldsig#'><XPath>blah</XPath></Signature></envelope>");
t.LoadInput (doc);
nl = (XmlNodeList) t.GetOutput ();
#if NET_2_0
Assert.AreEqual (0, nl.Count, "4");
#else
Assert.AreEqual (1, nl.Count, "4");
Assert.AreEqual (XmlNodeType.Attribute, nl [0].NodeType, "NodeType");
#endif
}
}
}

View File

@@ -10,6 +10,7 @@
//
using System;
using System.Collections;
using System.IO;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
@@ -117,11 +118,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
[ExpectedException (typeof (NullReferenceException))]
#endif
public void EmptyXslt ()
{
string test = "<Test>XmlDsigXsltTransform</Test>";
@@ -158,15 +155,10 @@ namespace MonoTests.System.Security.Cryptography.Xml {
transform.LoadInnerXml (doc.ChildNodes);
Stream s = (Stream) transform.GetOutput ();
}
#if NET_2_0
catch (Exception e) {
// we must deal with an internal exception
result = (e.GetType ().ToString ().EndsWith ("XsltLoadException"));
result = true;
#else
catch (XsltCompileException) {
result = true;
#endif
}
finally {
Assert.IsTrue (result, "Exception not thrown");
@@ -174,11 +166,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
[Test]
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
#else
[ExpectedException (typeof (NullReferenceException))]
#endif
public void OnlyInner ()
{
string test = "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns=\"http://www.w3.org/TR/xhtml1/strict\" version=\"1.0\">";
@@ -256,7 +244,19 @@ namespace MonoTests.System.Security.Cryptography.Xml {
XmlDocument doc = GetXslDoc ();
transform.LoadInnerXml (doc.DocumentElement.ChildNodes);
XmlNodeList xnl = transform.UnprotectedGetInnerXml ();
Assert.AreEqual (doc.DocumentElement.ChildNodes, xnl, "LoadInnerXml");
AssertNodeListEqual (doc.DocumentElement.ChildNodes, xnl, "LoadInnerXml");
}
void AssertNodeListEqual (XmlNodeList nl1, XmlNodeList nl2, string label)
{
Assert.AreEqual (nl1.Count, nl2.Count, label + ": node count");
IEnumerator e1, e2;
int i;
for (i = 0, e1 = nl1.GetEnumerator (), e2 = nl2.GetEnumerator (); e1.MoveNext (); i++) {
Assert.IsTrue (e2.MoveNext (), label + " : nl2.MoveNext");
Assert.AreEqual (e1.Current, e2.Current, label + " : node at " + i);
}
Assert.IsFalse (e2.MoveNext (), label + " : nl2 has extras");
}
[Test]

View File

@@ -13,7 +13,6 @@
// (C) 2008 Gert Driesen
//
#if NET_2_0
using System;
using System.IO;
@@ -90,4 +89,3 @@ namespace MonoTests.System.Security.Cryptography.Xml {
}
}
#endif