Merge pull request #5260 from BrzVlad/fix-handler-block
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Xml / XmlDsigExcC14NTransformTest.cs
index 1ba7a8ef6cc2311141f2fce9d3d7279bcdfb370c..d14b5ee2802f7cf076b1e913ff02ae48b03aa315 100644 (file)
@@ -19,7 +19,6 @@
 //     output XML. So, they are *not* from c14n specification.
 //
 
-#if NET_2_0
 
 using System;
 using System.IO;
@@ -34,6 +33,24 @@ namespace MonoTests.System.Security.Cryptography.Xml {
        // Note: GetInnerXml is protected in XmlDsigExcC14NTransform making it
        // difficult to test properly. This class "open it up" :-)
        public class UnprotectedXmlDsigExcC14NTransform : XmlDsigExcC14NTransform {
+               public UnprotectedXmlDsigExcC14NTransform ()
+               {
+               }
+
+               public UnprotectedXmlDsigExcC14NTransform (bool includeComments)
+                       : base (includeComments)
+               {
+               }
+
+               public UnprotectedXmlDsigExcC14NTransform (string inclusiveNamespacesPrefixList)
+                       : base (inclusiveNamespacesPrefixList)
+               {
+               }
+
+               public UnprotectedXmlDsigExcC14NTransform (bool includeComments, string inclusiveNamespacesPrefixList)
+                       : base (includeComments, inclusiveNamespacesPrefixList)
+               {
+               }
 
                public XmlNodeList UnprotectedGetInnerXml () {
                        return base.GetInnerXml ();
@@ -41,7 +58,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
        }
 
        [TestFixture]
-       public class XmlDsigExcC14NTransformTest : Assertion {
+       public class XmlDsigExcC14NTransformTest {
 
                protected UnprotectedXmlDsigExcC14NTransform transform;
 
@@ -63,13 +80,85 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        catch {}
                }
 
-               [Test]
-               public void Properties () 
+               [Test] // ctor ()
+               public void Constructor1 ()
                {
-                       AssertEquals ("Algorithm", "http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm);
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
+                       Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+               }
 
+               [Test] // ctor (Boolean)
+               public void Constructor2 ()
+               {
+                       transform = new UnprotectedXmlDsigExcC14NTransform (true);
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
+                       Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+
+                       transform = new UnprotectedXmlDsigExcC14NTransform (false);
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
+                       Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+               }
+
+               [Test] // ctor (String)
+               public void Constructor3 ()
+               {
+                       transform = new UnprotectedXmlDsigExcC14NTransform (null);
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
+                       Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+
+                       transform = new UnprotectedXmlDsigExcC14NTransform (string.Empty);
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
+                       Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+
+                       transform = new UnprotectedXmlDsigExcC14NTransform ("#default xsd");
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
+                       Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+               }
+
+               [Test] // ctor (Boolean, String)
+               public void Constructor4 ()
+               {
+                       transform = new UnprotectedXmlDsigExcC14NTransform (true, null);
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
+                       Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+
+                       transform = new UnprotectedXmlDsigExcC14NTransform (true, string.Empty);
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
+                       Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+
+                       transform = new UnprotectedXmlDsigExcC14NTransform (true, "#default xsd");
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
+                       Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+
+                       transform = new UnprotectedXmlDsigExcC14NTransform (false, null);
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
+                       Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+
+                       transform = new UnprotectedXmlDsigExcC14NTransform (false, string.Empty);
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
+                       Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+
+                       transform = new UnprotectedXmlDsigExcC14NTransform (false, "#default xsd");
+                       Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
+                       Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
+                       CheckProperties (transform);
+               }
+
+               void CheckProperties (XmlDsigExcC14NTransform transform)
+               {
                        Type[] input = transform.InputTypes;
-                       Assert ("Input #", (input.Length == 3));
+                       Assert.IsTrue ((input.Length == 3), "Input #");
                        // check presence of every supported input types
                        bool istream = false;
                        bool ixmldoc = false;
@@ -82,19 +171,19 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                                if (t.ToString () == "System.Xml.XmlNodeList")
                                        ixmlnl = true;
                        }
-                       Assert ("Input Stream", istream);
-                       Assert ("Input XmlDocument", ixmldoc);
-                       Assert ("Input XmlNodeList", ixmlnl);
+                       Assert.IsTrue (istream, "Input Stream");
+                       Assert.IsTrue (ixmldoc, "Input XmlDocument");
+                       Assert.IsTrue (ixmlnl, "Input XmlNodeList");
 
                        Type[] output = transform.OutputTypes;
-                       Assert ("Output #", (output.Length == 1));
+                       Assert.IsTrue ((output.Length == 1), "Output #");
                        // check presence of every supported output types
                        bool ostream = false;
                        foreach (Type t in output) {
                                if (t.ToString () == "System.IO.Stream")
                                        ostream = true;
                        }
-                       Assert ("Output Stream", ostream);
+                       Assert.IsTrue (ostream, "Output Stream");
                }
 
                [Test]
@@ -106,12 +195,12 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        input [2] = null;
                        // property does not return a clone
                        foreach (Type t in transform.InputTypes) {
-                               AssertNull (t);
+                               Assert.IsNull (t);
                        }
                        // it's not a static array
                        XmlDsigExcC14NTransform t2 = new XmlDsigExcC14NTransform ();
                        foreach (Type t in t2.InputTypes) {
-                               AssertNotNull (t);
+                               Assert.IsNotNull (t);
                        }
                }
 
@@ -119,7 +208,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                public void GetInnerXml () 
                {
                        XmlNodeList xnl = transform.UnprotectedGetInnerXml ();
-                       AssertNull ("Default InnerXml", xnl);
+                       Assert.IsNull (xnl, "Default InnerXml");
                }
 
                private string Stream2String (Stream s) 
@@ -158,19 +247,11 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        transform.LoadInput (doc);
                        Stream s = (Stream) transform.GetOutput ();
                        string output = Stream2String (s);
-#if NET_1_1
-                       AssertEquals("XmlDocument", c14xml3, output);
-#else
-                       // .NET 1.0 keeps the \r\n (0x0D, 0x0A) - bug
-                       AssertEquals("XmlDocument", c14xml1, output);
-#endif
+                       Assert.AreEqual (c14xml3, output, "XmlDocument");
                }
 
                [Test]
-#if NET_2_0
-               [Category ("NotDotNet")]
                // see LoadInputAsXmlNodeList2 description
-#endif
                public void LoadInputAsXmlNodeList () 
                {
                        XmlDocument doc = GetDoc ();
@@ -178,11 +259,10 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        transform.LoadInput (doc.ChildNodes);
                        Stream s = (Stream) transform.GetOutput ();
                        string output = Stream2String (s);
-                       AssertEquals ("XmlChildNodes", "<Test></Test>", output);
+                       Assert.AreEqual ("<Test xmlns=\"http://www.go-mono.com/\"></Test>", output, "XmlChildNodes");
                }
 
                [Test]
-               [Category ("NotDotNet")]
                // MS has a bug that those namespace declaration nodes in
                // the node-set are written to output. Related spec section is:
                // http://www.w3.org/TR/2001/REC-xml-c14n-20010315#ProcessingModel
@@ -192,8 +272,8 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        transform.LoadInput (doc.SelectNodes ("//*"));
                        Stream s = (Stream) transform.GetOutput ();
                        string output = Stream2String (s);
-                       string expected = @"<Test><Toto></Toto></Test>";
-                       AssertEquals ("XmlChildNodes", expected, output);
+                       string expected = "<Test xmlns=\"http://www.go-mono.com/\"><Toto></Toto></Test>";
+                       Assert.AreEqual (expected, output, "XmlChildNodes");
                }
 
                [Test]
@@ -206,7 +286,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        transform.LoadInput (ms);
                        Stream s = (Stream) transform.GetOutput ();
                        string output = Stream2String (s);
-                       AssertEquals ("MemoryStream", c14xml2, output);
+                       Assert.AreEqual (c14xml2, output, "MemoryStream");
                }
 
                [Test]
@@ -233,24 +313,21 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                                sw.Close ();
                        }
                        string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample1Input);
-                       AssertEquals ("Example 1 from c14n spec - PIs, Comments, and Outside of Document Element (without comments)", 
-                                       ExcC14NSpecExample1Output, res);
+                       Assert.AreEqual (ExcC14NSpecExample1Output, res, "Example 1 from c14n spec - PIs, Comments, and Outside of Document Element (without comments)");
                }
 
                [Test]
                public void ExcC14NSpecExample2 ()
                {
                        string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample2Input);
-                       AssertEquals ("Example 2 from c14n spec - Whitespace in Document Content (without comments)", 
-                                       ExcC14NSpecExample2Output, res);
+                       Assert.AreEqual (ExcC14NSpecExample2Output, res, "Example 2 from c14n spec - Whitespace in Document Content (without comments)");
                }
 
                [Test]
                public void ExcC14NSpecExample3 ()
                {
                        string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample3Input);
-                       AssertEquals ("Example 3 from c14n spec - Start and End Tags (without comments)", 
-                                       ExcC14NSpecExample3Output, res);
+                       Assert.AreEqual (ExcC14NSpecExample3Output, res, "Example 3 from c14n spec - Start and End Tags (without comments)");
                }
            
                [Test]
@@ -258,8 +335,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                public void ExcC14NSpecExample4 ()
                {
                        string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample4Input);
-                       AssertEquals ("Example 4 from c14n spec - Character Modifications and Character References (without comments)", 
-                                       ExcC14NSpecExample4Output, res);
+                       Assert.AreEqual (ExcC14NSpecExample4Output, res, "Example 4 from c14n spec - Character Modifications and Character References (without comments)");
                }
            
                [Test]
@@ -270,16 +346,14 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                                sw.Close ();
                        }
                        string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample5Input);
-                       AssertEquals ("Example 5 from c14n spec - Entity References (without comments)", 
-                                       ExcC14NSpecExample5Output, res);
+                       Assert.AreEqual (ExcC14NSpecExample5Output, res, "Example 5 from c14n spec - Entity References (without comments)");
                }
     
                [Test]
                public void ExcC14NSpecExample6 ()
                {
                        string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample6Input);
-                       AssertEquals ("Example 6 from c14n spec - UTF-8 Encoding (without comments)", 
-                                       ExcC14NSpecExample6Output, res);
+                       Assert.AreEqual (ExcC14NSpecExample6Output, res, "Example 6 from c14n spec - UTF-8 Encoding (without comments)");
                }
 
                private string ExecuteXmlDSigExcC14NTransform (string InputXml)
@@ -509,9 +583,15 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform ();
                        t.LoadInput (doc);
                        Stream s = t.GetOutput () as Stream;
-                       AssertEquals (expected, new StreamReader (s, Encoding.UTF8).ReadToEnd ());
+                       Assert.AreEqual (new StreamReader (s, Encoding.UTF8).ReadToEnd (), expected);
+               }
+
+               [Test]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void GetDigestedOutput_Null ()
+               {
+                       new XmlDsigExcC14NTransform ().GetDigestedOutput (null);
                }
        }    
 }
 
-#endif