7b56a240055b784aef0c81f6bd023cde63602d35
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Xml / XmlDsigExcC14NTransformTest.cs
1 //
2 // XmlDsigExcC14NTransformTest.cs - NUnit Test Cases for XmlDsigExcC14NTransform
3 //
4 // Author:
5 //  original:
6 //      Sebastien Pouliot <sebastien@ximian.com>
7 //      Aleksey Sanin (aleksey@aleksey.com)
8 //  this file:
9 //      Atsushi Enomoto <atsushi@ximian.com>
10 //
11 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
12 // (C) 2003 Aleksey Sanin (aleksey@aleksey.com)
13 // (C) 2004 Novell (http://www.novell.com)
14 //
15
16 //
17 // WARNING!!
18 //      This file is simply replaced C14N->ExcC14N, and then replaced expected
19 //      output XML. So, they are *not* from c14n specification.
20 //
21
22
23 using System;
24 using System.IO;
25 using System.Security.Cryptography.Xml;
26 using System.Text;
27 using System.Xml;
28
29 using NUnit.Framework;
30
31 namespace MonoTests.System.Security.Cryptography.Xml {
32
33         // Note: GetInnerXml is protected in XmlDsigExcC14NTransform making it
34         // difficult to test properly. This class "open it up" :-)
35         public class UnprotectedXmlDsigExcC14NTransform : XmlDsigExcC14NTransform {
36                 public UnprotectedXmlDsigExcC14NTransform ()
37                 {
38                 }
39
40                 public UnprotectedXmlDsigExcC14NTransform (bool includeComments)
41                         : base (includeComments)
42                 {
43                 }
44
45                 public UnprotectedXmlDsigExcC14NTransform (string inclusiveNamespacesPrefixList)
46                         : base (inclusiveNamespacesPrefixList)
47                 {
48                 }
49
50                 public UnprotectedXmlDsigExcC14NTransform (bool includeComments, string inclusiveNamespacesPrefixList)
51                         : base (includeComments, inclusiveNamespacesPrefixList)
52                 {
53                 }
54
55                 public XmlNodeList UnprotectedGetInnerXml () {
56                         return base.GetInnerXml ();
57                 }
58         }
59
60         [TestFixture]
61         public class XmlDsigExcC14NTransformTest {
62
63                 protected UnprotectedXmlDsigExcC14NTransform transform;
64
65                 [SetUp]
66                 protected void SetUp () 
67                 {
68                         transform = new UnprotectedXmlDsigExcC14NTransform ();
69                 }
70
71                 [TearDown]
72                 protected void CleanUp () 
73                 {
74                         try {
75                                 if (File.Exists ("doc.dtd"))
76                                         File.Delete ("doc.dtd");
77                                 if (File.Exists ("world.txt"))
78                                         File.Delete ("world.txt");
79                         }
80                         catch {}
81                 }
82
83                 [Test] // ctor ()
84                 public void Constructor1 ()
85                 {
86                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
87                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
88                         CheckProperties (transform);
89                 }
90
91                 [Test] // ctor (Boolean)
92                 public void Constructor2 ()
93                 {
94                         transform = new UnprotectedXmlDsigExcC14NTransform (true);
95                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
96                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
97                         CheckProperties (transform);
98
99                         transform = new UnprotectedXmlDsigExcC14NTransform (false);
100                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
101                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
102                         CheckProperties (transform);
103                 }
104
105                 [Test] // ctor (String)
106                 public void Constructor3 ()
107                 {
108                         transform = new UnprotectedXmlDsigExcC14NTransform (null);
109                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
110                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
111                         CheckProperties (transform);
112
113                         transform = new UnprotectedXmlDsigExcC14NTransform (string.Empty);
114                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
115                         Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
116                         CheckProperties (transform);
117
118                         transform = new UnprotectedXmlDsigExcC14NTransform ("#default xsd");
119                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
120                         Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
121                         CheckProperties (transform);
122                 }
123
124                 [Test] // ctor (Boolean, String)
125                 public void Constructor4 ()
126                 {
127                         transform = new UnprotectedXmlDsigExcC14NTransform (true, null);
128                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
129                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
130                         CheckProperties (transform);
131
132                         transform = new UnprotectedXmlDsigExcC14NTransform (true, string.Empty);
133                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
134                         Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
135                         CheckProperties (transform);
136
137                         transform = new UnprotectedXmlDsigExcC14NTransform (true, "#default xsd");
138                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
139                         Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
140                         CheckProperties (transform);
141
142                         transform = new UnprotectedXmlDsigExcC14NTransform (false, null);
143                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
144                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
145                         CheckProperties (transform);
146
147                         transform = new UnprotectedXmlDsigExcC14NTransform (false, string.Empty);
148                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
149                         Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
150                         CheckProperties (transform);
151
152                         transform = new UnprotectedXmlDsigExcC14NTransform (false, "#default xsd");
153                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
154                         Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
155                         CheckProperties (transform);
156                 }
157
158                 void CheckProperties (XmlDsigExcC14NTransform transform)
159                 {
160                         Type[] input = transform.InputTypes;
161                         Assert.IsTrue ((input.Length == 3), "Input #");
162                         // check presence of every supported input types
163                         bool istream = false;
164                         bool ixmldoc = false;
165                         bool ixmlnl = false;
166                         foreach (Type t in input) {
167                                 if (t.ToString () == "System.IO.Stream")
168                                         istream = true;
169                                 if (t.ToString () == "System.Xml.XmlDocument")
170                                         ixmldoc = true;
171                                 if (t.ToString () == "System.Xml.XmlNodeList")
172                                         ixmlnl = true;
173                         }
174                         Assert.IsTrue (istream, "Input Stream");
175                         Assert.IsTrue (ixmldoc, "Input XmlDocument");
176                         Assert.IsTrue (ixmlnl, "Input XmlNodeList");
177
178                         Type[] output = transform.OutputTypes;
179                         Assert.IsTrue ((output.Length == 1), "Output #");
180                         // check presence of every supported output types
181                         bool ostream = false;
182                         foreach (Type t in output) {
183                                 if (t.ToString () == "System.IO.Stream")
184                                         ostream = true;
185                         }
186                         Assert.IsTrue (ostream, "Output Stream");
187                 }
188
189                 [Test]
190                 public void Types ()
191                 {
192                         Type [] input = transform.InputTypes;
193                         input [0] = null;
194                         input [1] = null;
195                         input [2] = null;
196                         // property does not return a clone
197                         foreach (Type t in transform.InputTypes) {
198                                 Assert.IsNull (t);
199                         }
200                         // it's not a static array
201                         XmlDsigExcC14NTransform t2 = new XmlDsigExcC14NTransform ();
202                         foreach (Type t in t2.InputTypes) {
203                                 Assert.IsNotNull (t);
204                         }
205                 }
206
207                 [Test]
208                 public void GetInnerXml () 
209                 {
210                         XmlNodeList xnl = transform.UnprotectedGetInnerXml ();
211                         Assert.IsNull (xnl, "Default InnerXml");
212                 }
213
214                 private string Stream2String (Stream s) 
215                 {
216                         StringBuilder sb = new StringBuilder ();
217                         int b = s.ReadByte ();
218                         while (b != -1) {
219                                 sb.Append (Convert.ToChar (b));
220                                 b = s.ReadByte ();
221                         }
222                         return sb.ToString ();
223                 }
224
225                 static string xml = "<Test  attrib='at ' xmlns=\"http://www.go-mono.com/\" > \r\n &#xD; <Toto/> text &amp; </Test   >";
226                 // BAD for XmlDocument input (framework 1.0 result)
227                 static string c14xml1 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \r\n \r <Toto></Toto> text &amp; </Test>";
228                 // GOOD for Stream input
229                 static string c14xml2 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \n &#xD; <Toto></Toto> text &amp; </Test>";
230                 // GOOD for XmlDocument input. The difference is because once
231                 // xml string is loaded to XmlDocument, there is no difference
232                 // between \r and &#xD;, so every \r must be handled as &#xD;.
233                 static string c14xml3 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> &#xD;\n &#xD; <Toto></Toto> text &amp; </Test>";
234
235                 private XmlDocument GetDoc () 
236                 {
237                         XmlDocument doc = new XmlDocument ();
238                         doc.PreserveWhitespace = true;
239                         doc.LoadXml (xml);
240                         return doc;
241                 }
242
243                 [Test]
244                 public void LoadInputAsXmlDocument () 
245                 {
246                         XmlDocument doc = GetDoc ();
247                         transform.LoadInput (doc);
248                         Stream s = (Stream) transform.GetOutput ();
249                         string output = Stream2String (s);
250                         Assert.AreEqual (c14xml3, output, "XmlDocument");
251                 }
252
253                 [Test]
254                 [Category ("NotDotNet")]
255                 // see LoadInputAsXmlNodeList2 description
256                 public void LoadInputAsXmlNodeList () 
257                 {
258                         XmlDocument doc = GetDoc ();
259                         // Argument list just contains element Test.
260                         transform.LoadInput (doc.ChildNodes);
261                         Stream s = (Stream) transform.GetOutput ();
262                         string output = Stream2String (s);
263                         Assert.AreEqual ("<Test></Test>", output, "XmlChildNodes");
264                 }
265
266                 [Test]
267                 [Category ("NotDotNet")]
268                 // MS has a bug that those namespace declaration nodes in
269                 // the node-set are written to output. Related spec section is:
270                 // http://www.w3.org/TR/2001/REC-xml-c14n-20010315#ProcessingModel
271                 public void LoadInputAsXmlNodeList2 () 
272                 {
273                         XmlDocument doc = GetDoc ();
274                         transform.LoadInput (doc.SelectNodes ("//*"));
275                         Stream s = (Stream) transform.GetOutput ();
276                         string output = Stream2String (s);
277                         string expected = @"<Test><Toto></Toto></Test>";
278                         Assert.AreEqual (expected, output, "XmlChildNodes");
279                 }
280
281                 [Test]
282                 public void LoadInputAsStream () 
283                 {
284                         MemoryStream ms = new MemoryStream ();
285                         byte[] x = Encoding.ASCII.GetBytes (xml);
286                         ms.Write (x, 0, x.Length);
287                         ms.Position = 0;
288                         transform.LoadInput (ms);
289                         Stream s = (Stream) transform.GetOutput ();
290                         string output = Stream2String (s);
291                         Assert.AreEqual (c14xml2, output, "MemoryStream");
292                 }
293
294                 [Test]
295                 [Ignore ("LAMESPEC: input MUST be one of InputType - but no exception is thrown (not documented)")]
296                 public void LoadInputWithUnsupportedType () 
297                 {
298                         byte[] bad = { 0xBA, 0xD };
299                         transform.LoadInput (bad);
300                 }
301
302                 [Test]
303                 [ExpectedException (typeof (ArgumentException))]
304                 public void UnsupportedOutput () 
305                 {
306                         XmlDocument doc = new XmlDocument();
307                         object o = transform.GetOutput (doc.GetType ());
308                 }
309
310                 [Test]
311                 public void ExcC14NSpecExample1 ()
312                 {
313                         using (StreamWriter sw = new StreamWriter ("doc.dtd", false, Encoding.ASCII)) {
314                                 sw.Write ("<!-- presence, not content, required -->");
315                                 sw.Close ();
316                         }
317                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample1Input);
318                         Assert.AreEqual (ExcC14NSpecExample1Output, res, "Example 1 from c14n spec - PIs, Comments, and Outside of Document Element (without comments)");
319                 }
320
321                 [Test]
322                 public void ExcC14NSpecExample2 ()
323                 {
324                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample2Input);
325                         Assert.AreEqual (ExcC14NSpecExample2Output, res, "Example 2 from c14n spec - Whitespace in Document Content (without comments)");
326                 }
327
328                 [Test]
329                 public void ExcC14NSpecExample3 ()
330                 {
331                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample3Input);
332                         Assert.AreEqual (ExcC14NSpecExample3Output, res, "Example 3 from c14n spec - Start and End Tags (without comments)");
333                 }
334             
335                 [Test]
336 //              [Ignore ("This test should be fine, but it does not pass under MS.NET")]
337                 public void ExcC14NSpecExample4 ()
338                 {
339                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample4Input);
340                         Assert.AreEqual (ExcC14NSpecExample4Output, res, "Example 4 from c14n spec - Character Modifications and Character References (without comments)");
341                 }
342             
343                 [Test]
344                 public void ExcC14NSpecExample5 ()
345                 {
346                         using (StreamWriter sw = new StreamWriter ("world.txt", false, Encoding.ASCII)) {
347                                 sw.Write ("world");
348                                 sw.Close ();
349                         }
350                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample5Input);
351                         Assert.AreEqual (ExcC14NSpecExample5Output, res, "Example 5 from c14n spec - Entity References (without comments)");
352                 }
353     
354                 [Test]
355                 public void ExcC14NSpecExample6 ()
356                 {
357                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample6Input);
358                         Assert.AreEqual (ExcC14NSpecExample6Output, res, "Example 6 from c14n spec - UTF-8 Encoding (without comments)");
359                 }
360
361                 private string ExecuteXmlDSigExcC14NTransform (string InputXml)
362                 {
363                         XmlDocument doc = new XmlDocument ();
364                         doc.PreserveWhitespace = true;
365                         doc.LoadXml (InputXml);
366                 
367                         // Testing default attribute support with
368                         // vreader.ValidationType = ValidationType.None.
369                         //
370                         UTF8Encoding utf8 = new UTF8Encoding ();
371                         byte[] data = utf8.GetBytes (InputXml.ToString ());
372                         Stream stream = new MemoryStream (data);
373                         XmlTextReader reader = new XmlTextReader (stream);
374                         XmlValidatingReader vreader = new XmlValidatingReader (reader);
375                         vreader.ValidationType = ValidationType.None;
376                         vreader.EntityHandling = EntityHandling.ExpandCharEntities;
377                         doc.Load (vreader);
378
379                         transform.LoadInput (doc);
380                         return Stream2String ((Stream)transform.GetOutput ());
381                 }
382
383                 //
384                 // Example 1 from ExcC14N spec - PIs, Comments, and Outside of Document Element: 
385                 // http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
386                 // 
387                 // Aleksey: 
388                 // removed reference to an empty external DTD
389                 //
390                 static string ExcC14NSpecExample1Input =  
391                         "<?xml version=\"1.0\"?>\n" +
392                         "\n" +
393                         "<?xml-stylesheet   href=\"doc.xsl\"\n" +
394                         "   type=\"text/xsl\"   ?>\n" +
395                         "\n" +
396                         // "<!DOCTYPE doc SYSTEM \"doc.dtd\">\n" +
397                         "\n" +
398                         "<doc>Hello, world!<!-- Comment 1 --></doc>\n" +
399                         "\n" +
400                         "<?pi-without-data     ?>\n\n" +
401                         "<!-- Comment 2 -->\n\n" +
402                         "<!-- Comment 3 -->\n";
403                 static string ExcC14NSpecExample1Output =   
404                         "<?xml-stylesheet href=\"doc.xsl\"\n" +
405                         "   type=\"text/xsl\"   ?>\n" +
406                         "<doc>Hello, world!</doc>\n" +
407                         "<?pi-without-data?>";
408                 
409                 //
410                 // Example 2 from ExcC14N spec - Whitespace in Document Content: 
411                 // http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
412                 // 
413                 static string ExcC14NSpecExample2Input =  
414                         "<doc>\n" +
415                         "  <clean>   </clean>\n" +
416                         "   <dirty>   A   B   </dirty>\n" +
417                         "   <mixed>\n" +
418                         "      A\n" +
419                         "      <clean>   </clean>\n" +
420                         "      B\n" +
421                         "      <dirty>   A   B   </dirty>\n" +
422                         "      C\n" +
423                         "   </mixed>\n" +
424                         "</doc>\n";
425                 static string ExcC14NSpecExample2Output =   
426                         "<doc>\n" +
427                         "  <clean>   </clean>\n" +
428                         "   <dirty>   A   B   </dirty>\n" +
429                         "   <mixed>\n" +
430                         "      A\n" +
431                         "      <clean>   </clean>\n" +
432                         "      B\n" +
433                         "      <dirty>   A   B   </dirty>\n" +
434                         "      C\n" +
435                         "   </mixed>\n" +
436                         "</doc>";
437             
438                 //
439                 // Example 3 from ExcC14N spec - Start and End Tags: 
440                 // http://www.w3.org/TR/xml-c14n#Example-SETags
441                 //
442                 static string ExcC14NSpecExample3Input =  
443                         "<!DOCTYPE doc [<!ATTLIST e9 attr CDATA \"default\">]>\n" +
444                         "<doc>\n" +
445                         "   <e1   />\n" +
446                         "   <e2   ></e2>\n" +
447                         "   <e3    name = \"elem3\"   id=\"elem3\"    />\n" +
448                         "   <e4    name=\"elem4\"   id=\"elem4\"    ></e4>\n" +
449                         "   <e5 a:attr=\"out\" b:attr=\"sorted\" attr2=\"all\" attr=\"I\'m\"\n" +
450                         "       xmlns:b=\"http://www.ietf.org\" \n" +
451                         "       xmlns:a=\"http://www.w3.org\"\n" +
452                         "       xmlns=\"http://www.uvic.ca\"/>\n" +
453                         "   <e6 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n" +
454                         "       <e7 xmlns=\"http://www.ietf.org\">\n" +
455                         "           <e8 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n" +
456                         "               <e9 xmlns=\"\" xmlns:a=\"http://www.ietf.org\"/>\n" +
457                         "           </e8>\n" +
458                         "       </e7>\n" +
459                         "   </e6>\n" +
460                         "</doc>\n";
461                 static string ExcC14NSpecExample3Output =   
462                         "<doc>\n" +
463                         "   <e1></e1>\n" +
464                         "   <e2></e2>\n" +
465                         "   <e3 id=\"elem3\" name=\"elem3\"></e3>\n" +
466                         "   <e4 id=\"elem4\" name=\"elem4\"></e4>\n" +
467                         "   <e5 xmlns=\"http://www.uvic.ca\" xmlns:a=\"http://www.w3.org\" xmlns:b=\"http://www.ietf.org\" attr=\"I\'m\" attr2=\"all\" b:attr=\"sorted\" a:attr=\"out\"></e5>\n" +
468                         "   <e6>\n" +
469                         "       <e7 xmlns=\"http://www.ietf.org\">\n" +
470                         "           <e8 xmlns=\"\">\n" +
471                         "               <e9 attr=\"default\"></e9>\n" +
472 //                      "               <e9 xmlns:a=\"http://www.ietf.org\"></e9>\n" +
473                         "           </e8>\n" +
474                         "       </e7>\n" +
475                         "   </e6>\n" +
476                         "</doc>";
477             
478             
479                 //
480                 // Example 4 from ExcC14N spec - Character Modifications and Character References: 
481                 // http://www.w3.org/TR/xml-c14n#Example-Chars
482                 //
483                 // Aleksey: 
484                 // This test does not include "normId" element
485                 // because it has an invalid ID attribute "id" which
486                 // should be normalized by XML parser. Currently Mono
487                 // does not support this (see comment after this example
488                 // in the spec).
489                 static string ExcC14NSpecExample4Input =  
490                         "<!DOCTYPE doc [<!ATTLIST normId id ID #IMPLIED>]>\n" +
491                         "<doc>\n" +
492                         "   <text>First line&#x0d;&#10;Second line</text>\n" +
493                         "   <value>&#x32;</value>\n" +
494                         "   <compute><![CDATA[value>\"0\" && value<\"10\" ?\"valid\":\"error\"]]></compute>\n" +
495                         "   <compute expr=\'value>\"0\" &amp;&amp; value&lt;\"10\" ?\"valid\":\"error\"\'>valid</compute>\n" +
496                         "   <norm attr=\' &apos;   &#x20;&#13;&#xa;&#9;   &apos; \'/>\n" +
497                         // "   <normId id=\' &apos;   &#x20;&#13;&#xa;&#9;   &apos; \'/>\n" +
498                         "</doc>\n";
499                 static string ExcC14NSpecExample4Output =   
500                         "<doc>\n" +
501                         "   <text>First line&#xD;\n" +
502                         "Second line</text>\n" +
503                         "   <value>2</value>\n" +
504                         "   <compute>value&gt;\"0\" &amp;&amp; value&lt;\"10\" ?\"valid\":\"error\"</compute>\n" +
505                         "   <compute expr=\"value>&quot;0&quot; &amp;&amp; value&lt;&quot;10&quot; ?&quot;valid&quot;:&quot;error&quot;\">valid</compute>\n" +
506                         "   <norm attr=\" \'    &#xD;&#xA;&#x9;   \' \"></norm>\n" +
507                         // "   <normId id=\"\' &#xD;&#xA;&#x9; \'\"></normId>\n" +
508                         "</doc>";
509             
510                 //
511                 // Example 5 from ExcC14N spec - Entity References: 
512                 // http://www.w3.org/TR/xml-c14n#Example-Entities
513                 //
514                 static string ExcC14NSpecExample5Input =  
515                         "<!DOCTYPE doc [\n" +
516                         "<!ATTLIST doc attrExtEnt ENTITY #IMPLIED>\n" +
517                         "<!ENTITY ent1 \"Hello\">\n" +
518                         "<!ENTITY ent2 SYSTEM \"world.txt\">\n" +
519                         "<!ENTITY entExt SYSTEM \"earth.gif\" NDATA gif>\n" +
520                         "<!NOTATION gif SYSTEM \"viewgif.exe\">\n" +
521                         "]>\n" +
522                         "<doc attrExtEnt=\"entExt\">\n" +
523                         "   &ent1;, &ent2;!\n" +
524                         "</doc>\n" +
525                         "\n" +
526                         "<!-- Let world.txt contain \"world\" (excluding the quotes) -->\n";
527                 static string ExcC14NSpecExample5Output =  
528                         "<doc attrExtEnt=\"entExt\">\n" +
529                         "   Hello, world!\n" +
530                         "</doc>";           
531     
532                 //
533                 // Example 6 from ExcC14N spec - UTF-8 Encoding: 
534                 // http://www.w3.org/TR/xml-c14n#Example-UTF8
535                 // 
536                 static string ExcC14NSpecExample6Input =  
537                         "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
538                         "<doc>&#169;</doc>\n";
539                 static string ExcC14NSpecExample6Output =  
540                         "<doc>\xC2\xA9</doc>";
541             
542
543                 //
544                 // Example 7 from ExcC14N spec - Document Subsets: 
545                 // http://www.w3.org/TR/xml-c14n#Example-DocSubsets
546                 // 
547                 // Aleksey:
548                 // Well, XPath support in Mono is far from complete....
549                 // I was not able to simplify the xpath expression from this test
550                 // so it runs on Mono and still makes sense for testing this feature.
551                 // Thus this test is not included in the suite now.
552                 static string ExcC14NSpecExample7Input =  
553                         "<!DOCTYPE doc [\n" +
554                         "<!ATTLIST e2 xml:space (default|preserve) \'preserve\'>\n" +
555                         "<!ATTLIST e3 id ID #IMPLIED>\n" +
556                         "]>\n" +
557                         "<doc xmlns=\"http://www.ietf.org\" xmlns:w3c=\"http://www.w3.org\">\n" +
558                         "   <e1>\n" +
559                         "      <e2 xmlns=\"\">\n" +
560                         "         <e3 id=\"E3\"/>\n" +
561                         "      </e2>\n" +
562                         "   </e1>\n" +
563                         "</doc>\n";
564
565                 static string ExcC14NSpecExample7Xpath =  
566                         "(//.|//@*|//namespace::*)\n" +
567                         "[\n" +
568                         "self::ietf:e1\n" +
569                         "    or\n" +
570                         "(parent::ietf:e1 and not(self::text() or self::e2))\n" +
571                         "    or\n" +
572                         "count(id(\"E3\")|ancestor-or-self::node()) = count(ancestor-or-self::node())\n" +
573                         "]";
574                 static string ExcC14NSpecExample7Output =  
575                         "<e1 xmlns=\"http://www.ietf.org\" xmlns:w3c=\"http://www.w3.org\"><e3 xmlns=\"\" id=\"E3\" xml:space=\"preserve\"></e3></e1>";
576
577                 [Test]
578                 public void SimpleNamespacePrefixes ()
579                 {
580                         string input = "<a:Action xmlns:a='urn:foo'>http://tempuri.org/IFoo/Echo</a:Action>";
581                         string expected = @"<a:Action xmlns:a=""urn:foo"">http://tempuri.org/IFoo/Echo</a:Action>";
582
583                         XmlDocument doc = new XmlDocument ();
584                         doc.LoadXml (input);
585                         XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform ();
586                         t.LoadInput (doc);
587                         Stream s = t.GetOutput () as Stream;
588                         Assert.AreEqual (new StreamReader (s, Encoding.UTF8).ReadToEnd (), expected);
589                 }
590
591                 [Test]
592                 [ExpectedException (typeof (NullReferenceException))]
593                 public void GetDigestedOutput_Null ()
594                 {
595                         new XmlDsigExcC14NTransform ().GetDigestedOutput (null);
596                 }
597         }    
598 }
599