[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Xml / XmlDsigEnvelopedSignatureTransformTest.cs
blob8f88ef8a4465501bffadfe398f40627bb7b18c4e
1 //
2 // XmlDsigEnvelopedSignatureTransformTest.cs
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // (C) 2004 Novell Inc.
8 //
9 #if !MOBILE
11 using System;
12 using System.IO;
13 using System.Security.Cryptography;
14 using System.Security.Cryptography.Xml;
15 using System.Text;
16 using System.Xml;
17 using System.Xml.Xsl;
19 using NUnit.Framework;
21 namespace MonoTests.System.Security.Cryptography.Xml {
23 // Note: GetInnerXml is protected in XmlDsigEnvelopedSignatureTransform making it
24 // difficult to test properly. This class "open it up" :-)
25 public class UnprotectedXmlDsigEnvelopedSignatureTransform : XmlDsigEnvelopedSignatureTransform {
26 public UnprotectedXmlDsigEnvelopedSignatureTransform ()
30 public UnprotectedXmlDsigEnvelopedSignatureTransform (bool includeComments)
31 : base (includeComments)
35 public XmlNodeList UnprotectedGetInnerXml ()
37 return base.GetInnerXml ();
41 [TestFixture]
42 public class XmlDsigEnvelopedSignatureTransformTest {
43 private UnprotectedXmlDsigEnvelopedSignatureTransform transform;
45 [SetUp]
46 public void SetUp ()
48 transform = new UnprotectedXmlDsigEnvelopedSignatureTransform ();
51 [Test] // ctor ()
52 public void Constructor1 ()
54 CheckProperties (transform);
57 [Test] // ctor (Boolean)
58 public void Constructor2 ()
60 transform = new UnprotectedXmlDsigEnvelopedSignatureTransform (true);
61 CheckProperties (transform);
62 transform = new UnprotectedXmlDsigEnvelopedSignatureTransform (false);
63 CheckProperties (transform);
66 void CheckProperties (XmlDsigEnvelopedSignatureTransform transform)
68 Assert.AreEqual ("http://www.w3.org/2000/09/xmldsig#enveloped-signature",
69 transform.Algorithm, "Algorithm");
71 Type [] input = transform.InputTypes;
72 Assert.AreEqual (3, input.Length, "Input Length");
73 // check presence of every supported input types
74 bool istream = false;
75 bool ixmldoc = false;
76 bool ixmlnl = false;
77 foreach (Type t in input) {
78 if (t == typeof (XmlDocument))
79 ixmldoc = true;
80 if (t == typeof (XmlNodeList))
81 ixmlnl = true;
82 if (t == typeof (Stream))
83 istream = true;
85 Assert.IsTrue (istream, "Input Stream");
86 Assert.IsTrue (ixmldoc, "Input XmlDocument");
87 Assert.IsTrue (ixmlnl, "Input XmlNodeList");
89 Type [] output = transform.OutputTypes;
90 Assert.AreEqual (2, output.Length, "Output Length");
91 // check presence of every supported output types
92 bool oxmlnl = false;
93 bool oxmldoc = false;
94 foreach (Type t in output) {
95 if (t == typeof (XmlNodeList))
96 oxmlnl = true;
97 if (t == typeof (XmlDocument))
98 oxmldoc = true;
100 Assert.IsTrue (oxmlnl, "Output XmlNodeList");
101 Assert.IsTrue (oxmldoc, "Output XmlDocument");
104 void AssertEquals (XmlNodeList expected, XmlNodeList actual, string msg)
106 for (int i = 0; i < expected.Count; i++) {
107 if (expected [i].OuterXml != actual [i].OuterXml)
108 Assert.Fail (msg + " [" + i + "] expected " + expected [i].OuterXml + " bug got " + actual [i].OuterXml);
112 [Test]
113 public void GetInnerXml ()
115 // Always returns null
116 Assert.IsNull (transform.UnprotectedGetInnerXml ());
119 private XmlDocument GetDoc ()
121 string dsig = "<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#dsa-sha1\" /><Reference URI=\"\"><Transforms><Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\" /></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>fdy6S2NLpnT4fMdokUHSHsmpcvo=</DigestValue></Reference></Signature>";
122 string test = "<Envelope> " + dsig + " </Envelope>";
123 XmlDocument doc = new XmlDocument ();
124 doc.LoadXml (test);
125 return doc;
128 [Test]
129 public void LoadInputAsXmlDocument ()
131 XmlDocument doc = GetDoc ();
132 transform.LoadInput (doc);
133 object o = transform.GetOutput ();
134 Assert.AreEqual (doc, o, "EnvelopedSignature result");
137 [Test]
138 public void LoadInputAsXmlNodeList ()
140 XmlDocument doc = GetDoc ();
141 transform.LoadInput (doc.ChildNodes);
142 XmlNodeList xnl = (XmlNodeList) transform.GetOutput ();
143 AssertEquals (doc.ChildNodes, xnl, "EnvelopedSignature result");
147 #endif