| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- //
- // XmlDsigC14NTransformTest.cs - NUnit Test Cases for XmlDsigC14NTransform
- //
- // Author:
- // Sebastien Pouliot ([email protected])
- //
- // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
- //
- using System;
- using System.IO;
- using System.Security.Cryptography.Xml;
- using System.Text;
- using System.Xml;
- using NUnit.Framework;
- namespace MonoTests.System.Security.Cryptography.Xml {
- [TestFixture]
- public class XmlDsigC14NTransformTest : Assertion {
- protected XmlDsigC14NTransform transform;
- [SetUp]
- protected void SetUp ()
- {
- transform = new XmlDsigC14NTransform ();
- }
- [Test]
- public void Properties ()
- {
- AssertEquals ("Algorithm", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", transform.Algorithm);
- Type[] input = transform.InputTypes;
- Assert ("Input #", (input.Length == 3));
- // check presence of every supported input types
- bool istream = false;
- bool ixmldoc = false;
- bool ixmlnl = false;
- foreach (Type t in input) {
- if (t.ToString () == "System.IO.Stream")
- istream = true;
- if (t.ToString () == "System.Xml.XmlDocument")
- ixmldoc = true;
- if (t.ToString () == "System.Xml.XmlNodeList")
- ixmlnl = true;
- }
- Assert ("Input Stream", istream);
- Assert ("Input XmlDocument", ixmldoc);
- Assert ("Input XmlNodeList", ixmlnl);
- Type[] output = transform.OutputTypes;
- Assert ("Output #", (output.Length == 1));
- // check presence of every supported output types
- bool ostream = false;
- foreach (Type t in input) {
- if (t.ToString () == "System.IO.Stream")
- ostream = true;
- }
- Assert ("Output Stream", ostream);
- }
- private string Stream2String (Stream s)
- {
- StringBuilder sb = new StringBuilder ();
- int b = s.ReadByte ();
- while (b != -1) {
- sb.Append (Convert.ToChar (b));
- b = s.ReadByte ();
- }
- return sb.ToString ();
- }
- static string xml = "<Test attrib='at ' xmlns=\"http://www.go-mono.com/\" > \r\n <Toto/> text & </Test >";
- static string c14xml1 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \r\n <Toto></Toto> text & </Test>";
- static string c14xml2 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \n <Toto></Toto> text & </Test>";
- private XmlDocument GetDoc ()
- {
- XmlDocument doc = new XmlDocument ();
- doc.PreserveWhitespace = true;
- doc.LoadXml (xml);
- return doc;
- }
- [Test]
- public void LoadInputAsXmlDocument ()
- {
- XmlDocument doc = GetDoc ();
- transform.LoadInput (doc);
- Stream s = (Stream) transform.GetOutput ();
- string output = Stream2String (s);
- // ??? this keeps the \r\n (0x0D, 0x0A) ???
- AssertEquals("XmlDocument", c14xml1, output);
- }
- [Test]
- [Ignore("FIXME: why doesn't this works with MS ???")]
- public void LoadInputAsXmlNodeList ()
- {
- XmlDocument doc = GetDoc ();
- transform.LoadInput (doc.ChildNodes);
- Stream s = (Stream) transform.GetOutput ();
- string output = Stream2String (s);
- AssertEquals("XmlChildNodes", c14xml2, output);
- }
- [Test]
- public void LoadInputAsStream ()
- {
- MemoryStream ms = new MemoryStream ();
- byte[] x = Encoding.ASCII.GetBytes (xml);
- ms.Write (x, 0, x.Length);
- ms.Position = 0;
- transform.LoadInput (ms);
- Stream s = (Stream) transform.GetOutput ();
- string output = Stream2String (s);
- AssertEquals("MemoryStream", c14xml2, output);
- }
- [Test]
- public void LoadInputWithUnsupportedType ()
- {
- byte[] bad = { 0xBA, 0xD };
- // LAMESPEC: input MUST be one of InputType - but no exception is thrown (not documented)
- transform.LoadInput (bad);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void UnsupportedOutput ()
- {
- XmlDocument doc = new XmlDocument();
- object o = transform.GetOutput (doc.GetType ());
- }
- }
- }
|